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); | |
Charlie Reis
2016/09/28 00:05:24
Can you add cases after this showing that renderer
Takashi Toyoshima
2016/09/28 10:37:21
I tried to use setTimeout, but it still run with t
Charlie Reis
2016/09/28 16:58:58
ExecuteJavaScriptForTests seems right, thanks.
| |
6184 | |
6185 // Go back to the first page. Reload tracking information should be reset. | |
6186 shell()->web_contents()->GetController().GoBack(); | |
6187 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | |
6188 histogram.ExpectTotalCount(kReloadToReloadMetricName, 3); | |
6189 histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 2); | |
6190 | |
6191 controller.ReloadToRefreshContent(false); | |
6192 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | |
6193 histogram.ExpectTotalCount(kReloadToReloadMetricName, 3); | |
6194 histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 2); | |
6195 } | |
6196 | |
6123 } // namespace content | 6197 } // namespace content |
OLD | NEW |