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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/file_path.h" | 6 #include "base/file_path.h" |
7 #include "base/time.h" | 7 #include "base/time.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/defaults.h" | 10 #include "chrome/browser/defaults.h" |
11 #include "chrome/browser/first_run/first_run.h" | 11 #include "chrome/browser/first_run/first_run.h" |
12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/browser/profiles/profile_manager.h" | 13 #include "chrome/browser/profiles/profile_manager.h" |
14 #include "chrome/browser/sessions/session_restore.h" | 14 #include "chrome/browser/sessions/session_restore.h" |
15 #include "chrome/browser/sessions/session_service.h" | 15 #include "chrome/browser/sessions/session_service.h" |
16 #include "chrome/browser/sessions/session_service_factory.h" | 16 #include "chrome/browser/sessions/session_service_factory.h" |
17 #include "chrome/browser/sessions/session_service_test_helper.h" | 17 #include "chrome/browser/sessions/session_service_test_helper.h" |
18 #include "chrome/browser/sessions/session_types.h" | 18 #include "chrome/browser/sessions/session_types.h" |
19 #include "chrome/browser/sessions/session_types_test_helper.h" | 19 #include "chrome/browser/sessions/session_types_test_helper.h" |
20 #include "chrome/browser/sessions/tab_restore_service.h" | 20 #include "chrome/browser/sessions/tab_restore_service.h" |
21 #include "chrome/browser/sessions/tab_restore_service_factory.h" | 21 #include "chrome/browser/sessions/tab_restore_service_factory.h" |
22 #include "chrome/browser/ui/browser.h" | 22 #include "chrome/browser/ui/browser.h" |
23 #include "chrome/browser/ui/browser_commands.h" | 23 #include "chrome/browser/ui/browser_commands.h" |
24 #include "chrome/browser/ui/browser_list.h" | 24 #include "chrome/browser/ui/browser_list_impl.h" |
25 #include "chrome/browser/ui/browser_tabstrip.h" | 25 #include "chrome/browser/ui/browser_tabstrip.h" |
26 #include "chrome/browser/ui/browser_window.h" | 26 #include "chrome/browser/ui/browser_window.h" |
27 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 27 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
28 #include "chrome/common/chrome_notification_types.h" | 28 #include "chrome/common/chrome_notification_types.h" |
29 #include "chrome/common/chrome_switches.h" | 29 #include "chrome/common/chrome_switches.h" |
30 #include "chrome/common/url_constants.h" | 30 #include "chrome/common/url_constants.h" |
31 #include "chrome/test/base/in_process_browser_test.h" | 31 #include "chrome/test/base/in_process_browser_test.h" |
32 #include "chrome/test/base/ui_test_utils.h" | 32 #include "chrome/test/base/ui_test_utils.h" |
33 #include "content/public/browser/navigation_controller.h" | 33 #include "content/public/browser/navigation_controller.h" |
34 #include "content/public/browser/navigation_entry.h" | 34 #include "content/public/browser/navigation_entry.h" |
35 #include "content/public/browser/notification_service.h" | 35 #include "content/public/browser/notification_service.h" |
36 #include "content/public/browser/notification_types.h" | 36 #include "content/public/browser/notification_types.h" |
37 #include "content/public/browser/render_process_host.h" | 37 #include "content/public/browser/render_process_host.h" |
38 #include "content/public/browser/web_contents.h" | 38 #include "content/public/browser/web_contents.h" |
39 #include "content/public/common/page_transition_types.h" | 39 #include "content/public/common/page_transition_types.h" |
40 #include "content/public/test/test_navigation_observer.h" | 40 #include "content/public/test/test_navigation_observer.h" |
41 #include "sync/protocol/session_specifics.pb.h" | 41 #include "sync/protocol/session_specifics.pb.h" |
42 | 42 |
43 #if defined(OS_MACOSX) | 43 #if defined(OS_MACOSX) |
44 #include "base/mac/scoped_nsautorelease_pool.h" | 44 #include "base/mac/scoped_nsautorelease_pool.h" |
45 #endif | 45 #endif |
46 | 46 |
47 class SessionRestoreTest : public InProcessBrowserTest { | 47 class SessionRestoreTest : public InProcessBrowserTest { |
| 48 public: |
| 49 SessionRestoreTest() |
| 50 : native_browser_list(chrome::BrowserListImpl::GetInstance( |
| 51 chrome::HOST_DESKTOP_TYPE_NATIVE)) { |
| 52 } |
| 53 |
48 protected: | 54 protected: |
49 #if defined(OS_CHROMEOS) | 55 #if defined(OS_CHROMEOS) |
50 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 56 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
51 // TODO(nkostylev): Investigate if we can remove this switch. | 57 // TODO(nkostylev): Investigate if we can remove this switch. |
52 command_line->AppendSwitch(switches::kCreateBrowserOnStartupForTests); | 58 command_line->AppendSwitch(switches::kCreateBrowserOnStartupForTests); |
53 InProcessBrowserTest::SetUpCommandLine(command_line); | 59 InProcessBrowserTest::SetUpCommandLine(command_line); |
54 } | 60 } |
55 #endif | 61 #endif |
56 | 62 |
57 virtual void SetUpOnMainThread() OVERRIDE { | 63 virtual void SetUpOnMainThread() OVERRIDE { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 | 140 |
135 void GoForward(Browser* browser) { | 141 void GoForward(Browser* browser) { |
136 content::WindowedNotificationObserver observer( | 142 content::WindowedNotificationObserver observer( |
137 content::NOTIFICATION_LOAD_STOP, | 143 content::NOTIFICATION_LOAD_STOP, |
138 content::NotificationService::AllSources()); | 144 content::NotificationService::AllSources()); |
139 chrome::GoForward(browser, CURRENT_TAB); | 145 chrome::GoForward(browser, CURRENT_TAB); |
140 observer.Wait(); | 146 observer.Wait(); |
141 } | 147 } |
142 | 148 |
143 void AssertOneWindowWithOneTab(Browser* browser) { | 149 void AssertOneWindowWithOneTab(Browser* browser) { |
144 ASSERT_EQ(1u, BrowserList::size()); | 150 ASSERT_EQ(1u, native_browser_list->size()); |
145 ASSERT_EQ(1, browser->tab_strip_model()->count()); | 151 ASSERT_EQ(1, browser->tab_strip_model()->count()); |
146 } | 152 } |
147 | 153 |
148 int RenderProcessHostCount() { | 154 int RenderProcessHostCount() { |
149 content::RenderProcessHost::iterator hosts = | 155 content::RenderProcessHost::iterator hosts = |
150 content::RenderProcessHost::AllHostsIterator(); | 156 content::RenderProcessHost::AllHostsIterator(); |
151 int count = 0; | 157 int count = 0; |
152 while (!hosts.IsAtEnd()) { | 158 while (!hosts.IsAtEnd()) { |
153 if (hosts.GetCurrentValue()->HasConnection()) | 159 if (hosts.GetCurrentValue()->HasConnection()) |
154 count++; | 160 count++; |
155 hosts.Advance(); | 161 hosts.Advance(); |
156 } | 162 } |
157 return count; | 163 return count; |
158 } | 164 } |
159 | 165 |
160 GURL url1_; | 166 GURL url1_; |
161 GURL url2_; | 167 GURL url2_; |
162 GURL url3_; | 168 GURL url3_; |
| 169 |
| 170 // The SessionRestore browser tests only uses the native desktop for now. |
| 171 const chrome::BrowserListImpl* native_browser_list; |
163 }; | 172 }; |
164 | 173 |
165 #if defined(OS_CHROMEOS) | 174 #if defined(OS_CHROMEOS) |
166 // Verify that session restore does not occur when a user opens a browser window | 175 // Verify that session restore does not occur when a user opens a browser window |
167 // when no other browser windows are open on ChromeOS. | 176 // when no other browser windows are open on ChromeOS. |
168 // TODO(pkotwicz): Add test which doesn't open incognito browser once | 177 // TODO(pkotwicz): Add test which doesn't open incognito browser once |
169 // disable-zero-browsers-open-for-tests is removed. | 178 // disable-zero-browsers-open-for-tests is removed. |
170 // (http://crbug.com/119175) | 179 // (http://crbug.com/119175) |
171 // TODO(pkotwicz): Mac should have the behavior outlined by this test. It should | 180 // TODO(pkotwicz): Mac should have the behavior outlined by this test. It should |
172 // not do session restore if an incognito window is already open. | 181 // not do session restore if an incognito window is already open. |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
526 tab2.SetFromSyncData(sync_data, base::Time::Now()); | 535 tab2.SetFromSyncData(sync_data, base::Time::Now()); |
527 } | 536 } |
528 window.tabs.push_back(&tab2); | 537 window.tabs.push_back(&tab2); |
529 | 538 |
530 session.push_back(static_cast<const SessionWindow*>(&window)); | 539 session.push_back(static_cast<const SessionWindow*>(&window)); |
531 ui_test_utils::BrowserAddedObserver window_observer; | 540 ui_test_utils::BrowserAddedObserver window_observer; |
532 SessionRestore::RestoreForeignSessionWindows( | 541 SessionRestore::RestoreForeignSessionWindows( |
533 profile, browser()->host_desktop_type(), session.begin(), session.end()); | 542 profile, browser()->host_desktop_type(), session.begin(), session.end()); |
534 Browser* new_browser = window_observer.WaitForSingleNewBrowser(); | 543 Browser* new_browser = window_observer.WaitForSingleNewBrowser(); |
535 ASSERT_TRUE(new_browser); | 544 ASSERT_TRUE(new_browser); |
536 ASSERT_EQ(2u, BrowserList::size()); | 545 ASSERT_EQ(2u, native_browser_list->size()); |
537 ASSERT_EQ(2, new_browser->tab_strip_model()->count()); | 546 ASSERT_EQ(2, new_browser->tab_strip_model()->count()); |
538 | 547 |
539 content::WebContents* web_contents_1 = | 548 content::WebContents* web_contents_1 = |
540 new_browser->tab_strip_model()->GetWebContentsAt(0); | 549 new_browser->tab_strip_model()->GetWebContentsAt(0); |
541 content::WebContents* web_contents_2 = | 550 content::WebContents* web_contents_2 = |
542 new_browser->tab_strip_model()->GetWebContentsAt(1); | 551 new_browser->tab_strip_model()->GetWebContentsAt(1); |
543 ASSERT_EQ(url1, web_contents_1->GetURL()); | 552 ASSERT_EQ(url1, web_contents_1->GetURL()); |
544 ASSERT_EQ(url2, web_contents_2->GetURL()); | 553 ASSERT_EQ(url2, web_contents_2->GetURL()); |
545 | 554 |
546 // Check user agent override state. | 555 // Check user agent override state. |
(...skipping 12 matching lines...) Expand all Loading... |
559 // The SessionWindow destructor deletes the tabs, so we have to clear them | 568 // The SessionWindow destructor deletes the tabs, so we have to clear them |
560 // here to avoid a crash. | 569 // here to avoid a crash. |
561 window.tabs.clear(); | 570 window.tabs.clear(); |
562 } | 571 } |
563 | 572 |
564 IN_PROC_BROWSER_TEST_F(SessionRestoreTest, Basic) { | 573 IN_PROC_BROWSER_TEST_F(SessionRestoreTest, Basic) { |
565 ui_test_utils::NavigateToURL(browser(), url1_); | 574 ui_test_utils::NavigateToURL(browser(), url1_); |
566 ui_test_utils::NavigateToURL(browser(), url2_); | 575 ui_test_utils::NavigateToURL(browser(), url2_); |
567 | 576 |
568 Browser* new_browser = QuitBrowserAndRestore(browser(), 1); | 577 Browser* new_browser = QuitBrowserAndRestore(browser(), 1); |
569 ASSERT_EQ(1u, BrowserList::size()); | 578 ASSERT_EQ(1u, native_browser_list->size()); |
570 ASSERT_EQ(url2_, | 579 ASSERT_EQ(url2_, |
571 new_browser->tab_strip_model()->GetActiveWebContents()->GetURL()); | 580 new_browser->tab_strip_model()->GetActiveWebContents()->GetURL()); |
572 GoBack(new_browser); | 581 GoBack(new_browser); |
573 ASSERT_EQ(url1_, | 582 ASSERT_EQ(url1_, |
574 new_browser->tab_strip_model()->GetActiveWebContents()->GetURL()); | 583 new_browser->tab_strip_model()->GetActiveWebContents()->GetURL()); |
575 } | 584 } |
576 | 585 |
577 IN_PROC_BROWSER_TEST_F(SessionRestoreTest, RestoresForwardAndBackwardNavs) { | 586 IN_PROC_BROWSER_TEST_F(SessionRestoreTest, RestoresForwardAndBackwardNavs) { |
578 ui_test_utils::NavigateToURL(browser(), url1_); | 587 ui_test_utils::NavigateToURL(browser(), url1_); |
579 ui_test_utils::NavigateToURL(browser(), url2_); | 588 ui_test_utils::NavigateToURL(browser(), url2_); |
580 ui_test_utils::NavigateToURL(browser(), url3_); | 589 ui_test_utils::NavigateToURL(browser(), url3_); |
581 | 590 |
582 GoBack(browser()); | 591 GoBack(browser()); |
583 Browser* new_browser = QuitBrowserAndRestore(browser(), 1); | 592 Browser* new_browser = QuitBrowserAndRestore(browser(), 1); |
584 ASSERT_EQ(1u, BrowserList::size()); | 593 ASSERT_EQ(1u, native_browser_list->size()); |
585 ASSERT_EQ(url2_, | 594 ASSERT_EQ(url2_, |
586 new_browser->tab_strip_model()->GetActiveWebContents()->GetURL()); | 595 new_browser->tab_strip_model()->GetActiveWebContents()->GetURL()); |
587 GoForward(new_browser); | 596 GoForward(new_browser); |
588 ASSERT_EQ(url3_, | 597 ASSERT_EQ(url3_, |
589 new_browser->tab_strip_model()->GetActiveWebContents()->GetURL()); | 598 new_browser->tab_strip_model()->GetActiveWebContents()->GetURL()); |
590 GoBack(new_browser); | 599 GoBack(new_browser); |
591 ASSERT_EQ(url2_, | 600 ASSERT_EQ(url2_, |
592 new_browser->tab_strip_model()->GetActiveWebContents()->GetURL()); | 601 new_browser->tab_strip_model()->GetActiveWebContents()->GetURL()); |
593 | 602 |
594 // Test renderer-initiated back/forward as well. | 603 // Test renderer-initiated back/forward as well. |
(...skipping 12 matching lines...) Expand all Loading... |
607 | 616 |
608 GURL cross_site_url(test_server()->GetURL("files/title2.html")); | 617 GURL cross_site_url(test_server()->GetURL("files/title2.html")); |
609 | 618 |
610 // Visit URLs on different sites. | 619 // Visit URLs on different sites. |
611 ui_test_utils::NavigateToURL(browser(), url1_); | 620 ui_test_utils::NavigateToURL(browser(), url1_); |
612 ui_test_utils::NavigateToURL(browser(), cross_site_url); | 621 ui_test_utils::NavigateToURL(browser(), cross_site_url); |
613 ui_test_utils::NavigateToURL(browser(), url2_); | 622 ui_test_utils::NavigateToURL(browser(), url2_); |
614 | 623 |
615 GoBack(browser()); | 624 GoBack(browser()); |
616 Browser* new_browser = QuitBrowserAndRestore(browser(), 1); | 625 Browser* new_browser = QuitBrowserAndRestore(browser(), 1); |
617 ASSERT_EQ(1u, BrowserList::size()); | 626 ASSERT_EQ(1u, native_browser_list->size()); |
618 ASSERT_EQ(1, new_browser->tab_strip_model()->count()); | 627 ASSERT_EQ(1, new_browser->tab_strip_model()->count()); |
619 | 628 |
620 // Check that back and forward work as expected. | 629 // Check that back and forward work as expected. |
621 ASSERT_EQ(cross_site_url, | 630 ASSERT_EQ(cross_site_url, |
622 new_browser->tab_strip_model()->GetActiveWebContents()->GetURL()); | 631 new_browser->tab_strip_model()->GetActiveWebContents()->GetURL()); |
623 | 632 |
624 GoBack(new_browser); | 633 GoBack(new_browser); |
625 ASSERT_EQ(url1_, | 634 ASSERT_EQ(url1_, |
626 new_browser->tab_strip_model()->GetActiveWebContents()->GetURL()); | 635 new_browser->tab_strip_model()->GetActiveWebContents()->GetURL()); |
627 | 636 |
(...skipping 10 matching lines...) Expand all Loading... |
638 | 647 |
639 IN_PROC_BROWSER_TEST_F(SessionRestoreTest, TwoTabsSecondSelected) { | 648 IN_PROC_BROWSER_TEST_F(SessionRestoreTest, TwoTabsSecondSelected) { |
640 ui_test_utils::NavigateToURL(browser(), url1_); | 649 ui_test_utils::NavigateToURL(browser(), url1_); |
641 | 650 |
642 ui_test_utils::NavigateToURLWithDisposition( | 651 ui_test_utils::NavigateToURLWithDisposition( |
643 browser(), url2_, NEW_FOREGROUND_TAB, | 652 browser(), url2_, NEW_FOREGROUND_TAB, |
644 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 653 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
645 | 654 |
646 Browser* new_browser = QuitBrowserAndRestore(browser(), 2); | 655 Browser* new_browser = QuitBrowserAndRestore(browser(), 2); |
647 | 656 |
648 ASSERT_EQ(1u, BrowserList::size()); | 657 ASSERT_EQ(1u, native_browser_list->size()); |
649 ASSERT_EQ(2, new_browser->tab_strip_model()->count()); | 658 ASSERT_EQ(2, new_browser->tab_strip_model()->count()); |
650 ASSERT_EQ(1, new_browser->tab_strip_model()->active_index()); | 659 ASSERT_EQ(1, new_browser->tab_strip_model()->active_index()); |
651 ASSERT_EQ(url2_, | 660 ASSERT_EQ(url2_, |
652 new_browser->tab_strip_model()->GetActiveWebContents()->GetURL()); | 661 new_browser->tab_strip_model()->GetActiveWebContents()->GetURL()); |
653 | 662 |
654 ASSERT_EQ(url1_, | 663 ASSERT_EQ(url1_, |
655 new_browser->tab_strip_model()->GetWebContentsAt(0)->GetURL()); | 664 new_browser->tab_strip_model()->GetWebContentsAt(0)->GetURL()); |
656 } | 665 } |
657 | 666 |
658 // Creates two tabs, closes one, quits and makes sure only one tab is restored. | 667 // Creates two tabs, closes one, quits and makes sure only one tab is restored. |
(...skipping 20 matching lines...) Expand all Loading... |
679 ui_test_utils::NavigateToURL(browser(), url1_); | 688 ui_test_utils::NavigateToURL(browser(), url1_); |
680 | 689 |
681 // Make sure we have one window. | 690 // Make sure we have one window. |
682 AssertOneWindowWithOneTab(browser()); | 691 AssertOneWindowWithOneTab(browser()); |
683 | 692 |
684 // Open a popup. | 693 // Open a popup. |
685 Browser* popup = new Browser( | 694 Browser* popup = new Browser( |
686 Browser::CreateParams(Browser::TYPE_POPUP, browser()->profile(), | 695 Browser::CreateParams(Browser::TYPE_POPUP, browser()->profile(), |
687 browser()->host_desktop_type())); | 696 browser()->host_desktop_type())); |
688 popup->window()->Show(); | 697 popup->window()->Show(); |
689 ASSERT_EQ(2u, BrowserList::size()); | 698 ASSERT_EQ(2u, native_browser_list->size()); |
690 | 699 |
691 ui_test_utils::NavigateToURL(popup, url1_); | 700 ui_test_utils::NavigateToURL(popup, url1_); |
692 | 701 |
693 // Simulate an exit by shuting down the session service. If we don't do this | 702 // Simulate an exit by shuting down the session service. If we don't do this |
694 // the first window close is treated as though the user closed the window | 703 // the first window close is treated as though the user closed the window |
695 // and won't be restored. | 704 // and won't be restored. |
696 SessionServiceFactory::ShutdownForProfile(browser()->profile()); | 705 SessionServiceFactory::ShutdownForProfile(browser()->profile()); |
697 | 706 |
698 // Restart and make sure we have two windows. | 707 // Restart and make sure we have two windows. |
699 QuitBrowserAndRestore(browser(), 1); | 708 QuitBrowserAndRestore(browser(), 1); |
700 | 709 |
701 ASSERT_EQ(2u, BrowserList::size()); | 710 ASSERT_EQ(2u, native_browser_list->size()); |
702 | 711 |
703 Browser* browser1 = *BrowserList::begin(); | 712 Browser* browser1 = native_browser_list->get(0); |
704 Browser* browser2 = *(++BrowserList::begin()); | 713 Browser* browser2 = native_browser_list->get(1); |
705 | 714 |
706 Browser::Type type1 = browser1->type(); | 715 Browser::Type type1 = browser1->type(); |
707 Browser::Type type2 = browser2->type(); | 716 Browser::Type type2 = browser2->type(); |
708 | 717 |
709 // The order of whether the normal window or popup is first depends upon | 718 // The order of whether the normal window or popup is first depends upon |
710 // activation order, which is not necessarily consistant across runs. | 719 // activation order, which is not necessarily consistant across runs. |
711 if (type1 == Browser::TYPE_TABBED) { | 720 if (type1 == Browser::TYPE_TABBED) { |
712 EXPECT_EQ(type2, Browser::TYPE_POPUP); | 721 EXPECT_EQ(type2, Browser::TYPE_POPUP); |
713 } else { | 722 } else { |
714 EXPECT_EQ(type1, Browser::TYPE_POPUP); | 723 EXPECT_EQ(type1, Browser::TYPE_POPUP); |
(...skipping 15 matching lines...) Expand all Loading... |
730 | 739 |
731 // Launch an app. | 740 // Launch an app. |
732 CommandLine app_launch_arguments = GetCommandLineForRelaunch(); | 741 CommandLine app_launch_arguments = GetCommandLineForRelaunch(); |
733 app_launch_arguments.AppendSwitchASCII(switches::kApp, url2_.spec()); | 742 app_launch_arguments.AppendSwitchASCII(switches::kApp, url2_.spec()); |
734 | 743 |
735 ui_test_utils::BrowserAddedObserver window_observer; | 744 ui_test_utils::BrowserAddedObserver window_observer; |
736 | 745 |
737 base::LaunchProcess(app_launch_arguments, base::LaunchOptions(), NULL); | 746 base::LaunchProcess(app_launch_arguments, base::LaunchOptions(), NULL); |
738 | 747 |
739 Browser* app_window = window_observer.WaitForSingleNewBrowser(); | 748 Browser* app_window = window_observer.WaitForSingleNewBrowser(); |
740 ASSERT_EQ(2u, BrowserList::size()); | 749 ASSERT_EQ(2u, native_browser_list->size()); |
741 | 750 |
742 // Close the first window. The only window left is the App window. | 751 // Close the first window. The only window left is the App window. |
743 CloseBrowserSynchronously(browser()); | 752 CloseBrowserSynchronously(browser()); |
744 | 753 |
745 // Restore the session, which should bring back the first window with url1_. | 754 // Restore the session, which should bring back the first window with url1_. |
746 Browser* new_browser = QuitBrowserAndRestore(app_window, 1); | 755 Browser* new_browser = QuitBrowserAndRestore(app_window, 1); |
747 | 756 |
748 AssertOneWindowWithOneTab(new_browser); | 757 AssertOneWindowWithOneTab(new_browser); |
749 | 758 |
750 ASSERT_EQ(url1_, | 759 ASSERT_EQ(url1_, |
751 new_browser->tab_strip_model()->GetActiveWebContents()->GetURL()); | 760 new_browser->tab_strip_model()->GetActiveWebContents()->GetURL()); |
752 } | 761 } |
753 | 762 |
754 #endif // !defined(OS_CHROMEOS) && !defined(OS_MACOSX) | 763 #endif // !defined(OS_CHROMEOS) && !defined(OS_MACOSX) |
755 | 764 |
756 // Creates two windows, closes one, restores, make sure only one window open. | 765 // Creates two windows, closes one, restores, make sure only one window open. |
757 IN_PROC_BROWSER_TEST_F(SessionRestoreTest, TwoWindowsCloseOneRestoreOnlyOne) { | 766 IN_PROC_BROWSER_TEST_F(SessionRestoreTest, TwoWindowsCloseOneRestoreOnlyOne) { |
758 ui_test_utils::NavigateToURL(browser(), url1_); | 767 ui_test_utils::NavigateToURL(browser(), url1_); |
759 | 768 |
760 // Open a second window. | 769 // Open a second window. |
761 ui_test_utils::NavigateToURLWithDisposition( | 770 ui_test_utils::NavigateToURLWithDisposition( |
762 browser(), GURL(chrome::kAboutBlankURL), NEW_WINDOW, | 771 browser(), GURL(chrome::kAboutBlankURL), NEW_WINDOW, |
763 ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER); | 772 ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER); |
764 | 773 |
765 ASSERT_EQ(2u, BrowserList::size()); | 774 ASSERT_EQ(2u, native_browser_list->size()); |
766 | 775 |
767 // Close it. | 776 // Close it. |
768 Browser* new_window = *(++BrowserList::begin()); | 777 Browser* new_window = native_browser_list->get(1); |
769 CloseBrowserSynchronously(new_window); | 778 CloseBrowserSynchronously(new_window); |
770 | 779 |
771 // Restart and make sure we have only one window with one tab and the url | 780 // Restart and make sure we have only one window with one tab and the url |
772 // is url1_. | 781 // is url1_. |
773 Browser* new_browser = QuitBrowserAndRestore(browser(), 1); | 782 Browser* new_browser = QuitBrowserAndRestore(browser(), 1); |
774 | 783 |
775 AssertOneWindowWithOneTab(new_browser); | 784 AssertOneWindowWithOneTab(new_browser); |
776 | 785 |
777 ASSERT_EQ(url1_, | 786 ASSERT_EQ(url1_, |
778 new_browser->tab_strip_model()->GetActiveWebContents()->GetURL()); | 787 new_browser->tab_strip_model()->GetActiveWebContents()->GetURL()); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
817 SetUserAgentOverride("override"); | 826 SetUserAgentOverride("override"); |
818 | 827 |
819 // Create a tab without an overridden user agent. | 828 // Create a tab without an overridden user agent. |
820 ui_test_utils::NavigateToURLWithDisposition( | 829 ui_test_utils::NavigateToURLWithDisposition( |
821 browser(), url2_, NEW_FOREGROUND_TAB, | 830 browser(), url2_, NEW_FOREGROUND_TAB, |
822 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 831 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
823 ASSERT_EQ(1, browser()->tab_strip_model()->active_index()); | 832 ASSERT_EQ(1, browser()->tab_strip_model()->active_index()); |
824 | 833 |
825 // Kill the original browser then open a new one to trigger a restore. | 834 // Kill the original browser then open a new one to trigger a restore. |
826 Browser* new_browser = QuitBrowserAndRestore(browser(), 1); | 835 Browser* new_browser = QuitBrowserAndRestore(browser(), 1); |
827 ASSERT_EQ(1u, BrowserList::size()); | 836 ASSERT_EQ(1u, native_browser_list->size()); |
828 ASSERT_EQ(2, new_browser->tab_strip_model()->count()); | 837 ASSERT_EQ(2, new_browser->tab_strip_model()->count()); |
829 ASSERT_EQ(1, new_browser->tab_strip_model()->active_index()); | 838 ASSERT_EQ(1, new_browser->tab_strip_model()->active_index()); |
830 | 839 |
831 // Confirm that the user agent overrides are properly set. | 840 // Confirm that the user agent overrides are properly set. |
832 EXPECT_EQ("override", | 841 EXPECT_EQ("override", |
833 new_browser->tab_strip_model()->GetWebContentsAt(0)-> | 842 new_browser->tab_strip_model()->GetWebContentsAt(0)-> |
834 GetUserAgentOverride()); | 843 GetUserAgentOverride()); |
835 EXPECT_EQ("", | 844 EXPECT_EQ("", |
836 new_browser->tab_strip_model()->GetWebContentsAt(1)-> | 845 new_browser->tab_strip_model()->GetWebContentsAt(1)-> |
837 GetUserAgentOverride()); | 846 GetUserAgentOverride()); |
(...skipping 13 matching lines...) Expand all Loading... |
851 browser(), url2_, NEW_FOREGROUND_TAB, | 860 browser(), url2_, NEW_FOREGROUND_TAB, |
852 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 861 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
853 ASSERT_EQ(1, browser()->tab_strip_model()->active_index()); | 862 ASSERT_EQ(1, browser()->tab_strip_model()->active_index()); |
854 // Select the pinned tab. | 863 // Select the pinned tab. |
855 browser()->tab_strip_model()->ActivateTabAt(0, true); | 864 browser()->tab_strip_model()->ActivateTabAt(0, true); |
856 ASSERT_EQ(0, browser()->tab_strip_model()->active_index()); | 865 ASSERT_EQ(0, browser()->tab_strip_model()->active_index()); |
857 Profile* profile = browser()->profile(); | 866 Profile* profile = browser()->profile(); |
858 | 867 |
859 // This will also initiate a session restore, but we're not interested in it. | 868 // This will also initiate a session restore, but we're not interested in it. |
860 Browser* new_browser = QuitBrowserAndRestore(browser(), 1); | 869 Browser* new_browser = QuitBrowserAndRestore(browser(), 1); |
861 ASSERT_EQ(1u, BrowserList::size()); | 870 ASSERT_EQ(1u, native_browser_list->size()); |
862 ASSERT_EQ(2, new_browser->tab_strip_model()->count()); | 871 ASSERT_EQ(2, new_browser->tab_strip_model()->count()); |
863 ASSERT_EQ(0, new_browser->tab_strip_model()->active_index()); | 872 ASSERT_EQ(0, new_browser->tab_strip_model()->active_index()); |
864 // Close the pinned tab. | 873 // Close the pinned tab. |
865 chrome::CloseTab(new_browser); | 874 chrome::CloseTab(new_browser); |
866 ASSERT_EQ(1, new_browser->tab_strip_model()->count()); | 875 ASSERT_EQ(1, new_browser->tab_strip_model()->count()); |
867 ASSERT_EQ(0, new_browser->tab_strip_model()->active_index()); | 876 ASSERT_EQ(0, new_browser->tab_strip_model()->active_index()); |
868 // Use the existing tab to navigate away, so that we can verify it was really | 877 // Use the existing tab to navigate away, so that we can verify it was really |
869 // clobbered. | 878 // clobbered. |
870 ui_test_utils::NavigateToURL(new_browser, url3_); | 879 ui_test_utils::NavigateToURL(new_browser, url3_); |
871 | 880 |
(...skipping 14 matching lines...) Expand all Loading... |
886 } | 895 } |
887 | 896 |
888 IN_PROC_BROWSER_TEST_F(SessionRestoreTest, SessionStorage) { | 897 IN_PROC_BROWSER_TEST_F(SessionRestoreTest, SessionStorage) { |
889 ui_test_utils::NavigateToURL(browser(), url1_); | 898 ui_test_utils::NavigateToURL(browser(), url1_); |
890 content::NavigationController* controller = | 899 content::NavigationController* controller = |
891 &browser()->tab_strip_model()->GetActiveWebContents()->GetController(); | 900 &browser()->tab_strip_model()->GetActiveWebContents()->GetController(); |
892 ASSERT_TRUE(controller->GetDefaultSessionStorageNamespace()); | 901 ASSERT_TRUE(controller->GetDefaultSessionStorageNamespace()); |
893 std::string session_storage_persistent_id = | 902 std::string session_storage_persistent_id = |
894 controller->GetDefaultSessionStorageNamespace()->persistent_id(); | 903 controller->GetDefaultSessionStorageNamespace()->persistent_id(); |
895 Browser* new_browser = QuitBrowserAndRestore(browser(), 1); | 904 Browser* new_browser = QuitBrowserAndRestore(browser(), 1); |
896 ASSERT_EQ(1u, BrowserList::size()); | 905 ASSERT_EQ(1u, native_browser_list->size()); |
897 ASSERT_EQ(url1_, | 906 ASSERT_EQ(url1_, |
898 new_browser->tab_strip_model()->GetActiveWebContents()->GetURL()); | 907 new_browser->tab_strip_model()->GetActiveWebContents()->GetURL()); |
899 content::NavigationController* new_controller = | 908 content::NavigationController* new_controller = |
900 &new_browser->tab_strip_model()->GetActiveWebContents()->GetController(); | 909 &new_browser->tab_strip_model()->GetActiveWebContents()->GetController(); |
901 ASSERT_TRUE(new_controller->GetDefaultSessionStorageNamespace()); | 910 ASSERT_TRUE(new_controller->GetDefaultSessionStorageNamespace()); |
902 std::string restored_session_storage_persistent_id = | 911 std::string restored_session_storage_persistent_id = |
903 new_controller->GetDefaultSessionStorageNamespace()->persistent_id(); | 912 new_controller->GetDefaultSessionStorageNamespace()->persistent_id(); |
904 EXPECT_EQ(session_storage_persistent_id, | 913 EXPECT_EQ(session_storage_persistent_id, |
905 restored_session_storage_persistent_id); | 914 restored_session_storage_persistent_id); |
906 } | 915 } |
(...skipping 24 matching lines...) Expand all Loading... |
931 } | 940 } |
932 | 941 |
933 // Check that the sessionStorage data is going to be persisted. | 942 // Check that the sessionStorage data is going to be persisted. |
934 content::NavigationController* controller = | 943 content::NavigationController* controller = |
935 &browser()->tab_strip_model()->GetActiveWebContents()->GetController(); | 944 &browser()->tab_strip_model()->GetActiveWebContents()->GetController(); |
936 EXPECT_TRUE( | 945 EXPECT_TRUE( |
937 controller->GetDefaultSessionStorageNamespace()->should_persist()); | 946 controller->GetDefaultSessionStorageNamespace()->should_persist()); |
938 | 947 |
939 // Quit and restore. Check that no extra tabs were created. | 948 // Quit and restore. Check that no extra tabs were created. |
940 Browser* new_browser = QuitBrowserAndRestore(browser(), 1); | 949 Browser* new_browser = QuitBrowserAndRestore(browser(), 1); |
941 ASSERT_EQ(1u, BrowserList::size()); | 950 ASSERT_EQ(1u, native_browser_list->size()); |
942 EXPECT_EQ(1, new_browser->tab_strip_model()->count()); | 951 EXPECT_EQ(1, new_browser->tab_strip_model()->count()); |
943 } | 952 } |
OLD | NEW |