OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "public/web/WebDocument.h" | 5 #include "public/web/WebDocument.h" |
6 | 6 |
7 #include "core/CSSPropertyNames.h" | 7 #include "core/CSSPropertyNames.h" |
8 #include "core/HTMLNames.h" | 8 #include "core/HTMLNames.h" |
9 #include "core/dom/NodeComputedStyle.h" | 9 #include "core/dom/NodeComputedStyle.h" |
10 #include "core/dom/StyleEngine.h" | 10 #include "core/dom/StyleEngine.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
53 | 53 |
54 Document* WebDocumentTest::TopDocument() const { | 54 Document* WebDocumentTest::TopDocument() const { |
55 return ToLocalFrame(web_view_helper_.WebView()->GetPage()->MainFrame()) | 55 return ToLocalFrame(web_view_helper_.WebView()->GetPage()->MainFrame()) |
56 ->GetDocument(); | 56 ->GetDocument(); |
57 } | 57 } |
58 | 58 |
59 WebDocument WebDocumentTest::TopWebDocument() const { | 59 WebDocument WebDocumentTest::TopWebDocument() const { |
60 return web_view_helper_.WebView()->MainFrame()->GetDocument(); | 60 return web_view_helper_.WebView()->MainFrame()->GetDocument(); |
61 } | 61 } |
62 | 62 |
63 TEST_F(WebDocumentTest, InsertStyleSheet) { | 63 TEST_F(WebDocumentTest, InsertAndRemoveStyleSheet) { |
64 LoadURL("about:blank"); | 64 LoadURL("about:blank"); |
65 | 65 |
66 WebDocument web_doc = TopWebDocument(); | 66 WebDocument web_doc = TopWebDocument(); |
67 Document* core_doc = TopDocument(); | 67 Document* core_doc = TopDocument(); |
68 | 68 |
69 unsigned start_count = core_doc->GetStyleEngine().StyleForElementCount(); | 69 unsigned start_count = core_doc->GetStyleEngine().StyleForElementCount(); |
70 | 70 |
71 web_doc.InsertStyleSheet("body { color: green }"); | 71 unsigned stylesheet_id = web_doc.InsertStyleSheet("body { color: green }"); |
rune
2017/05/18 13:13:21
WebStyleSheetId?
limasdf
2017/05/18 14:32:26
Done.
| |
72 | 72 |
73 // Check insertStyleSheet did not cause a synchronous style recalc. | 73 // Check insertStyleSheet did not cause a synchronous style recalc. |
74 unsigned element_count = | 74 unsigned element_count = |
75 core_doc->GetStyleEngine().StyleForElementCount() - start_count; | 75 core_doc->GetStyleEngine().StyleForElementCount() - start_count; |
76 ASSERT_EQ(0U, element_count); | 76 ASSERT_EQ(0U, element_count); |
77 | 77 |
78 HTMLElement* body_element = core_doc->body(); | 78 HTMLElement* body_element = core_doc->body(); |
79 DCHECK(body_element); | 79 DCHECK(body_element); |
80 | 80 |
81 const ComputedStyle& style_before_insertion = | 81 const ComputedStyle& style_before_insertion = |
82 body_element->ComputedStyleRef(); | 82 body_element->ComputedStyleRef(); |
83 | 83 |
84 // Inserted stylesheet not yet applied. | 84 // Inserted stylesheet not yet applied. |
85 ASSERT_EQ(Color(0, 0, 0), | 85 ASSERT_EQ(Color(0, 0, 0), |
86 style_before_insertion.VisitedDependentColor(CSSPropertyColor)); | 86 style_before_insertion.VisitedDependentColor(CSSPropertyColor)); |
87 | 87 |
88 // Apply inserted stylesheet. | 88 // Apply inserted stylesheet. |
89 core_doc->UpdateStyleAndLayoutTree(); | 89 core_doc->UpdateStyleAndLayoutTree(); |
90 | 90 |
91 const ComputedStyle& style_after_insertion = body_element->ComputedStyleRef(); | 91 const ComputedStyle& style_after_insertion = body_element->ComputedStyleRef(); |
92 | 92 |
93 // Inserted stylesheet applied. | 93 // Inserted stylesheet applied. |
94 ASSERT_EQ(Color(0, 128, 0), | 94 ASSERT_EQ(Color(0, 128, 0), |
95 style_after_insertion.VisitedDependentColor(CSSPropertyColor)); | 95 style_after_insertion.VisitedDependentColor(CSSPropertyColor)); |
96 | |
97 start_count = core_doc->GetStyleEngine().StyleForElementCount(); | |
98 | |
99 // Check RemoveInsertedStyleSheet did not cause a synchronous style recalc. | |
100 web_doc.RemoveInsertedStyleSheet(stylesheet_id); | |
101 element_count = | |
102 core_doc->GetStyleEngine().StyleForElementCount() - start_count; | |
103 ASSERT_EQ(0U, element_count); | |
104 | |
105 const ComputedStyle& style_before_removing = body_element->ComputedStyleRef(); | |
106 | |
107 // Removed stylesheet not yet applied. | |
108 ASSERT_EQ(Color(0, 128, 0), | |
109 style_before_removing.VisitedDependentColor(CSSPropertyColor)); | |
110 | |
111 // Apply removed stylesheet. | |
112 core_doc->UpdateStyleAndLayoutTree(); | |
113 | |
114 const ComputedStyle& style_after_removing = body_element->ComputedStyleRef(); | |
115 ASSERT_EQ(Color(0, 0, 0), | |
116 style_after_removing.VisitedDependentColor(CSSPropertyColor)); | |
96 } | 117 } |
97 | 118 |
98 TEST_F(WebDocumentTest, ManifestURL) { | 119 TEST_F(WebDocumentTest, ManifestURL) { |
99 LoadURL(std::string(kDefaultOrigin) + kManifestDummyFilePath); | 120 LoadURL(std::string(kDefaultOrigin) + kManifestDummyFilePath); |
100 | 121 |
101 WebDocument web_doc = TopWebDocument(); | 122 WebDocument web_doc = TopWebDocument(); |
102 Document* document = TopDocument(); | 123 Document* document = TopDocument(); |
103 HTMLLinkElement* link_manifest = document->LinkManifest(); | 124 HTMLLinkElement* link_manifest = document->LinkManifest(); |
104 | 125 |
105 // No href attribute was set. | 126 // No href attribute was set. |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
354 | 375 |
355 ASSERT_EQ(ToOriginA(g_nested_origin_a_in_origin_b), | 376 ASSERT_EQ(ToOriginA(g_nested_origin_a_in_origin_b), |
356 TopDocument()->FirstPartyForCookies()); | 377 TopDocument()->FirstPartyForCookies()); |
357 ASSERT_EQ(ToOriginA(g_nested_origin_a_in_origin_b), | 378 ASSERT_EQ(ToOriginA(g_nested_origin_a_in_origin_b), |
358 NestedDocument()->FirstPartyForCookies()); | 379 NestedDocument()->FirstPartyForCookies()); |
359 ASSERT_EQ(ToOriginA(g_nested_origin_a_in_origin_b), | 380 ASSERT_EQ(ToOriginA(g_nested_origin_a_in_origin_b), |
360 NestedNestedDocument()->FirstPartyForCookies()); | 381 NestedNestedDocument()->FirstPartyForCookies()); |
361 } | 382 } |
362 | 383 |
363 } // namespace blink | 384 } // namespace blink |
OLD | NEW |