Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1127)

Side by Side Diff: third_party/WebKit/Source/web/tests/WebDocumentTest.cpp

Issue 2835183002: Provide a method to remove inserted style sheet (Closed)
Patch Set: rebase Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 WebStyleSheetId stylesheet_id =
72 web_doc.InsertStyleSheet("body { color: green }");
72 73
73 // Check insertStyleSheet did not cause a synchronous style recalc. 74 // Check insertStyleSheet did not cause a synchronous style recalc.
74 unsigned element_count = 75 unsigned element_count =
75 core_doc->GetStyleEngine().StyleForElementCount() - start_count; 76 core_doc->GetStyleEngine().StyleForElementCount() - start_count;
76 ASSERT_EQ(0U, element_count); 77 ASSERT_EQ(0U, element_count);
77 78
78 HTMLElement* body_element = core_doc->body(); 79 HTMLElement* body_element = core_doc->body();
79 DCHECK(body_element); 80 DCHECK(body_element);
80 81
81 const ComputedStyle& style_before_insertion = 82 const ComputedStyle& style_before_insertion =
82 body_element->ComputedStyleRef(); 83 body_element->ComputedStyleRef();
83 84
84 // Inserted stylesheet not yet applied. 85 // Inserted stylesheet not yet applied.
85 ASSERT_EQ(Color(0, 0, 0), 86 ASSERT_EQ(Color(0, 0, 0),
86 style_before_insertion.VisitedDependentColor(CSSPropertyColor)); 87 style_before_insertion.VisitedDependentColor(CSSPropertyColor));
87 88
88 // Apply inserted stylesheet. 89 // Apply inserted stylesheet.
89 core_doc->UpdateStyleAndLayoutTree(); 90 core_doc->UpdateStyleAndLayoutTree();
90 91
91 const ComputedStyle& style_after_insertion = body_element->ComputedStyleRef(); 92 const ComputedStyle& style_after_insertion = body_element->ComputedStyleRef();
92 93
93 // Inserted stylesheet applied. 94 // Inserted stylesheet applied.
94 ASSERT_EQ(Color(0, 128, 0), 95 ASSERT_EQ(Color(0, 128, 0),
95 style_after_insertion.VisitedDependentColor(CSSPropertyColor)); 96 style_after_insertion.VisitedDependentColor(CSSPropertyColor));
97
98 start_count = core_doc->GetStyleEngine().StyleForElementCount();
99
100 // Check RemoveInsertedStyleSheet did not cause a synchronous style recalc.
101 web_doc.RemoveInsertedStyleSheet(stylesheet_id);
102 element_count =
103 core_doc->GetStyleEngine().StyleForElementCount() - start_count;
104 ASSERT_EQ(0U, element_count);
105
106 const ComputedStyle& style_before_removing = body_element->ComputedStyleRef();
107
108 // Removed stylesheet not yet applied.
109 ASSERT_EQ(Color(0, 128, 0),
110 style_before_removing.VisitedDependentColor(CSSPropertyColor));
111
112 // Apply removed stylesheet.
113 core_doc->UpdateStyleAndLayoutTree();
114
115 const ComputedStyle& style_after_removing = body_element->ComputedStyleRef();
116 ASSERT_EQ(Color(0, 0, 0),
117 style_after_removing.VisitedDependentColor(CSSPropertyColor));
96 } 118 }
97 119
98 TEST_F(WebDocumentTest, ManifestURL) { 120 TEST_F(WebDocumentTest, ManifestURL) {
99 LoadURL(std::string(kDefaultOrigin) + kManifestDummyFilePath); 121 LoadURL(std::string(kDefaultOrigin) + kManifestDummyFilePath);
100 122
101 WebDocument web_doc = TopWebDocument(); 123 WebDocument web_doc = TopWebDocument();
102 Document* document = TopDocument(); 124 Document* document = TopDocument();
103 HTMLLinkElement* link_manifest = document->LinkManifest(); 125 HTMLLinkElement* link_manifest = document->LinkManifest();
104 126
105 // No href attribute was set. 127 // No href attribute was set.
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 376
355 ASSERT_EQ(ToOriginA(g_nested_origin_a_in_origin_b), 377 ASSERT_EQ(ToOriginA(g_nested_origin_a_in_origin_b),
356 TopDocument()->FirstPartyForCookies()); 378 TopDocument()->FirstPartyForCookies());
357 ASSERT_EQ(ToOriginA(g_nested_origin_a_in_origin_b), 379 ASSERT_EQ(ToOriginA(g_nested_origin_a_in_origin_b),
358 NestedDocument()->FirstPartyForCookies()); 380 NestedDocument()->FirstPartyForCookies());
359 ASSERT_EQ(ToOriginA(g_nested_origin_a_in_origin_b), 381 ASSERT_EQ(ToOriginA(g_nested_origin_a_in_origin_b),
360 NestedNestedDocument()->FirstPartyForCookies()); 382 NestedNestedDocument()->FirstPartyForCookies());
361 } 383 }
362 384
363 } // namespace blink 385 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/web/WebDocument.cpp ('k') | third_party/WebKit/public/web/WebDocument.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698