| 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 <algorithm> |     8 #include <algorithm> | 
|     9 #include <utility> |     9 #include <utility> | 
|    10 #include <vector> |    10 #include <vector> | 
| (...skipping 6672 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  6683   // Navigate to a page, and check if metrics are initialized correctly. |  6683   // Navigate to a page, and check if metrics are initialized correctly. | 
|  6684   EXPECT_TRUE(NavigateToURL( |  6684   EXPECT_TRUE(NavigateToURL( | 
|  6685       shell(), embedded_test_server()->GetURL( |  6685       shell(), embedded_test_server()->GetURL( | 
|  6686                    "/navigation_controller/page_with_links.html"))); |  6686                    "/navigation_controller/page_with_links.html"))); | 
|  6687   histogram.ExpectTotalCount(kReloadToReloadMetricName, 0); |  6687   histogram.ExpectTotalCount(kReloadToReloadMetricName, 0); | 
|  6688   histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 0); |  6688   histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 0); | 
|  6689  |  6689  | 
|  6690   NavigationControllerImpl& controller = static_cast<NavigationControllerImpl&>( |  6690   NavigationControllerImpl& controller = static_cast<NavigationControllerImpl&>( | 
|  6691       shell()->web_contents()->GetController()); |  6691       shell()->web_contents()->GetController()); | 
|  6692  |  6692  | 
|  6693   // ReloadToRefreshContent triggers a reload of ReloadType::MAIN_RESOURCE.  The |  6693   // Reload triggers a reload of ReloadType::MAIN_RESOURCE.  The first reload | 
|  6694   // first reload should not be counted. |  6694   // should not be counted. | 
|  6695   controller.ReloadToRefreshContent(false); |  6695   controller.Reload(false); | 
|  6696   EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |  6696   EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | 
|  6697   histogram.ExpectTotalCount(kReloadToReloadMetricName, 0); |  6697   histogram.ExpectTotalCount(kReloadToReloadMetricName, 0); | 
|  6698   histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 0); |  6698   histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 0); | 
|  6699  |  6699  | 
|  6700   // ReloadBypassingCache triggers a reload of ReloadType::BYPASSING_CACHE. |  6700   // ReloadBypassingCache triggers a reload of ReloadType::BYPASSING_CACHE. | 
|  6701   // Both metrics should count the consecutive reloads. |  6701   // Both metrics should count the consecutive reloads. | 
|  6702   controller.ReloadBypassingCache(false); |  6702   controller.ReloadBypassingCache(false); | 
|  6703   EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |  6703   EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | 
|  6704   histogram.ExpectTotalCount(kReloadToReloadMetricName, 1); |  6704   histogram.ExpectTotalCount(kReloadToReloadMetricName, 1); | 
|  6705   histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 1); |  6705   histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 1); | 
|  6706  |  6706  | 
|  6707   // Triggers another reload of ReloadType::BYPASSING_CACHE. |  6707   // Triggers another reload of ReloadType::BYPASSING_CACHE. | 
|  6708   // ReloadMainResourceToReload should not be counted here. |  6708   // ReloadMainResourceToReload should not be counted here. | 
|  6709   controller.ReloadBypassingCache(false); |  6709   controller.ReloadBypassingCache(false); | 
|  6710   EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |  6710   EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | 
|  6711   histogram.ExpectTotalCount(kReloadToReloadMetricName, 2); |  6711   histogram.ExpectTotalCount(kReloadToReloadMetricName, 2); | 
|  6712   histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 1); |  6712   histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 1); | 
|  6713  |  6713  | 
|  6714   // A browser-initiated navigation should reset the reload tracking |  6714   // A browser-initiated navigation should reset the reload tracking | 
|  6715   // information. |  6715   // information. | 
|  6716   EXPECT_TRUE( |  6716   EXPECT_TRUE( | 
|  6717       NavigateToURL(shell(), embedded_test_server()->GetURL( |  6717       NavigateToURL(shell(), embedded_test_server()->GetURL( | 
|  6718                                  "/navigation_controller/simple_page_1.html"))); |  6718                                  "/navigation_controller/simple_page_1.html"))); | 
|  6719   histogram.ExpectTotalCount(kReloadToReloadMetricName, 2); |  6719   histogram.ExpectTotalCount(kReloadToReloadMetricName, 2); | 
|  6720   histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 1); |  6720   histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 1); | 
|  6721  |  6721  | 
|  6722   // Then, the next reload should be assumed as the first reload.  Metrics |  6722   // Then, the next reload should be assumed as the first reload.  Metrics | 
|  6723   // should not be changed for the first reload. |  6723   // should not be changed for the first reload. | 
|  6724   controller.ReloadToRefreshContent(false); |  6724   controller.Reload(false); | 
|  6725   EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |  6725   EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | 
|  6726   histogram.ExpectTotalCount(kReloadToReloadMetricName, 2); |  6726   histogram.ExpectTotalCount(kReloadToReloadMetricName, 2); | 
|  6727   histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 1); |  6727   histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 1); | 
|  6728  |  6728  | 
|  6729   // Another reload of ReloadType::MAIN_RESOURCE should be counted by both |  6729   // Another reload of ReloadType::MAIN_RESOURCE should be counted by both | 
|  6730   // metrics again. |  6730   // metrics again. | 
|  6731   controller.ReloadToRefreshContent(false); |  6731   controller.Reload(false); | 
|  6732   EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |  6732   EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | 
|  6733   histogram.ExpectTotalCount(kReloadToReloadMetricName, 3); |  6733   histogram.ExpectTotalCount(kReloadToReloadMetricName, 3); | 
|  6734   histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 2); |  6734   histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 2); | 
|  6735  |  6735  | 
|  6736   // A renderer-initiated navigations with no user gesture don't reset reload |  6736   // A renderer-initiated navigations with no user gesture don't reset reload | 
|  6737   // tracking information, and the following reload will be counted by metrics. |  6737   // tracking information, and the following reload will be counted by metrics. | 
|  6738   ExecuteJavaScriptAndWaitForLoadStop( |  6738   ExecuteJavaScriptAndWaitForLoadStop( | 
|  6739       shell()->web_contents(), |  6739       shell()->web_contents(), | 
|  6740       "history.pushState({}, 'page 1', 'simple_page_1.html')"); |  6740       "history.pushState({}, 'page 1', 'simple_page_1.html')"); | 
|  6741   histogram.ExpectTotalCount(kReloadToReloadMetricName, 3); |  6741   histogram.ExpectTotalCount(kReloadToReloadMetricName, 3); | 
|  6742   histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 2); |  6742   histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 2); | 
|  6743   ExecuteJavaScriptAndWaitForLoadStop(shell()->web_contents(), |  6743   ExecuteJavaScriptAndWaitForLoadStop(shell()->web_contents(), | 
|  6744                                       "location.href='simple_page_2.html'"); |  6744                                       "location.href='simple_page_2.html'"); | 
|  6745   histogram.ExpectTotalCount(kReloadToReloadMetricName, 3); |  6745   histogram.ExpectTotalCount(kReloadToReloadMetricName, 3); | 
|  6746   histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 2); |  6746   histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 2); | 
|  6747  |  6747  | 
|  6748   controller.ReloadToRefreshContent(false); |  6748   controller.Reload(false); | 
|  6749   EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |  6749   EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | 
|  6750   histogram.ExpectTotalCount(kReloadToReloadMetricName, 4); |  6750   histogram.ExpectTotalCount(kReloadToReloadMetricName, 4); | 
|  6751   histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 3); |  6751   histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 3); | 
|  6752  |  6752  | 
|  6753   // Go back to the first page. Reload tracking information should be reset. |  6753   // Go back to the first page. Reload tracking information should be reset. | 
|  6754   shell()->web_contents()->GetController().GoBack(); |  6754   shell()->web_contents()->GetController().GoBack(); | 
|  6755   EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |  6755   EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | 
|  6756   histogram.ExpectTotalCount(kReloadToReloadMetricName, 4); |  6756   histogram.ExpectTotalCount(kReloadToReloadMetricName, 4); | 
|  6757   histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 3); |  6757   histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 3); | 
|  6758  |  6758  | 
|  6759   controller.ReloadToRefreshContent(false); |  6759   controller.Reload(false); | 
|  6760   EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |  6760   EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | 
|  6761   histogram.ExpectTotalCount(kReloadToReloadMetricName, 4); |  6761   histogram.ExpectTotalCount(kReloadToReloadMetricName, 4); | 
|  6762   histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 3); |  6762   histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 3); | 
|  6763 } |  6763 } | 
|  6764  |  6764  | 
|  6765 // Check that the referrer is stored inside FrameNavigationEntry for subframes. |  6765 // Check that the referrer is stored inside FrameNavigationEntry for subframes. | 
|  6766 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |  6766 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | 
|  6767                        RefererStoredForSubFrame) { |  6767                        RefererStoredForSubFrame) { | 
|  6768   if (!SiteIsolationPolicy::UseSubframeNavigationEntries()) |  6768   if (!SiteIsolationPolicy::UseSubframeNavigationEntries()) | 
|  6769     return; |  6769     return; | 
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  7022   NavigationHandleCommitObserver handle_observer(shell()->web_contents(), |  7022   NavigationHandleCommitObserver handle_observer(shell()->web_contents(), | 
|  7023                                                  kFragmentURL); |  7023                                                  kFragmentURL); | 
|  7024   EXPECT_TRUE(NavigateToURL(shell(), kFragmentURL)); |  7024   EXPECT_TRUE(NavigateToURL(shell(), kFragmentURL)); | 
|  7025  |  7025  | 
|  7026   EXPECT_TRUE(handle_observer.has_committed()); |  7026   EXPECT_TRUE(handle_observer.has_committed()); | 
|  7027   EXPECT_TRUE(handle_observer.was_same_page()); |  7027   EXPECT_TRUE(handle_observer.was_same_page()); | 
|  7028   EXPECT_FALSE(handle_observer.was_renderer_initiated()); |  7028   EXPECT_FALSE(handle_observer.was_renderer_initiated()); | 
|  7029 } |  7029 } | 
|  7030  |  7030  | 
|  7031 }  // namespace content |  7031 }  // namespace content | 
| OLD | NEW |