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

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: Refine tests 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 1069 matching lines...) Expand 10 before | Expand all | Expand 10 after
1135 std::unique_ptr<ScopedKeepAlive> keep_alive(new ScopedKeepAlive( 1147 std::unique_ptr<ScopedKeepAlive> keep_alive(new ScopedKeepAlive(
1136 KeepAliveOrigin::SESSION_RESTORE, KeepAliveRestartOption::DISABLED)); 1148 KeepAliveOrigin::SESSION_RESTORE, KeepAliveRestartOption::DISABLED));
1137 CloseBrowserSynchronously(browser); 1149 CloseBrowserSynchronously(browser);
1138 1150
1139 // Create a new window, which should trigger session restore. 1151 // Create a new window, which should trigger session restore.
1140 chrome::NewEmptyWindow(profile); 1152 chrome::NewEmptyWindow(profile);
1141 ui_test_utils::BrowserAddedObserver window_observer; 1153 ui_test_utils::BrowserAddedObserver window_observer;
1142 return window_observer.WaitForSingleNewBrowser(); 1154 return window_observer.WaitForSingleNewBrowser();
1143 } 1155 }
1144 1156
1157 std::unique_ptr<PageLoadMetricsWaiter> CreatePageLoadMetricsWaiter(
Charlie Harrison 2017/08/07 14:30:08 nit: I would just remove this method, it doesn't g
ducbui 2017/08/08 16:29:48 Acknowledged. I will remove it.
1158 content::WebContents* web_contents) const {
1159 return base::MakeUnique<PageLoadMetricsWaiter>(web_contents);
1160 }
1161
1162 void WaitForFirstMeaningfulPaintOfActiveTab(Browser* browser) const {
1163 WaitForFirstMeaningfulPaintOfTab(
1164 browser->tab_strip_model()->GetActiveWebContents());
1165 }
1166
1167 void WaitForFirstMeaningfulPaintOfTab(
1168 content::WebContents* web_contents) const {
1169 auto waiter = CreatePageLoadMetricsWaiter(web_contents);
Bryan McQuade 2017/08/09 15:41:34 generally we prefer to create the waiter before na
ducbui 2017/08/09 19:43:06 Ack. We should ensure to create the Waiter before
1170 waiter->AddPageExpectation(TimingField::FIRST_MEANINGFUL_PAINT);
1171 waiter->Wait();
1172 }
1173
1145 void WaitForTabsToLoad(Browser* browser) { 1174 void WaitForTabsToLoad(Browser* browser) {
1146 for (int i = 0; i < browser->tab_strip_model()->count(); ++i) { 1175 for (int i = 0; i < browser->tab_strip_model()->count(); ++i) {
1147 content::WebContents* contents = 1176 content::WebContents* contents =
1148 browser->tab_strip_model()->GetWebContentsAt(i); 1177 browser->tab_strip_model()->GetWebContentsAt(i);
1149 contents->GetController().LoadIfNecessary(); 1178 contents->GetController().LoadIfNecessary();
1150 content::WaitForLoadStop(contents); 1179 content::WaitForLoadStop(contents);
1151 } 1180 }
1152 } 1181 }
1153 1182
1183 // The PageLoadMetricsWaiter can observe first meaningful paints on these test
1184 // pages while not on other simple pages such as /title1.html.
1154 GURL GetTestURL() const { 1185 GURL GetTestURL() const {
1155 return embedded_test_server()->GetURL("/title1.html"); 1186 return embedded_test_server()->GetURL(
1187 "/page_load_metrics/page_with_css.html");
Charlie Harrison 2017/08/07 14:30:08 page_with_css is not very aptly named, it does a l
ducbui 2017/08/08 16:29:48 Using "/title1.html" yields the first paint and fi
Charlie Harrison 2017/08/08 17:00:29 Hm maybe FMP needs > 1 layout to work correctly? I
ducbui 2017/08/08 22:21:06 Heuristics in FirstMeaningfulPaintDetector.cpp ski
1188 }
1189
1190 GURL GetTestURL2() const {
1191 return embedded_test_server()->GetURL(
1192 "/page_load_metrics/main_frame_with_iframe.html");
Bryan McQuade 2017/08/09 15:41:34 can we use title2.html to be consistent?
ducbui 2017/08/09 19:43:06 Acknowledged. I will change this to title2.html.
1193 }
1194
1195 void ExpectFirstPaintMetricsTotalCount(int expected_total_count) const {
1196 histogram_tester_.ExpectTotalCount(
1197 internal::kHistogramSessionRestoreForegroundTabFirstPaint,
1198 expected_total_count);
1199 histogram_tester_.ExpectTotalCount(
1200 internal::kHistogramSessionRestoreForegroundTabFirstContentfulPaint,
1201 expected_total_count);
1202 histogram_tester_.ExpectTotalCount(
1203 internal::kHistogramSessionRestoreForegroundTabFirstMeaningfulPaint,
1204 expected_total_count);
1156 } 1205 }
1157 1206
1158 private: 1207 private:
1159 DISALLOW_COPY_AND_ASSIGN(SessionRestorePageLoadMetricsBrowserTest); 1208 DISALLOW_COPY_AND_ASSIGN(SessionRestorePageLoadMetricsBrowserTest);
1160 }; 1209 };
1161 1210
1162 IN_PROC_BROWSER_TEST_F(SessionRestorePageLoadMetricsBrowserTest, 1211 IN_PROC_BROWSER_TEST_F(SessionRestorePageLoadMetricsBrowserTest,
1163 InitialVisibilityOfSingleRestoredTab) { 1212 InitialVisibilityOfSingleRestoredTab) {
1164 ui_test_utils::NavigateToURL(browser(), GetTestURL()); 1213 ui_test_utils::NavigateToURL(browser(), GetTestURL());
1165 histogram_tester_.ExpectTotalCount( 1214 histogram_tester_.ExpectTotalCount(
(...skipping 28 matching lines...) Expand all
1194 ASSERT_TRUE(tab_strip); 1243 ASSERT_TRUE(tab_strip);
1195 ASSERT_EQ(2, tab_strip->count()); 1244 ASSERT_EQ(2, tab_strip->count());
1196 1245
1197 histogram_tester_.ExpectTotalCount( 1246 histogram_tester_.ExpectTotalCount(
1198 page_load_metrics::internal::kPageLoadStartedInForeground, 4); 1247 page_load_metrics::internal::kPageLoadStartedInForeground, 4);
1199 histogram_tester_.ExpectBucketCount( 1248 histogram_tester_.ExpectBucketCount(
1200 page_load_metrics::internal::kPageLoadStartedInForeground, true, 2); 1249 page_load_metrics::internal::kPageLoadStartedInForeground, true, 2);
1201 histogram_tester_.ExpectBucketCount( 1250 histogram_tester_.ExpectBucketCount(
1202 page_load_metrics::internal::kPageLoadStartedInForeground, false, 2); 1251 page_load_metrics::internal::kPageLoadStartedInForeground, false, 2);
1203 } 1252 }
1253
1254 IN_PROC_BROWSER_TEST_F(SessionRestorePageLoadMetricsBrowserTest,
1255 NoSessionRestore) {
1256 ui_test_utils::NavigateToURL(browser(), GetTestURL());
1257 ExpectFirstPaintMetricsTotalCount(0);
1258 }
1259
1260 IN_PROC_BROWSER_TEST_F(SessionRestorePageLoadMetricsBrowserTest,
1261 SingleTabSessionRestore) {
1262 ui_test_utils::NavigateToURL(browser(), GetTestURL());
1263 Browser* new_browser = QuitBrowserAndRestore(browser());
1264 WaitForFirstMeaningfulPaintOfActiveTab(new_browser);
1265 ExpectFirstPaintMetricsTotalCount(1);
1266 }
1267
1268 IN_PROC_BROWSER_TEST_F(SessionRestorePageLoadMetricsBrowserTest,
1269 MultipleTabsSessionRestore) {
1270 ui_test_utils::NavigateToURL(browser(), GetTestURL());
1271 ui_test_utils::NavigateToURLWithDisposition(
1272 browser(), GetTestURL(), WindowOpenDisposition::NEW_BACKGROUND_TAB,
1273 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
1274 Browser* new_browser = QuitBrowserAndRestore(browser());
1275
1276 TabStripModel* tab_strip = new_browser->tab_strip_model();
1277 ASSERT_TRUE(tab_strip);
1278 ASSERT_EQ(2, tab_strip->count());
1279
1280 WaitForFirstMeaningfulPaintOfActiveTab(new_browser);
1281 WaitForTabsToLoad(new_browser);
1282
1283 // Only metrics of the initial foreground tab are recorded.
1284 ExpectFirstPaintMetricsTotalCount(1);
1285 }
1286
1287 IN_PROC_BROWSER_TEST_F(SessionRestorePageLoadMetricsBrowserTest,
1288 NavigationDuringSessionRestore) {
1289 ui_test_utils::NavigateToURL(browser(), GetTestURL());
1290 Browser* new_browser = QuitBrowserAndRestore(browser());
1291
1292 content::WebContents* active_web_contents =
1293 new_browser->tab_strip_model()->GetActiveWebContents();
1294 auto waiter = base::MakeUnique<PageLoadMetricsWaiter>(active_web_contents);
1295 waiter->AddPageExpectation(TimingField::FIRST_MEANINGFUL_PAINT);
1296
1297 // Load another url in the initial tab before its first paints.
1298 ExpectFirstPaintMetricsTotalCount(0);
1299 // If the current web contents is not stopped, the next navigation
1300 // will not yield any paints.
1301 active_web_contents->Stop();
Charlie Harrison 2017/08/07 14:30:08 I'm not quite sure why this is needed? Shouldn't l
ducbui 2017/08/08 16:29:48 Acknowledged. I tried to use ui_test_utils::Naviga
Charlie Harrison 2017/08/08 17:00:29 I see. Don't let this block you too much if it tur
ducbui 2017/08/08 22:21:07 I added a TODO for this issue. I tried other APIs
Bryan McQuade 2017/08/09 15:41:34 agree - if you have to call this method, something
ducbui 2017/08/10 01:01:17 I removed the Stop() and added some calculation to
1302 active_web_contents->GetController().LoadURL(
1303 GetTestURL2(), content::Referrer(), ui::PAGE_TRANSITION_TYPED,
1304 std::string());
1305
1306 waiter->Wait();
1307
1308 // No metrics recorded because it navigates away during session restore.
Charlie Harrison 2017/08/07 14:30:08 s/it/the tab
ducbui 2017/08/08 16:29:48 Done.
1309 ExpectFirstPaintMetricsTotalCount(0);
1310 }
1311
1312 IN_PROC_BROWSER_TEST_F(SessionRestorePageLoadMetricsBrowserTest,
1313 LoadingAfterSessionRestore) {
1314 ui_test_utils::NavigateToURL(browser(), GetTestURL());
1315 Browser* new_browser = QuitBrowserAndRestore(browser());
1316
1317 WaitForFirstMeaningfulPaintOfActiveTab(new_browser);
1318 ExpectFirstPaintMetricsTotalCount(1);
1319
1320 // Load a new page after session restore.
1321 auto waiter = CreatePageLoadMetricsWaiter(
1322 new_browser->tab_strip_model()->GetActiveWebContents());
1323 waiter->AddPageExpectation(TimingField::FIRST_MEANINGFUL_PAINT);
1324 ui_test_utils::NavigateToURL(new_browser, GetTestURL2());
1325 waiter->Wait();
1326
1327 // No more metrics because the navigation is after session restore.
1328 ExpectFirstPaintMetricsTotalCount(1);
1329 }
1330
1331 IN_PROC_BROWSER_TEST_F(SessionRestorePageLoadMetricsBrowserTest,
1332 InitialForegroundTabChanged) {
1333 ui_test_utils::NavigateToURL(browser(), GetTestURL());
1334 ui_test_utils::NavigateToURLWithDisposition(
1335 browser(), GetTestURL2(), WindowOpenDisposition::NEW_BACKGROUND_TAB,
1336 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
1337 Browser* new_browser = QuitBrowserAndRestore(browser());
1338
1339 // Change the foreground tab before the first meaningful paint.
1340 TabStripModel* tab_strip = new_browser->tab_strip_model();
1341 ASSERT_TRUE(tab_strip);
1342 ASSERT_EQ(2, tab_strip->count());
1343 ASSERT_EQ(0, tab_strip->active_index());
1344 tab_strip->ActivateTabAt(1, true);
1345
1346 WaitForFirstMeaningfulPaintOfActiveTab(new_browser);
1347
1348 // No metrics were recorded because initial foreground tab was switched away.
1349 ExpectFirstPaintMetricsTotalCount(0);
1350 }
1351
1352 IN_PROC_BROWSER_TEST_F(SessionRestorePageLoadMetricsBrowserTest,
1353 MultipleSessionRestores) {
1354 ui_test_utils::NavigateToURL(browser(), GetTestURL());
1355
1356 Browser* current_browser = browser();
1357 const int num_session_restores = 3;
1358 for (int i = 1; i <= num_session_restores; ++i) {
1359 current_browser = QuitBrowserAndRestore(current_browser);
1360 WaitForFirstMeaningfulPaintOfActiveTab(current_browser);
1361 ExpectFirstPaintMetricsTotalCount(i);
1362 }
1363 }
1364
1365 IN_PROC_BROWSER_TEST_F(SessionRestorePageLoadMetricsBrowserTest,
1366 RestoreForeignTab) {
1367 sessions::SerializedNavigationEntry nav =
1368 sessions::SerializedNavigationEntryTestHelper::CreateNavigation(
1369 GetTestURL().spec(), "one");
1370
1371 // Set up the restore data.
1372 sync_pb::SessionTab sync_data;
1373 sync_data.set_tab_visual_index(0);
1374 sync_data.set_current_navigation_index(1);
1375 sync_data.set_pinned(false);
1376 sync_data.add_navigation()->CopyFrom(nav.ToSyncData());
1377
1378 sessions::SessionTab tab;
1379 tab.SetFromSyncData(sync_data, base::Time::Now());
1380 ASSERT_EQ(1, browser()->tab_strip_model()->count());
1381
1382 // Restore in the current tab.
1383 content::WebContents* tab_content = SessionRestore::RestoreForeignSessionTab(
1384 browser()->tab_strip_model()->GetActiveWebContents(), tab,
1385 WindowOpenDisposition::CURRENT_TAB);
1386 ASSERT_EQ(1, browser()->tab_strip_model()->count());
1387 ASSERT_TRUE(tab_content);
1388 ASSERT_EQ(GetTestURL(), tab_content->GetURL());
1389
1390 WaitForFirstMeaningfulPaintOfTab(tab_content);
1391 ExpectFirstPaintMetricsTotalCount(1);
1392
1393 // Restore in a new foreground tab.
1394 tab_content = SessionRestore::RestoreForeignSessionTab(
1395 browser()->tab_strip_model()->GetActiveWebContents(), tab,
1396 WindowOpenDisposition::NEW_FOREGROUND_TAB);
1397 ASSERT_EQ(2, browser()->tab_strip_model()->count());
1398 ASSERT_EQ(1, browser()->tab_strip_model()->active_index());
1399 ASSERT_TRUE(tab_content);
1400 ASSERT_EQ(GetTestURL(), tab_content->GetURL());
1401
1402 WaitForFirstMeaningfulPaintOfTab(tab_content);
1403 ExpectFirstPaintMetricsTotalCount(2);
1404
1405 // Restore in a new background tab.
1406 tab_content = SessionRestore::RestoreForeignSessionTab(
1407 browser()->tab_strip_model()->GetActiveWebContents(), tab,
1408 WindowOpenDisposition::NEW_BACKGROUND_TAB);
1409 ASSERT_EQ(3, browser()->tab_strip_model()->count());
1410 ASSERT_EQ(1, browser()->tab_strip_model()->active_index());
1411 ASSERT_TRUE(tab_content);
1412 ASSERT_EQ(GetTestURL(), tab_content->GetURL());
1413 WaitForTabsToLoad(browser());
1414
1415 // Do not record timings of initially background tabs.
1416 ExpectFirstPaintMetricsTotalCount(2);
1417 }
1418
1419 IN_PROC_BROWSER_TEST_F(SessionRestorePageLoadMetricsBrowserTest,
1420 RestoreForeignSession) {
1421 Profile* profile = browser()->profile();
1422
1423 sessions::SerializedNavigationEntry nav1 =
1424 sessions::SerializedNavigationEntryTestHelper::CreateNavigation(
1425 GetTestURL().spec(), "one");
1426 sessions::SerializedNavigationEntry nav2 =
1427 sessions::SerializedNavigationEntryTestHelper::CreateNavigation(
1428 GetTestURL2().spec(), "two");
1429
1430 // Set up the restore data: one window with two tabs.
1431 std::vector<const sessions::SessionWindow*> session;
1432 sessions::SessionWindow window;
1433 auto tab1 = base::MakeUnique<sessions::SessionTab>();
1434 {
1435 sync_pb::SessionTab sync_data;
1436 sync_data.set_tab_visual_index(0);
1437 sync_data.set_current_navigation_index(0);
1438 sync_data.set_pinned(true);
1439 sync_data.add_navigation()->CopyFrom(nav1.ToSyncData());
1440 tab1->SetFromSyncData(sync_data, base::Time::Now());
1441 }
1442 window.tabs.push_back(std::move(tab1));
1443
1444 auto tab2 = base::MakeUnique<sessions::SessionTab>();
1445 {
1446 sync_pb::SessionTab sync_data;
1447 sync_data.set_tab_visual_index(1);
1448 sync_data.set_current_navigation_index(0);
1449 sync_data.set_pinned(false);
1450 sync_data.add_navigation()->CopyFrom(nav2.ToSyncData());
1451 tab2->SetFromSyncData(sync_data, base::Time::Now());
1452 }
1453 window.tabs.push_back(std::move(tab2));
1454
1455 // Restore the session window with 2 tabs.
1456 session.push_back(static_cast<const sessions::SessionWindow*>(&window));
1457 ui_test_utils::BrowserAddedObserver window_observer;
1458 SessionRestore::RestoreForeignSessionWindows(profile, session.begin(),
1459 session.end());
1460 Browser* new_browser = window_observer.WaitForSingleNewBrowser();
1461 ASSERT_TRUE(new_browser);
1462 ASSERT_EQ(2, new_browser->tab_strip_model()->count());
1463
1464 WaitForFirstMeaningfulPaintOfActiveTab(new_browser);
1465 ExpectFirstPaintMetricsTotalCount(1);
1466 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698