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
3 // found in the LICENSE file.
5 #include "base/basictypes.h"
6 #include "base/command_line.h"
7 #include "base/files/file_path.h"
8 #include "base/run_loop.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "base/test/test_timeouts.h"
11 #include "chrome/app/chrome_command_ids.h"
12 #include "chrome/browser/chrome_notification_types.h"
13 #include "chrome/browser/sessions/tab_restore_service_factory.h"
14 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/browser_commands.h"
16 #include "chrome/browser/ui/browser_list.h"
17 #include "chrome/browser/ui/browser_tabstrip.h"
18 #include "chrome/browser/ui/find_bar/find_notification_details.h"
19 #include "chrome/browser/ui/tabs/tab_strip_model.h"
20 #include "chrome/common/chrome_paths.h"
21 #include "chrome/common/url_constants.h"
22 #include "chrome/test/base/in_process_browser_test.h"
23 #include "chrome/test/base/ui_test_utils.h"
24 #include "components/sessions/core/tab_restore_service.h"
25 #include "components/sessions/core/tab_restore_service_observer.h"
26 #include "content/public/browser/navigation_controller.h"
27 #include "content/public/browser/notification_service.h"
28 #include "content/public/browser/notification_source.h"
29 #include "content/public/browser/notification_types.h"
30 #include "content/public/browser/page_navigator.h"
31 #include "content/public/browser/render_view_host.h"
32 #include "content/public/browser/web_contents.h"
33 #include "content/public/test/browser_test_utils.h"
34 #include "net/base/net_util.h"
35 #include "net/test/embedded_test_server/embedded_test_server.h"
38 // Class used to run a message loop waiting for the TabRestoreService to finish
39 // loading. Does nothing if the TabRestoreService was already loaded.
40 class WaitForLoadObserver
: public sessions::TabRestoreServiceObserver
{
42 explicit WaitForLoadObserver(Browser
* browser
)
43 : tab_restore_service_(
44 TabRestoreServiceFactory::GetForProfile(browser
->profile())),
45 do_wait_(!tab_restore_service_
->IsLoaded()) {
47 tab_restore_service_
->AddObserver(this);
50 ~WaitForLoadObserver() override
{
52 tab_restore_service_
->RemoveObserver(this);
61 // Overridden from TabRestoreServiceObserver:
62 void TabRestoreServiceChanged(sessions::TabRestoreService
* service
) override
{
64 void TabRestoreServiceDestroyed(
65 sessions::TabRestoreService
* service
) override
{}
66 void TabRestoreServiceLoaded(sessions::TabRestoreService
* service
) override
{
71 sessions::TabRestoreService
* tab_restore_service_
;
73 base::RunLoop run_loop_
;
75 DISALLOW_COPY_AND_ASSIGN(WaitForLoadObserver
);
78 class TabRestoreTest
: public InProcessBrowserTest
{
80 TabRestoreTest() : active_browser_list_(NULL
) {
81 url1_
= ui_test_utils::GetTestUrl(
82 base::FilePath().AppendASCII("session_history"),
83 base::FilePath().AppendASCII("bot1.html"));
84 url2_
= ui_test_utils::GetTestUrl(
85 base::FilePath().AppendASCII("session_history"),
86 base::FilePath().AppendASCII("bot2.html"));
90 void SetUpOnMainThread() override
{
91 active_browser_list_
= BrowserList::GetInstance(chrome::GetActiveDesktop());
92 InProcessBrowserTest::SetUpOnMainThread();
95 Browser
* GetBrowser(int index
) {
96 CHECK(static_cast<int>(active_browser_list_
->size()) > index
);
97 return active_browser_list_
->get(index
);
100 // Adds tabs to the given browser, all navigated to url1_. Returns
101 // the final number of tabs.
102 int AddSomeTabs(Browser
* browser
, int how_many
) {
103 int starting_tab_count
= browser
->tab_strip_model()->count();
105 for (int i
= 0; i
< how_many
; ++i
) {
106 ui_test_utils::NavigateToURLWithDisposition(
107 browser
, url1_
, NEW_FOREGROUND_TAB
,
108 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION
);
110 int tab_count
= browser
->tab_strip_model()->count();
111 EXPECT_EQ(starting_tab_count
+ how_many
, tab_count
);
115 void CloseTab(int index
) {
116 content::WebContentsDestroyedWatcher
destroyed_watcher(
117 browser()->tab_strip_model()->GetWebContentsAt(index
));
118 browser()->tab_strip_model()->CloseWebContentsAt(
119 index
, TabStripModel::CLOSE_CREATE_HISTORICAL_TAB
);
120 destroyed_watcher
.Wait();
123 // Uses the undo-close-tab accelerator to undo a close-tab or close-window
124 // operation. The newly restored tab is expected to appear in the
125 // window at index |expected_window_index|, at the |expected_tabstrip_index|,
126 // and to be active. If |expected_window_index| is equal to the number of
127 // current windows, the restored tab is expected to be created in a new
128 // window (since the index is 0-based).
129 void RestoreTab(int expected_window_index
, int expected_tabstrip_index
) {
130 int window_count
= static_cast<int>(active_browser_list_
->size());
131 ASSERT_GT(window_count
, 0);
133 bool expect_new_window
= (expected_window_index
== window_count
);
136 if (expect_new_window
) {
137 browser
= active_browser_list_
->get(0);
139 browser
= GetBrowser(expected_window_index
);
141 int tab_count
= browser
->tab_strip_model()->count();
142 ASSERT_GT(tab_count
, 0);
145 content::WindowedNotificationObserver
tab_added_observer(
146 chrome::NOTIFICATION_TAB_PARENTED
,
147 content::NotificationService::AllSources());
148 content::WindowedNotificationObserver
tab_loaded_observer(
149 content::NOTIFICATION_LOAD_STOP
,
150 content::NotificationService::AllSources());
152 WaitForLoadObserver
waiter(browser
);
153 chrome::RestoreTab(browser
);
156 tab_added_observer
.Wait();
157 tab_loaded_observer
.Wait();
159 if (expect_new_window
) {
160 int new_window_count
= static_cast<int>(active_browser_list_
->size());
161 EXPECT_EQ(++window_count
, new_window_count
);
162 browser
= GetBrowser(expected_window_index
);
164 EXPECT_EQ(++tab_count
, browser
->tab_strip_model()->count());
167 // Get a handle to the restored tab.
168 ASSERT_GT(browser
->tab_strip_model()->count(), expected_tabstrip_index
);
170 // Ensure that the tab and window are active.
171 EXPECT_EQ(expected_tabstrip_index
,
172 browser
->tab_strip_model()->active_index());
175 void GoBack(Browser
* browser
) {
176 content::WindowedNotificationObserver
observer(
177 content::NOTIFICATION_LOAD_STOP
,
178 content::NotificationService::AllSources());
179 chrome::GoBack(browser
, CURRENT_TAB
);
183 void EnsureTabFinishedRestoring(content::WebContents
* tab
) {
184 content::NavigationController
* controller
= &tab
->GetController();
185 if (!controller
->NeedsReload() && !controller
->GetPendingEntry() &&
186 !controller
->GetWebContents()->IsLoading())
189 content::WindowedNotificationObserver
observer(
190 content::NOTIFICATION_LOAD_STOP
,
191 content::Source
<content::NavigationController
>(controller
));
198 const BrowserList
* active_browser_list_
;
201 DISALLOW_COPY_AND_ASSIGN(TabRestoreTest
);
204 // Close the end tab in the current window, then restore it. The tab should be
205 // in its original position, and active.
206 IN_PROC_BROWSER_TEST_F(TabRestoreTest
, Basic
) {
207 int starting_tab_count
= browser()->tab_strip_model()->count();
208 int tab_count
= AddSomeTabs(browser(), 1);
210 int closed_tab_index
= tab_count
- 1;
211 CloseTab(closed_tab_index
);
212 EXPECT_EQ(starting_tab_count
, browser()->tab_strip_model()->count());
214 ASSERT_NO_FATAL_FAILURE(RestoreTab(0, closed_tab_index
));
216 // And make sure everything looks right.
217 EXPECT_EQ(starting_tab_count
+ 1, browser()->tab_strip_model()->count());
218 EXPECT_EQ(closed_tab_index
, browser()->tab_strip_model()->active_index());
220 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
223 // Close a tab not at the end of the current window, then restore it. The tab
224 // should be in its original position, and active.
225 IN_PROC_BROWSER_TEST_F(TabRestoreTest
, MiddleTab
) {
226 int starting_tab_count
= browser()->tab_strip_model()->count();
227 AddSomeTabs(browser(), 3);
229 // Close one in the middle
230 int closed_tab_index
= starting_tab_count
+ 1;
231 CloseTab(closed_tab_index
);
232 EXPECT_EQ(starting_tab_count
+ 2, browser()->tab_strip_model()->count());
234 ASSERT_NO_FATAL_FAILURE(RestoreTab(0, closed_tab_index
));
236 // And make sure everything looks right.
237 EXPECT_EQ(starting_tab_count
+ 3, browser()->tab_strip_model()->count());
238 EXPECT_EQ(closed_tab_index
, browser()->tab_strip_model()->active_index());
240 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
243 // Close a tab, switch windows, then restore the tab. The tab should be in its
244 // original window and position, and active.
245 IN_PROC_BROWSER_TEST_F(TabRestoreTest
, RestoreToDifferentWindow
) {
246 int starting_tab_count
= browser()->tab_strip_model()->count();
247 AddSomeTabs(browser(), 3);
249 // Close one in the middle
250 int closed_tab_index
= starting_tab_count
+ 1;
251 CloseTab(closed_tab_index
);
252 EXPECT_EQ(starting_tab_count
+ 2, browser()->tab_strip_model()->count());
254 // Create a new browser.
255 ui_test_utils::NavigateToURLWithDisposition(
256 browser(), GURL(chrome::kChromeUINewTabURL
), NEW_WINDOW
,
257 ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER
);
258 EXPECT_EQ(2u, active_browser_list_
->size());
260 // Restore tab into original browser.
261 ASSERT_NO_FATAL_FAILURE(RestoreTab(0, closed_tab_index
));
263 // And make sure everything looks right.
264 EXPECT_EQ(starting_tab_count
+ 3, browser()->tab_strip_model()->count());
265 EXPECT_EQ(closed_tab_index
, browser()->tab_strip_model()->active_index());
267 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
270 // Close a tab, open a new window, close the first window, then restore the
271 // tab. It should be in a new window.
272 // If this becomes flaky, use http://crbug.com/14774
273 IN_PROC_BROWSER_TEST_F(TabRestoreTest
, DISABLED_BasicRestoreFromClosedWindow
) {
274 // Navigate to url1 then url2.
275 ui_test_utils::NavigateToURL(browser(), url1_
);
276 ui_test_utils::NavigateToURL(browser(), url2_
);
278 // Create a new browser.
279 ui_test_utils::NavigateToURLWithDisposition(
280 browser(), GURL(chrome::kChromeUINewTabURL
), NEW_WINDOW
,
281 ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER
);
282 EXPECT_EQ(2u, active_browser_list_
->size());
284 // Close the final tab in the first browser.
285 content::WindowedNotificationObserver
window_observer(
286 chrome::NOTIFICATION_BROWSER_CLOSED
,
287 content::NotificationService::AllSources());
289 window_observer
.Wait();
291 ASSERT_NO_FATAL_FAILURE(RestoreTab(1, 0));
293 // Tab should be in a new window.
294 Browser
* browser
= GetBrowser(1);
295 content::WebContents
* web_contents
=
296 browser
->tab_strip_model()->GetActiveWebContents();
297 // And make sure the URLs match.
298 EXPECT_EQ(url2_
, web_contents
->GetURL());
300 EXPECT_EQ(url1_
, web_contents
->GetURL());
304 // Flakily times out: http://crbug.com/171503
305 #define MAYBE_DontLoadRestoredTab DISABLED_DontLoadRestoredTab
307 #define MAYBE_DontLoadRestoredTab DontLoadRestoredTab
310 // Restore a tab then make sure it doesn't restore again.
311 IN_PROC_BROWSER_TEST_F(TabRestoreTest
, MAYBE_DontLoadRestoredTab
) {
313 int starting_tab_count
= browser()->tab_strip_model()->count();
314 AddSomeTabs(browser(), 2);
315 ASSERT_EQ(browser()->tab_strip_model()->count(), starting_tab_count
+ 2);
317 // Close one of them.
319 ASSERT_EQ(browser()->tab_strip_model()->count(), starting_tab_count
+ 1);
322 ASSERT_NO_FATAL_FAILURE(RestoreTab(0, 0));
323 ASSERT_EQ(browser()->tab_strip_model()->count(), starting_tab_count
+ 2);
325 // Make sure that there's nothing else to restore.
326 ASSERT_EQ(chrome::GetRestoreTabType(browser()),
327 TabStripModelDelegate::RESTORE_NONE
);
330 // Open a window with multiple tabs, close a tab, then close the window.
331 // Restore both and make sure the tab goes back into the window.
332 IN_PROC_BROWSER_TEST_F(TabRestoreTest
, RestoreWindowAndTab
) {
333 int starting_tab_count
= browser()->tab_strip_model()->count();
334 AddSomeTabs(browser(), 3);
336 // Close one in the middle
337 int closed_tab_index
= starting_tab_count
+ 1;
338 CloseTab(closed_tab_index
);
339 EXPECT_EQ(starting_tab_count
+ 2, browser()->tab_strip_model()->count());
341 // Create a new browser.
342 ui_test_utils::NavigateToURLWithDisposition(
343 browser(), GURL(chrome::kChromeUINewTabURL
), NEW_WINDOW
,
344 ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER
);
345 EXPECT_EQ(2u, active_browser_list_
->size());
347 // Close the first browser.
348 content::WindowedNotificationObserver
observer(
349 chrome::NOTIFICATION_BROWSER_CLOSED
,
350 content::NotificationService::AllSources());
351 chrome::CloseWindow(browser());
353 EXPECT_EQ(1u, active_browser_list_
->size());
355 // Restore the first window. The expected_tabstrip_index (second argument)
356 // indicates the expected active tab.
357 ASSERT_NO_FATAL_FAILURE(RestoreTab(1, starting_tab_count
+ 1));
358 Browser
* browser
= GetBrowser(1);
359 EXPECT_EQ(starting_tab_count
+ 2, browser
->tab_strip_model()->count());
361 // Restore the closed tab.
362 ASSERT_NO_FATAL_FAILURE(RestoreTab(1, closed_tab_index
));
363 EXPECT_EQ(starting_tab_count
+ 3, browser
->tab_strip_model()->count());
365 browser
->tab_strip_model()->GetActiveWebContents()->GetURL());
368 // Open a window with two tabs, close both (closing the window), then restore
369 // both. Make sure both restored tabs are in the same window.
370 IN_PROC_BROWSER_TEST_F(TabRestoreTest
, RestoreIntoSameWindow
) {
371 ui_test_utils::NavigateToURLWithDisposition(
372 browser(), url1_
, NEW_FOREGROUND_TAB
,
373 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION
);
374 // Navigate the rightmost one to url2_ for easier identification.
375 ui_test_utils::NavigateToURLWithDisposition(
376 browser(), url2_
, NEW_FOREGROUND_TAB
,
377 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION
);
379 // Create a new browser.
380 ui_test_utils::NavigateToURLWithDisposition(
381 browser(), GURL(chrome::kChromeUINewTabURL
), NEW_WINDOW
,
382 ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER
);
383 EXPECT_EQ(2u, active_browser_list_
->size());
385 // Close all but one tab in the first browser, left to right.
386 while (browser()->tab_strip_model()->count() > 1)
389 // Close the last tab, closing the browser.
390 content::WindowedNotificationObserver
observer(
391 chrome::NOTIFICATION_BROWSER_CLOSED
,
392 content::NotificationService::AllSources());
395 EXPECT_EQ(1u, active_browser_list_
->size());
397 // Restore the last-closed tab into a new window.
398 ASSERT_NO_FATAL_FAILURE(RestoreTab(1, 0));
399 Browser
* browser
= GetBrowser(1);
400 EXPECT_EQ(1, browser
->tab_strip_model()->count());
402 browser
->tab_strip_model()->GetActiveWebContents()->GetURL());
404 // Restore the next-to-last-closed tab into the same window.
405 ASSERT_NO_FATAL_FAILURE(RestoreTab(1, 0));
406 EXPECT_EQ(2, browser
->tab_strip_model()->count());
408 browser
->tab_strip_model()->GetActiveWebContents()->GetURL());
411 // Tests that a duplicate history entry is not created when we restore a page
412 // to an existing SiteInstance. (Bug 1230446)
413 IN_PROC_BROWSER_TEST_F(TabRestoreTest
, RestoreWithExistingSiteInstance
) {
414 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
416 GURL
http_url1(embedded_test_server()->GetURL("/title1.html"));
417 GURL
http_url2(embedded_test_server()->GetURL("/title2.html"));
418 int tab_count
= browser()->tab_strip_model()->count();
421 ui_test_utils::NavigateToURLWithDisposition(
422 browser(), http_url1
, NEW_FOREGROUND_TAB
,
423 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION
);
424 EXPECT_EQ(++tab_count
, browser()->tab_strip_model()->count());
426 // Navigate to another same-site URL.
427 content::WebContents
* tab
=
428 browser()->tab_strip_model()->GetWebContentsAt(tab_count
- 1);
429 content::WindowedNotificationObserver
observer(
430 content::NOTIFICATION_LOAD_STOP
,
431 content::NotificationService::AllSources());
432 static_cast<content::WebContentsDelegate
*>(browser())->OpenURLFromTab(
434 content::OpenURLParams(http_url2
, content::Referrer(), CURRENT_TAB
,
435 ui::PAGE_TRANSITION_TYPED
, false));
441 // Create a new tab to the original site. Assuming process-per-site is
442 // enabled, this will ensure that the SiteInstance used by the restored tab
443 // will already exist when the restore happens.
444 ui_test_utils::NavigateToURLWithDisposition(
445 browser(), http_url2
, NEW_FOREGROUND_TAB
,
446 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION
);
448 // Restore the closed tab.
449 ASSERT_NO_FATAL_FAILURE(RestoreTab(0, tab_count
- 1));
451 // And make sure the URLs match.
453 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
456 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
459 // See crbug.com/248574
461 #define MAYBE_RestoreCrossSiteWithExistingSiteInstance DISABLED_RestoreCrossSiteWithExistingSiteInstance
463 #define MAYBE_RestoreCrossSiteWithExistingSiteInstance RestoreCrossSiteWithExistingSiteInstance
466 // Tests that the SiteInstances used for entries in a restored tab's history
467 // are given appropriate max page IDs, even if the renderer for the entry
468 // already exists. (Bug 1204135)
469 IN_PROC_BROWSER_TEST_F(TabRestoreTest
,
470 MAYBE_RestoreCrossSiteWithExistingSiteInstance
) {
471 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
473 GURL
http_url1(embedded_test_server()->GetURL("/title1.html"));
474 GURL
http_url2(embedded_test_server()->GetURL("/title2.html"));
476 int tab_count
= browser()->tab_strip_model()->count();
479 ui_test_utils::NavigateToURLWithDisposition(
480 browser(), http_url1
, NEW_FOREGROUND_TAB
,
481 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION
);
482 EXPECT_EQ(++tab_count
, browser()->tab_strip_model()->count());
484 // Navigate to more URLs, then a cross-site URL.
485 ui_test_utils::NavigateToURL(browser(), http_url2
);
486 ui_test_utils::NavigateToURL(browser(), http_url1
);
487 ui_test_utils::NavigateToURL(browser(), url1_
);
492 // Create a new tab to the original site. Assuming process-per-site is
493 // enabled, this will ensure that the SiteInstance will already exist when
494 // the user clicks Back in the restored tab.
495 ui_test_utils::NavigateToURLWithDisposition(
496 browser(), http_url2
, NEW_FOREGROUND_TAB
,
497 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION
);
499 // Restore the closed tab.
500 ASSERT_NO_FATAL_FAILURE(RestoreTab(0, tab_count
- 1));
502 // And make sure the URLs match.
504 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
507 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
509 // Navigating to a new URL should clear the forward list, because the max
510 // page ID of the renderer should have been updated when we restored the tab.
511 ui_test_utils::NavigateToURL(browser(), http_url2
);
512 EXPECT_FALSE(chrome::CanGoForward(browser()));
514 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
517 IN_PROC_BROWSER_TEST_F(TabRestoreTest
, RestoreWindow
) {
518 // Create a new window.
519 size_t window_count
= active_browser_list_
->size();
520 ui_test_utils::NavigateToURLWithDisposition(
521 browser(), GURL(chrome::kChromeUINewTabURL
), NEW_WINDOW
,
522 ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER
);
523 EXPECT_EQ(++window_count
, active_browser_list_
->size());
525 // Create two more tabs, one with url1, the other url2.
526 int initial_tab_count
= browser()->tab_strip_model()->count();
527 ui_test_utils::NavigateToURLWithDisposition(
528 browser(), url1_
, NEW_FOREGROUND_TAB
,
529 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION
);
530 ui_test_utils::NavigateToURLWithDisposition(
531 browser(), url2_
, NEW_FOREGROUND_TAB
,
532 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION
);
535 content::WindowedNotificationObserver
close_window_observer(
536 chrome::NOTIFICATION_BROWSER_CLOSED
,
537 content::NotificationService::AllSources());
538 chrome::CloseWindow(browser());
539 close_window_observer
.Wait();
540 EXPECT_EQ(window_count
- 1, active_browser_list_
->size());
542 // Restore the window.
543 content::WindowedNotificationObserver
open_window_observer(
544 chrome::NOTIFICATION_BROWSER_OPENED
,
545 content::NotificationService::AllSources());
546 content::WindowedNotificationObserver
load_stop_observer(
547 content::NOTIFICATION_LOAD_STOP
,
548 content::NotificationService::AllSources());
549 chrome::RestoreTab(active_browser_list_
->get(0));
550 open_window_observer
.Wait();
551 EXPECT_EQ(window_count
, active_browser_list_
->size());
553 Browser
* browser
= GetBrowser(1);
554 EXPECT_EQ(initial_tab_count
+ 2, browser
->tab_strip_model()->count());
555 load_stop_observer
.Wait();
557 content::WebContents
* restored_tab
=
558 browser
->tab_strip_model()->GetWebContentsAt(initial_tab_count
);
559 EnsureTabFinishedRestoring(restored_tab
);
560 EXPECT_EQ(url1_
, restored_tab
->GetURL());
563 browser
->tab_strip_model()->GetWebContentsAt(initial_tab_count
+ 1);
564 EnsureTabFinishedRestoring(restored_tab
);
565 EXPECT_EQ(url2_
, restored_tab
->GetURL());
568 // Restore tab with special URL chrome://credits/ and make sure the page loads
569 // properly after restore. See http://crbug.com/31905.
570 IN_PROC_BROWSER_TEST_F(TabRestoreTest
, RestoreTabWithSpecialURL
) {
571 // Navigate new tab to a special URL.
572 ui_test_utils::NavigateToURLWithDisposition(
573 browser(), GURL(chrome::kChromeUICreditsURL
), NEW_FOREGROUND_TAB
,
574 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION
);
579 // Restore the closed tab.
580 ASSERT_NO_FATAL_FAILURE(RestoreTab(0, 1));
581 content::WebContents
* tab
= browser()->tab_strip_model()->GetWebContentsAt(1);
582 EnsureTabFinishedRestoring(tab
);
584 // See if content is as expected.
586 ui_test_utils::FindInPage(tab
, base::ASCIIToUTF16("webkit"), true, false,
591 // Restore tab with special URL in its navigation history, go back to that
592 // entry and see that it loads properly. See http://crbug.com/31905
593 IN_PROC_BROWSER_TEST_F(TabRestoreTest
, RestoreTabWithSpecialURLOnBack
) {
594 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
596 const GURL
http_url(embedded_test_server()->GetURL("/title1.html"));
598 // Navigate new tab to a special URL.
599 ui_test_utils::NavigateToURLWithDisposition(
600 browser(), GURL(chrome::kChromeUICreditsURL
), NEW_FOREGROUND_TAB
,
601 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION
);
603 // Then navigate to a normal URL.
604 ui_test_utils::NavigateToURL(browser(), http_url
);
609 // Restore the closed tab.
610 ASSERT_NO_FATAL_FAILURE(RestoreTab(0, 1));
611 content::WebContents
* tab
= browser()->tab_strip_model()->GetWebContentsAt(1);
612 EnsureTabFinishedRestoring(tab
);
613 ASSERT_EQ(http_url
, tab
->GetURL());
615 // Go back, and see if content is as expected.
618 ui_test_utils::FindInPage(tab
, base::ASCIIToUTF16("webkit"), true, false,
623 IN_PROC_BROWSER_TEST_F(TabRestoreTest
, PRE_RestoreOnStartup
) {
624 // This results in a new tab at the end with url1.
625 AddSomeTabs(browser(), 1);
627 while (browser()->tab_strip_model()->count())
631 // Verifies restoring a tab works on startup.
632 IN_PROC_BROWSER_TEST_F(TabRestoreTest
, RestoreOnStartup
) {
633 ASSERT_NO_FATAL_FAILURE(RestoreTab(0, 1));
635 browser()->tab_strip_model()->GetWebContentsAt(1)->GetURL());