Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Side by Side Diff: chrome/browser/page_load_metrics/page_load_metrics_browsertest.cc

Issue 2930013005: [Tab Metrics] Measure FP, FCP and FMP for Foreground Tab during Session Restore (Closed)
Patch Set: Fix a typo Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <utility>
8 #include <vector>
9
5 #include "base/command_line.h" 10 #include "base/command_line.h"
6 #include "base/files/scoped_temp_dir.h" 11 #include "base/files/scoped_temp_dir.h"
7 #include "base/logging.h" 12 #include "base/logging.h"
8 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/ptr_util.h"
9 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
10 #include "base/run_loop.h" 16 #include "base/run_loop.h"
11 #include "base/test/histogram_tester.h" 17 #include "base/test/histogram_tester.h"
12 #include "base/threading/thread_restrictions.h" 18 #include "base/threading/thread_restrictions.h"
13 #include "base/time/time.h" 19 #include "base/time/time.h"
14 #include "build/build_config.h" 20 #include "build/build_config.h"
15 #include "chrome/browser/lifetime/keep_alive_types.h" 21 #include "chrome/browser/lifetime/keep_alive_types.h"
16 #include "chrome/browser/lifetime/scoped_keep_alive.h" 22 #include "chrome/browser/lifetime/scoped_keep_alive.h"
17 #include "chrome/browser/page_load_metrics/metrics_web_contents_observer.h" 23 #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" 24 #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" 25 #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" 26 #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" 27 #include "chrome/browser/page_load_metrics/observers/no_state_prefetch_page_load _metrics_observer.h"
28 #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" 29 #include "chrome/browser/page_load_metrics/observers/use_counter_page_load_metri cs_observer.h"
23 #include "chrome/browser/page_load_metrics/page_load_tracker.h" 30 #include "chrome/browser/page_load_metrics/page_load_tracker.h"
24 #include "chrome/browser/prefs/session_startup_pref.h" 31 #include "chrome/browser/prefs/session_startup_pref.h"
25 #include "chrome/browser/prerender/prerender_histograms.h" 32 #include "chrome/browser/prerender/prerender_histograms.h"
26 #include "chrome/browser/prerender/prerender_origin.h" 33 #include "chrome/browser/prerender/prerender_origin.h"
27 #include "chrome/browser/profiles/profile.h" 34 #include "chrome/browser/profiles/profile.h"
35 #include "chrome/browser/sessions/session_restore.h"
28 #include "chrome/browser/sessions/session_service_factory.h" 36 #include "chrome/browser/sessions/session_service_factory.h"
29 #include "chrome/browser/sessions/session_service_test_helper.h" 37 #include "chrome/browser/sessions/session_service_test_helper.h"
30 #include "chrome/browser/ui/browser.h" 38 #include "chrome/browser/ui/browser.h"
31 #include "chrome/browser/ui/browser_commands.h" 39 #include "chrome/browser/ui/browser_commands.h"
32 #include "chrome/browser/ui/browser_navigator_params.h" 40 #include "chrome/browser/ui/browser_navigator_params.h"
33 #include "chrome/browser/ui/tabs/tab_strip_model.h" 41 #include "chrome/browser/ui/tabs/tab_strip_model.h"
34 #include "chrome/common/chrome_features.h" 42 #include "chrome/common/chrome_features.h"
35 #include "chrome/common/pref_names.h" 43 #include "chrome/common/pref_names.h"
36 #include "chrome/common/url_constants.h" 44 #include "chrome/common/url_constants.h"
37 #include "chrome/test/base/in_process_browser_test.h" 45 #include "chrome/test/base/in_process_browser_test.h"
38 #include "chrome/test/base/ui_test_utils.h" 46 #include "chrome/test/base/ui_test_utils.h"
39 #include "components/prefs/pref_service.h" 47 #include "components/prefs/pref_service.h"
48 #include "components/sessions/core/serialized_navigation_entry.h"
49 #include "components/sessions/core/serialized_navigation_entry_test_helper.h"
40 #include "content/public/browser/browser_thread.h" 50 #include "content/public/browser/browser_thread.h"
41 #include "content/public/browser/render_process_host.h" 51 #include "content/public/browser/render_process_host.h"
42 #include "content/public/browser/render_view_host.h" 52 #include "content/public/browser/render_view_host.h"
43 #include "content/public/common/content_features.h" 53 #include "content/public/common/content_features.h"
44 #include "content/public/common/content_switches.h" 54 #include "content/public/common/content_switches.h"
55 #include "content/public/common/referrer.h"
45 #include "content/public/test/browser_test_utils.h" 56 #include "content/public/test/browser_test_utils.h"
46 #include "content/public/test/download_test_observer.h" 57 #include "content/public/test/download_test_observer.h"
47 #include "net/base/net_errors.h" 58 #include "net/base/net_errors.h"
48 #include "net/dns/mock_host_resolver.h" 59 #include "net/dns/mock_host_resolver.h"
49 #include "net/http/failing_http_transaction_factory.h" 60 #include "net/http/failing_http_transaction_factory.h"
50 #include "net/http/http_cache.h" 61 #include "net/http/http_cache.h"
51 #include "net/test/embedded_test_server/embedded_test_server.h" 62 #include "net/test/embedded_test_server/embedded_test_server.h"
52 #include "net/test/url_request/url_request_failed_job.h" 63 #include "net/test/url_request/url_request_failed_job.h"
53 #include "net/url_request/url_request_context.h" 64 #include "net/url_request/url_request_context.h"
54 #include "net/url_request/url_request_context_getter.h" 65 #include "net/url_request/url_request_context_getter.h"
55 #include "third_party/WebKit/public/platform/web_feature.mojom.h" 66 #include "third_party/WebKit/public/platform/web_feature.mojom.h"
67 #include "url/gurl.h"
56 68
57 namespace { 69 namespace {
58 70
59 void FailAllNetworkTransactions(net::URLRequestContextGetter* getter) { 71 void FailAllNetworkTransactions(net::URLRequestContextGetter* getter) {
60 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 72 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
61 net::HttpCache* cache( 73 net::HttpCache* cache(
62 getter->GetURLRequestContext()->http_transaction_factory()->GetCache()); 74 getter->GetURLRequestContext()->http_transaction_factory()->GetCache());
63 DCHECK(cache); 75 DCHECK(cache);
64 std::unique_ptr<net::FailingHttpTransactionFactory> factory = 76 std::unique_ptr<net::FailingHttpTransactionFactory> factory =
65 base::MakeUnique<net::FailingHttpTransactionFactory>(cache->GetSession(), 77 base::MakeUnique<net::FailingHttpTransactionFactory>(cache->GetSession(),
(...skipping 1037 matching lines...) Expand 10 before | Expand all | Expand 10 after
1103 NavigateToUntrackedUrl(); 1115 NavigateToUntrackedUrl();
1104 1116
1105 histogram_tester_.ExpectBucketCount( 1117 histogram_tester_.ExpectBucketCount(
1106 internal::kFeaturesHistogramName, 1118 internal::kFeaturesHistogramName,
1107 static_cast<int32_t>(WebFeature::kTextWholeText), 1); 1119 static_cast<int32_t>(WebFeature::kTextWholeText), 1);
1108 histogram_tester_.ExpectBucketCount( 1120 histogram_tester_.ExpectBucketCount(
1109 internal::kFeaturesHistogramName, 1121 internal::kFeaturesHistogramName,
1110 static_cast<int32_t>(WebFeature::kV8Element_Animate_Method), 1); 1122 static_cast<int32_t>(WebFeature::kV8Element_Animate_Method), 1);
1111 } 1123 }
1112 1124
1113 class SessionRestorePageLoadMetricsBrowserTest 1125 class SessionRestorePageLoadMetricsBrowserTest
Charlie Harrison 2017/08/09 02:42:05 Optional: There's enough tests here to warrant pul
ducbui 2017/08/09 03:25:21 Ack, I agree to separate these tests, but the chan
1114 : public PageLoadMetricsBrowserTest { 1126 : public PageLoadMetricsBrowserTest {
1115 public: 1127 public:
1116 SessionRestorePageLoadMetricsBrowserTest() {} 1128 SessionRestorePageLoadMetricsBrowserTest() {}
1117 1129
1118 // PageLoadMetricsBrowserTest: 1130 // PageLoadMetricsBrowserTest:
1119 void SetUpOnMainThread() override { 1131 void SetUpOnMainThread() override {
1120 PageLoadMetricsBrowserTest::SetUpOnMainThread(); 1132 PageLoadMetricsBrowserTest::SetUpOnMainThread();
1121 SessionStartupPref::SetStartupPref(
1122 browser()->profile(), SessionStartupPref(SessionStartupPref::LAST));
1123 ASSERT_TRUE(embedded_test_server()->Start()); 1133 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 } 1134 }
1131 1135
1132 Browser* QuitBrowserAndRestore(Browser* browser) { 1136 Browser* QuitBrowserAndRestore(Browser* browser) {
1133 Profile* profile = browser->profile(); 1137 Profile* profile = browser->profile();
1134 1138
1139 SessionStartupPref::SetStartupPref(
1140 profile, SessionStartupPref(SessionStartupPref::LAST));
1141 #if defined(OS_CHROMEOS)
1142 SessionServiceTestHelper helper(
1143 SessionServiceFactory::GetForProfile(profile);
1144 helper.SetForceBrowserNotAliveWithNoWindows(true);
1145 helper.ReleaseService();
1146 #endif
1147
1135 std::unique_ptr<ScopedKeepAlive> keep_alive(new ScopedKeepAlive( 1148 std::unique_ptr<ScopedKeepAlive> keep_alive(new ScopedKeepAlive(
1136 KeepAliveOrigin::SESSION_RESTORE, KeepAliveRestartOption::DISABLED)); 1149 KeepAliveOrigin::SESSION_RESTORE, KeepAliveRestartOption::DISABLED));
1137 CloseBrowserSynchronously(browser); 1150 CloseBrowserSynchronously(browser);
1138 1151
1139 // Create a new window, which should trigger session restore. 1152 // Create a new window, which should trigger session restore.
1140 chrome::NewEmptyWindow(profile); 1153 chrome::NewEmptyWindow(profile);
1141 ui_test_utils::BrowserAddedObserver window_observer; 1154 ui_test_utils::BrowserAddedObserver window_observer;
1142 return window_observer.WaitForSingleNewBrowser(); 1155 return window_observer.WaitForSingleNewBrowser();
1143 } 1156 }
1144 1157
1158 void WaitForFirstMeaningfulPaintOfActiveTab(Browser* browser) const {
1159 WaitForFirstMeaningfulPaintOfTab(
1160 browser->tab_strip_model()->GetActiveWebContents());
1161 }
1162
1163 void WaitForFirstMeaningfulPaintOfTab(
1164 content::WebContents* web_contents) const {
1165 auto waiter = base::MakeUnique<PageLoadMetricsWaiter>(web_contents);
1166 waiter->AddPageExpectation(TimingField::FIRST_MEANINGFUL_PAINT);
1167 waiter->Wait();
1168 }
1169
1145 void WaitForTabsToLoad(Browser* browser) { 1170 void WaitForTabsToLoad(Browser* browser) {
1146 for (int i = 0; i < browser->tab_strip_model()->count(); ++i) { 1171 for (int i = 0; i < browser->tab_strip_model()->count(); ++i) {
1147 content::WebContents* contents = 1172 content::WebContents* contents =
1148 browser->tab_strip_model()->GetWebContentsAt(i); 1173 browser->tab_strip_model()->GetWebContentsAt(i);
1149 contents->GetController().LoadIfNecessary(); 1174 contents->GetController().LoadIfNecessary();
1150 content::WaitForLoadStop(contents); 1175 content::WaitForLoadStop(contents);
1151 } 1176 }
1152 } 1177 }
1153 1178
1179 // The PageLoadMetricsWaiter can observe first meaningful paints on these test
1180 // pages while not on other simple pages such as /title1.html.
1154 GURL GetTestURL() const { 1181 GURL GetTestURL() const {
1155 return embedded_test_server()->GetURL("/title1.html"); 1182 return embedded_test_server()->GetURL(
1183 "/page_load_metrics/main_frame_with_iframe.html");
1184 }
1185
1186 GURL GetTestURL2() const {
1187 return embedded_test_server()->GetURL("/page_load_metrics/iframes.html");
1188 }
1189
1190 void ExpectFirstPaintMetricsTotalCount(int expected_total_count) const {
1191 histogram_tester_.ExpectTotalCount(
1192 internal::kHistogramSessionRestoreForegroundTabFirstPaint,
1193 expected_total_count);
1194 histogram_tester_.ExpectTotalCount(
1195 internal::kHistogramSessionRestoreForegroundTabFirstContentfulPaint,
1196 expected_total_count);
1197 histogram_tester_.ExpectTotalCount(
1198 internal::kHistogramSessionRestoreForegroundTabFirstMeaningfulPaint,
1199 expected_total_count);
1156 } 1200 }
1157 1201
1158 private: 1202 private:
1159 DISALLOW_COPY_AND_ASSIGN(SessionRestorePageLoadMetricsBrowserTest); 1203 DISALLOW_COPY_AND_ASSIGN(SessionRestorePageLoadMetricsBrowserTest);
1160 }; 1204 };
1161 1205
1162 IN_PROC_BROWSER_TEST_F(SessionRestorePageLoadMetricsBrowserTest, 1206 IN_PROC_BROWSER_TEST_F(SessionRestorePageLoadMetricsBrowserTest,
1163 InitialVisibilityOfSingleRestoredTab) { 1207 InitialVisibilityOfSingleRestoredTab) {
1164 ui_test_utils::NavigateToURL(browser(), GetTestURL()); 1208 ui_test_utils::NavigateToURL(browser(), GetTestURL());
1165 histogram_tester_.ExpectTotalCount( 1209 histogram_tester_.ExpectTotalCount(
(...skipping 28 matching lines...) Expand all
1194 ASSERT_TRUE(tab_strip); 1238 ASSERT_TRUE(tab_strip);
1195 ASSERT_EQ(2, tab_strip->count()); 1239 ASSERT_EQ(2, tab_strip->count());
1196 1240
1197 histogram_tester_.ExpectTotalCount( 1241 histogram_tester_.ExpectTotalCount(
1198 page_load_metrics::internal::kPageLoadStartedInForeground, 4); 1242 page_load_metrics::internal::kPageLoadStartedInForeground, 4);
1199 histogram_tester_.ExpectBucketCount( 1243 histogram_tester_.ExpectBucketCount(
1200 page_load_metrics::internal::kPageLoadStartedInForeground, true, 2); 1244 page_load_metrics::internal::kPageLoadStartedInForeground, true, 2);
1201 histogram_tester_.ExpectBucketCount( 1245 histogram_tester_.ExpectBucketCount(
1202 page_load_metrics::internal::kPageLoadStartedInForeground, false, 2); 1246 page_load_metrics::internal::kPageLoadStartedInForeground, false, 2);
1203 } 1247 }
1248
1249 IN_PROC_BROWSER_TEST_F(SessionRestorePageLoadMetricsBrowserTest,
1250 NoSessionRestore) {
1251 ui_test_utils::NavigateToURL(browser(), GetTestURL());
1252 ExpectFirstPaintMetricsTotalCount(0);
1253 }
1254
1255 IN_PROC_BROWSER_TEST_F(SessionRestorePageLoadMetricsBrowserTest,
1256 SingleTabSessionRestore) {
1257 ui_test_utils::NavigateToURL(browser(), GetTestURL());
1258 Browser* new_browser = QuitBrowserAndRestore(browser());
1259 WaitForFirstMeaningfulPaintOfActiveTab(new_browser);
1260 ExpectFirstPaintMetricsTotalCount(1);
1261 }
1262
1263 IN_PROC_BROWSER_TEST_F(SessionRestorePageLoadMetricsBrowserTest,
1264 MultipleTabsSessionRestore) {
1265 ui_test_utils::NavigateToURL(browser(), GetTestURL());
1266 ui_test_utils::NavigateToURLWithDisposition(
1267 browser(), GetTestURL(), WindowOpenDisposition::NEW_BACKGROUND_TAB,
1268 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
1269 Browser* new_browser = QuitBrowserAndRestore(browser());
1270
1271 TabStripModel* tab_strip = new_browser->tab_strip_model();
1272 ASSERT_TRUE(tab_strip);
1273 ASSERT_EQ(2, tab_strip->count());
1274
1275 WaitForFirstMeaningfulPaintOfActiveTab(new_browser);
1276 WaitForTabsToLoad(new_browser);
1277
1278 // Only metrics of the initial foreground tab are recorded.
1279 ExpectFirstPaintMetricsTotalCount(1);
1280 }
1281
1282 IN_PROC_BROWSER_TEST_F(SessionRestorePageLoadMetricsBrowserTest,
1283 NavigationDuringSessionRestore) {
1284 ui_test_utils::NavigateToURL(browser(), GetTestURL());
1285 Browser* new_browser = QuitBrowserAndRestore(browser());
1286
1287 content::WebContents* active_web_contents =
1288 new_browser->tab_strip_model()->GetActiveWebContents();
1289 auto waiter = base::MakeUnique<PageLoadMetricsWaiter>(active_web_contents);
1290 waiter->AddPageExpectation(TimingField::FIRST_MEANINGFUL_PAINT);
1291
1292 // Load another url in the initial tab before its first paints.
1293 ExpectFirstPaintMetricsTotalCount(0);
1294 // If the current web contents is not stopped, the next navigation
1295 // may not yield any meaningful paints (even it yields the first paint and
1296 // contentful paint).
1297 // TODO(ducbui): remove Stop().
1298 active_web_contents->Stop();
1299 active_web_contents->GetController().LoadURL(
1300 GetTestURL2(), content::Referrer(), ui::PAGE_TRANSITION_TYPED,
1301 std::string());
1302
1303 waiter->Wait();
1304
1305 // No metrics recorded because the tab navigates away during session restore.
1306 ExpectFirstPaintMetricsTotalCount(0);
1307 }
1308
1309 IN_PROC_BROWSER_TEST_F(SessionRestorePageLoadMetricsBrowserTest,
1310 LoadingAfterSessionRestore) {
1311 ui_test_utils::NavigateToURL(browser(), GetTestURL());
1312 Browser* new_browser = QuitBrowserAndRestore(browser());
1313
1314 WaitForFirstMeaningfulPaintOfActiveTab(new_browser);
1315 ExpectFirstPaintMetricsTotalCount(1);
1316
1317 // Load a new page after session restore.
1318 auto waiter = base::MakeUnique<PageLoadMetricsWaiter>(
1319 new_browser->tab_strip_model()->GetActiveWebContents());
1320 waiter->AddPageExpectation(TimingField::FIRST_MEANINGFUL_PAINT);
1321 ui_test_utils::NavigateToURL(new_browser, GetTestURL2());
1322 waiter->Wait();
1323
1324 // No more metrics because the navigation is after session restore.
1325 ExpectFirstPaintMetricsTotalCount(1);
1326 }
1327
1328 IN_PROC_BROWSER_TEST_F(SessionRestorePageLoadMetricsBrowserTest,
1329 InitialForegroundTabChanged) {
1330 ui_test_utils::NavigateToURL(browser(), GetTestURL());
1331 ui_test_utils::NavigateToURLWithDisposition(
1332 browser(), GetTestURL2(), WindowOpenDisposition::NEW_BACKGROUND_TAB,
1333 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
1334 Browser* new_browser = QuitBrowserAndRestore(browser());
1335
1336 // Change the foreground tab before the first meaningful paint.
1337 TabStripModel* tab_strip = new_browser->tab_strip_model();
1338 ASSERT_TRUE(tab_strip);
1339 ASSERT_EQ(2, tab_strip->count());
1340 ASSERT_EQ(0, tab_strip->active_index());
1341 tab_strip->ActivateTabAt(1, true);
1342
1343 WaitForFirstMeaningfulPaintOfActiveTab(new_browser);
1344
1345 // No metrics were recorded because initial foreground tab was switched away.
1346 ExpectFirstPaintMetricsTotalCount(0);
1347 }
1348
1349 IN_PROC_BROWSER_TEST_F(SessionRestorePageLoadMetricsBrowserTest,
1350 MultipleSessionRestores) {
1351 ui_test_utils::NavigateToURL(browser(), GetTestURL());
1352
1353 Browser* current_browser = browser();
1354 const int num_session_restores = 2;
1355 for (int i = 1; i <= num_session_restores; ++i) {
1356 current_browser = QuitBrowserAndRestore(current_browser);
1357 WaitForFirstMeaningfulPaintOfActiveTab(current_browser);
1358 ExpectFirstPaintMetricsTotalCount(i);
1359 }
1360 }
1361
1362 IN_PROC_BROWSER_TEST_F(SessionRestorePageLoadMetricsBrowserTest,
1363 RestoreForeignTab) {
1364 sessions::SerializedNavigationEntry nav =
1365 sessions::SerializedNavigationEntryTestHelper::CreateNavigation(
1366 GetTestURL().spec(), "one");
1367
1368 // Set up the restore data.
1369 sync_pb::SessionTab sync_data;
1370 sync_data.set_tab_visual_index(0);
1371 sync_data.set_current_navigation_index(1);
1372 sync_data.set_pinned(false);
1373 sync_data.add_navigation()->CopyFrom(nav.ToSyncData());
1374
1375 sessions::SessionTab tab;
1376 tab.SetFromSyncData(sync_data, base::Time::Now());
1377 ASSERT_EQ(1, browser()->tab_strip_model()->count());
1378
1379 // Restore in the current tab.
1380 content::WebContents* tab_content = SessionRestore::RestoreForeignSessionTab(
1381 browser()->tab_strip_model()->GetActiveWebContents(), tab,
1382 WindowOpenDisposition::CURRENT_TAB);
1383 ASSERT_EQ(1, browser()->tab_strip_model()->count());
1384 ASSERT_TRUE(tab_content);
1385 ASSERT_EQ(GetTestURL(), tab_content->GetURL());
1386
1387 WaitForFirstMeaningfulPaintOfTab(tab_content);
1388 ExpectFirstPaintMetricsTotalCount(1);
1389
1390 // Restore in a new foreground tab.
1391 tab_content = SessionRestore::RestoreForeignSessionTab(
1392 browser()->tab_strip_model()->GetActiveWebContents(), tab,
1393 WindowOpenDisposition::NEW_FOREGROUND_TAB);
1394 ASSERT_EQ(2, browser()->tab_strip_model()->count());
1395 ASSERT_EQ(1, browser()->tab_strip_model()->active_index());
1396 ASSERT_TRUE(tab_content);
1397 ASSERT_EQ(GetTestURL(), tab_content->GetURL());
1398
1399 WaitForFirstMeaningfulPaintOfTab(tab_content);
1400 ExpectFirstPaintMetricsTotalCount(2);
1401
1402 // Restore in a new background tab.
1403 tab_content = SessionRestore::RestoreForeignSessionTab(
1404 browser()->tab_strip_model()->GetActiveWebContents(), tab,
1405 WindowOpenDisposition::NEW_BACKGROUND_TAB);
1406 ASSERT_EQ(3, browser()->tab_strip_model()->count());
1407 ASSERT_EQ(1, browser()->tab_strip_model()->active_index());
1408 ASSERT_TRUE(tab_content);
1409 ASSERT_EQ(GetTestURL(), tab_content->GetURL());
1410 WaitForTabsToLoad(browser());
1411
1412 // Do not record timings of initially background tabs.
1413 ExpectFirstPaintMetricsTotalCount(2);
1414 }
1415
1416 IN_PROC_BROWSER_TEST_F(SessionRestorePageLoadMetricsBrowserTest,
1417 RestoreForeignSession) {
1418 Profile* profile = browser()->profile();
1419
1420 sessions::SerializedNavigationEntry nav1 =
1421 sessions::SerializedNavigationEntryTestHelper::CreateNavigation(
1422 GetTestURL().spec(), "one");
1423 sessions::SerializedNavigationEntry nav2 =
1424 sessions::SerializedNavigationEntryTestHelper::CreateNavigation(
1425 GetTestURL2().spec(), "two");
1426
1427 // Set up the restore data: one window with two tabs.
1428 std::vector<const sessions::SessionWindow*> session;
1429 sessions::SessionWindow window;
1430 auto tab1 = base::MakeUnique<sessions::SessionTab>();
1431 {
1432 sync_pb::SessionTab sync_data;
1433 sync_data.set_tab_visual_index(0);
1434 sync_data.set_current_navigation_index(0);
1435 sync_data.set_pinned(true);
1436 sync_data.add_navigation()->CopyFrom(nav1.ToSyncData());
1437 tab1->SetFromSyncData(sync_data, base::Time::Now());
1438 }
1439 window.tabs.push_back(std::move(tab1));
1440
1441 auto tab2 = base::MakeUnique<sessions::SessionTab>();
1442 {
1443 sync_pb::SessionTab sync_data;
1444 sync_data.set_tab_visual_index(1);
1445 sync_data.set_current_navigation_index(0);
1446 sync_data.set_pinned(false);
1447 sync_data.add_navigation()->CopyFrom(nav2.ToSyncData());
1448 tab2->SetFromSyncData(sync_data, base::Time::Now());
1449 }
1450 window.tabs.push_back(std::move(tab2));
1451
1452 // Restore the session window with 2 tabs.
1453 session.push_back(static_cast<const sessions::SessionWindow*>(&window));
1454 ui_test_utils::BrowserAddedObserver window_observer;
1455 SessionRestore::RestoreForeignSessionWindows(profile, session.begin(),
1456 session.end());
1457 Browser* new_browser = window_observer.WaitForSingleNewBrowser();
1458 ASSERT_TRUE(new_browser);
1459 ASSERT_EQ(2, new_browser->tab_strip_model()->count());
1460
1461 WaitForFirstMeaningfulPaintOfActiveTab(new_browser);
1462 ExpectFirstPaintMetricsTotalCount(1);
1463 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698