Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/browser/frame_host/navigation_controller_impl.h" | 5 #include "content/browser/frame_host/navigation_controller_impl.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/test/histogram_tester.h" | |
| 15 #include "content/browser/frame_host/frame_navigation_entry.h" | 16 #include "content/browser/frame_host/frame_navigation_entry.h" |
| 16 #include "content/browser/frame_host/frame_tree.h" | 17 #include "content/browser/frame_host/frame_tree.h" |
| 17 #include "content/browser/frame_host/navigation_entry_impl.h" | 18 #include "content/browser/frame_host/navigation_entry_impl.h" |
| 18 #include "content/browser/loader/resource_dispatcher_host_impl.h" | 19 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
| 19 #include "content/browser/web_contents/web_contents_impl.h" | 20 #include "content/browser/web_contents/web_contents_impl.h" |
| 20 #include "content/common/frame_messages.h" | 21 #include "content/common/frame_messages.h" |
| 21 #include "content/common/page_state_serialization.h" | 22 #include "content/common/page_state_serialization.h" |
| 22 #include "content/common/site_isolation_policy.h" | 23 #include "content/common/site_isolation_policy.h" |
| 23 #include "content/public/browser/navigation_handle.h" | 24 #include "content/public/browser/navigation_handle.h" |
| 24 #include "content/public/browser/render_view_host.h" | 25 #include "content/public/browser/render_view_host.h" |
| (...skipping 6088 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6113 entry = controller.GetLastCommittedEntry(); | 6114 entry = controller.GetLastCommittedEntry(); |
| 6114 content::FaviconStatus& favicon_status2 = entry->GetFavicon(); | 6115 content::FaviconStatus& favicon_status2 = entry->GetFavicon(); |
| 6115 EXPECT_TRUE(favicon_status2.valid); | 6116 EXPECT_TRUE(favicon_status2.valid); |
| 6116 | 6117 |
| 6117 ASSERT_TRUE(RendererLocationReplace(shell(), GURL("data:text/html,page2"))); | 6118 ASSERT_TRUE(RendererLocationReplace(shell(), GURL("data:text/html,page2"))); |
| 6118 entry = controller.GetLastCommittedEntry(); | 6119 entry = controller.GetLastCommittedEntry(); |
| 6119 content::FaviconStatus& favicon_status3 = entry->GetFavicon(); | 6120 content::FaviconStatus& favicon_status3 = entry->GetFavicon(); |
| 6120 EXPECT_FALSE(favicon_status3.valid); | 6121 EXPECT_FALSE(favicon_status3.valid); |
| 6121 } | 6122 } |
| 6122 | 6123 |
| 6124 // Check if consecutive reloads can be correctly captured by metrics. | |
| 6125 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | |
| 6126 ConsecutiveReloadMetrics) { | |
| 6127 base::HistogramTester histogram; | |
| 6128 | |
| 6129 const char kReloadToReloadMetricName[] = | |
| 6130 "Navigation.Reload.ReloadToReloadDuration"; | |
| 6131 const char kReloadMainResourceToReloadMetricName[] = | |
| 6132 "Navigation.Reload.ReloadMainResourceToReloadDuration"; | |
| 6133 | |
| 6134 // Navigate to a page, and check if metrics are initialized correctly. | |
| 6135 NavigateToURL(shell(), embedded_test_server()->GetURL( | |
| 6136 "/navigation_controller/page_with_links.html")); | |
| 6137 histogram.ExpectTotalCount(kReloadToReloadMetricName, 0); | |
| 6138 histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 0); | |
| 6139 | |
| 6140 NavigationControllerImpl& controller = static_cast<NavigationControllerImpl&>( | |
| 6141 shell()->web_contents()->GetController()); | |
| 6142 | |
| 6143 // ReloadToRefreshContent triggers a reload of ReloadType::MAIN_RESOURCE. The | |
| 6144 // first reload should not be counted. | |
| 6145 controller.ReloadToRefreshContent(false); | |
| 6146 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | |
| 6147 histogram.ExpectTotalCount(kReloadToReloadMetricName, 0); | |
| 6148 histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 0); | |
| 6149 | |
| 6150 // ReloadBypassingCache triggers a reload of ReloadType::BYPASSING_CACHE. | |
| 6151 // Both metrics should count the consecutive reloads. | |
| 6152 controller.ReloadBypassingCache(false); | |
| 6153 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | |
| 6154 histogram.ExpectTotalCount(kReloadToReloadMetricName, 1); | |
| 6155 histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 1); | |
| 6156 | |
| 6157 // Triggers another reload of ReloadType::BYPASSING_CACHE. | |
| 6158 // ReloadMainResourceToReload should not be counted here. | |
| 6159 controller.ReloadBypassingCache(false); | |
| 6160 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | |
| 6161 histogram.ExpectTotalCount(kReloadToReloadMetricName, 2); | |
| 6162 histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 1); | |
| 6163 | |
| 6164 // A browser-initiated navigation should reset the reload tracking | |
| 6165 // information. | |
| 6166 NavigateToURL(shell(), embedded_test_server()->GetURL( | |
| 6167 "/navigation_controller/simple_page_1.html")); | |
| 6168 histogram.ExpectTotalCount(kReloadToReloadMetricName, 2); | |
| 6169 histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 1); | |
| 6170 | |
| 6171 // Then, the next reload should be assumed as the first reload. Metrics | |
| 6172 // should not be changed for the first reload. | |
| 6173 controller.ReloadToRefreshContent(false); | |
| 6174 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | |
| 6175 histogram.ExpectTotalCount(kReloadToReloadMetricName, 2); | |
| 6176 histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 1); | |
| 6177 | |
| 6178 // Another reload of ReloadType::MAIN_RESOURCE should be counted by both | |
| 6179 // metrics again. | |
| 6180 controller.ReloadToRefreshContent(false); | |
| 6181 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | |
| 6182 histogram.ExpectTotalCount(kReloadToReloadMetricName, 3); | |
| 6183 histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 2); | |
| 6184 | |
| 6185 // A renderer-initiated navigations with no user gesture don't reset reload | |
| 6186 // tracking information, and the following reload will be counted by metrics. | |
| 6187 { | |
| 6188 // WaitForLoadStop() does not work to wait for loading that is triggered by | |
| 6189 // JavaScript asynchronously. | |
| 6190 TestNavigationObserver observer(shell()->web_contents()); | |
| 6191 EXPECT_TRUE(ExecuteScript( | |
| 6192 shell()->web_contents(), | |
| 6193 "history.pushState({}, 'page 1', 'simple_page_1.html')")); | |
| 6194 observer.Wait(); | |
| 6195 } | |
| 6196 histogram.ExpectTotalCount(kReloadToReloadMetricName, 3); | |
| 6197 histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 2); | |
| 6198 { | |
| 6199 TestNavigationObserver observer(shell()->web_contents()); | |
| 6200 // ExecuteScript() sets a user gesture flag internally for testing, but we | |
| 6201 // want to run JavaScript without the flag. Call ExecuteJavaScriptForTests | |
| 6202 // directory. | |
| 6203 static_cast<WebContentsImpl*>(shell()->web_contents()) | |
| 6204 ->GetFrameTree() | |
| 6205 ->root() | |
| 6206 ->render_manager() | |
| 6207 ->current_frame_host() | |
|
Charlie Reis
2016/09/28 16:58:58
Just call GetMainFrame() on the WebContents, rathe
| |
| 6208 ->ExecuteJavaScriptForTests( | |
| 6209 base::UTF8ToUTF16("location.href='simple_page_2.html'")); | |
| 6210 observer.Wait(); | |
| 6211 } | |
| 6212 histogram.ExpectTotalCount(kReloadToReloadMetricName, 3); | |
| 6213 histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 2); | |
| 6214 | |
| 6215 controller.ReloadToRefreshContent(false); | |
| 6216 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | |
| 6217 histogram.ExpectTotalCount(kReloadToReloadMetricName, 4); | |
| 6218 histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 3); | |
| 6219 | |
| 6220 // Go back to the first page. Reload tracking information should be reset. | |
| 6221 shell()->web_contents()->GetController().GoBack(); | |
| 6222 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | |
| 6223 histogram.ExpectTotalCount(kReloadToReloadMetricName, 4); | |
| 6224 histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 3); | |
| 6225 | |
| 6226 controller.ReloadToRefreshContent(false); | |
| 6227 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | |
| 6228 histogram.ExpectTotalCount(kReloadToReloadMetricName, 4); | |
| 6229 histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 3); | |
| 6230 } | |
| 6231 | |
| 6123 } // namespace content | 6232 } // namespace content |
| OLD | NEW |