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 "config.h" | 5 #include "config.h" |
6 | 6 |
7 #include "core/dom/Document.h" | 7 #include "core/dom/Document.h" |
| 8 #include "core/frame/FrameView.h" |
8 #include "web/WebLocalFrameImpl.h" | 9 #include "web/WebLocalFrameImpl.h" |
9 #include "web/tests/FrameTestHelpers.h" | 10 #include "web/tests/FrameTestHelpers.h" |
| 11 #include "web/tests/sim/SimCompositor.h" |
10 #include "web/tests/sim/SimLayerTreeView.h" | 12 #include "web/tests/sim/SimLayerTreeView.h" |
11 #include "web/tests/sim/SimNetwork.h" | 13 #include "web/tests/sim/SimNetwork.h" |
12 #include "web/tests/sim/SimRequest.h" | 14 #include "web/tests/sim/SimRequest.h" |
13 #include "web/tests/sim/SimWebViewClient.h" | 15 #include "web/tests/sim/SimWebViewClient.h" |
14 #include <gtest/gtest.h> | 16 #include <gtest/gtest.h> |
15 | 17 |
16 namespace blink { | 18 namespace blink { |
17 | 19 |
18 class DocumentLoadingRenderingTest : public ::testing::Test { | 20 class DocumentLoadingRenderingTest : public ::testing::Test { |
19 protected: | 21 protected: |
20 DocumentLoadingRenderingTest() | 22 DocumentLoadingRenderingTest() |
21 : m_webViewClient(m_layerTreeView) | 23 : m_webViewClient(m_layerTreeView) |
| 24 , m_compositor(m_layerTreeView) |
22 { | 25 { |
23 m_webViewHelper.initialize(true, nullptr, &m_webViewClient); | 26 m_webViewHelper.initialize(true, nullptr, &m_webViewClient); |
| 27 m_compositor.setWebViewImpl(webView()); |
24 Document::setThreadedParsingEnabledForUnitTestsOnly(false); | 28 Document::setThreadedParsingEnabledForUnitTestsOnly(false); |
25 } | 29 } |
26 | 30 |
27 virtual ~DocumentLoadingRenderingTest() | 31 virtual ~DocumentLoadingRenderingTest() |
28 { | 32 { |
29 Document::setThreadedParsingEnabledForUnitTestsOnly(true); | 33 Document::setThreadedParsingEnabledForUnitTestsOnly(true); |
30 } | 34 } |
31 | 35 |
32 void loadURL(const String& url) | 36 void loadURL(const String& url) |
33 { | 37 { |
34 WebURLRequest request; | 38 WebURLRequest request; |
35 request.initialize(); | 39 request.initialize(); |
36 request.setURL(KURL(ParsedURLString, url)); | 40 request.setURL(KURL(ParsedURLString, url)); |
37 m_webViewHelper.webViewImpl()->mainFrameImpl()->loadRequest(request); | 41 webView().mainFrameImpl()->loadRequest(request); |
| 42 } |
| 43 |
| 44 WebViewImpl& webView() |
| 45 { |
| 46 return *m_webViewHelper.webViewImpl(); |
38 } | 47 } |
39 | 48 |
40 SimNetwork m_network; | 49 SimNetwork m_network; |
41 SimLayerTreeView m_layerTreeView; | 50 SimLayerTreeView m_layerTreeView; |
42 SimWebViewClient m_webViewClient; | 51 SimWebViewClient m_webViewClient; |
| 52 SimCompositor m_compositor; |
43 FrameTestHelpers::WebViewHelper m_webViewHelper; | 53 FrameTestHelpers::WebViewHelper m_webViewHelper; |
44 }; | 54 }; |
45 | 55 |
46 TEST_F(DocumentLoadingRenderingTest, ShouldResumeCommitsAfterBodyParsedWithoutSh
eets) | 56 TEST_F(DocumentLoadingRenderingTest, ShouldResumeCommitsAfterBodyParsedWithoutSh
eets) |
47 { | 57 { |
48 SimRequest mainResource("https://example.com/test.html", "text/html"); | 58 SimRequest mainResource("https://example.com/test.html", "text/html"); |
49 | 59 |
50 loadURL("https://example.com/test.html"); | 60 loadURL("https://example.com/test.html"); |
51 | 61 |
52 mainResource.start(); | 62 mainResource.start(); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 | 163 |
154 // Sheet finished, but no body since it's svg so don't resume. | 164 // Sheet finished, but no body since it's svg so don't resume. |
155 cssResource.finish(); | 165 cssResource.finish(); |
156 EXPECT_TRUE(m_layerTreeView.deferCommits()); | 166 EXPECT_TRUE(m_layerTreeView.deferCommits()); |
157 | 167 |
158 // Finish the load and resume. | 168 // Finish the load and resume. |
159 mainResource.finish(); | 169 mainResource.finish(); |
160 EXPECT_FALSE(m_layerTreeView.deferCommits()); | 170 EXPECT_FALSE(m_layerTreeView.deferCommits()); |
161 } | 171 } |
162 | 172 |
| 173 TEST_F(DocumentLoadingRenderingTest, ShouldNotPaintIframeContentWithPendingSheet
s) |
| 174 { |
| 175 SimRequest mainResource("https://example.com/test.html", "text/html"); |
| 176 SimRequest frameResource("https://example.com/frame.html", "text/html"); |
| 177 SimRequest cssResource("https://example.com/test.css", "text/css"); |
| 178 |
| 179 loadURL("https://example.com/test.html"); |
| 180 |
| 181 webView().resize(WebSize(800, 600)); |
| 182 |
| 183 mainResource.start(); |
| 184 mainResource.write( |
| 185 "<!DOCTYPE html>" |
| 186 "<iframe src=frame.html></iframe>" |
| 187 "<p style='transform: translateZ(0)'>Hello World</p>" |
| 188 ); |
| 189 mainResource.finish(); |
| 190 |
| 191 // Main page is ready to begin painting as there's no pending sheets. |
| 192 // The frame is not yet loaded, so we only paint the top level page. |
| 193 SimCompositor::BeginFrameResult frame1 = m_compositor.beginFrame(); |
| 194 EXPECT_TRUE(frame1.didDrawText); |
| 195 |
| 196 frameResource.start(); |
| 197 frameResource.write( |
| 198 "<!DOCTYPE html>" |
| 199 "<style>html { background: pink }</style>" |
| 200 "<link rel=stylesheet href=test.css>" |
| 201 "<p style='background: yellow'>Hello World</p>" |
| 202 "<div style='transform: translateZ(0); background: green;'>" |
| 203 " <p style='background: blue'>Hello Layer</p>" |
| 204 " <div style='position: relative; background: red;'>Hello World</div>
" |
| 205 "</div>" |
| 206 ); |
| 207 frameResource.finish(); |
| 208 |
| 209 // Trigger a layout with pending sheets. For example a page could trigger th
is |
| 210 // by doing offsetTop in a setTimeout, or by a parent frame executing script |
| 211 // that touched offsetTop in the child frame. |
| 212 LocalFrame* childFrame = toLocalFrame(webView().mainFrameImpl()->frame()->tr
ee().firstChild()); |
| 213 childFrame->document()->updateLayoutIgnorePendingStylesheets(); |
| 214 |
| 215 SimCompositor::BeginFrameResult frame2 = m_compositor.beginFrame(); |
| 216 |
| 217 // The child frame still has pending sheets, and the parent frame has no |
| 218 // invalid paint so we shouldn't draw any text. |
| 219 EXPECT_FALSE(frame2.didDrawText); |
| 220 |
| 221 // One per DeprecatedPaintLayer, 2 in the main frame and 3 in the iframe = 5
. |
| 222 // 1 for the background of the iframe. |
| 223 // 1 for the background of the composited transform layer. |
| 224 // TODO(esprehn): Why FOUC the background (borders, etc.) of iframes and |
| 225 // composited layers? Seems like a bug. |
| 226 EXPECT_EQ(7, frame2.drawCount); |
| 227 |
| 228 // Finish loading the sheets in the child frame. After it should issue a |
| 229 // paint invalidation for every layer since frame2 painted them but skipped |
| 230 // painting the real content to avoid FOUC. |
| 231 cssResource.start(); |
| 232 cssResource.finish(); |
| 233 |
| 234 // First frame where all frames are loaded, should paint the text in the |
| 235 // child frame. |
| 236 SimCompositor::BeginFrameResult frame3 = m_compositor.beginFrame(); |
| 237 EXPECT_TRUE(frame3.didDrawText); |
| 238 } |
| 239 |
163 } // namespace blink | 240 } // namespace blink |
OLD | NEW |