| 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 "config.h" | 5 #include "config.h" |
| 6 | 6 |
| 7 #include "public/web/WebDocument.h" | 7 #include "public/web/WebDocument.h" |
| 8 | 8 |
| 9 #include "core/CSSPropertyNames.h" | 9 #include "core/CSSPropertyNames.h" |
| 10 #include "core/dom/NodeRenderStyle.h" | 10 #include "core/dom/NodeRenderStyle.h" |
| 11 #include "core/dom/StyleEngine.h" | 11 #include "core/dom/StyleEngine.h" |
| 12 #include "core/frame/LocalFrame.h" | 12 #include "core/frame/LocalFrame.h" |
| 13 #include "core/html/HTMLElement.h" | 13 #include "core/html/HTMLElement.h" |
| 14 #include "core/page/Page.h" | 14 #include "core/page/Page.h" |
| 15 #include "core/rendering/style/RenderStyle.h" | 15 #include "core/rendering/style/RenderStyle.h" |
| 16 #include "platform/graphics/Color.h" | 16 #include "platform/graphics/Color.h" |
| 17 #include "web/tests/FrameTestHelpers.h" | 17 #include "web/tests/FrameTestHelpers.h" |
| 18 | 18 |
| 19 #include <gtest/gtest.h> | 19 #include <gtest/gtest.h> |
| 20 | 20 |
| 21 using WebCore::Color; | 21 using blink::Color; |
| 22 using WebCore::Document; | 22 using blink::Document; |
| 23 using WebCore::HTMLElement; | 23 using blink::HTMLElement; |
| 24 using WebCore::RenderStyle; | 24 using blink::RenderStyle; |
| 25 using blink::FrameTestHelpers::WebViewHelper; | 25 using blink::FrameTestHelpers::WebViewHelper; |
| 26 using blink::WebDocument; | 26 using blink::WebDocument; |
| 27 | 27 |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 TEST(WebDocumentTest, InsertStyleSheet) | 30 TEST(WebDocumentTest, InsertStyleSheet) |
| 31 { | 31 { |
| 32 WebViewHelper webViewHelper; | 32 WebViewHelper webViewHelper; |
| 33 webViewHelper.initializeAndLoad("about:blank"); | 33 webViewHelper.initializeAndLoad("about:blank"); |
| 34 | 34 |
| 35 WebDocument webDoc = webViewHelper.webView()->mainFrame()->document(); | 35 WebDocument webDoc = webViewHelper.webView()->mainFrame()->document(); |
| 36 Document* coreDoc = toLocalFrame(webViewHelper.webViewImpl()->page()->mainFr
ame())->document(); | 36 Document* coreDoc = toLocalFrame(webViewHelper.webViewImpl()->page()->mainFr
ame())->document(); |
| 37 | 37 |
| 38 webDoc.insertStyleSheet("body { color: green }"); | 38 webDoc.insertStyleSheet("body { color: green }"); |
| 39 | 39 |
| 40 // Check insertStyleSheet did not cause a synchronous style recalc. | 40 // Check insertStyleSheet did not cause a synchronous style recalc. |
| 41 unsigned accessCount = coreDoc->styleEngine()->resolverAccessCount(); | 41 unsigned accessCount = coreDoc->styleEngine()->resolverAccessCount(); |
| 42 ASSERT_EQ(0U, accessCount); | 42 ASSERT_EQ(0U, accessCount); |
| 43 | 43 |
| 44 HTMLElement* bodyElement = coreDoc->body(); | 44 HTMLElement* bodyElement = coreDoc->body(); |
| 45 ASSERT(bodyElement); | 45 ASSERT(bodyElement); |
| 46 | 46 |
| 47 RenderStyle* style = bodyElement->renderStyle(); | 47 RenderStyle* style = bodyElement->renderStyle(); |
| 48 ASSERT(style); | 48 ASSERT(style); |
| 49 | 49 |
| 50 // Inserted stylesheet not yet applied. | 50 // Inserted stylesheet not yet applied. |
| 51 ASSERT_EQ(Color(0, 0, 0), style->visitedDependentColor(WebCore::CSSPropertyC
olor)); | 51 ASSERT_EQ(Color(0, 0, 0), style->visitedDependentColor(blink::CSSPropertyCol
or)); |
| 52 | 52 |
| 53 // Apply inserted stylesheet. | 53 // Apply inserted stylesheet. |
| 54 coreDoc->updateRenderTreeIfNeeded(); | 54 coreDoc->updateRenderTreeIfNeeded(); |
| 55 | 55 |
| 56 style = bodyElement->renderStyle(); | 56 style = bodyElement->renderStyle(); |
| 57 ASSERT(style); | 57 ASSERT(style); |
| 58 | 58 |
| 59 // Inserted stylesheet applied. | 59 // Inserted stylesheet applied. |
| 60 ASSERT_EQ(Color(0, 128, 0), style->visitedDependentColor(WebCore::CSSPropert
yColor)); | 60 ASSERT_EQ(Color(0, 128, 0), style->visitedDependentColor(blink::CSSPropertyC
olor)); |
| 61 } | 61 } |
| 62 | 62 |
| 63 } | 63 } |
| OLD | NEW |