 Chromium Code Reviews
 Chromium Code Reviews Issue 2174293002:
  NonValidatingReload: Monitor reload operations in NavigationControllerImpl  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 2174293002:
  NonValidatingReload: Monitor reload operations in NavigationControllerImpl  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| Index: content/browser/frame_host/navigation_controller_impl_browsertest.cc | 
| diff --git a/content/browser/frame_host/navigation_controller_impl_browsertest.cc b/content/browser/frame_host/navigation_controller_impl_browsertest.cc | 
| index d732bd929d9166d72bc251883dd149cc68316481..1fda6fe26aa2b5d8069de7c220f7152fc09d4eef 100644 | 
| --- a/content/browser/frame_host/navigation_controller_impl_browsertest.cc | 
| +++ b/content/browser/frame_host/navigation_controller_impl_browsertest.cc | 
| @@ -12,6 +12,7 @@ | 
| #include "base/macros.h" | 
| #include "base/strings/stringprintf.h" | 
| #include "base/strings/utf_string_conversions.h" | 
| +#include "base/test/histogram_tester.h" | 
| #include "content/browser/frame_host/frame_navigation_entry.h" | 
| #include "content/browser/frame_host/frame_tree.h" | 
| #include "content/browser/frame_host/navigation_entry_impl.h" | 
| @@ -6120,4 +6121,77 @@ IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | 
| EXPECT_FALSE(favicon_status3.valid); | 
| } | 
| +// Check if consecutive reloads can be correctly captured by metrics. | 
| +IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | 
| + ConsecutiveReloadMetrics) { | 
| + base::HistogramTester histogram; | 
| + | 
| + const char kReloadToReloadMetricName[] = | 
| + "Navigation.Reload.ReloadToReloadDuration"; | 
| + const char kReloadMainResourceToReloadMetricName[] = | 
| + "Navigation.Reload.ReloadMainResourceToReloadDuration"; | 
| + | 
| + // Navigate to a page, and check if metrics are initialized correctly. | 
| + NavigateToURL(shell(), embedded_test_server()->GetURL( | 
| + "/navigation_controller/page_with_links.html")); | 
| + histogram.ExpectTotalCount(kReloadToReloadMetricName, 0); | 
| + histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 0); | 
| + | 
| + NavigationControllerImpl& controller = static_cast<NavigationControllerImpl&>( | 
| + shell()->web_contents()->GetController()); | 
| + | 
| + // ReloadToRefreshContent triggers a reload of ReloadType::MAIN_RESOURCE. The | 
| + // first reload should not be counted. | 
| + controller.ReloadToRefreshContent(false); | 
| + EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | 
| + histogram.ExpectTotalCount(kReloadToReloadMetricName, 0); | 
| + histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 0); | 
| + | 
| + // ReloadBypassingCache triggers a reload of ReloadType::BYPASSING_CACHE. | 
| + // Both metrics should count the consecutive reloads. | 
| + controller.ReloadBypassingCache(false); | 
| + EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | 
| + histogram.ExpectTotalCount(kReloadToReloadMetricName, 1); | 
| + histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 1); | 
| + | 
| + // Triggers another reload of ReloadType::BYPASSING_CACHE. | 
| + // ReloadMainResourceToReload should not be counted here. | 
| + controller.ReloadBypassingCache(false); | 
| + EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | 
| + histogram.ExpectTotalCount(kReloadToReloadMetricName, 2); | 
| + histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 1); | 
| + | 
| + // A browser-initiated navigation should reset the reload tracking | 
| + // information. | 
| + NavigateToURL(shell(), embedded_test_server()->GetURL( | 
| + "/navigation_controller/simple_page_1.html")); | 
| + histogram.ExpectTotalCount(kReloadToReloadMetricName, 2); | 
| + histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 1); | 
| + | 
| + // Then, the next reload should be assumed as the first reload. Metrics | 
| + // should not be changed for the first reload. | 
| + controller.ReloadToRefreshContent(false); | 
| + EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | 
| + histogram.ExpectTotalCount(kReloadToReloadMetricName, 2); | 
| + histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 1); | 
| + | 
| + // Another reload of ReloadType::MAIN_RESOURCE should be counted by both | 
| + // metrics again. | 
| + controller.ReloadToRefreshContent(false); | 
| + EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | 
| + histogram.ExpectTotalCount(kReloadToReloadMetricName, 3); | 
| + 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.
 | 
| + | 
| + // Go back to the first page. Reload tracking information should be reset. | 
| + shell()->web_contents()->GetController().GoBack(); | 
| + EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | 
| + histogram.ExpectTotalCount(kReloadToReloadMetricName, 3); | 
| + histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 2); | 
| + | 
| + controller.ReloadToRefreshContent(false); | 
| + EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | 
| + histogram.ExpectTotalCount(kReloadToReloadMetricName, 3); | 
| + histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 2); | 
| +} | 
| + | 
| } // namespace content |