OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/browser/page_load_metrics/observers/https_engagement_metrics/ht
tps_engagement_page_load_metrics_observer.h" | 5 #include "chrome/browser/page_load_metrics/observers/https_engagement_metrics/ht
tps_engagement_page_load_metrics_observer.h" |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "base/test/histogram_tester.h" | 9 #include "base/test/histogram_tester.h" |
10 #include "base/threading/platform_thread.h" | 10 #include "base/threading/platform_thread.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 destroyed_watcher.Wait(); | 73 destroyed_watcher.Wait(); |
74 } | 74 } |
75 | 75 |
76 // Navigate to a URL in a foreground tab, move it to the background, then | 76 // Navigate to a URL in a foreground tab, move it to the background, then |
77 // close it. Return the upper bound for how long the URL was open in the | 77 // close it. Return the upper bound for how long the URL was open in the |
78 // foreground. | 78 // foreground. |
79 base::TimeDelta NavigateInForegroundAndCloseInBackgroundWithTiming(GURL url) { | 79 base::TimeDelta NavigateInForegroundAndCloseInBackgroundWithTiming(GURL url) { |
80 base::TimeTicks start = base::TimeTicks::Now(); | 80 base::TimeTicks start = base::TimeTicks::Now(); |
81 ui_test_utils::NavigateToURL(browser(), url); | 81 ui_test_utils::NavigateToURL(browser(), url); |
82 ui_test_utils::NavigateToURLWithDisposition( | 82 ui_test_utils::NavigateToURLWithDisposition( |
83 browser(), GURL(chrome::kChromeUIVersionURL), NEW_FOREGROUND_TAB, | 83 browser(), GURL(chrome::kChromeUIVersionURL), |
| 84 WindowOpenDisposition::NEW_FOREGROUND_TAB, |
84 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 85 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
85 base::TimeDelta upper_bound_delta = base::TimeTicks::Now() - start; | 86 base::TimeDelta upper_bound_delta = base::TimeTicks::Now() - start; |
86 | 87 |
87 // Make sure the correct tab is in the foreground. | 88 // Make sure the correct tab is in the foreground. |
88 TabStripModel* tab_strip_model = browser()->tab_strip_model(); | 89 TabStripModel* tab_strip_model = browser()->tab_strip_model(); |
89 EXPECT_EQ(2, tab_strip_model->count()); | 90 EXPECT_EQ(2, tab_strip_model->count()); |
90 EXPECT_EQ(url, tab_strip_model->GetWebContentsAt(0)->GetURL()); | 91 EXPECT_EQ(url, tab_strip_model->GetWebContentsAt(0)->GetURL()); |
91 EXPECT_NE(url, tab_strip_model->GetActiveWebContents()->GetURL()); | 92 EXPECT_NE(url, tab_strip_model->GetActiveWebContents()->GetURL()); |
92 | 93 |
93 content::WebContentsDestroyedWatcher destroyed_watcher( | 94 content::WebContentsDestroyedWatcher destroyed_watcher( |
94 tab_strip_model->GetWebContentsAt(0)); | 95 tab_strip_model->GetWebContentsAt(0)); |
95 EXPECT_TRUE(tab_strip_model->CloseWebContentsAt(0, 0)); | 96 EXPECT_TRUE(tab_strip_model->CloseWebContentsAt(0, 0)); |
96 destroyed_watcher.Wait(); | 97 destroyed_watcher.Wait(); |
97 EXPECT_EQ(1, tab_strip_model->count()); | 98 EXPECT_EQ(1, tab_strip_model->count()); |
98 | 99 |
99 return upper_bound_delta; | 100 return upper_bound_delta; |
100 } | 101 } |
101 | 102 |
102 // Open and close a tab without ever bringing it to the foreground. | 103 // Open and close a tab without ever bringing it to the foreground. |
103 void NavigateInBackgroundAndClose(GURL url) { | 104 void NavigateInBackgroundAndClose(GURL url) { |
104 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIVersionURL)); | 105 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIVersionURL)); |
105 ui_test_utils::NavigateToURLWithDisposition( | 106 ui_test_utils::NavigateToURLWithDisposition( |
106 browser(), url, NEW_BACKGROUND_TAB, | 107 browser(), url, WindowOpenDisposition::NEW_BACKGROUND_TAB, |
107 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 108 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
108 | 109 |
109 // Make sure the correct tab is in the foreground. | 110 // Make sure the correct tab is in the foreground. |
110 TabStripModel* tab_strip_model = browser()->tab_strip_model(); | 111 TabStripModel* tab_strip_model = browser()->tab_strip_model(); |
111 EXPECT_EQ(2, tab_strip_model->count()); | 112 EXPECT_EQ(2, tab_strip_model->count()); |
112 EXPECT_EQ(url, tab_strip_model->GetWebContentsAt(1)->GetURL()); | 113 EXPECT_EQ(url, tab_strip_model->GetWebContentsAt(1)->GetURL()); |
113 EXPECT_NE(url, tab_strip_model->GetActiveWebContents()->GetURL()); | 114 EXPECT_NE(url, tab_strip_model->GetActiveWebContents()->GetURL()); |
114 | 115 |
115 content::WebContentsDestroyedWatcher destroyed_watcher( | 116 content::WebContentsDestroyedWatcher destroyed_watcher( |
116 tab_strip_model->GetWebContentsAt(1)); | 117 tab_strip_model->GetWebContentsAt(1)); |
117 EXPECT_TRUE(tab_strip_model->CloseWebContentsAt(1, 0)); | 118 EXPECT_TRUE(tab_strip_model->CloseWebContentsAt(1, 0)); |
118 destroyed_watcher.Wait(); | 119 destroyed_watcher.Wait(); |
119 EXPECT_EQ(1, tab_strip_model->count()); | 120 EXPECT_EQ(1, tab_strip_model->count()); |
120 } | 121 } |
121 | 122 |
122 // Open a tab in the background, then bring it to the foreground. Return the | 123 // Open a tab in the background, then bring it to the foreground. Return the |
123 // upper bound for how long the URL was open in the foreground. | 124 // upper bound for how long the URL was open in the foreground. |
124 base::TimeDelta NavigateInBackgroundAndCloseInForegroundWithTiming(GURL url) { | 125 base::TimeDelta NavigateInBackgroundAndCloseInForegroundWithTiming(GURL url) { |
125 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIVersionURL)); | 126 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIVersionURL)); |
126 ui_test_utils::NavigateToURLWithDisposition( | 127 ui_test_utils::NavigateToURLWithDisposition( |
127 browser(), url, NEW_BACKGROUND_TAB, | 128 browser(), url, WindowOpenDisposition::NEW_BACKGROUND_TAB, |
128 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 129 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
129 | 130 |
130 // Make sure the correct tab is in the foreground. | 131 // Make sure the correct tab is in the foreground. |
131 TabStripModel* tab_strip_model = browser()->tab_strip_model(); | 132 TabStripModel* tab_strip_model = browser()->tab_strip_model(); |
132 EXPECT_EQ(2, tab_strip_model->count()); | 133 EXPECT_EQ(2, tab_strip_model->count()); |
133 EXPECT_EQ(url, tab_strip_model->GetWebContentsAt(1)->GetURL()); | 134 EXPECT_EQ(url, tab_strip_model->GetWebContentsAt(1)->GetURL()); |
134 EXPECT_NE(url, tab_strip_model->GetActiveWebContents()->GetURL()); | 135 EXPECT_NE(url, tab_strip_model->GetActiveWebContents()->GetURL()); |
135 | 136 |
136 // Close the foreground tab. | 137 // Close the foreground tab. |
137 base::TimeTicks start = base::TimeTicks::Now(); | 138 base::TimeTicks start = base::TimeTicks::Now(); |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 NavigateInForegroundAndCloseWithTiming( | 488 NavigateInForegroundAndCloseWithTiming( |
488 https_test_server_->GetURL("/simple.html")); | 489 https_test_server_->GetURL("/simple.html")); |
489 histogram_tester_.ExpectTotalCount( | 490 histogram_tester_.ExpectTotalCount( |
490 internal::kHttpsEngagementSessionPercentage, 0); | 491 internal::kHttpsEngagementSessionPercentage, 0); |
491 FakeUserMetricsUpload(); | 492 FakeUserMetricsUpload(); |
492 FakeUserMetricsUpload(); | 493 FakeUserMetricsUpload(); |
493 FakeUserMetricsUpload(); | 494 FakeUserMetricsUpload(); |
494 histogram_tester_.ExpectTotalCount( | 495 histogram_tester_.ExpectTotalCount( |
495 internal::kHttpsEngagementSessionPercentage, 1); | 496 internal::kHttpsEngagementSessionPercentage, 1); |
496 } | 497 } |
OLD | NEW |