OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/dom/StyleElement.h" | 5 #include "core/dom/StyleElement.h" |
6 | 6 |
| 7 #include <memory> |
7 #include "core/css/StyleSheetContents.h" | 8 #include "core/css/StyleSheetContents.h" |
8 #include "core/dom/Comment.h" | 9 #include "core/dom/Comment.h" |
9 #include "core/html/HTMLStyleElement.h" | 10 #include "core/html/HTMLStyleElement.h" |
10 #include "core/testing/DummyPageHolder.h" | 11 #include "core/testing/DummyPageHolder.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
12 #include <memory> | |
13 | 13 |
14 namespace blink { | 14 namespace blink { |
15 | 15 |
16 TEST(StyleElementTest, CreateSheetUsesCache) { | 16 TEST(StyleElementTest, CreateSheetUsesCache) { |
17 std::unique_ptr<DummyPageHolder> dummyPageHolder = | 17 std::unique_ptr<DummyPageHolder> dummyPageHolder = |
18 DummyPageHolder::create(IntSize(800, 600)); | 18 DummyPageHolder::create(IntSize(800, 600)); |
19 Document& document = dummyPageHolder->document(); | 19 Document& document = dummyPageHolder->document(); |
20 | 20 |
21 document.documentElement()->setInnerHTML( | 21 document.documentElement()->setInnerHTML( |
22 "<style id=style>a { top: 0; }</style>"); | 22 "<style id=style>a { top: 0; }</style>"); |
23 | 23 |
24 HTMLStyleElement& styleElement = | 24 HTMLStyleElement& styleElement = |
25 toHTMLStyleElement(*document.getElementById("style")); | 25 toHTMLStyleElement(*document.getElementById("style")); |
26 StyleSheetContents* sheet = styleElement.sheet()->contents(); | 26 StyleSheetContents* sheet = styleElement.sheet()->contents(); |
27 | 27 |
28 Comment* comment = document.createComment("hello!"); | 28 Comment* comment = document.createComment("hello!"); |
29 styleElement.appendChild(comment); | 29 styleElement.appendChild(comment); |
30 EXPECT_EQ(styleElement.sheet()->contents(), sheet); | 30 EXPECT_EQ(styleElement.sheet()->contents(), sheet); |
31 | 31 |
32 styleElement.removeChild(comment); | 32 styleElement.removeChild(comment); |
33 EXPECT_EQ(styleElement.sheet()->contents(), sheet); | 33 EXPECT_EQ(styleElement.sheet()->contents(), sheet); |
34 } | 34 } |
35 | 35 |
36 } // namespace blink | 36 } // namespace blink |
OLD | NEW |