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

Side by Side Diff: Source/web/tests/DocumentLoadingRenderingTest.cpp

Issue 1308043003: Add a bunch more tests for deferred commit handling. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: typos Created 5 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "web/WebLocalFrameImpl.h" 8 #include "web/WebLocalFrameImpl.h"
9 #include "web/tests/FrameTestHelpers.h" 9 #include "web/tests/FrameTestHelpers.h"
10 #include "web/tests/sim/SimLayerTreeView.h" 10 #include "web/tests/sim/SimLayerTreeView.h"
11 #include "web/tests/sim/SimNetwork.h" 11 #include "web/tests/sim/SimNetwork.h"
12 #include "web/tests/sim/SimRequest.h" 12 #include "web/tests/sim/SimRequest.h"
13 #include "web/tests/sim/SimWebViewClient.h" 13 #include "web/tests/sim/SimWebViewClient.h"
14 #include <gtest/gtest.h> 14 #include <gtest/gtest.h>
15 15
16 namespace blink { 16 namespace blink {
17 17
18 class DocumentLoadingRenderingTest : public ::testing::Test { 18 class DocumentLoadingRenderingTest : public ::testing::Test {
19 void SetUp() override 19 protected:
20 DocumentLoadingRenderingTest()
21 : m_webViewClient(m_layerTreeView)
20 { 22 {
23 m_webViewHelper.initialize(true, nullptr, &m_webViewClient);
21 Document::setThreadedParsingEnabledForUnitTestsOnly(false); 24 Document::setThreadedParsingEnabledForUnitTestsOnly(false);
22 } 25 }
23 26
24 void TearDown() override 27 virtual ~DocumentLoadingRenderingTest()
25 { 28 {
26 Document::setThreadedParsingEnabledForUnitTestsOnly(true); 29 Document::setThreadedParsingEnabledForUnitTestsOnly(true);
27 } 30 }
31
32 void loadURL(const String& url)
33 {
34 WebURLRequest request;
35 request.initialize();
36 request.setURL(KURL(ParsedURLString, url));
37 m_webViewHelper.webViewImpl()->mainFrameImpl()->loadRequest(request);
38 }
39
40 SimNetwork m_network;
41 SimLayerTreeView m_layerTreeView;
42 SimWebViewClient m_webViewClient;
43 FrameTestHelpers::WebViewHelper m_webViewHelper;
28 }; 44 };
29 45
30 TEST_F(DocumentLoadingRenderingTest, ShouldResumeCommitsAfterBodyParsedWithoutSh eets) 46 TEST_F(DocumentLoadingRenderingTest, ShouldResumeCommitsAfterBodyParsedWithoutSh eets)
31 { 47 {
32 SimLayerTreeView layerTreeView;
33 SimWebViewClient webViewClient(layerTreeView);
34 FrameTestHelpers::WebViewHelper webViewHelper;
35 webViewHelper.initialize(true, nullptr, &webViewClient);
36
37 SimNetwork network;
38 SimRequest mainResource("https://example.com/test.html", "text/html"); 48 SimRequest mainResource("https://example.com/test.html", "text/html");
39 49
40 WebURLRequest request; 50 loadURL("https://example.com/test.html");
41 request.initialize();
42 request.setURL(KURL(ParsedURLString, "https://example.com/test.html"));
43
44 webViewHelper.webViewImpl()->mainFrameImpl()->loadRequest(request);
45 51
46 mainResource.start(); 52 mainResource.start();
47 53
48 // Still in the head, should not resume commits. 54 // Still in the head, should not resume commits.
49 mainResource.write("<!DOCTYPE html>"); 55 mainResource.write("<!DOCTYPE html>");
50 EXPECT_TRUE(layerTreeView.deferCommits()); 56 EXPECT_TRUE(m_layerTreeView.deferCommits());
51 mainResource.write("<title>Test</title><style>div { color red; }</style>"); 57 mainResource.write("<title>Test</title><style>div { color red; }</style>");
52 EXPECT_TRUE(layerTreeView.deferCommits()); 58 EXPECT_TRUE(m_layerTreeView.deferCommits());
53 59
54 // Implicitly inserts the body. Since there's no loading stylesheets we 60 // Implicitly inserts the body. Since there's no loading stylesheets we
55 // should resume commits. 61 // should resume commits.
56 mainResource.write("<p>Hello World</p>"); 62 mainResource.write("<p>Hello World</p>");
57 EXPECT_FALSE(layerTreeView.deferCommits()); 63 EXPECT_FALSE(m_layerTreeView.deferCommits());
58 64
59 // Finish the load, should stay resumed. 65 // Finish the load, should stay resumed.
60 mainResource.finish(); 66 mainResource.finish();
61 EXPECT_FALSE(layerTreeView.deferCommits()); 67 EXPECT_FALSE(m_layerTreeView.deferCommits());
68 }
69
70 TEST_F(DocumentLoadingRenderingTest, ShouldResumeCommitsAfterBodyIfSheetsLoaded)
71 {
72 SimRequest mainResource("https://example.com/test.html", "text/html");
73 SimRequest cssResource("https://example.com/test.css", "text/css");
74
75 loadURL("https://example.com/test.html");
76
77 mainResource.start();
78
79 // Still in the head, should not resume commits.
80 mainResource.write("<!DOCTYPE html><link rel=stylesheet href=test.css>");
81 EXPECT_TRUE(m_layerTreeView.deferCommits());
82
83 // Sheet is streaming in, but not ready yet.
84 cssResource.start();
85 cssResource.write("a { color: red; }");
86 EXPECT_TRUE(m_layerTreeView.deferCommits());
87
88 // Sheet finished, but no body yet, so don't resume.
89 cssResource.finish();
90 EXPECT_TRUE(m_layerTreeView.deferCommits());
91
92 // Body inserted and sheet is loaded so resume commits.
93 mainResource.write("<body>");
94 EXPECT_FALSE(m_layerTreeView.deferCommits());
95
96 // Finish the load, should stay resumed.
97 mainResource.finish();
98 EXPECT_FALSE(m_layerTreeView.deferCommits());
99 }
100
101 TEST_F(DocumentLoadingRenderingTest, ShouldResumeCommitsAfterSheetsLoaded)
102 {
103 SimRequest mainResource("https://example.com/test.html", "text/html");
104 SimRequest cssResource("https://example.com/test.css", "text/css");
105
106 loadURL("https://example.com/test.html");
107
108 mainResource.start();
109
110 // Still in the head, should not resume commits.
111 mainResource.write("<!DOCTYPE html><link rel=stylesheet href=test.css>");
112 EXPECT_TRUE(m_layerTreeView.deferCommits());
113
114 // Sheet is streaming in, but not ready yet.
115 cssResource.start();
116 cssResource.write("a { color: red; }");
117 EXPECT_TRUE(m_layerTreeView.deferCommits());
118
119 // Body inserted, but sheet is still loading so don't resume.
120 mainResource.write("<body>");
121 EXPECT_TRUE(m_layerTreeView.deferCommits());
122
123 // Sheet finished and there's a body so resume.
124 cssResource.finish();
125 EXPECT_FALSE(m_layerTreeView.deferCommits());
126
127 // Finish the load, should stay resumed.
128 mainResource.finish();
129 EXPECT_FALSE(m_layerTreeView.deferCommits());
130 }
131
132 TEST_F(DocumentLoadingRenderingTest, ShouldResumeCommitsAfterParsingSvg)
133 {
134 SimRequest mainResource("https://example.com/test.svg", "image/svg+xml");
135 SimRequest cssResource("https://example.com/test.css", "text/css");
136
137 loadURL("https://example.com/test.svg");
138
139 mainResource.start();
140
141 // Not done parsing.
142 mainResource.write("<?xml-stylesheet type='text/css' href='test.css'?>");
143 EXPECT_TRUE(m_layerTreeView.deferCommits());
144
145 // Sheet is streaming in, but not ready yet.
146 cssResource.start();
147 cssResource.write("a { color: red; }");
148 EXPECT_TRUE(m_layerTreeView.deferCommits());
149
150 // Root inserted, but sheet is still loading so don't resume.
151 mainResource.write("<svg>");
152 EXPECT_TRUE(m_layerTreeView.deferCommits());
153
154 // Sheet finished, but no body since it's svg so don't resume.
155 cssResource.finish();
156 EXPECT_TRUE(m_layerTreeView.deferCommits());
157
158 // Finish the load and resume.
159 mainResource.finish();
160 EXPECT_FALSE(m_layerTreeView.deferCommits());
62 } 161 }
63 162
64 } // namespace blink 163 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698