OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <vector> | |
6 | |
5 #include "base/command_line.h" | 7 #include "base/command_line.h" |
6 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
7 #include "base/process/launch.h" | 9 #include "base/process/launch.h" |
8 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
9 #include "base/time/time.h" | 11 #include "base/time/time.h" |
10 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
11 #include "chrome/browser/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" |
12 #include "chrome/browser/defaults.h" | 14 #include "chrome/browser/defaults.h" |
13 #include "chrome/browser/first_run/first_run.h" | 15 #include "chrome/browser/first_run/first_run.h" |
14 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
358 | 360 |
359 // Find the SessionID for entry2. Since the session service was destroyed, | 361 // Find the SessionID for entry2. Since the session service was destroyed, |
360 // there is no guarantee that the SessionID for the tab has remained the same. | 362 // there is no guarantee that the SessionID for the tab has remained the same. |
361 base::Time timestamp; | 363 base::Time timestamp; |
362 for (std::vector<TabRestoreService::Tab>::const_iterator it = | 364 for (std::vector<TabRestoreService::Tab>::const_iterator it = |
363 window->tabs.begin(); it != window->tabs.end(); ++it) { | 365 window->tabs.begin(); it != window->tabs.end(); ++it) { |
364 const TabRestoreService::Tab& tab = *it; | 366 const TabRestoreService::Tab& tab = *it; |
365 // If this tab held url2, then restore this single tab. | 367 // If this tab held url2, then restore this single tab. |
366 if (tab.navigations[0].virtual_url() == url2) { | 368 if (tab.navigations[0].virtual_url() == url2) { |
367 timestamp = tab.navigations[0].timestamp(); | 369 timestamp = tab.navigations[0].timestamp(); |
368 service->RestoreEntryById(NULL, tab.id, host_desktop_type, UNKNOWN); | 370 std::vector<content::WebContents*> content = |
371 service->RestoreEntryById(NULL, tab.id, host_desktop_type, UNKNOWN); | |
372 EXPECT_EQ(1U, content.size()); | |
sky
2013/08/05 16:16:17
This should be an assert. As if the size isn't 1,
Kristen Dwan
2013/08/05 18:01:38
Done.
| |
373 ASSERT_TRUE(content[0]); | |
374 EXPECT_EQ(url2, content[0]->GetURL()); | |
369 break; | 375 break; |
370 } | 376 } |
371 } | 377 } |
372 EXPECT_FALSE(timestamp.is_null()); | 378 EXPECT_FALSE(timestamp.is_null()); |
373 | 379 |
374 // Make sure that the restored tab is removed from the service. | 380 // Make sure that the restored tab is removed from the service. |
375 ASSERT_EQ(1U, service->entries().size()); | 381 ASSERT_EQ(1U, service->entries().size()); |
376 ASSERT_EQ(TabRestoreService::WINDOW, service->entries().front()->type); | 382 ASSERT_EQ(TabRestoreService::WINDOW, service->entries().front()->type); |
377 window = static_cast<TabRestoreService::Window*>(service->entries().front()); | 383 window = static_cast<TabRestoreService::Window*>(service->entries().front()); |
378 EXPECT_EQ(2U, window->tabs.size()); | 384 EXPECT_EQ(2U, window->tabs.size()); |
(...skipping 27 matching lines...) Expand all Loading... | |
406 // Close the window. | 412 // Close the window. |
407 browser()->window()->Close(); | 413 browser()->window()->Close(); |
408 | 414 |
409 // Expect the window to be converted to a tab by the TRS. | 415 // Expect the window to be converted to a tab by the TRS. |
410 EXPECT_EQ(1U, service->entries().size()); | 416 EXPECT_EQ(1U, service->entries().size()); |
411 ASSERT_EQ(TabRestoreService::TAB, service->entries().front()->type); | 417 ASSERT_EQ(TabRestoreService::TAB, service->entries().front()->type); |
412 const TabRestoreService::Tab* tab = | 418 const TabRestoreService::Tab* tab = |
413 static_cast<TabRestoreService::Tab*>(service->entries().front()); | 419 static_cast<TabRestoreService::Tab*>(service->entries().front()); |
414 | 420 |
415 // Restore the tab. | 421 // Restore the tab. |
416 service->RestoreEntryById(NULL, tab->id, host_desktop_type, UNKNOWN); | 422 std::vector<content::WebContents*> content = |
423 service->RestoreEntryById(NULL, tab->id, host_desktop_type, UNKNOWN); | |
424 EXPECT_EQ(1U, content.size()); | |
sky
2013/08/05 16:16:17
ASSERT
sky
2013/08/05 16:16:17
ASSERT
Kristen Dwan
2013/08/05 18:01:38
Done.
| |
425 ASSERT_TRUE(content[0]); | |
426 EXPECT_EQ(url, content[0]->GetURL()); | |
417 | 427 |
418 // Make sure the restore was successful. | 428 // Make sure the restore was successful. |
419 EXPECT_EQ(0U, service->entries().size()); | 429 EXPECT_EQ(0U, service->entries().size()); |
420 } | 430 } |
421 | 431 |
422 #if !defined(OS_CHROMEOS) | 432 #if !defined(OS_CHROMEOS) |
423 // This test does not apply to ChromeOS as ChromeOS does not do session | 433 // This test does not apply to ChromeOS as ChromeOS does not do session |
424 // restore when a new window is open. | 434 // restore when a new window is open. |
425 | 435 |
426 // Verifies we remember the last browser window when closing the last | 436 // Verifies we remember the last browser window when closing the last |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
489 | 499 |
490 SessionTab tab; | 500 SessionTab tab; |
491 tab.SetFromSyncData(sync_data, base::Time::Now()); | 501 tab.SetFromSyncData(sync_data, base::Time::Now()); |
492 EXPECT_EQ(2U, tab.navigations.size()); | 502 EXPECT_EQ(2U, tab.navigations.size()); |
493 for (size_t i = 0; i < tab.navigations.size(); ++i) | 503 for (size_t i = 0; i < tab.navigations.size(); ++i) |
494 EXPECT_TRUE(tab.navigations[i].timestamp().is_null()); | 504 EXPECT_TRUE(tab.navigations[i].timestamp().is_null()); |
495 | 505 |
496 ASSERT_EQ(1, browser()->tab_strip_model()->count()); | 506 ASSERT_EQ(1, browser()->tab_strip_model()->count()); |
497 | 507 |
498 // Restore in the current tab. | 508 // Restore in the current tab. |
509 content::WebContents* tab_content = NULL; | |
499 { | 510 { |
500 content::WindowedNotificationObserver observer( | 511 content::WindowedNotificationObserver observer( |
501 content::NOTIFICATION_LOAD_STOP, | 512 content::NOTIFICATION_LOAD_STOP, |
502 content::NotificationService::AllSources()); | 513 content::NotificationService::AllSources()); |
503 SessionRestore::RestoreForeignSessionTab( | 514 tab_content = SessionRestore::RestoreForeignSessionTab( |
504 browser()->tab_strip_model()->GetActiveWebContents(), tab, CURRENT_TAB); | 515 browser()->tab_strip_model()->GetActiveWebContents(), tab, CURRENT_TAB); |
505 observer.Wait(); | 516 observer.Wait(); |
506 } | 517 } |
507 ASSERT_EQ(1, browser()->tab_strip_model()->count()); | 518 ASSERT_EQ(1, browser()->tab_strip_model()->count()); |
508 content::WebContents* web_contents = | 519 content::WebContents* web_contents = |
509 browser()->tab_strip_model()->GetWebContentsAt(0); | 520 browser()->tab_strip_model()->GetWebContentsAt(0); |
510 VerifyNavigationEntries(web_contents->GetController(), url1, url2); | 521 VerifyNavigationEntries(web_contents->GetController(), url1, url2); |
511 ASSERT_TRUE(web_contents->GetUserAgentOverride().empty()); | 522 ASSERT_TRUE(web_contents->GetUserAgentOverride().empty()); |
523 ASSERT_TRUE(tab_content); | |
524 ASSERT_EQ(url2, tab_content->GetURL()); | |
512 | 525 |
513 // Restore in a new tab. | 526 // Restore in a new tab. |
527 tab_content = NULL; | |
514 { | 528 { |
515 content::WindowedNotificationObserver observer( | 529 content::WindowedNotificationObserver observer( |
516 content::NOTIFICATION_LOAD_STOP, | 530 content::NOTIFICATION_LOAD_STOP, |
517 content::NotificationService::AllSources()); | 531 content::NotificationService::AllSources()); |
518 SessionRestore::RestoreForeignSessionTab( | 532 tab_content = SessionRestore::RestoreForeignSessionTab( |
519 browser()->tab_strip_model()->GetActiveWebContents(), | 533 browser()->tab_strip_model()->GetActiveWebContents(), |
520 tab, NEW_BACKGROUND_TAB); | 534 tab, NEW_BACKGROUND_TAB); |
521 observer.Wait(); | 535 observer.Wait(); |
522 } | 536 } |
523 ASSERT_EQ(2, browser()->tab_strip_model()->count()); | 537 ASSERT_EQ(2, browser()->tab_strip_model()->count()); |
524 ASSERT_EQ(0, browser()->tab_strip_model()->active_index()); | 538 ASSERT_EQ(0, browser()->tab_strip_model()->active_index()); |
525 web_contents = browser()->tab_strip_model()->GetWebContentsAt(1); | 539 web_contents = browser()->tab_strip_model()->GetWebContentsAt(1); |
526 VerifyNavigationEntries(web_contents->GetController(), url1, url2); | 540 VerifyNavigationEntries(web_contents->GetController(), url1, url2); |
527 ASSERT_TRUE(web_contents->GetUserAgentOverride().empty()); | 541 ASSERT_TRUE(web_contents->GetUserAgentOverride().empty()); |
542 ASSERT_TRUE(tab_content); | |
543 ASSERT_EQ(url2, tab_content->GetURL()); | |
528 | 544 |
529 // Restore in a new window. | 545 // Restore in a new window. |
530 Browser* new_browser = NULL; | 546 Browser* new_browser = NULL; |
547 tab_content = NULL; | |
531 { | 548 { |
532 ui_test_utils::BrowserAddedObserver browser_observer; | 549 ui_test_utils::BrowserAddedObserver browser_observer; |
533 content::WindowedNotificationObserver observer( | 550 content::WindowedNotificationObserver observer( |
534 content::NOTIFICATION_LOAD_STOP, | 551 content::NOTIFICATION_LOAD_STOP, |
535 content::NotificationService::AllSources()); | 552 content::NotificationService::AllSources()); |
536 SessionRestore::RestoreForeignSessionTab( | 553 tab_content = SessionRestore::RestoreForeignSessionTab( |
537 browser()->tab_strip_model()->GetActiveWebContents(), tab, NEW_WINDOW); | 554 browser()->tab_strip_model()->GetActiveWebContents(), tab, NEW_WINDOW); |
538 new_browser = browser_observer.WaitForSingleNewBrowser(); | 555 new_browser = browser_observer.WaitForSingleNewBrowser(); |
539 observer.Wait(); | 556 observer.Wait(); |
540 } | 557 } |
541 | 558 |
542 ASSERT_EQ(1, new_browser->tab_strip_model()->count()); | 559 ASSERT_EQ(1, new_browser->tab_strip_model()->count()); |
543 web_contents = new_browser->tab_strip_model()->GetWebContentsAt(0); | 560 web_contents = new_browser->tab_strip_model()->GetWebContentsAt(0); |
544 VerifyNavigationEntries(web_contents->GetController(), url1, url2); | 561 VerifyNavigationEntries(web_contents->GetController(), url1, url2); |
545 ASSERT_TRUE(web_contents->GetUserAgentOverride().empty()); | 562 ASSERT_TRUE(web_contents->GetUserAgentOverride().empty()); |
563 ASSERT_TRUE(tab_content); | |
564 ASSERT_EQ(url2, tab_content->GetURL()); | |
546 } | 565 } |
547 | 566 |
548 IN_PROC_BROWSER_TEST_F(SessionRestoreTest, RestoreForeignSession) { | 567 IN_PROC_BROWSER_TEST_F(SessionRestoreTest, RestoreForeignSession) { |
549 Profile* profile = browser()->profile(); | 568 Profile* profile = browser()->profile(); |
550 | 569 |
551 GURL url1("http://google.com"); | 570 GURL url1("http://google.com"); |
552 GURL url2("http://google2.com"); | 571 GURL url2("http://google2.com"); |
553 SerializedNavigationEntry nav1 = | 572 SerializedNavigationEntry nav1 = |
554 SerializedNavigationEntryTestHelper::CreateNavigation(url1.spec(), "one"); | 573 SerializedNavigationEntryTestHelper::CreateNavigation(url1.spec(), "one"); |
555 SerializedNavigationEntry nav2 = | 574 SerializedNavigationEntry nav2 = |
(...skipping 20 matching lines...) Expand all Loading... | |
576 sync_data.set_tab_visual_index(1); | 595 sync_data.set_tab_visual_index(1); |
577 sync_data.set_current_navigation_index(0); | 596 sync_data.set_current_navigation_index(0); |
578 sync_data.set_pinned(false); | 597 sync_data.set_pinned(false); |
579 sync_data.add_navigation()->CopyFrom(nav2.ToSyncData()); | 598 sync_data.add_navigation()->CopyFrom(nav2.ToSyncData()); |
580 tab2.SetFromSyncData(sync_data, base::Time::Now()); | 599 tab2.SetFromSyncData(sync_data, base::Time::Now()); |
581 } | 600 } |
582 window.tabs.push_back(&tab2); | 601 window.tabs.push_back(&tab2); |
583 | 602 |
584 session.push_back(static_cast<const SessionWindow*>(&window)); | 603 session.push_back(static_cast<const SessionWindow*>(&window)); |
585 ui_test_utils::BrowserAddedObserver window_observer; | 604 ui_test_utils::BrowserAddedObserver window_observer; |
586 SessionRestore::RestoreForeignSessionWindows( | 605 std::vector<Browser*> browsers = |
587 profile, browser()->host_desktop_type(), session.begin(), session.end()); | 606 SessionRestore::RestoreForeignSessionWindows( |
607 profile, browser()->host_desktop_type(), session.begin(), | |
608 session.end()); | |
588 Browser* new_browser = window_observer.WaitForSingleNewBrowser(); | 609 Browser* new_browser = window_observer.WaitForSingleNewBrowser(); |
589 ASSERT_TRUE(new_browser); | 610 ASSERT_TRUE(new_browser); |
590 ASSERT_EQ(2u, active_browser_list_->size()); | 611 ASSERT_EQ(2u, active_browser_list_->size()); |
591 ASSERT_EQ(2, new_browser->tab_strip_model()->count()); | 612 ASSERT_EQ(2, new_browser->tab_strip_model()->count()); |
592 | 613 |
614 ASSERT_EQ(1u, browsers.size()); | |
615 ASSERT_TRUE(browsers[0]); | |
616 ASSERT_EQ(2, browsers[0]->tab_strip_model()->count()); | |
617 | |
593 content::WebContents* web_contents_1 = | 618 content::WebContents* web_contents_1 = |
594 new_browser->tab_strip_model()->GetWebContentsAt(0); | 619 new_browser->tab_strip_model()->GetWebContentsAt(0); |
595 content::WebContents* web_contents_2 = | 620 content::WebContents* web_contents_2 = |
596 new_browser->tab_strip_model()->GetWebContentsAt(1); | 621 new_browser->tab_strip_model()->GetWebContentsAt(1); |
597 ASSERT_EQ(url1, web_contents_1->GetURL()); | 622 ASSERT_EQ(url1, web_contents_1->GetURL()); |
598 ASSERT_EQ(url2, web_contents_2->GetURL()); | 623 ASSERT_EQ(url2, web_contents_2->GetURL()); |
599 | 624 |
600 // Check user agent override state. | 625 // Check user agent override state. |
601 ASSERT_TRUE(web_contents_1->GetUserAgentOverride().empty()); | 626 ASSERT_TRUE(web_contents_1->GetUserAgentOverride().empty()); |
602 ASSERT_TRUE(web_contents_2->GetUserAgentOverride().empty()); | 627 ASSERT_TRUE(web_contents_2->GetUserAgentOverride().empty()); |
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1129 content::NavigationController* controller = | 1154 content::NavigationController* controller = |
1130 &browser()->tab_strip_model()->GetActiveWebContents()->GetController(); | 1155 &browser()->tab_strip_model()->GetActiveWebContents()->GetController(); |
1131 EXPECT_TRUE( | 1156 EXPECT_TRUE( |
1132 controller->GetDefaultSessionStorageNamespace()->should_persist()); | 1157 controller->GetDefaultSessionStorageNamespace()->should_persist()); |
1133 | 1158 |
1134 // Quit and restore. Check that no extra tabs were created. | 1159 // Quit and restore. Check that no extra tabs were created. |
1135 Browser* new_browser = QuitBrowserAndRestore(browser(), 1); | 1160 Browser* new_browser = QuitBrowserAndRestore(browser(), 1); |
1136 ASSERT_EQ(1u, active_browser_list_->size()); | 1161 ASSERT_EQ(1u, active_browser_list_->size()); |
1137 EXPECT_EQ(1, new_browser->tab_strip_model()->count()); | 1162 EXPECT_EQ(1, new_browser->tab_strip_model()->count()); |
1138 } | 1163 } |
OLD | NEW |