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

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

Issue 2437193002: Log to UMA why we would load a third-party frame (Closed)
Patch Set: don't copy SimRequest Created 4 years, 1 month 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
« no previous file with comments | « third_party/WebKit/Source/web/BUILD.gn ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "platform/testing/HistogramTester.h"
6 #include "platform/testing/UnitTestHelpers.h"
7 #include "web/WebViewImpl.h"
8 #include "web/tests/sim/SimCompositor.h"
9 #include "web/tests/sim/SimDisplayItemList.h"
10 #include "web/tests/sim/SimRequest.h"
11 #include "web/tests/sim/SimTest.h"
12
13 namespace blink {
14
15 static const char* kHistogramName =
16 "Navigation.DeferredDocumentLoading.StatesV2";
17
18 class DeferredLoadingTest : public SimTest {
19 protected:
20 DeferredLoadingTest() { webView().resize(WebSize(640, 480)); }
21 void compositeFrame() {
22 compositor().beginFrame();
23 testing::runPendingTasks();
24 if (compositor().needsBeginFrame())
25 compositor().beginFrame(); // VisibleNestedInRight doesn't need this.
26 ASSERT_FALSE(compositor().needsBeginFrame());
27 }
28
29 std::unique_ptr<SimRequest> createMainResource() {
30 std::unique_ptr<SimRequest> mainResource =
31 wrapUnique(new SimRequest("https://example.com/", "text/html"));
32 loadURL("https://example.com/");
33 return mainResource;
34 }
35 };
36
37 TEST_F(DeferredLoadingTest, Visible) {
38 HistogramTester histogramTester;
39 std::unique_ptr<SimRequest> mainResource = createMainResource();
40
41 mainResource->complete("<iframe sandbox></iframe>");
42
43 compositeFrame();
44
45 histogramTester.expectBucketCount(kHistogramName, Created, 1);
46 histogramTester.expectBucketCount(kHistogramName, WouldLoadVisible, 1);
47 }
48
49 TEST_F(DeferredLoadingTest, Right) {
50 HistogramTester histogramTester;
51 std::unique_ptr<SimRequest> mainResource = createMainResource();
52
53 mainResource->complete(
54 "<iframe style='position:absolute; left:105vw;' sandbox></iframe>");
55
56 compositeFrame();
57
58 histogramTester.expectBucketCount(kHistogramName, Created, 1);
59 histogramTester.expectTotalCount(kHistogramName, 1);
60 }
61
62 TEST_F(DeferredLoadingTest, Below) {
63 HistogramTester histogramTester;
64 std::unique_ptr<SimRequest> mainResource = createMainResource();
65
66 mainResource->complete(
67 "<iframe style='position:absolute; top:105vh;' sandbox></iframe>");
68
69 compositeFrame();
70
71 histogramTester.expectBucketCount(kHistogramName, Created, 1);
72 histogramTester.expectTotalCount(kHistogramName, 1);
73 }
74
75 TEST_F(DeferredLoadingTest, Above) {
76 HistogramTester histogramTester;
77 std::unique_ptr<SimRequest> mainResource = createMainResource();
78
79 mainResource->complete(
80 "<iframe style='position:absolute; top:-10000px;' sandbox></iframe>");
81
82 compositeFrame();
83
84 histogramTester.expectBucketCount(kHistogramName, Created, 1);
85 histogramTester.expectBucketCount(kHistogramName, WouldLoadAbove, 1);
86 }
87
88 TEST_F(DeferredLoadingTest, Left) {
89 HistogramTester histogramTester;
90 std::unique_ptr<SimRequest> mainResource = createMainResource();
91
92 mainResource->complete(
93 "<iframe style='position:absolute; left:-10000px;' sandbox></iframe>");
94
95 compositeFrame();
96
97 histogramTester.expectBucketCount(kHistogramName, Created, 1);
98 histogramTester.expectBucketCount(kHistogramName, WouldLoadLeft, 1);
99 }
100
101 TEST_F(DeferredLoadingTest, AboveAndLeft) {
102 HistogramTester histogramTester;
103 std::unique_ptr<SimRequest> mainResource = createMainResource();
104
105 mainResource->complete(
106 "<iframe style='position:absolute; left:-10000px; top:-10000px' sandbox>"
107 "</iframe>");
108
109 compositeFrame();
110
111 // Don't log WouldLoadAbove AND WouldLoadLeft.
112 histogramTester.expectBucketCount(kHistogramName, Created, 1);
113 histogramTester.expectBucketCount(kHistogramName, WouldLoadAbove, 1);
114 histogramTester.expectTotalCount(kHistogramName, 2);
115 }
116
117 TEST_F(DeferredLoadingTest, ZeroByZero) {
118 HistogramTester histogramTester;
119 std::unique_ptr<SimRequest> mainResource = createMainResource();
120
121 mainResource->complete(
122 "<iframe style='height:0px;width:0px;' sandbox></iframe>");
123
124 compositeFrame();
125
126 histogramTester.expectBucketCount(kHistogramName, Created, 1);
127 histogramTester.expectBucketCount(kHistogramName, WouldLoadZeroByZero, 1);
128 }
129
130 TEST_F(DeferredLoadingTest, DisplayNone) {
131 HistogramTester histogramTester;
132 std::unique_ptr<SimRequest> mainResource = createMainResource();
133
134 mainResource->complete("<iframe style='display:none' sandbox></iframe>");
135
136 compositeFrame();
137
138 histogramTester.expectBucketCount(kHistogramName, Created, 1);
139 histogramTester.expectBucketCount(kHistogramName, WouldLoadDisplayNone, 1);
140 }
141
142 TEST_F(DeferredLoadingTest, VisibleNestedInRight) {
143 HistogramTester histogramTester;
144 std::unique_ptr<SimRequest> mainResource = createMainResource();
145 SimRequest frameResource("https://example.com/iframe.html", "text/html");
146
147 mainResource->complete(
148 "<iframe style='position:absolute; left:105vw;' src='iframe.html' "
149 "sandbox></iframe>");
150 frameResource.complete("<iframe sandbox></iframe>");
151
152 compositeFrame();
153
154 histogramTester.expectBucketCount(kHistogramName, Created, 2);
155 histogramTester.expectTotalCount(kHistogramName, 2);
156 }
157
158 TEST_F(DeferredLoadingTest, LeftNestedInBelow) {
159 HistogramTester histogramTester;
160 std::unique_ptr<SimRequest> mainResource = createMainResource();
161 SimRequest frameResource("https://example.com/iframe.html", "text/html");
162
163 mainResource->complete(
164 "<iframe style='position:absolute; top:105vh;' src='iframe.html' "
165 "sandbox></iframe>");
166 frameResource.complete(
167 "<iframe style='position:absolute; left:-10000px;' sandbox></iframe>");
168
169 compositeFrame();
170
171 histogramTester.expectBucketCount(kHistogramName, Created, 2);
172 histogramTester.expectTotalCount(kHistogramName, 2);
173 }
174
175 TEST_F(DeferredLoadingTest, SameOriginNotCounted) {
176 HistogramTester histogramTester;
177 std::unique_ptr<SimRequest> mainResource = createMainResource();
178 SimRequest frameResource("https://example.com/iframe.html", "text/html");
179
180 mainResource->complete("<iframe src='iframe.html'></iframe>");
181 frameResource.complete("<iframe></iframe>");
182 compositeFrame();
183
184 histogramTester.expectTotalCount(kHistogramName, 0);
185 }
186
187 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/web/BUILD.gn ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698