| 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/NodeLayoutStyle.h" | 10 #include "core/dom/NodeComputedStyle.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/layout/style/LayoutStyle.h" | 14 #include "core/layout/style/ComputedStyle.h" |
| 15 #include "core/page/Page.h" | 15 #include "core/page/Page.h" |
| 16 #include "platform/graphics/Color.h" | 16 #include "platform/graphics/Color.h" |
| 17 #include "platform/testing/URLTestHelpers.h" | 17 #include "platform/testing/URLTestHelpers.h" |
| 18 #include "web/tests/FrameTestHelpers.h" | 18 #include "web/tests/FrameTestHelpers.h" |
| 19 #include <gtest/gtest.h> | 19 #include <gtest/gtest.h> |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 using blink::FrameTestHelpers::WebViewHelper; | 23 using blink::FrameTestHelpers::WebViewHelper; |
| 24 using blink::URLTestHelpers::toKURL; | 24 using blink::URLTestHelpers::toKURL; |
| 25 using namespace blink; | 25 using namespace blink; |
| 26 | 26 |
| 27 TEST(WebDocumentTest, InsertStyleSheet) | 27 TEST(WebDocumentTest, InsertStyleSheet) |
| 28 { | 28 { |
| 29 WebViewHelper webViewHelper; | 29 WebViewHelper webViewHelper; |
| 30 webViewHelper.initializeAndLoad("about:blank"); | 30 webViewHelper.initializeAndLoad("about:blank"); |
| 31 | 31 |
| 32 WebDocument webDoc = webViewHelper.webView()->mainFrame()->document(); | 32 WebDocument webDoc = webViewHelper.webView()->mainFrame()->document(); |
| 33 Document* coreDoc = toLocalFrame(webViewHelper.webViewImpl()->page()->mainFr
ame())->document(); | 33 Document* coreDoc = toLocalFrame(webViewHelper.webViewImpl()->page()->mainFr
ame())->document(); |
| 34 | 34 |
| 35 webDoc.insertStyleSheet("body { color: green }"); | 35 webDoc.insertStyleSheet("body { color: green }"); |
| 36 | 36 |
| 37 // Check insertStyleSheet did not cause a synchronous style recalc. | 37 // Check insertStyleSheet did not cause a synchronous style recalc. |
| 38 unsigned accessCount = coreDoc->styleEngine().resolverAccessCount(); | 38 unsigned accessCount = coreDoc->styleEngine().resolverAccessCount(); |
| 39 ASSERT_EQ(0U, accessCount); | 39 ASSERT_EQ(0U, accessCount); |
| 40 | 40 |
| 41 HTMLElement* bodyElement = coreDoc->body(); | 41 HTMLElement* bodyElement = coreDoc->body(); |
| 42 ASSERT(bodyElement); | 42 ASSERT(bodyElement); |
| 43 | 43 |
| 44 const LayoutStyle& styleBeforeInsertion = bodyElement->layoutStyleRef(); | 44 const ComputedStyle& styleBeforeInsertion = bodyElement->computedStyleRef(); |
| 45 | 45 |
| 46 // Inserted stylesheet not yet applied. | 46 // Inserted stylesheet not yet applied. |
| 47 ASSERT_EQ(Color(0, 0, 0), styleBeforeInsertion.visitedDependentColor(CSSProp
ertyColor)); | 47 ASSERT_EQ(Color(0, 0, 0), styleBeforeInsertion.visitedDependentColor(CSSProp
ertyColor)); |
| 48 | 48 |
| 49 // Apply inserted stylesheet. | 49 // Apply inserted stylesheet. |
| 50 coreDoc->updateRenderTreeIfNeeded(); | 50 coreDoc->updateRenderTreeIfNeeded(); |
| 51 | 51 |
| 52 const LayoutStyle& styleAfterInsertion = bodyElement->layoutStyleRef(); | 52 const ComputedStyle& styleAfterInsertion = bodyElement->computedStyleRef(); |
| 53 | 53 |
| 54 // Inserted stylesheet applied. | 54 // Inserted stylesheet applied. |
| 55 ASSERT_EQ(Color(0, 128, 0), styleAfterInsertion.visitedDependentColor(CSSPro
pertyColor)); | 55 ASSERT_EQ(Color(0, 128, 0), styleAfterInsertion.visitedDependentColor(CSSPro
pertyColor)); |
| 56 } | 56 } |
| 57 | 57 |
| 58 TEST(WebDocumentTest, BeginExitTransition) | 58 TEST(WebDocumentTest, BeginExitTransition) |
| 59 { | 59 { |
| 60 std::string baseURL = "http://www.test.com:0/"; | 60 std::string baseURL = "http://www.test.com:0/"; |
| 61 const char* htmlURL = "transition_exit.html"; | 61 const char* htmlURL = "transition_exit.html"; |
| 62 const char* cssURL = "transition_exit.css"; | 62 const char* cssURL = "transition_exit.css"; |
| 63 URLTestHelpers::registerMockedURLLoad(toKURL(baseURL + htmlURL), WebString::
fromUTF8(htmlURL)); | 63 URLTestHelpers::registerMockedURLLoad(toKURL(baseURL + htmlURL), WebString::
fromUTF8(htmlURL)); |
| 64 URLTestHelpers::registerMockedURLLoad(toKURL(baseURL + cssURL), WebString::f
romUTF8(cssURL)); | 64 URLTestHelpers::registerMockedURLLoad(toKURL(baseURL + cssURL), WebString::f
romUTF8(cssURL)); |
| 65 | 65 |
| 66 WebViewHelper webViewHelper; | 66 WebViewHelper webViewHelper; |
| 67 webViewHelper.initializeAndLoad(baseURL + htmlURL); | 67 webViewHelper.initializeAndLoad(baseURL + htmlURL); |
| 68 | 68 |
| 69 WebFrame* frame = webViewHelper.webView()->mainFrame(); | 69 WebFrame* frame = webViewHelper.webView()->mainFrame(); |
| 70 Document* coreDoc = toLocalFrame(webViewHelper.webViewImpl()->page()->mainFr
ame())->document(); | 70 Document* coreDoc = toLocalFrame(webViewHelper.webViewImpl()->page()->mainFr
ame())->document(); |
| 71 Element* transitionElement = coreDoc->getElementById("foo"); | 71 Element* transitionElement = coreDoc->getElementById("foo"); |
| 72 ASSERT(transitionElement); | 72 ASSERT(transitionElement); |
| 73 | 73 |
| 74 const LayoutStyle* transitionStyle = transitionElement->layoutStyle(); | 74 const ComputedStyle* transitionStyle = transitionElement->computedStyle(); |
| 75 ASSERT(transitionStyle); | 75 ASSERT(transitionStyle); |
| 76 | 76 |
| 77 HTMLElement* bodyElement = coreDoc->body(); | 77 HTMLElement* bodyElement = coreDoc->body(); |
| 78 ASSERT(bodyElement); | 78 ASSERT(bodyElement); |
| 79 | 79 |
| 80 const LayoutStyle* bodyStyle = bodyElement->layoutStyle(); | 80 const ComputedStyle* bodyStyle = bodyElement->computedStyle(); |
| 81 ASSERT(bodyStyle); | 81 ASSERT(bodyStyle); |
| 82 // The transition_exit.css stylesheet should not have been applied at this p
oint. | 82 // The transition_exit.css stylesheet should not have been applied at this p
oint. |
| 83 ASSERT_EQ(Color(0, 0, 0), bodyStyle->visitedDependentColor(CSSPropertyColor)
); | 83 ASSERT_EQ(Color(0, 0, 0), bodyStyle->visitedDependentColor(CSSPropertyColor)
); |
| 84 | 84 |
| 85 frame->document().beginExitTransition("#foo", false); | 85 frame->document().beginExitTransition("#foo", false); |
| 86 | 86 |
| 87 // Make sure the stylesheet load request gets processed. | 87 // Make sure the stylesheet load request gets processed. |
| 88 FrameTestHelpers::pumpPendingRequestsDoNotUse(frame); | 88 FrameTestHelpers::pumpPendingRequestsDoNotUse(frame); |
| 89 coreDoc->updateRenderTreeIfNeeded(); | 89 coreDoc->updateRenderTreeIfNeeded(); |
| 90 | 90 |
| 91 // The element should now be hidden. | 91 // The element should now be hidden. |
| 92 transitionStyle = transitionElement->layoutStyle(); | 92 transitionStyle = transitionElement->computedStyle(); |
| 93 ASSERT_TRUE(transitionStyle); | 93 ASSERT_TRUE(transitionStyle); |
| 94 ASSERT_EQ(transitionStyle->opacity(), 0); | 94 ASSERT_EQ(transitionStyle->opacity(), 0); |
| 95 | 95 |
| 96 // The stylesheet should now have been applied. | 96 // The stylesheet should now have been applied. |
| 97 bodyStyle = bodyElement->layoutStyle(); | 97 bodyStyle = bodyElement->computedStyle(); |
| 98 ASSERT(bodyStyle); | 98 ASSERT(bodyStyle); |
| 99 ASSERT_EQ(Color(0, 128, 0), bodyStyle->visitedDependentColor(CSSPropertyColo
r)); | 99 ASSERT_EQ(Color(0, 128, 0), bodyStyle->visitedDependentColor(CSSPropertyColo
r)); |
| 100 } | 100 } |
| 101 | 101 |
| 102 | 102 |
| 103 TEST(WebDocumentTest, BeginExitTransitionToNativeApp) | 103 TEST(WebDocumentTest, BeginExitTransitionToNativeApp) |
| 104 { | 104 { |
| 105 std::string baseURL = "http://www.test.com:0/"; | 105 std::string baseURL = "http://www.test.com:0/"; |
| 106 const char* htmlURL = "transition_exit.html"; | 106 const char* htmlURL = "transition_exit.html"; |
| 107 const char* cssURL = "transition_exit.css"; | 107 const char* cssURL = "transition_exit.css"; |
| 108 URLTestHelpers::registerMockedURLLoad(toKURL(baseURL + htmlURL), WebString::
fromUTF8(htmlURL)); | 108 URLTestHelpers::registerMockedURLLoad(toKURL(baseURL + htmlURL), WebString::
fromUTF8(htmlURL)); |
| 109 URLTestHelpers::registerMockedURLLoad(toKURL(baseURL + cssURL), WebString::f
romUTF8(cssURL)); | 109 URLTestHelpers::registerMockedURLLoad(toKURL(baseURL + cssURL), WebString::f
romUTF8(cssURL)); |
| 110 | 110 |
| 111 WebViewHelper webViewHelper; | 111 WebViewHelper webViewHelper; |
| 112 webViewHelper.initializeAndLoad(baseURL + htmlURL); | 112 webViewHelper.initializeAndLoad(baseURL + htmlURL); |
| 113 | 113 |
| 114 WebFrame* frame = webViewHelper.webView()->mainFrame(); | 114 WebFrame* frame = webViewHelper.webView()->mainFrame(); |
| 115 Document* coreDoc = toLocalFrame(webViewHelper.webViewImpl()->page()->mainFr
ame())->document(); | 115 Document* coreDoc = toLocalFrame(webViewHelper.webViewImpl()->page()->mainFr
ame())->document(); |
| 116 Element* transitionElement = coreDoc->getElementById("foo"); | 116 Element* transitionElement = coreDoc->getElementById("foo"); |
| 117 ASSERT(transitionElement); | 117 ASSERT(transitionElement); |
| 118 | 118 |
| 119 const LayoutStyle* transitionStyle = transitionElement->layoutStyle(); | 119 const ComputedStyle* transitionStyle = transitionElement->computedStyle(); |
| 120 ASSERT(transitionStyle); | 120 ASSERT(transitionStyle); |
| 121 | 121 |
| 122 HTMLElement* bodyElement = coreDoc->body(); | 122 HTMLElement* bodyElement = coreDoc->body(); |
| 123 ASSERT(bodyElement); | 123 ASSERT(bodyElement); |
| 124 | 124 |
| 125 const LayoutStyle* bodyStyle = bodyElement->layoutStyle(); | 125 const ComputedStyle* bodyStyle = bodyElement->computedStyle(); |
| 126 ASSERT(bodyStyle); | 126 ASSERT(bodyStyle); |
| 127 // The transition_exit.css stylesheet should not have been applied at this p
oint. | 127 // The transition_exit.css stylesheet should not have been applied at this p
oint. |
| 128 ASSERT_EQ(Color(0, 0, 0), bodyStyle->visitedDependentColor(CSSPropertyColor)
); | 128 ASSERT_EQ(Color(0, 0, 0), bodyStyle->visitedDependentColor(CSSPropertyColor)
); |
| 129 | 129 |
| 130 frame->document().beginExitTransition("#foo", true); | 130 frame->document().beginExitTransition("#foo", true); |
| 131 | 131 |
| 132 // Make sure the stylesheet load request gets processed. | 132 // Make sure the stylesheet load request gets processed. |
| 133 FrameTestHelpers::pumpPendingRequestsDoNotUse(frame); | 133 FrameTestHelpers::pumpPendingRequestsDoNotUse(frame); |
| 134 coreDoc->updateRenderTreeIfNeeded(); | 134 coreDoc->updateRenderTreeIfNeeded(); |
| 135 | 135 |
| 136 // The element should not be hidden. | 136 // The element should not be hidden. |
| 137 transitionStyle = transitionElement->layoutStyle(); | 137 transitionStyle = transitionElement->computedStyle(); |
| 138 ASSERT_TRUE(transitionStyle); | 138 ASSERT_TRUE(transitionStyle); |
| 139 ASSERT_EQ(transitionStyle->opacity(), 1); | 139 ASSERT_EQ(transitionStyle->opacity(), 1); |
| 140 | 140 |
| 141 // The stylesheet should now have been applied. | 141 // The stylesheet should now have been applied. |
| 142 bodyStyle = bodyElement->layoutStyle(); | 142 bodyStyle = bodyElement->computedStyle(); |
| 143 ASSERT(bodyStyle); | 143 ASSERT(bodyStyle); |
| 144 ASSERT_EQ(Color(0, 128, 0), bodyStyle->visitedDependentColor(CSSPropertyColo
r)); | 144 ASSERT_EQ(Color(0, 128, 0), bodyStyle->visitedDependentColor(CSSPropertyColo
r)); |
| 145 } | 145 } |
| 146 | 146 |
| 147 | 147 |
| 148 TEST(WebDocumentTest, HideAndShowTransitionElements) | 148 TEST(WebDocumentTest, HideAndShowTransitionElements) |
| 149 { | 149 { |
| 150 std::string baseURL = "http://www.test.com:0/"; | 150 std::string baseURL = "http://www.test.com:0/"; |
| 151 const char* htmlURL = "transition_hide_and_show.html"; | 151 const char* htmlURL = "transition_hide_and_show.html"; |
| 152 URLTestHelpers::registerMockedURLLoad(toKURL(baseURL + htmlURL), WebString::
fromUTF8(htmlURL)); | 152 URLTestHelpers::registerMockedURLLoad(toKURL(baseURL + htmlURL), WebString::
fromUTF8(htmlURL)); |
| 153 | 153 |
| 154 WebViewHelper webViewHelper; | 154 WebViewHelper webViewHelper; |
| 155 webViewHelper.initializeAndLoad(baseURL + htmlURL); | 155 webViewHelper.initializeAndLoad(baseURL + htmlURL); |
| 156 | 156 |
| 157 WebFrame* frame = webViewHelper.webView()->mainFrame(); | 157 WebFrame* frame = webViewHelper.webView()->mainFrame(); |
| 158 Document* coreDoc = toLocalFrame(webViewHelper.webViewImpl()->page()->mainFr
ame())->document(); | 158 Document* coreDoc = toLocalFrame(webViewHelper.webViewImpl()->page()->mainFr
ame())->document(); |
| 159 Element* transitionElement = coreDoc->getElementById("foo"); | 159 Element* transitionElement = coreDoc->getElementById("foo"); |
| 160 ASSERT(transitionElement); | 160 ASSERT(transitionElement); |
| 161 | 161 |
| 162 const LayoutStyle* transitionStyle = transitionElement->layoutStyle(); | 162 const ComputedStyle* transitionStyle = transitionElement->computedStyle(); |
| 163 ASSERT(transitionStyle); | 163 ASSERT(transitionStyle); |
| 164 EXPECT_EQ(transitionStyle->opacity(), 1); | 164 EXPECT_EQ(transitionStyle->opacity(), 1); |
| 165 | 165 |
| 166 // Hide transition elements | 166 // Hide transition elements |
| 167 frame->document().hideTransitionElements("#foo"); | 167 frame->document().hideTransitionElements("#foo"); |
| 168 FrameTestHelpers::pumpPendingRequestsDoNotUse(frame); | 168 FrameTestHelpers::pumpPendingRequestsDoNotUse(frame); |
| 169 coreDoc->updateRenderTreeIfNeeded(); | 169 coreDoc->updateRenderTreeIfNeeded(); |
| 170 transitionStyle = transitionElement->layoutStyle(); | 170 transitionStyle = transitionElement->computedStyle(); |
| 171 ASSERT_TRUE(transitionStyle); | 171 ASSERT_TRUE(transitionStyle); |
| 172 EXPECT_EQ(transitionStyle->opacity(), 0); | 172 EXPECT_EQ(transitionStyle->opacity(), 0); |
| 173 | 173 |
| 174 // Show transition elements | 174 // Show transition elements |
| 175 frame->document().showTransitionElements("#foo"); | 175 frame->document().showTransitionElements("#foo"); |
| 176 FrameTestHelpers::pumpPendingRequestsDoNotUse(frame); | 176 FrameTestHelpers::pumpPendingRequestsDoNotUse(frame); |
| 177 coreDoc->updateRenderTreeIfNeeded(); | 177 coreDoc->updateRenderTreeIfNeeded(); |
| 178 transitionStyle = transitionElement->layoutStyle(); | 178 transitionStyle = transitionElement->computedStyle(); |
| 179 ASSERT_TRUE(transitionStyle); | 179 ASSERT_TRUE(transitionStyle); |
| 180 EXPECT_EQ(transitionStyle->opacity(), 1); | 180 EXPECT_EQ(transitionStyle->opacity(), 1); |
| 181 } | 181 } |
| 182 | 182 |
| 183 | 183 |
| 184 TEST(WebDocumentTest, SetIsTransitionDocument) | 184 TEST(WebDocumentTest, SetIsTransitionDocument) |
| 185 { | 185 { |
| 186 std::string baseURL = "http://www.test.com:0/"; | 186 std::string baseURL = "http://www.test.com:0/"; |
| 187 const char* htmlURL = "transition_exit.html"; | 187 const char* htmlURL = "transition_exit.html"; |
| 188 const char* cssURL = "transition_exit.css"; | 188 const char* cssURL = "transition_exit.css"; |
| 189 URLTestHelpers::registerMockedURLLoad(toKURL(baseURL + htmlURL), WebString::
fromUTF8(htmlURL)); | 189 URLTestHelpers::registerMockedURLLoad(toKURL(baseURL + htmlURL), WebString::
fromUTF8(htmlURL)); |
| 190 URLTestHelpers::registerMockedURLLoad(toKURL(baseURL + cssURL), WebString::f
romUTF8(cssURL)); | 190 URLTestHelpers::registerMockedURLLoad(toKURL(baseURL + cssURL), WebString::f
romUTF8(cssURL)); |
| 191 | 191 |
| 192 WebViewHelper webViewHelper; | 192 WebViewHelper webViewHelper; |
| 193 webViewHelper.initializeAndLoad(baseURL + htmlURL); | 193 webViewHelper.initializeAndLoad(baseURL + htmlURL); |
| 194 | 194 |
| 195 WebFrame* frame = webViewHelper.webView()->mainFrame(); | 195 WebFrame* frame = webViewHelper.webView()->mainFrame(); |
| 196 Document* coreDoc = toLocalFrame(webViewHelper.webViewImpl()->page()->mainFr
ame())->document(); | 196 Document* coreDoc = toLocalFrame(webViewHelper.webViewImpl()->page()->mainFr
ame())->document(); |
| 197 | 197 |
| 198 ASSERT_FALSE(coreDoc->isTransitionDocument()); | 198 ASSERT_FALSE(coreDoc->isTransitionDocument()); |
| 199 | 199 |
| 200 frame->document().setIsTransitionDocument(true); | 200 frame->document().setIsTransitionDocument(true); |
| 201 ASSERT_TRUE(coreDoc->isTransitionDocument()); | 201 ASSERT_TRUE(coreDoc->isTransitionDocument()); |
| 202 | 202 |
| 203 frame->document().setIsTransitionDocument(false); | 203 frame->document().setIsTransitionDocument(false); |
| 204 ASSERT_FALSE(coreDoc->isTransitionDocument()); | 204 ASSERT_FALSE(coreDoc->isTransitionDocument()); |
| 205 } | 205 } |
| 206 | 206 |
| 207 } | 207 } |
| OLD | NEW |