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

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

Issue 1596573002: Remove extra calls of didMeaningfulLayout() during the same navigation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix tests Created 4 years, 11 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 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 "core/dom/Document.h" 5 #include "core/dom/Document.h"
6 #include "platform/testing/UnitTestHelpers.h" 6 #include "platform/testing/UnitTestHelpers.h"
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "web/tests/sim/SimCompositor.h" 8 #include "web/tests/sim/SimCompositor.h"
9 #include "web/tests/sim/SimDisplayItemList.h" 9 #include "web/tests/sim/SimDisplayItemList.h"
10 #include "web/tests/sim/SimRequest.h" 10 #include "web/tests/sim/SimRequest.h"
(...skipping 15 matching lines...) Expand all
26 // Write 201 characters. 26 // Write 201 characters.
27 const char* tenCharacters = "0123456789"; 27 const char* tenCharacters = "0123456789";
28 for (int i = 0; i < 20; ++i) 28 for (int i = 0; i < 20; ++i)
29 mainResource.write(tenCharacters); 29 mainResource.write(tenCharacters);
30 mainResource.write("!"); 30 mainResource.write("!");
31 31
32 mainResource.finish(); 32 mainResource.finish();
33 33
34 compositor().beginFrame(); 34 compositor().beginFrame();
35 35
36 EXPECT_TRUE(webViewClient().hadVisuallyNonEmptyLayout()); 36 EXPECT_EQ(1, webViewClient().visuallyNonEmptyLayoutCount());
37 } 37 }
38 38
39 TEST_F(WebMeaningfulLayoutsTest, VisuallyNonEmptyTextCharactersEventually) 39 TEST_F(WebMeaningfulLayoutsTest, VisuallyNonEmptyTextCharactersEventually)
40 { 40 {
41 SimRequest mainResource("https://example.com/index.html", "text/html"); 41 SimRequest mainResource("https://example.com/index.html", "text/html");
42 42
43 loadURL("https://example.com/index.html"); 43 loadURL("https://example.com/index.html");
44 44
45 mainResource.start(); 45 mainResource.start();
46 46
47 // Write 200 characters. 47 // Write 200 characters.
48 const char* tenCharacters = "0123456789"; 48 const char* tenCharacters = "0123456789";
49 for (int i = 0; i < 20; ++i) 49 for (int i = 0; i < 20; ++i)
50 mainResource.write(tenCharacters); 50 mainResource.write(tenCharacters);
51 51
52 // Pump a frame mid-load. 52 // Pump a frame mid-load.
53 compositor().beginFrame(); 53 compositor().beginFrame();
54 54
55 EXPECT_FALSE(webViewClient().hadVisuallyNonEmptyLayout()); 55 EXPECT_EQ(0, webViewClient().visuallyNonEmptyLayoutCount());
56 56
57 // Write more than 200 characters. 57 // Write more than 200 characters.
58 mainResource.write("!"); 58 mainResource.write("!");
59 59
60 mainResource.finish(); 60 mainResource.finish();
61 61
62 // setting visually non-empty happens when the parsing finishes, 62 // setting visually non-empty happens when the parsing finishes,
63 // not as the character count goes over 200. 63 // not as the character count goes over 200.
64 compositor().beginFrame(); 64 compositor().beginFrame();
65 65
66 EXPECT_TRUE(webViewClient().hadVisuallyNonEmptyLayout()); 66 EXPECT_EQ(1, webViewClient().visuallyNonEmptyLayoutCount());
67 } 67 }
68 68
69 // TODO(dglazkov): Write pixel-count and canvas-based VisuallyNonEmpty tests 69 // TODO(dglazkov): Write pixel-count and canvas-based VisuallyNonEmpty tests
70 70
71 TEST_F(WebMeaningfulLayoutsTest, VisuallyNonEmptyMissingPump) 71 TEST_F(WebMeaningfulLayoutsTest, VisuallyNonEmptyMissingPump)
72 { 72 {
73 SimRequest mainResource("https://example.com/index.html", "text/html"); 73 SimRequest mainResource("https://example.com/index.html", "text/html");
74 74
75 loadURL("https://example.com/index.html"); 75 loadURL("https://example.com/index.html");
76 76
77 mainResource.start(); 77 mainResource.start();
78 78
79 // Write <200 characters. 79 // Write <200 characters.
80 mainResource.write("less than 200 characters."); 80 mainResource.write("less than 200 characters.");
81 81
82 compositor().beginFrame(); 82 compositor().beginFrame();
83 83
84 mainResource.finish(); 84 mainResource.finish();
85 85
86 // Even though the layout state is clean ... 86 // Even though the layout state is clean ...
87 EXPECT_TRUE(document().lifecycle().state() >= DocumentLifecycle::LayoutClean ); 87 EXPECT_TRUE(document().lifecycle().state() >= DocumentLifecycle::LayoutClean );
88 88
89 // We should still generate a request for another (possibly last) frame. 89 // We should still generate a request for another (possibly last) frame.
90 EXPECT_TRUE(compositor().needsAnimate()); 90 EXPECT_TRUE(compositor().needsAnimate());
91 91
92 // ... which we (the scheduler) happily provide. 92 // ... which we (the scheduler) happily provide.
93 compositor().beginFrame(); 93 compositor().beginFrame();
94 94
95 // ... which correctly signals the VisuallyNonEmpty. 95 // ... which correctly signals the VisuallyNonEmpty.
96 EXPECT_TRUE(webViewClient().hadVisuallyNonEmptyLayout()); 96 EXPECT_EQ(1, webViewClient().visuallyNonEmptyLayoutCount());
97 } 97 }
98 98
99 TEST_F(WebMeaningfulLayoutsTest, FinishedParsing) 99 TEST_F(WebMeaningfulLayoutsTest, FinishedParsing)
100 { 100 {
101 SimRequest mainResource("https://example.com/index.html", "text/html"); 101 SimRequest mainResource("https://example.com/index.html", "text/html");
102 102
103 loadURL("https://example.com/index.html"); 103 loadURL("https://example.com/index.html");
104 104
105 mainResource.start(); 105 mainResource.complete("content");
106
107 mainResource.write("content");
108
109 mainResource.finish();
110 106
111 compositor().beginFrame(); 107 compositor().beginFrame();
112 108
113 EXPECT_TRUE(webViewClient().hadFinishedParsingLayout()); 109 EXPECT_EQ(1, webViewClient().finishedParsingLayoutCount());
114 } 110 }
115 111
116 TEST_F(WebMeaningfulLayoutsTest, FinishedLoading) 112 TEST_F(WebMeaningfulLayoutsTest, FinishedLoading)
117 { 113 {
118 SimRequest mainResource("https://example.com/index.html", "text/html"); 114 SimRequest mainResource("https://example.com/index.html", "text/html");
119 115
120 loadURL("https://example.com/index.html"); 116 loadURL("https://example.com/index.html");
121 117
122 mainResource.start(); 118 mainResource.complete("content");
123
124 mainResource.write("content");
125
126 mainResource.finish();
127 119
128 compositor().beginFrame(); 120 compositor().beginFrame();
129 121
130 EXPECT_TRUE(webViewClient().hadFinishedLoadingLayout()); 122 EXPECT_EQ(1, webViewClient().finishedLoadingLayoutCount());
131 } 123 }
132 124
133 TEST_F(WebMeaningfulLayoutsTest, FinishedParsingThenLoading) 125 TEST_F(WebMeaningfulLayoutsTest, FinishedParsingThenLoading)
134 { 126 {
135 SimRequest mainResource("https://example.com/index.html", "text/html"); 127 SimRequest mainResource("https://example.com/index.html", "text/html");
136 SimRequest imageResource("https://example.com/cat.png", "image/png"); 128 SimRequest imageResource("https://example.com/cat.png", "image/png");
137 129
138 loadURL("https://example.com/index.html"); 130 loadURL("https://example.com/index.html");
139 131
140 mainResource.start(); 132 mainResource.complete("<img src=cat.png>");
141
142 mainResource.write("<img src=cat.png>");
143
144 mainResource.finish();
145 133
146 compositor().beginFrame(); 134 compositor().beginFrame();
147 135
148 EXPECT_TRUE(webViewClient().hadFinishedParsingLayout()); 136 EXPECT_EQ(1, webViewClient().finishedParsingLayoutCount());
149 EXPECT_FALSE(webViewClient().hadFinishedLoadingLayout()); 137 EXPECT_EQ(0, webViewClient().finishedLoadingLayoutCount());
150 138
151 imageResource.complete("image data"); 139 imageResource.complete("image data");
152 140
153 // Pump the message loop to process the image loading task. 141 // Pump the message loop to process the image loading task.
154 testing::runPendingTasks(); 142 testing::runPendingTasks();
155 143
156 compositor().beginFrame(); 144 compositor().beginFrame();
157 145
158 EXPECT_TRUE(webViewClient().hadFinishedLoadingLayout()); 146 EXPECT_EQ(1, webViewClient().finishedParsingLayoutCount());
147 EXPECT_EQ(1, webViewClient().finishedLoadingLayoutCount());
148 }
149
150 TEST_F(WebMeaningfulLayoutsTest, WithIFrames)
151 {
152 SimRequest mainResource("https://example.com/index.html", "text/html");
153 SimRequest iframeResource("https://example.com/iframe.html", "text/html");
154
155 loadURL("https://example.com/index.html");
156
157 mainResource.complete("<iframe src=iframe.html></iframe>");
158
159 compositor().beginFrame();
160
161 EXPECT_EQ(1, webViewClient().visuallyNonEmptyLayoutCount());
162 EXPECT_EQ(1, webViewClient().finishedParsingLayoutCount());
163 EXPECT_EQ(0, webViewClient().finishedLoadingLayoutCount());
164
165 iframeResource.complete("iframe data");
166
167 // Pump the message loop to process the iframe loading task.
168 testing::runPendingTasks();
169
170 compositor().beginFrame();
171
172 EXPECT_EQ(1, webViewClient().visuallyNonEmptyLayoutCount());
173 EXPECT_EQ(1, webViewClient().finishedParsingLayoutCount());
174 EXPECT_EQ(1, webViewClient().finishedLoadingLayoutCount());
159 } 175 }
160 176
161 } 177 }
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/web/FrameLoaderClientImpl.cpp ('k') | third_party/WebKit/Source/web/tests/sim/SimWebViewClient.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698