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

Side by Side Diff: chrome/browser/sessions/session_restore_browsertest.cc

Issue 10202005: Convert the session restore ui_tests to browser_tests. I renabled the disabled tests; hopefully the… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: renable the mac test Created 8 years, 8 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 | Annotate | Revision Log
OLDNEW
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/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/browser_process.h"
8 #include "chrome/browser/defaults.h" 9 #include "chrome/browser/defaults.h"
9 #include "chrome/browser/first_run/first_run.h" 10 #include "chrome/browser/first_run/first_run.h"
10 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/profiles/profile_manager.h" 12 #include "chrome/browser/profiles/profile_manager.h"
12 #include "chrome/browser/sessions/session_restore.h" 13 #include "chrome/browser/sessions/session_restore.h"
13 #include "chrome/browser/sessions/session_service.h" 14 #include "chrome/browser/sessions/session_service.h"
14 #include "chrome/browser/sessions/session_service_factory.h" 15 #include "chrome/browser/sessions/session_service_factory.h"
15 #include "chrome/browser/sessions/tab_restore_service.h" 16 #include "chrome/browser/sessions/tab_restore_service.h"
16 #include "chrome/browser/sessions/tab_restore_service_factory.h" 17 #include "chrome/browser/sessions/tab_restore_service_factory.h"
17 #include "chrome/browser/tabs/tab_strip_model.h" 18 #include "chrome/browser/tabs/tab_strip_model.h"
18 #include "chrome/browser/ui/browser.h" 19 #include "chrome/browser/ui/browser.h"
19 #include "chrome/browser/ui/browser_init.h" 20 #include "chrome/browser/ui/browser_init.h"
20 #include "chrome/browser/ui/browser_list.h" 21 #include "chrome/browser/ui/browser_list.h"
21 #include "chrome/browser/ui/browser_window.h" 22 #include "chrome/browser/ui/browser_window.h"
22 #include "chrome/common/url_constants.h" 23 #include "chrome/common/url_constants.h"
23 #include "chrome/common/chrome_notification_types.h" 24 #include "chrome/common/chrome_notification_types.h"
25 #include "chrome/common/chrome_switches.h"
24 #include "chrome/test/base/in_process_browser_test.h" 26 #include "chrome/test/base/in_process_browser_test.h"
25 #include "chrome/test/base/ui_test_utils.h" 27 #include "chrome/test/base/ui_test_utils.h"
26 #include "content/public/browser/navigation_controller.h" 28 #include "content/public/browser/navigation_controller.h"
27 #include "content/public/browser/navigation_entry.h" 29 #include "content/public/browser/navigation_entry.h"
28 #include "content/public/browser/notification_service.h" 30 #include "content/public/browser/notification_service.h"
29 #include "content/public/browser/notification_types.h" 31 #include "content/public/browser/notification_types.h"
32 #include "content/public/browser/render_process_host.h"
30 #include "content/public/browser/web_contents.h" 33 #include "content/public/browser/web_contents.h"
31 #include "content/public/common/page_transition_types.h" 34 #include "content/public/common/page_transition_types.h"
35 #include "content/test/test_navigation_observer.h"
32 36
33 namespace { 37 #if defined(OS_MACOSX)
34 38 #include "base/mac/scoped_nsautorelease_pool.h"
35 // Verifies that the given NavigationController has exactly two entries that 39 #endif
36 // correspond to the given URLs.
37 void VerifyNavigationEntries(
38 content::NavigationController& controller, GURL url1, GURL url2) {
39 ASSERT_EQ(2, controller.GetEntryCount());
40 EXPECT_EQ(1, controller.GetCurrentEntryIndex());
41 EXPECT_EQ(url1, controller.GetEntryAtIndex(0)->GetURL());
42 EXPECT_EQ(url2, controller.GetEntryAtIndex(1)->GetURL());
43 }
44
45 void CloseBrowserSynchronously(Browser* browser) {
46 ui_test_utils::WindowedNotificationObserver observer(
47 chrome::NOTIFICATION_BROWSER_CLOSED,
48 content::NotificationService::AllSources());
49 browser->window()->Close();
50 observer.Wait();
51 }
52
53 } // namespace
54 40
55 class SessionRestoreTest : public InProcessBrowserTest { 41 class SessionRestoreTest : public InProcessBrowserTest {
56 protected: 42 protected:
43
44 virtual void SetUpOnMainThread() OVERRIDE {
45 SessionStartupPref pref(SessionStartupPref::LAST);
46 SessionStartupPref::SetStartupPref(browser()->profile(), pref);
47 #if defined(OS_CHROMEOS) || defined(OS_MACOSX)
48 const testing::TestInfo* const test_info =
49 testing::UnitTest::GetInstance()->current_test_info();
50 if (strcmp(test_info->name(), "NoSessionRestoreNewWindowChromeOS")) {
51 // Undo the effect of kBrowserAliveWithNoWindows in defaults.cc so that we
52 // can get these test to work without quitting.
53 SessionServiceFactory::GetForProfile(browser()->profile())->
54 force_browser_not_alive_with_no_windows_ = true;
55 }
56 #endif
57 }
58
57 virtual bool SetUpUserDataDirectory() OVERRIDE { 59 virtual bool SetUpUserDataDirectory() OVERRIDE {
58 // Make sure the first run sentinel file exists before running these tests, 60 // Make sure the first run sentinel file exists before running these tests,
59 // since some of them customize the session startup pref whose value can 61 // since some of them customize the session startup pref whose value can
60 // be different than the default during the first run. 62 // be different than the default during the first run.
61 // TODO(bauerb): set the first run flag instead of creating a sentinel file. 63 // TODO(bauerb): set the first run flag instead of creating a sentinel file.
62 first_run::CreateSentinel(); 64 first_run::CreateSentinel();
65
66 url1_ = ui_test_utils::GetTestUrl(
67 FilePath().AppendASCII("session_history"),
68 FilePath().AppendASCII("bot1.html"));
69 url2_ = ui_test_utils::GetTestUrl(
70 FilePath().AppendASCII("session_history"),
71 FilePath().AppendASCII("bot2.html"));
72 url3_ = ui_test_utils::GetTestUrl(
73 FilePath().AppendASCII("session_history"),
74 FilePath().AppendASCII("bot3.html"));
75
63 return InProcessBrowserTest::SetUpUserDataDirectory(); 76 return InProcessBrowserTest::SetUpUserDataDirectory();
64 } 77 }
78
79 // Verifies that the given NavigationController has exactly two entries that
80 // correspond to the given URLs.
81 void VerifyNavigationEntries(
82 content::NavigationController& controller, GURL url1, GURL url2) {
83 ASSERT_EQ(2, controller.GetEntryCount());
84 EXPECT_EQ(1, controller.GetCurrentEntryIndex());
85 EXPECT_EQ(url1, controller.GetEntryAtIndex(0)->GetURL());
86 EXPECT_EQ(url2, controller.GetEntryAtIndex(1)->GetURL());
87 }
88
89 void CloseBrowserSynchronously(Browser* browser) {
90 ui_test_utils::WindowedNotificationObserver observer(
91 chrome::NOTIFICATION_BROWSER_CLOSED,
92 content::NotificationService::AllSources());
93 browser->window()->Close();
94 #if defined(OS_MACOSX)
95 // BrowserWindowController depends on the auto release pool being recycled
96 // in the message loop to delete itself, which frees the Browser object
97 // which fires this event.
98 AutoreleasePool()->Recycle();
99 #endif
100 observer.Wait();
101 }
102
103 Browser* QuitBrowserAndRestore(Browser* browser, int expected_tab_count) {
104 // Create a new popup.
105 Profile* profile = browser->profile();
106
107 // Close the browser.
108 g_browser_process->AddRefModule();
109 CloseBrowserSynchronously(browser);
110
111 // Create a new window, which should trigger session restore.
112 ui_test_utils::BrowserAddedObserver window_observer;
113 TestNavigationObserver navigation_observer(
114 content::NotificationService::AllSources(), NULL, expected_tab_count);
115 Browser::NewEmptyWindow(profile);
116 Browser* new_browser = window_observer.WaitForSingleNewBrowser();
117 navigation_observer.Wait();
118 g_browser_process->ReleaseModule();
119
120 return new_browser;
121 }
122
123 void GoBack(Browser* browser) {
124 ui_test_utils::WindowedNotificationObserver observer(
125 content::NOTIFICATION_LOAD_STOP,
126 content::NotificationService::AllSources());
127 browser->GoBack(CURRENT_TAB);
128 observer.Wait();
129 }
130
131 void GoForward(Browser* browser) {
132 ui_test_utils::WindowedNotificationObserver observer(
133 content::NOTIFICATION_LOAD_STOP,
134 content::NotificationService::AllSources());
135 browser->GoForward(CURRENT_TAB);
136 observer.Wait();
137 }
138
139 void AssertOneWindowWithOneTab(Browser* browser) {
140 ASSERT_EQ(1u, BrowserList::size());
141 ASSERT_EQ(1, browser->tab_count());
142 }
143
144 int RenderProcessHostCount() {
145 content::RenderProcessHost::iterator hosts =
146 content::RenderProcessHost::AllHostsIterator();
147 int count = 0;
148 while (!hosts.IsAtEnd()) {
149 if (hosts.GetCurrentValue()->HasConnection())
150 count++;
151 hosts.Advance();
152 }
153 return count;
154 }
155
156 GURL url1_;
157 GURL url2_;
158 GURL url3_;
65 }; 159 };
66 160
67 #if defined(OS_CHROMEOS) 161 #if defined(OS_CHROMEOS)
68 // Verify that session restore does not occur when a user opens a browser window 162 // Verify that session restore does not occur when a user opens a browser window
69 // when no other browser windows are open on ChromeOS. 163 // when no other browser windows are open on ChromeOS.
70 // TODO(pkotwicz): Add test which doesn't open incognito browser once 164 // TODO(pkotwicz): Add test which doesn't open incognito browser once
71 // disable-zero-browsers-open-for-tests is removed. 165 // disable-zero-browsers-open-for-tests is removed.
72 // (http://crbug.com/119175) 166 // (http://crbug.com/119175)
73 // TODO(pkotwicz): Mac should have the behavior outlined by this test. It should 167 // TODO(pkotwicz): Mac should have the behavior outlined by this test. It should
74 // not do session restore if an incognito window is already open. 168 // not do session restore if an incognito window is already open.
75 // (http://crbug.com/120927) 169 // (http://crbug.com/120927)
76 IN_PROC_BROWSER_TEST_F(SessionRestoreTest, NoSessionRestoreNewWindowChromeOS) { 170 IN_PROC_BROWSER_TEST_F(SessionRestoreTest, NoSessionRestoreNewWindowChromeOS) {
77 // Turn on session restore.
78 SessionStartupPref pref(SessionStartupPref::LAST);
79 SessionStartupPref::SetStartupPref(browser()->profile(), pref);
80
81 GURL url(ui_test_utils::GetTestUrl( 171 GURL url(ui_test_utils::GetTestUrl(
82 FilePath(FilePath::kCurrentDirectory), 172 FilePath(FilePath::kCurrentDirectory),
83 FilePath(FILE_PATH_LITERAL("title1.html")))); 173 FilePath(FILE_PATH_LITERAL("title1.html"))));
84 174
85 // Add a single tab. 175 // Add a single tab.
86 ui_test_utils::NavigateToURL(browser(), url); 176 ui_test_utils::NavigateToURL(browser(), url);
87 177
88 Browser* incognito_browser = CreateIncognitoBrowser(); 178 Browser* incognito_browser = CreateIncognitoBrowser();
89 incognito_browser->AddBlankTab(true); 179 incognito_browser->AddBlankTab(true);
90 incognito_browser->window()->Show(); 180 incognito_browser->window()->Show();
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 EXPECT_EQ(0U, service->entries().size()); 338 EXPECT_EQ(0U, service->entries().size());
249 } 339 }
250 340
251 #if !defined(OS_CHROMEOS) 341 #if !defined(OS_CHROMEOS)
252 // This test does not apply to ChromeOS as ChromeOS does not do session 342 // This test does not apply to ChromeOS as ChromeOS does not do session
253 // restore when a new window is open. 343 // restore when a new window is open.
254 344
255 // Verifies we remember the last browser window when closing the last 345 // Verifies we remember the last browser window when closing the last
256 // non-incognito window while an incognito window is open. 346 // non-incognito window while an incognito window is open.
257 IN_PROC_BROWSER_TEST_F(SessionRestoreTest, IncognitotoNonIncognito) { 347 IN_PROC_BROWSER_TEST_F(SessionRestoreTest, IncognitotoNonIncognito) {
258 // Turn on session restore.
259 SessionStartupPref pref(SessionStartupPref::LAST);
260 SessionStartupPref::SetStartupPref(browser()->profile(), pref);
261
262 GURL url(ui_test_utils::GetTestUrl( 348 GURL url(ui_test_utils::GetTestUrl(
263 FilePath(FilePath::kCurrentDirectory), 349 FilePath(FilePath::kCurrentDirectory),
264 FilePath(FILE_PATH_LITERAL("title1.html")))); 350 FilePath(FILE_PATH_LITERAL("title1.html"))));
265 351
266 // Add a single tab. 352 // Add a single tab.
267 ui_test_utils::NavigateToURL(browser(), url); 353 ui_test_utils::NavigateToURL(browser(), url);
268 354
269 // Create a new incognito window. 355 // Create a new incognito window.
270 Browser* incognito_browser = CreateIncognitoBrowser(); 356 Browser* incognito_browser = CreateIncognitoBrowser();
271 incognito_browser->AddBlankTab(true); 357 incognito_browser->AddBlankTab(true);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 418
333 // Restore in a new window. 419 // Restore in a new window.
334 ui_test_utils::BrowserAddedObserver browser_observer; 420 ui_test_utils::BrowserAddedObserver browser_observer;
335 SessionRestore::RestoreForeignSessionTab(profile, tab, NEW_WINDOW); 421 SessionRestore::RestoreForeignSessionTab(profile, tab, NEW_WINDOW);
336 Browser* new_browser = browser_observer.WaitForSingleNewBrowser(); 422 Browser* new_browser = browser_observer.WaitForSingleNewBrowser();
337 423
338 ASSERT_EQ(1, new_browser->tab_count()); 424 ASSERT_EQ(1, new_browser->tab_count());
339 VerifyNavigationEntries( 425 VerifyNavigationEntries(
340 new_browser->GetWebContentsAt(0)->GetController(), url1, url2); 426 new_browser->GetWebContentsAt(0)->GetController(), url1, url2);
341 } 427 }
428
429 IN_PROC_BROWSER_TEST_F(SessionRestoreTest, Basic) {
430 ui_test_utils::NavigateToURL(browser(), url1_);
431 ui_test_utils::NavigateToURL(browser(), url2_);
432
433 Browser* new_browser = QuitBrowserAndRestore(browser(), 1);
434 ASSERT_EQ(1u, BrowserList::size());
435 ASSERT_EQ(url2_, new_browser->GetSelectedWebContents()->GetURL());
436 GoBack(new_browser);
437 ASSERT_EQ(url1_, new_browser->GetSelectedWebContents()->GetURL());
438 }
439
440 IN_PROC_BROWSER_TEST_F(SessionRestoreTest, RestoresForwardAndBackwardNavs) {
441 ui_test_utils::NavigateToURL(browser(), url1_);
442 ui_test_utils::NavigateToURL(browser(), url2_);
443 ui_test_utils::NavigateToURL(browser(), url3_);
444
445 GoBack(browser());
446 Browser* new_browser = QuitBrowserAndRestore(browser(), 1);
447 ASSERT_EQ(1u, BrowserList::size());
448 ASSERT_EQ(url2_, new_browser->GetSelectedWebContents()->GetURL());
449 GoForward(new_browser);
450 ASSERT_EQ(url3_, new_browser->GetSelectedWebContents()->GetURL());
451 GoBack(new_browser);
452 ASSERT_EQ(url2_, new_browser->GetSelectedWebContents()->GetURL());
453
454 // Test renderer-initiated back/forward as well.
455 GURL go_back_url("javascript:history.back();");
456 ui_test_utils::NavigateToURL(new_browser, go_back_url);
457 ASSERT_EQ(url1_, new_browser->GetSelectedWebContents()->GetURL());
458 }
459
460 // Tests that the SiteInstances used for entries in a restored tab's history
461 // are given appropriate max page IDs, so that going back to a restored
462 // cross-site page and then forward again works. (Bug 1204135)
463 IN_PROC_BROWSER_TEST_F(SessionRestoreTest,
464 RestoresCrossSiteForwardAndBackwardNavs) {
465 ASSERT_TRUE(test_server()->Start());
466
467 GURL cross_site_url(test_server()->GetURL("files/title2.html"));
468
469 // Visit URLs on different sites.
470 ui_test_utils::NavigateToURL(browser(), url1_);
471 ui_test_utils::NavigateToURL(browser(), cross_site_url);
472 ui_test_utils::NavigateToURL(browser(), url2_);
473
474 GoBack(browser());
475 Browser* new_browser = QuitBrowserAndRestore(browser(), 1);
476 ASSERT_EQ(1u, BrowserList::size());
477 ASSERT_EQ(1, new_browser->tab_count());
478
479 // Check that back and forward work as expected.
480 ASSERT_EQ(cross_site_url, new_browser->GetSelectedWebContents()->GetURL());
481
482 GoBack(new_browser);
483 ASSERT_EQ(url1_, new_browser->GetSelectedWebContents()->GetURL());
484
485 GoForward(new_browser);
486 ASSERT_EQ(cross_site_url, new_browser->GetSelectedWebContents()->GetURL());
487
488 // Test renderer-initiated back/forward as well.
489 GURL go_forward_url("javascript:history.forward();");
490 ui_test_utils::NavigateToURL(new_browser, go_forward_url);
491 ASSERT_EQ(url2_, new_browser->GetSelectedWebContents()->GetURL());
492 }
493
494 IN_PROC_BROWSER_TEST_F(SessionRestoreTest, TwoTabsSecondSelected) {
495 ui_test_utils::NavigateToURL(browser(), url1_);
496
497 ui_test_utils::NavigateToURLWithDisposition(
498 browser(), url2_, NEW_FOREGROUND_TAB,
499 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
500
501 Browser* new_browser = QuitBrowserAndRestore(browser(), 2);
502
503 ASSERT_EQ(1u, BrowserList::size());
504 ASSERT_EQ(2, new_browser->tab_count());
505 ASSERT_EQ(1, new_browser->active_index());
506 ASSERT_EQ(url2_, new_browser->GetSelectedWebContents()->GetURL());
507
508 ASSERT_EQ(url1_, new_browser->GetWebContentsAt(0)->GetURL());
509 }
510
511 // Creates two tabs, closes one, quits and makes sure only one tab is restored.
512 IN_PROC_BROWSER_TEST_F(SessionRestoreTest, ClosedTabStaysClosed) {
513 ui_test_utils::NavigateToURL(browser(), url1_);
514
515 ui_test_utils::NavigateToURLWithDisposition(
516 browser(), url2_, NEW_FOREGROUND_TAB,
517 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
518 browser()->CloseTab();
519
520 Browser* new_browser = QuitBrowserAndRestore(browser(), 1);
521
522 AssertOneWindowWithOneTab(new_browser);
523 ASSERT_EQ(url1_, new_browser->GetSelectedWebContents()->GetURL());
524 }
525
526 // Test to verify that the print preview tab is not restored.
527 IN_PROC_BROWSER_TEST_F(SessionRestoreTest, DontRestorePrintPreviewTabTest) {
528 ui_test_utils::NavigateToURL(browser(), url1_);
529
530 // Append the print preview tab.
531 ui_test_utils::NavigateToURLWithDisposition(
532 browser(), GURL(chrome::kChromeUIPrintURL), NEW_FOREGROUND_TAB,
533 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
534
535 // Restart and make sure we have only one window with one tab and the url
536 // is url1_.
537 Browser* new_browser = QuitBrowserAndRestore(browser(), 1);
538
539 AssertOneWindowWithOneTab(new_browser);
540 ASSERT_EQ(url1_, new_browser->GetSelectedWebContents()->GetURL());
541 }
542
543 // Creates a tabbed browser and popup and makes sure we restore both.
544 IN_PROC_BROWSER_TEST_F(SessionRestoreTest, NormalAndPopup) {
545 if (!browser_defaults::kRestorePopups)
546 return; // Test only applicable if restoring popups.
547
548 ui_test_utils::NavigateToURL(browser(), url1_);
549
550 // Make sure we have one window.
551 AssertOneWindowWithOneTab(browser());
552
553 // Open a popup.
554 Browser* popup = Browser::CreateWithParams(
555 Browser::CreateParams(Browser::TYPE_POPUP, browser()->profile()));
556 popup->window()->Show();
557 ASSERT_EQ(2u, BrowserList::size());
558
559 ui_test_utils::NavigateToURL(popup, url1_);
560
561 // Simulate an exit by shuting down the session service. If we don't do this
562 // the first window close is treated as though the user closed the window
563 // and won't be restored.
564 SessionServiceFactory::ShutdownForProfile(browser()->profile());
565
566 // Restart and make sure we have two windows.
567 QuitBrowserAndRestore(browser(), 1);
568
569 ASSERT_EQ(2u, BrowserList::size());
570
571 Browser* browser1 = *BrowserList::begin();
572 Browser* browser2 = *(++BrowserList::begin());
573
574 Browser::Type type1 = browser1->type();
575 Browser::Type type2 = browser2->type();
576
577 // The order of whether the normal window or popup is first depends upon
578 // activation order, which is not necessarily consistant across runs.
579 if (type1 == Browser::TYPE_TABBED) {
580 EXPECT_EQ(type2, Browser::TYPE_POPUP);
581 } else {
582 EXPECT_EQ(type1, Browser::TYPE_POPUP);
583 EXPECT_EQ(type2, Browser::TYPE_TABBED);
584 }
585 }
586
587 #if !defined(OS_CHROMEOS) && !defined(OS_MACOSX)
588 // This test doesn't apply to the Mac version; see GetCommandLineForRelaunch
589 // for details. It was disabled for a long time so might never have worked on
590 // ChromeOS.
591
592 // Launches an app window, closes tabbed browser, launches and makes sure
593 // we restore the tabbed browser url.
594 // If this test flakes, use http://crbug.com/29110
595 IN_PROC_BROWSER_TEST_F(SessionRestoreTest,
596 RestoreAfterClosingTabbedBrowserWithAppAndLaunching) {
597 ui_test_utils::NavigateToURL(browser(), url1_);
598
599 // Launch an app.
600 CommandLine app_launch_arguments = GetCommandLineForRelaunch();
601 app_launch_arguments.AppendSwitchASCII(switches::kApp, url2_.spec());
602
603 ui_test_utils::BrowserAddedObserver window_observer;
604
605 base::LaunchProcess(app_launch_arguments, base::LaunchOptions(), NULL);
606
607 Browser* app_window = window_observer.WaitForSingleNewBrowser();
608 ASSERT_EQ(2u, BrowserList::size());
609
610 // Close the first window. The only window left is the App window.
611 CloseBrowserSynchronously(browser());
612
613 // Restore the session, which should bring back the first window with url1_.
614 Browser* new_browser = QuitBrowserAndRestore(app_window, 1);
615
616 AssertOneWindowWithOneTab(new_browser);
617
618 ASSERT_EQ(url1_, new_browser->GetSelectedWebContents()->GetURL());
619 }
620
621 #endif // !defined(OS_CHROMEOS) && !defined(OS_MACOSX)
622
623 // Creates two windows, closes one, restores, make sure only one window open.
624 IN_PROC_BROWSER_TEST_F(SessionRestoreTest, TwoWindowsCloseOneRestoreOnlyOne) {
625 ui_test_utils::NavigateToURL(browser(), url1_);
626
627 // Open a second window.
628 ui_test_utils::NavigateToURLWithDisposition(
629 browser(), GURL(chrome::kAboutBlankURL), NEW_WINDOW,
630 ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER);
631
632 ASSERT_EQ(2u, BrowserList::size());
633
634 // Close it.
635 Browser* new_window = *(++BrowserList::begin());
636 CloseBrowserSynchronously(new_window);
637
638 // Restart and make sure we have only one window with one tab and the url
639 // is url1_.
640 Browser* new_browser = QuitBrowserAndRestore(browser(), 1);
641
642 AssertOneWindowWithOneTab(new_browser);
643
644 ASSERT_EQ(url1_, new_browser->GetSelectedWebContents()->GetURL());
645 }
646
647 // Make sure after a restore the number of processes matches that of the number
648 // of processes running before the restore. This creates a new tab so that
649 // we should have two new tabs running. (This test will pass in both
650 // process-per-site and process-per-site-instance, because we treat the new tab
651 // as a special case in process-per-site-instance so that it only ever uses one
652 // process.)
653 //
654 // Flaky: http://code.google.com/p/chromium/issues/detail?id=52022
655 // Unfortunately, the fix at http://codereview.chromium.org/6546078
656 // breaks NTP background image refreshing, so ThemeSource had to revert to
657 // replacing the existing data source.
658 IN_PROC_BROWSER_TEST_F(SessionRestoreTest, ShareProcessesOnRestore) {
659 // Create two new tabs.
660 ui_test_utils::NavigateToURLWithDisposition(
661 browser(), GURL(chrome::kAboutBlankURL), NEW_FOREGROUND_TAB,
662 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
663 ui_test_utils::NavigateToURLWithDisposition(
664 browser(), GURL(chrome::kAboutBlankURL), NEW_FOREGROUND_TAB,
665 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
666
667 int expected_process_count = RenderProcessHostCount();
668
669 // Restart.
670 Browser* new_browser = QuitBrowserAndRestore(browser(), 3);
671
672 ASSERT_EQ(3, new_browser->tab_count());
673
674 ASSERT_EQ(expected_process_count, RenderProcessHostCount());
675 }
OLDNEW
« no previous file with comments | « chrome/browser/chrome_main_browsertest.cc ('k') | chrome/browser/sessions/session_restore_uitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698