OLD | NEW |
(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 SimRequest createMainResource() { |
| 30 SimRequest mainResource("https://example.com/", "text/html"); |
| 31 loadURL("https://example.com/"); |
| 32 return mainResource; |
| 33 } |
| 34 }; |
| 35 |
| 36 TEST_F(DeferredLoadingTest, Visible) { |
| 37 HistogramTester histogramTester; |
| 38 SimRequest mainResource = createMainResource(); |
| 39 |
| 40 mainResource.complete("<iframe sandbox></iframe>"); |
| 41 |
| 42 compositeFrame(); |
| 43 |
| 44 histogramTester.expectBucketCount(kHistogramName, Created, 1); |
| 45 histogramTester.expectBucketCount(kHistogramName, WouldLoadVisible, 1); |
| 46 } |
| 47 |
| 48 TEST_F(DeferredLoadingTest, Right) { |
| 49 HistogramTester histogramTester; |
| 50 SimRequest mainResource = createMainResource(); |
| 51 |
| 52 mainResource.complete( |
| 53 "<iframe style='position:absolute; left:105vw;' sandbox></iframe>"); |
| 54 |
| 55 compositeFrame(); |
| 56 |
| 57 histogramTester.expectBucketCount(kHistogramName, Created, 1); |
| 58 histogramTester.expectTotalCount(kHistogramName, 1); |
| 59 } |
| 60 |
| 61 TEST_F(DeferredLoadingTest, Below) { |
| 62 HistogramTester histogramTester; |
| 63 SimRequest mainResource = createMainResource(); |
| 64 |
| 65 mainResource.complete( |
| 66 "<iframe style='position:absolute; top:105vh;' sandbox></iframe>"); |
| 67 |
| 68 compositeFrame(); |
| 69 |
| 70 histogramTester.expectBucketCount(kHistogramName, Created, 1); |
| 71 histogramTester.expectTotalCount(kHistogramName, 1); |
| 72 } |
| 73 |
| 74 TEST_F(DeferredLoadingTest, Above) { |
| 75 HistogramTester histogramTester; |
| 76 SimRequest mainResource = createMainResource(); |
| 77 |
| 78 mainResource.complete( |
| 79 "<iframe style='position:absolute; top:-10000px;' sandbox></iframe>"); |
| 80 |
| 81 compositeFrame(); |
| 82 |
| 83 histogramTester.expectBucketCount(kHistogramName, Created, 1); |
| 84 histogramTester.expectBucketCount(kHistogramName, WouldLoadAbove, 1); |
| 85 } |
| 86 |
| 87 TEST_F(DeferredLoadingTest, Left) { |
| 88 HistogramTester histogramTester; |
| 89 SimRequest mainResource = createMainResource(); |
| 90 |
| 91 mainResource.complete( |
| 92 "<iframe style='position:absolute; left:-10000px;' sandbox></iframe>"); |
| 93 |
| 94 compositeFrame(); |
| 95 |
| 96 histogramTester.expectBucketCount(kHistogramName, Created, 1); |
| 97 histogramTester.expectBucketCount(kHistogramName, WouldLoadLeft, 1); |
| 98 } |
| 99 |
| 100 // Don't log WouldLoadAbove AND WouldLoadLeft. |
| 101 TEST_F(DeferredLoadingTest, AboveAndLeft) { |
| 102 HistogramTester histogramTester; |
| 103 SimRequest mainResource = createMainResource(); |
| 104 |
| 105 mainResource.complete( |
| 106 "<iframe style='position:absolute; left:-10000px; top:-10000px' sandbox>" |
| 107 "</iframe>"); |
| 108 |
| 109 compositeFrame(); |
| 110 |
| 111 histogramTester.expectBucketCount(kHistogramName, Created, 1); |
| 112 histogramTester.expectBucketCount(kHistogramName, WouldLoadAbove, 1); |
| 113 histogramTester.expectTotalCount(kHistogramName, 2); |
| 114 } |
| 115 |
| 116 TEST_F(DeferredLoadingTest, ZeroByZero) { |
| 117 HistogramTester histogramTester; |
| 118 SimRequest mainResource = createMainResource(); |
| 119 |
| 120 mainResource.complete( |
| 121 "<iframe style='height:0px;width:0px;' sandbox></iframe>"); |
| 122 |
| 123 compositeFrame(); |
| 124 |
| 125 histogramTester.expectBucketCount(kHistogramName, Created, 1); |
| 126 histogramTester.expectBucketCount(kHistogramName, WouldLoadZeroByZero, 1); |
| 127 } |
| 128 |
| 129 TEST_F(DeferredLoadingTest, DisplayNone) { |
| 130 HistogramTester histogramTester; |
| 131 SimRequest mainResource = createMainResource(); |
| 132 |
| 133 mainResource.complete("<iframe style='display:none' sandbox></iframe>"); |
| 134 |
| 135 compositeFrame(); |
| 136 |
| 137 histogramTester.expectBucketCount(kHistogramName, Created, 1); |
| 138 histogramTester.expectBucketCount(kHistogramName, WouldLoadDisplayNone, 1); |
| 139 } |
| 140 |
| 141 TEST_F(DeferredLoadingTest, VisibleNestedInRight) { |
| 142 HistogramTester histogramTester; |
| 143 SimRequest mainResource = createMainResource(); |
| 144 SimRequest frameResource("https://example.com/iframe.html", "text/html"); |
| 145 |
| 146 mainResource.complete( |
| 147 "<iframe style='position:absolute; left:105vw;' src='iframe.html' " |
| 148 "sandbox></iframe>"); |
| 149 frameResource.complete("<iframe></iframe>"); |
| 150 |
| 151 compositeFrame(); |
| 152 |
| 153 histogramTester.expectBucketCount(kHistogramName, Created, 2); |
| 154 histogramTester.expectTotalCount(kHistogramName, 2); |
| 155 } |
| 156 |
| 157 TEST_F(DeferredLoadingTest, LeftNestedInBelow) { |
| 158 HistogramTester histogramTester; |
| 159 SimRequest mainResource = createMainResource(); |
| 160 SimRequest frameResource("https://example.com/iframe.html", "text/html"); |
| 161 |
| 162 mainResource.complete( |
| 163 "<iframe style='position:absolute; top:105vh;' src='iframe.html' " |
| 164 "sandbox></iframe>"); |
| 165 frameResource.complete( |
| 166 "<iframe style='position:absolute; left:-10000px;'> </iframe>"); |
| 167 |
| 168 compositeFrame(); |
| 169 |
| 170 histogramTester.expectBucketCount(kHistogramName, Created, 2); |
| 171 histogramTester.expectTotalCount(kHistogramName, 2); |
| 172 } |
| 173 |
| 174 } // namespace blink |
OLD | NEW |