Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <memory> | |
| 6 #include <string> | |
| 7 #include <unordered_set> | |
| 8 #include <utility> | |
| 9 #include <vector> | |
| 10 | |
| 5 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 6 #include "base/files/scoped_temp_dir.h" | 12 #include "base/files/scoped_temp_dir.h" |
| 7 #include "base/logging.h" | 13 #include "base/logging.h" |
| 8 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/ptr_util.h" | |
| 9 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 10 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
| 11 #include "base/test/histogram_tester.h" | 18 #include "base/test/histogram_tester.h" |
| 12 #include "base/threading/thread_restrictions.h" | 19 #include "base/threading/thread_restrictions.h" |
| 13 #include "base/time/time.h" | 20 #include "base/time/time.h" |
| 14 #include "build/build_config.h" | 21 #include "build/build_config.h" |
| 15 #include "chrome/browser/lifetime/keep_alive_types.h" | 22 #include "chrome/browser/lifetime/keep_alive_types.h" |
| 16 #include "chrome/browser/lifetime/scoped_keep_alive.h" | 23 #include "chrome/browser/lifetime/scoped_keep_alive.h" |
| 17 #include "chrome/browser/page_load_metrics/metrics_web_contents_observer.h" | 24 #include "chrome/browser/page_load_metrics/metrics_web_contents_observer.h" |
| 18 #include "chrome/browser/page_load_metrics/observers/aborts_page_load_metrics_ob server.h" | 25 #include "chrome/browser/page_load_metrics/observers/aborts_page_load_metrics_ob server.h" |
| 19 #include "chrome/browser/page_load_metrics/observers/core_page_load_metrics_obse rver.h" | 26 #include "chrome/browser/page_load_metrics/observers/core_page_load_metrics_obse rver.h" |
| 20 #include "chrome/browser/page_load_metrics/observers/document_write_page_load_me trics_observer.h" | 27 #include "chrome/browser/page_load_metrics/observers/document_write_page_load_me trics_observer.h" |
| 21 #include "chrome/browser/page_load_metrics/observers/no_state_prefetch_page_load _metrics_observer.h" | 28 #include "chrome/browser/page_load_metrics/observers/no_state_prefetch_page_load _metrics_observer.h" |
| 29 #include "chrome/browser/page_load_metrics/observers/session_restore_page_load_m etrics_observer.h" | |
| 22 #include "chrome/browser/page_load_metrics/observers/use_counter_page_load_metri cs_observer.h" | 30 #include "chrome/browser/page_load_metrics/observers/use_counter_page_load_metri cs_observer.h" |
| 31 #include "chrome/browser/page_load_metrics/page_load_metrics_initialize.h" | |
| 23 #include "chrome/browser/page_load_metrics/page_load_tracker.h" | 32 #include "chrome/browser/page_load_metrics/page_load_tracker.h" |
| 24 #include "chrome/browser/prefs/session_startup_pref.h" | 33 #include "chrome/browser/prefs/session_startup_pref.h" |
| 25 #include "chrome/browser/prerender/prerender_histograms.h" | 34 #include "chrome/browser/prerender/prerender_histograms.h" |
| 26 #include "chrome/browser/prerender/prerender_origin.h" | 35 #include "chrome/browser/prerender/prerender_origin.h" |
| 27 #include "chrome/browser/profiles/profile.h" | 36 #include "chrome/browser/profiles/profile.h" |
| 37 #include "chrome/browser/sessions/session_restore.h" | |
| 38 #include "chrome/browser/sessions/session_restore_test_helper.h" | |
| 28 #include "chrome/browser/sessions/session_service_factory.h" | 39 #include "chrome/browser/sessions/session_service_factory.h" |
| 29 #include "chrome/browser/sessions/session_service_test_helper.h" | 40 #include "chrome/browser/sessions/session_service_test_helper.h" |
| 30 #include "chrome/browser/ui/browser.h" | 41 #include "chrome/browser/ui/browser.h" |
| 31 #include "chrome/browser/ui/browser_commands.h" | 42 #include "chrome/browser/ui/browser_commands.h" |
| 32 #include "chrome/browser/ui/browser_navigator_params.h" | 43 #include "chrome/browser/ui/browser_navigator_params.h" |
| 33 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 44 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 34 #include "chrome/common/chrome_features.h" | 45 #include "chrome/common/chrome_features.h" |
| 35 #include "chrome/common/pref_names.h" | 46 #include "chrome/common/pref_names.h" |
| 36 #include "chrome/common/url_constants.h" | 47 #include "chrome/common/url_constants.h" |
| 37 #include "chrome/test/base/in_process_browser_test.h" | 48 #include "chrome/test/base/in_process_browser_test.h" |
| 38 #include "chrome/test/base/ui_test_utils.h" | 49 #include "chrome/test/base/ui_test_utils.h" |
| 39 #include "components/prefs/pref_service.h" | 50 #include "components/prefs/pref_service.h" |
| 51 #include "components/sessions/core/serialized_navigation_entry.h" | |
| 52 #include "components/sessions/core/serialized_navigation_entry_test_helper.h" | |
| 40 #include "content/public/browser/browser_thread.h" | 53 #include "content/public/browser/browser_thread.h" |
| 41 #include "content/public/browser/render_process_host.h" | 54 #include "content/public/browser/render_process_host.h" |
| 42 #include "content/public/browser/render_view_host.h" | 55 #include "content/public/browser/render_view_host.h" |
| 43 #include "content/public/common/content_features.h" | 56 #include "content/public/common/content_features.h" |
| 44 #include "content/public/common/content_switches.h" | 57 #include "content/public/common/content_switches.h" |
| 58 #include "content/public/common/referrer.h" | |
| 45 #include "content/public/test/browser_test_utils.h" | 59 #include "content/public/test/browser_test_utils.h" |
| 46 #include "content/public/test/download_test_observer.h" | 60 #include "content/public/test/download_test_observer.h" |
| 47 #include "net/base/net_errors.h" | 61 #include "net/base/net_errors.h" |
| 48 #include "net/dns/mock_host_resolver.h" | 62 #include "net/dns/mock_host_resolver.h" |
| 49 #include "net/http/failing_http_transaction_factory.h" | 63 #include "net/http/failing_http_transaction_factory.h" |
| 50 #include "net/http/http_cache.h" | 64 #include "net/http/http_cache.h" |
| 51 #include "net/test/embedded_test_server/embedded_test_server.h" | 65 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 52 #include "net/test/url_request/url_request_failed_job.h" | 66 #include "net/test/url_request/url_request_failed_job.h" |
| 53 #include "net/url_request/url_request_context.h" | 67 #include "net/url_request/url_request_context.h" |
| 54 #include "net/url_request/url_request_context_getter.h" | 68 #include "net/url_request/url_request_context_getter.h" |
| 55 #include "third_party/WebKit/public/platform/web_feature.mojom.h" | 69 #include "third_party/WebKit/public/platform/web_feature.mojom.h" |
| 70 #include "url/gurl.h" | |
| 56 | 71 |
| 57 namespace { | 72 namespace { |
| 58 | 73 |
| 59 void FailAllNetworkTransactions(net::URLRequestContextGetter* getter) { | 74 void FailAllNetworkTransactions(net::URLRequestContextGetter* getter) { |
| 60 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 75 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 61 net::HttpCache* cache( | 76 net::HttpCache* cache( |
| 62 getter->GetURLRequestContext()->http_transaction_factory()->GetCache()); | 77 getter->GetURLRequestContext()->http_transaction_factory()->GetCache()); |
| 63 DCHECK(cache); | 78 DCHECK(cache); |
| 64 std::unique_ptr<net::FailingHttpTransactionFactory> factory = | 79 std::unique_ptr<net::FailingHttpTransactionFactory> factory = |
| 65 base::MakeUnique<net::FailingHttpTransactionFactory>(cache->GetSession(), | 80 base::MakeUnique<net::FailingHttpTransactionFactory>(cache->GetSession(), |
| (...skipping 1045 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1111 } | 1126 } |
| 1112 | 1127 |
| 1113 class SessionRestorePageLoadMetricsBrowserTest | 1128 class SessionRestorePageLoadMetricsBrowserTest |
| 1114 : public PageLoadMetricsBrowserTest { | 1129 : public PageLoadMetricsBrowserTest { |
| 1115 public: | 1130 public: |
| 1116 SessionRestorePageLoadMetricsBrowserTest() {} | 1131 SessionRestorePageLoadMetricsBrowserTest() {} |
| 1117 | 1132 |
| 1118 // PageLoadMetricsBrowserTest: | 1133 // PageLoadMetricsBrowserTest: |
| 1119 void SetUpOnMainThread() override { | 1134 void SetUpOnMainThread() override { |
| 1120 PageLoadMetricsBrowserTest::SetUpOnMainThread(); | 1135 PageLoadMetricsBrowserTest::SetUpOnMainThread(); |
| 1121 SessionStartupPref::SetStartupPref( | |
| 1122 browser()->profile(), SessionStartupPref(SessionStartupPref::LAST)); | |
| 1123 ASSERT_TRUE(embedded_test_server()->Start()); | 1136 ASSERT_TRUE(embedded_test_server()->Start()); |
| 1124 #if defined(OS_CHROMEOS) | |
| 1125 SessionServiceTestHelper helper( | |
| 1126 SessionServiceFactory::GetForProfile(browser()->profile())); | |
| 1127 helper.SetForceBrowserNotAliveWithNoWindows(true); | |
| 1128 helper.ReleaseService(); | |
| 1129 #endif | |
| 1130 } | 1137 } |
| 1131 | 1138 |
| 1132 Browser* QuitBrowserAndRestore(Browser* browser) { | 1139 Browser* QuitBrowserAndRestore(Browser* browser) { |
| 1133 Profile* profile = browser->profile(); | 1140 Profile* profile = browser->profile(); |
| 1134 | 1141 |
| 1142 SessionStartupPref::SetStartupPref( | |
| 1143 profile, SessionStartupPref(SessionStartupPref::LAST)); | |
| 1144 #if defined(OS_CHROMEOS) | |
| 1145 SessionServiceTestHelper helper( | |
| 1146 SessionServiceFactory::GetForProfile(profile)); | |
| 1147 helper.SetForceBrowserNotAliveWithNoWindows(true); | |
| 1148 helper.ReleaseService(); | |
| 1149 #endif | |
| 1150 | |
| 1135 std::unique_ptr<ScopedKeepAlive> keep_alive(new ScopedKeepAlive( | 1151 std::unique_ptr<ScopedKeepAlive> keep_alive(new ScopedKeepAlive( |
| 1136 KeepAliveOrigin::SESSION_RESTORE, KeepAliveRestartOption::DISABLED)); | 1152 KeepAliveOrigin::SESSION_RESTORE, KeepAliveRestartOption::DISABLED)); |
| 1137 CloseBrowserSynchronously(browser); | 1153 CloseBrowserSynchronously(browser); |
| 1138 | 1154 |
| 1139 // Create a new window, which should trigger session restore. | 1155 // Create a new window, which should trigger session restore. |
| 1140 chrome::NewEmptyWindow(profile); | 1156 chrome::NewEmptyWindow(profile); |
| 1141 ui_test_utils::BrowserAddedObserver window_observer; | 1157 ui_test_utils::BrowserAddedObserver window_observer; |
| 1142 return window_observer.WaitForSingleNewBrowser(); | 1158 SessionRestoreTestHelper restore_observer; |
| 1159 | |
| 1160 Browser* new_browser = window_observer.WaitForSingleNewBrowser(); | |
| 1161 restore_observer.Wait(); | |
| 1162 return new_browser; | |
| 1143 } | 1163 } |
| 1144 | 1164 |
| 1145 void WaitForTabsToLoad(Browser* browser) { | 1165 void WaitForTabsToLoad(Browser* browser) { |
| 1146 for (int i = 0; i < browser->tab_strip_model()->count(); ++i) { | 1166 for (int i = 0; i < browser->tab_strip_model()->count(); ++i) { |
| 1147 content::WebContents* contents = | 1167 content::WebContents* contents = |
| 1148 browser->tab_strip_model()->GetWebContentsAt(i); | 1168 browser->tab_strip_model()->GetWebContentsAt(i); |
| 1149 contents->GetController().LoadIfNecessary(); | 1169 contents->GetController().LoadIfNecessary(); |
| 1150 content::WaitForLoadStop(contents); | 1170 ASSERT_TRUE(content::WaitForLoadStop(contents)); |
| 1151 } | 1171 } |
| 1152 } | 1172 } |
| 1153 | 1173 |
| 1174 // The PageLoadMetricsWaiter can observe first meaningful paints on these test | |
| 1175 // pages while not on other simple pages such as /title1.html. | |
| 1154 GURL GetTestURL() const { | 1176 GURL GetTestURL() const { |
| 1155 return embedded_test_server()->GetURL("/title1.html"); | 1177 return embedded_test_server()->GetURL( |
| 1178 "/page_load_metrics/main_frame_with_iframe.html"); | |
| 1179 } | |
| 1180 | |
| 1181 GURL GetTestURL2() const { | |
| 1182 return embedded_test_server()->GetURL("/title2.html"); | |
| 1183 } | |
| 1184 | |
| 1185 void ExpectFirstPaintMetricsTotalCount(int expected_total_count) const { | |
| 1186 histogram_tester_.ExpectTotalCount( | |
| 1187 internal::kHistogramSessionRestoreForegroundTabFirstPaint, | |
| 1188 expected_total_count); | |
| 1189 histogram_tester_.ExpectTotalCount( | |
| 1190 internal::kHistogramSessionRestoreForegroundTabFirstContentfulPaint, | |
| 1191 expected_total_count); | |
| 1192 histogram_tester_.ExpectTotalCount( | |
| 1193 internal::kHistogramSessionRestoreForegroundTabFirstMeaningfulPaint, | |
| 1194 expected_total_count); | |
| 1156 } | 1195 } |
| 1157 | 1196 |
| 1158 private: | 1197 private: |
| 1159 DISALLOW_COPY_AND_ASSIGN(SessionRestorePageLoadMetricsBrowserTest); | 1198 DISALLOW_COPY_AND_ASSIGN(SessionRestorePageLoadMetricsBrowserTest); |
| 1160 }; | 1199 }; |
| 1161 | 1200 |
| 1201 class SessionRestoreFirstMeaningfulPaintWaiter : public SessionRestoreObserver { | |
|
Bryan McQuade
2017/08/10 12:36:05
let's call this SessionRestorePaintWater and wait
ducbui
2017/08/10 17:21:14
Done.
| |
| 1202 public: | |
| 1203 SessionRestoreFirstMeaningfulPaintWaiter() { | |
| 1204 SessionRestore::AddObserver(this); | |
| 1205 } | |
| 1206 ~SessionRestoreFirstMeaningfulPaintWaiter() { | |
| 1207 SessionRestore::RemoveObserver(this); | |
| 1208 } | |
| 1209 | |
| 1210 // SessionRestoreObserver implementation: | |
| 1211 void OnWillRestoreTab(content::WebContents* contents) override { | |
| 1212 chrome::InitializePageLoadMetricsForWebContents(contents); | |
| 1213 auto waiter = base::MakeUnique<PageLoadMetricsWaiter>(contents); | |
| 1214 waiter->AddPageExpectation(TimingField::FIRST_MEANINGFUL_PAINT); | |
|
Bryan McQuade
2017/08/10 12:36:05
we should include all TimingFields we're testing f
ducbui
2017/08/10 17:21:14
Done.
| |
| 1215 waiters_[contents] = std::move(waiter); | |
| 1216 } | |
| 1217 | |
| 1218 // First meaningful paints occur only on foreground tabs. | |
| 1219 void WaitForForegroundTabs() { | |
|
Bryan McQuade
2017/08/10 12:36:05
it strikes me that if OnWillRestoreTab isn't calle
ducbui
2017/08/10 17:21:14
Done.
| |
| 1220 for (auto iter = waiters_.begin(); iter != waiters_.end(); ++iter) { | |
| 1221 if (iter->first->IsVisible()) | |
| 1222 iter->second->Wait(); | |
| 1223 } | |
| 1224 } | |
| 1225 | |
| 1226 private: | |
| 1227 std::unordered_map<content::WebContents*, | |
| 1228 std::unique_ptr<PageLoadMetricsWaiter>> | |
| 1229 waiters_; | |
| 1230 | |
| 1231 DISALLOW_COPY_AND_ASSIGN(SessionRestoreFirstMeaningfulPaintWaiter); | |
| 1232 }; | |
| 1233 | |
| 1162 IN_PROC_BROWSER_TEST_F(SessionRestorePageLoadMetricsBrowserTest, | 1234 IN_PROC_BROWSER_TEST_F(SessionRestorePageLoadMetricsBrowserTest, |
| 1163 InitialVisibilityOfSingleRestoredTab) { | 1235 InitialVisibilityOfSingleRestoredTab) { |
| 1164 ui_test_utils::NavigateToURL(browser(), GetTestURL()); | 1236 ui_test_utils::NavigateToURL(browser(), GetTestURL()); |
| 1165 histogram_tester_.ExpectTotalCount( | 1237 histogram_tester_.ExpectTotalCount( |
| 1166 page_load_metrics::internal::kPageLoadStartedInForeground, 1); | 1238 page_load_metrics::internal::kPageLoadStartedInForeground, 1); |
| 1167 histogram_tester_.ExpectBucketCount( | 1239 histogram_tester_.ExpectBucketCount( |
| 1168 page_load_metrics::internal::kPageLoadStartedInForeground, true, 1); | 1240 page_load_metrics::internal::kPageLoadStartedInForeground, true, 1); |
| 1169 | 1241 |
| 1170 Browser* new_browser = QuitBrowserAndRestore(browser()); | 1242 Browser* new_browser = QuitBrowserAndRestore(browser()); |
| 1171 WaitForTabsToLoad(new_browser); | 1243 ASSERT_NO_FATAL_FAILURE(WaitForTabsToLoad(new_browser)); |
| 1172 | 1244 |
| 1173 histogram_tester_.ExpectTotalCount( | 1245 histogram_tester_.ExpectTotalCount( |
| 1174 page_load_metrics::internal::kPageLoadStartedInForeground, 2); | 1246 page_load_metrics::internal::kPageLoadStartedInForeground, 2); |
| 1175 histogram_tester_.ExpectBucketCount( | 1247 histogram_tester_.ExpectBucketCount( |
| 1176 page_load_metrics::internal::kPageLoadStartedInForeground, true, 2); | 1248 page_load_metrics::internal::kPageLoadStartedInForeground, true, 2); |
| 1177 } | 1249 } |
| 1178 | 1250 |
| 1179 IN_PROC_BROWSER_TEST_F(SessionRestorePageLoadMetricsBrowserTest, | 1251 IN_PROC_BROWSER_TEST_F(SessionRestorePageLoadMetricsBrowserTest, |
| 1180 InitialVisibilityOfMultipleRestoredTabs) { | 1252 InitialVisibilityOfMultipleRestoredTabs) { |
| 1181 ui_test_utils::NavigateToURL(browser(), GetTestURL()); | 1253 ui_test_utils::NavigateToURL(browser(), GetTestURL()); |
| 1182 ui_test_utils::NavigateToURLWithDisposition( | 1254 ui_test_utils::NavigateToURLWithDisposition( |
| 1183 browser(), GetTestURL(), WindowOpenDisposition::NEW_BACKGROUND_TAB, | 1255 browser(), GetTestURL(), WindowOpenDisposition::NEW_BACKGROUND_TAB, |
| 1184 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 1256 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 1185 histogram_tester_.ExpectTotalCount( | 1257 histogram_tester_.ExpectTotalCount( |
| 1186 page_load_metrics::internal::kPageLoadStartedInForeground, 2); | 1258 page_load_metrics::internal::kPageLoadStartedInForeground, 2); |
| 1187 histogram_tester_.ExpectBucketCount( | 1259 histogram_tester_.ExpectBucketCount( |
| 1188 page_load_metrics::internal::kPageLoadStartedInForeground, false, 1); | 1260 page_load_metrics::internal::kPageLoadStartedInForeground, false, 1); |
| 1189 | 1261 |
| 1190 Browser* new_browser = QuitBrowserAndRestore(browser()); | 1262 Browser* new_browser = QuitBrowserAndRestore(browser()); |
| 1191 WaitForTabsToLoad(new_browser); | 1263 ASSERT_NO_FATAL_FAILURE(WaitForTabsToLoad(new_browser)); |
| 1192 | 1264 |
| 1193 TabStripModel* tab_strip = new_browser->tab_strip_model(); | 1265 TabStripModel* tab_strip = new_browser->tab_strip_model(); |
| 1194 ASSERT_TRUE(tab_strip); | 1266 ASSERT_TRUE(tab_strip); |
| 1195 ASSERT_EQ(2, tab_strip->count()); | 1267 ASSERT_EQ(2, tab_strip->count()); |
| 1196 | 1268 |
| 1197 histogram_tester_.ExpectTotalCount( | 1269 histogram_tester_.ExpectTotalCount( |
| 1198 page_load_metrics::internal::kPageLoadStartedInForeground, 4); | 1270 page_load_metrics::internal::kPageLoadStartedInForeground, 4); |
| 1199 histogram_tester_.ExpectBucketCount( | 1271 histogram_tester_.ExpectBucketCount( |
| 1200 page_load_metrics::internal::kPageLoadStartedInForeground, true, 2); | 1272 page_load_metrics::internal::kPageLoadStartedInForeground, true, 2); |
| 1201 histogram_tester_.ExpectBucketCount( | 1273 histogram_tester_.ExpectBucketCount( |
| 1202 page_load_metrics::internal::kPageLoadStartedInForeground, false, 2); | 1274 page_load_metrics::internal::kPageLoadStartedInForeground, false, 2); |
| 1203 } | 1275 } |
| 1276 | |
| 1277 IN_PROC_BROWSER_TEST_F(SessionRestorePageLoadMetricsBrowserTest, | |
| 1278 NoSessionRestore) { | |
| 1279 ui_test_utils::NavigateToURL(browser(), GetTestURL()); | |
| 1280 ExpectFirstPaintMetricsTotalCount(0); | |
| 1281 } | |
| 1282 | |
| 1283 IN_PROC_BROWSER_TEST_F(SessionRestorePageLoadMetricsBrowserTest, | |
| 1284 SingleTabSessionRestore) { | |
| 1285 ui_test_utils::NavigateToURL(browser(), GetTestURL()); | |
| 1286 | |
| 1287 SessionRestoreFirstMeaningfulPaintWaiter session_restore_fmp_waiter; | |
| 1288 QuitBrowserAndRestore(browser()); | |
| 1289 | |
| 1290 session_restore_fmp_waiter.WaitForForegroundTabs(); | |
| 1291 ExpectFirstPaintMetricsTotalCount(1); | |
| 1292 } | |
| 1293 | |
| 1294 IN_PROC_BROWSER_TEST_F(SessionRestorePageLoadMetricsBrowserTest, | |
| 1295 MultipleTabsSessionRestore) { | |
| 1296 ui_test_utils::NavigateToURL(browser(), GetTestURL()); | |
| 1297 ui_test_utils::NavigateToURLWithDisposition( | |
| 1298 browser(), GetTestURL(), WindowOpenDisposition::NEW_BACKGROUND_TAB, | |
| 1299 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | |
| 1300 | |
| 1301 SessionRestoreFirstMeaningfulPaintWaiter session_restore_fmp_waiter; | |
| 1302 Browser* new_browser = QuitBrowserAndRestore(browser()); | |
| 1303 | |
| 1304 TabStripModel* tab_strip = new_browser->tab_strip_model(); | |
| 1305 ASSERT_TRUE(tab_strip); | |
| 1306 ASSERT_EQ(2, tab_strip->count()); | |
| 1307 | |
| 1308 session_restore_fmp_waiter.WaitForForegroundTabs(); | |
| 1309 ASSERT_NO_FATAL_FAILURE(WaitForTabsToLoad(new_browser)); | |
|
Bryan McQuade
2017/08/10 12:36:05
is the call to WaitForTabsToLoad needed here? seem
ducbui
2017/08/10 17:21:14
Acknowledged. I is unnecessary and I will remove i
| |
| 1310 | |
| 1311 // Only metrics of the initial foreground tab are recorded. | |
| 1312 ExpectFirstPaintMetricsTotalCount(1); | |
| 1313 } | |
| 1314 | |
| 1315 IN_PROC_BROWSER_TEST_F(SessionRestorePageLoadMetricsBrowserTest, | |
| 1316 NavigationDuringSessionRestore) { | |
| 1317 ui_test_utils::NavigateToURL(browser(), GetTestURL2()); | |
| 1318 Browser* new_browser = QuitBrowserAndRestore(browser()); | |
| 1319 ASSERT_NO_FATAL_FAILURE(WaitForTabsToLoad(new_browser)); | |
| 1320 | |
| 1321 content::WebContents* active_web_contents = | |
| 1322 new_browser->tab_strip_model()->GetActiveWebContents(); | |
| 1323 auto waiter = base::MakeUnique<PageLoadMetricsWaiter>(active_web_contents); | |
| 1324 waiter->AddPageExpectation(TimingField::FIRST_MEANINGFUL_PAINT); | |
| 1325 | |
| 1326 ui_test_utils::NavigateToURL(new_browser, GetTestURL()); | |
|
Bryan McQuade
2017/08/10 12:36:05
is the purpose of this test to verify that this pa
ducbui
2017/08/10 17:21:14
Yes, this test case checks that the second navigat
| |
| 1327 | |
| 1328 // Number of first paints of the first navigation which are counted for | |
| 1329 // session restore. They are measured here because some paints of the previous | |
| 1330 // navigation happen inside ui_test_utils::NavigateToURL(). | |
| 1331 size_t first_paints = | |
| 1332 histogram_tester_ | |
| 1333 .GetTotalCountsForPrefix( | |
| 1334 internal::kHistogramSessionRestoreForegroundTabFirstPaint) | |
| 1335 .size(); | |
| 1336 size_t first_contentful_paints = | |
| 1337 histogram_tester_ | |
| 1338 .GetTotalCountsForPrefix( | |
| 1339 internal:: | |
| 1340 kHistogramSessionRestoreForegroundTabFirstContentfulPaint) | |
| 1341 .size(); | |
| 1342 size_t first_meaningful_paints = | |
| 1343 histogram_tester_ | |
| 1344 .GetTotalCountsForPrefix( | |
| 1345 internal:: | |
| 1346 kHistogramSessionRestoreForegroundTabFirstMeaningfulPaint) | |
| 1347 .size(); | |
| 1348 EXPECT_LE(first_paints, 1u); | |
| 1349 EXPECT_LE(first_contentful_paints, 1u); | |
| 1350 EXPECT_LE(first_meaningful_paints, 1u); | |
| 1351 | |
| 1352 waiter->Wait(); | |
| 1353 | |
| 1354 // No metrics recorded for the second navigation because the tab navigated | |
| 1355 // away during session restore. | |
| 1356 EXPECT_EQ( | |
| 1357 0u, histogram_tester_ | |
| 1358 .GetTotalCountsForPrefix( | |
| 1359 internal::kHistogramSessionRestoreForegroundTabFirstPaint) | |
| 1360 .size() - | |
| 1361 first_paints); | |
| 1362 EXPECT_EQ( | |
| 1363 0u, | |
| 1364 histogram_tester_ | |
| 1365 .GetTotalCountsForPrefix( | |
| 1366 internal:: | |
| 1367 kHistogramSessionRestoreForegroundTabFirstContentfulPaint) | |
| 1368 .size() - | |
| 1369 first_contentful_paints); | |
| 1370 EXPECT_EQ( | |
| 1371 0u, | |
| 1372 histogram_tester_ | |
| 1373 .GetTotalCountsForPrefix( | |
| 1374 internal:: | |
| 1375 kHistogramSessionRestoreForegroundTabFirstMeaningfulPaint) | |
| 1376 .size() - | |
| 1377 first_meaningful_paints); | |
| 1378 } | |
| 1379 | |
| 1380 IN_PROC_BROWSER_TEST_F(SessionRestorePageLoadMetricsBrowserTest, | |
| 1381 LoadingAfterSessionRestore) { | |
| 1382 ui_test_utils::NavigateToURL(browser(), GetTestURL()); | |
| 1383 | |
| 1384 Browser* new_browser = nullptr; | |
| 1385 { | |
| 1386 SessionRestoreFirstMeaningfulPaintWaiter session_restore_fmp_waiter; | |
| 1387 new_browser = QuitBrowserAndRestore(browser()); | |
| 1388 | |
| 1389 session_restore_fmp_waiter.WaitForForegroundTabs(); | |
| 1390 ExpectFirstPaintMetricsTotalCount(1); | |
| 1391 } | |
| 1392 | |
| 1393 // Load a new page after session restore. | |
| 1394 auto waiter = base::MakeUnique<PageLoadMetricsWaiter>( | |
| 1395 new_browser->tab_strip_model()->GetActiveWebContents()); | |
| 1396 waiter->AddPageExpectation(TimingField::FIRST_MEANINGFUL_PAINT); | |
| 1397 ui_test_utils::NavigateToURL(new_browser, GetTestURL()); | |
| 1398 waiter->Wait(); | |
| 1399 | |
| 1400 // No more metrics because the navigation is after session restore. | |
| 1401 ExpectFirstPaintMetricsTotalCount(1); | |
| 1402 } | |
| 1403 | |
| 1404 IN_PROC_BROWSER_TEST_F(SessionRestorePageLoadMetricsBrowserTest, | |
| 1405 InitialForegroundTabChanged) { | |
| 1406 ui_test_utils::NavigateToURL(browser(), GetTestURL()); | |
| 1407 ui_test_utils::NavigateToURLWithDisposition( | |
| 1408 browser(), GetTestURL(), WindowOpenDisposition::NEW_BACKGROUND_TAB, | |
| 1409 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | |
| 1410 | |
| 1411 SessionRestoreFirstMeaningfulPaintWaiter session_restore_fmp_waiter; | |
| 1412 Browser* new_browser = QuitBrowserAndRestore(browser()); | |
| 1413 | |
| 1414 // Change the foreground tab before the first meaningful paint. | |
| 1415 TabStripModel* tab_strip = new_browser->tab_strip_model(); | |
| 1416 ASSERT_TRUE(tab_strip); | |
| 1417 ASSERT_EQ(2, tab_strip->count()); | |
| 1418 ASSERT_EQ(0, tab_strip->active_index()); | |
| 1419 tab_strip->ActivateTabAt(1, true); | |
| 1420 | |
| 1421 session_restore_fmp_waiter.WaitForForegroundTabs(); | |
| 1422 | |
| 1423 // No metrics were recorded because initial foreground tab was switched away. | |
| 1424 ExpectFirstPaintMetricsTotalCount(0); | |
| 1425 } | |
| 1426 | |
| 1427 IN_PROC_BROWSER_TEST_F(SessionRestorePageLoadMetricsBrowserTest, | |
| 1428 MultipleSessionRestores) { | |
| 1429 ui_test_utils::NavigateToURL(browser(), GetTestURL()); | |
| 1430 | |
| 1431 Browser* current_browser = browser(); | |
| 1432 const int num_session_restores = 2; | |
| 1433 for (int i = 1; i <= num_session_restores; ++i) { | |
| 1434 SessionRestoreFirstMeaningfulPaintWaiter session_restore_fmp_waiter; | |
| 1435 current_browser = QuitBrowserAndRestore(current_browser); | |
| 1436 session_restore_fmp_waiter.WaitForForegroundTabs(); | |
| 1437 ExpectFirstPaintMetricsTotalCount(i); | |
| 1438 } | |
| 1439 } | |
| 1440 | |
| 1441 IN_PROC_BROWSER_TEST_F(SessionRestorePageLoadMetricsBrowserTest, | |
| 1442 RestoreForeignTab) { | |
| 1443 sessions::SerializedNavigationEntry nav = | |
| 1444 sessions::SerializedNavigationEntryTestHelper::CreateNavigation( | |
| 1445 GetTestURL().spec(), "one"); | |
| 1446 | |
| 1447 // Set up the restore data. | |
| 1448 sync_pb::SessionTab sync_data; | |
| 1449 sync_data.set_tab_visual_index(0); | |
| 1450 sync_data.set_current_navigation_index(1); | |
| 1451 sync_data.set_pinned(false); | |
| 1452 sync_data.add_navigation()->CopyFrom(nav.ToSyncData()); | |
| 1453 | |
| 1454 sessions::SessionTab tab; | |
| 1455 tab.SetFromSyncData(sync_data, base::Time::Now()); | |
| 1456 ASSERT_EQ(1, browser()->tab_strip_model()->count()); | |
| 1457 | |
| 1458 // Restore in the current tab. | |
| 1459 content::WebContents* tab_contents = nullptr; | |
| 1460 { | |
| 1461 SessionRestoreFirstMeaningfulPaintWaiter session_restore_fmp_waiter; | |
| 1462 tab_contents = SessionRestore::RestoreForeignSessionTab( | |
| 1463 browser()->tab_strip_model()->GetActiveWebContents(), tab, | |
| 1464 WindowOpenDisposition::CURRENT_TAB); | |
| 1465 ASSERT_EQ(1, browser()->tab_strip_model()->count()); | |
| 1466 ASSERT_TRUE(tab_contents); | |
| 1467 ASSERT_EQ(GetTestURL(), tab_contents->GetURL()); | |
| 1468 | |
| 1469 session_restore_fmp_waiter.WaitForForegroundTabs(); | |
| 1470 ExpectFirstPaintMetricsTotalCount(1); | |
| 1471 } | |
| 1472 | |
| 1473 // Restore in a new foreground tab. | |
| 1474 { | |
| 1475 SessionRestoreFirstMeaningfulPaintWaiter session_restore_fmp_waiter; | |
| 1476 tab_contents = SessionRestore::RestoreForeignSessionTab( | |
| 1477 browser()->tab_strip_model()->GetActiveWebContents(), tab, | |
| 1478 WindowOpenDisposition::NEW_FOREGROUND_TAB); | |
| 1479 ASSERT_EQ(2, browser()->tab_strip_model()->count()); | |
| 1480 ASSERT_EQ(1, browser()->tab_strip_model()->active_index()); | |
| 1481 ASSERT_TRUE(tab_contents); | |
| 1482 ASSERT_EQ(GetTestURL(), tab_contents->GetURL()); | |
| 1483 | |
| 1484 session_restore_fmp_waiter.WaitForForegroundTabs(); | |
| 1485 ExpectFirstPaintMetricsTotalCount(2); | |
| 1486 } | |
| 1487 | |
| 1488 // Restore in a new background tab. | |
| 1489 { | |
| 1490 tab_contents = SessionRestore::RestoreForeignSessionTab( | |
| 1491 browser()->tab_strip_model()->GetActiveWebContents(), tab, | |
| 1492 WindowOpenDisposition::NEW_BACKGROUND_TAB); | |
| 1493 ASSERT_EQ(3, browser()->tab_strip_model()->count()); | |
| 1494 ASSERT_EQ(1, browser()->tab_strip_model()->active_index()); | |
| 1495 ASSERT_TRUE(tab_contents); | |
| 1496 ASSERT_EQ(GetTestURL(), tab_contents->GetURL()); | |
| 1497 ASSERT_NO_FATAL_FAILURE(WaitForTabsToLoad(browser())); | |
| 1498 | |
| 1499 // Do not record timings of initially background tabs. | |
| 1500 ExpectFirstPaintMetricsTotalCount(2); | |
| 1501 } | |
| 1502 } | |
| 1503 | |
| 1504 IN_PROC_BROWSER_TEST_F(SessionRestorePageLoadMetricsBrowserTest, | |
| 1505 RestoreForeignSession) { | |
| 1506 Profile* profile = browser()->profile(); | |
| 1507 | |
| 1508 sessions::SerializedNavigationEntry nav1 = | |
| 1509 sessions::SerializedNavigationEntryTestHelper::CreateNavigation( | |
| 1510 GetTestURL().spec(), "one"); | |
| 1511 sessions::SerializedNavigationEntry nav2 = | |
| 1512 sessions::SerializedNavigationEntryTestHelper::CreateNavigation( | |
| 1513 GetTestURL2().spec(), "two"); | |
| 1514 | |
| 1515 // Set up the restore data: one window with two tabs. | |
| 1516 std::vector<const sessions::SessionWindow*> session; | |
| 1517 sessions::SessionWindow window; | |
| 1518 auto tab1 = base::MakeUnique<sessions::SessionTab>(); | |
| 1519 { | |
| 1520 sync_pb::SessionTab sync_data; | |
| 1521 sync_data.set_tab_visual_index(0); | |
| 1522 sync_data.set_current_navigation_index(0); | |
| 1523 sync_data.set_pinned(true); | |
| 1524 sync_data.add_navigation()->CopyFrom(nav1.ToSyncData()); | |
| 1525 tab1->SetFromSyncData(sync_data, base::Time::Now()); | |
| 1526 } | |
| 1527 window.tabs.push_back(std::move(tab1)); | |
| 1528 | |
| 1529 auto tab2 = base::MakeUnique<sessions::SessionTab>(); | |
| 1530 { | |
| 1531 sync_pb::SessionTab sync_data; | |
| 1532 sync_data.set_tab_visual_index(1); | |
| 1533 sync_data.set_current_navigation_index(0); | |
| 1534 sync_data.set_pinned(false); | |
| 1535 sync_data.add_navigation()->CopyFrom(nav2.ToSyncData()); | |
| 1536 tab2->SetFromSyncData(sync_data, base::Time::Now()); | |
| 1537 } | |
| 1538 window.tabs.push_back(std::move(tab2)); | |
| 1539 | |
| 1540 // Restore the session window with 2 tabs. | |
| 1541 session.push_back(static_cast<const sessions::SessionWindow*>(&window)); | |
| 1542 ui_test_utils::BrowserAddedObserver window_observer; | |
| 1543 SessionRestoreFirstMeaningfulPaintWaiter session_restore_fmp_waiter; | |
| 1544 SessionRestore::RestoreForeignSessionWindows(profile, session.begin(), | |
| 1545 session.end()); | |
| 1546 Browser* new_browser = window_observer.WaitForSingleNewBrowser(); | |
| 1547 ASSERT_TRUE(new_browser); | |
| 1548 ASSERT_EQ(2, new_browser->tab_strip_model()->count()); | |
| 1549 | |
| 1550 session_restore_fmp_waiter.WaitForForegroundTabs(); | |
| 1551 ExpectFirstPaintMetricsTotalCount(1); | |
| 1552 } | |
| OLD | NEW |