Fix build break
[chromium-blink-merge.git] / chrome / browser / sessions / tab_restore_browsertest.cc
blobd57e6c1ff9674ee0a060a532221c87c0f6ccb604
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/test/test_timeouts.h"
9 #include "base/utf_string_conversions.h"
10 #include "chrome/app/chrome_command_ids.h"
11 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/browser_commands.h"
13 #include "chrome/browser/ui/browser_list.h"
14 #include "chrome/browser/ui/browser_tabstrip.h"
15 #include "chrome/browser/ui/find_bar/find_notification_details.h"
16 #include "chrome/browser/ui/tabs/tab_strip_model.h"
17 #include "chrome/common/chrome_notification_types.h"
18 #include "chrome/common/chrome_paths.h"
19 #include "chrome/common/url_constants.h"
20 #include "chrome/test/base/in_process_browser_test.h"
21 #include "chrome/test/base/ui_test_utils.h"
22 #include "content/public/browser/navigation_controller.h"
23 #include "content/public/browser/notification_service.h"
24 #include "content/public/browser/notification_source.h"
25 #include "content/public/browser/notification_types.h"
26 #include "content/public/browser/page_navigator.h"
27 #include "content/public/browser/render_view_host.h"
28 #include "content/public/browser/web_contents.h"
29 #include "googleurl/src/gurl.h"
30 #include "net/base/net_util.h"
31 #include "net/test/test_server.h"
32 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFindOptions.h"
34 class TabRestoreTest : public InProcessBrowserTest {
35 public:
36 TabRestoreTest()
37 : native_browser_list(BrowserList::GetInstance(
38 chrome::HOST_DESKTOP_TYPE_NATIVE)) {
39 url1_ = ui_test_utils::GetTestUrl(
40 base::FilePath().AppendASCII("session_history"),
41 base::FilePath().AppendASCII("bot1.html"));
42 url2_ = ui_test_utils::GetTestUrl(
43 base::FilePath().AppendASCII("session_history"),
44 base::FilePath().AppendASCII("bot2.html"));
47 protected:
48 Browser* GetBrowser(int index) {
50 CHECK(static_cast<int>(native_browser_list->size()) > index);
51 return native_browser_list->get(index);
54 // Adds tabs to the given browser, all navigated to url1_. Returns
55 // the final number of tabs.
56 int AddSomeTabs(Browser* browser, int how_many) {
57 int starting_tab_count = browser->tab_strip_model()->count();
59 for (int i = 0; i < how_many; ++i) {
60 ui_test_utils::NavigateToURLWithDisposition(
61 browser, url1_, NEW_FOREGROUND_TAB,
62 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
64 int tab_count = browser->tab_strip_model()->count();
65 EXPECT_EQ(starting_tab_count + how_many, tab_count);
66 return tab_count;
69 void CloseTab(int index) {
70 content::WindowedNotificationObserver tab_close_observer(
71 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
72 content::NotificationService::AllSources());
73 browser()->tab_strip_model()->CloseWebContentsAt(
74 index, TabStripModel::CLOSE_CREATE_HISTORICAL_TAB);
75 tab_close_observer.Wait();
78 // Uses the undo-close-tab accelerator to undo a close-tab or close-window
79 // operation. The newly restored tab is expected to appear in the
80 // window at index |expected_window_index|, at the |expected_tabstrip_index|,
81 // and to be active. If |expected_window_index| is equal to the number of
82 // current windows, the restored tab is expected to be created in a new
83 // window (since the index is 0-based).
84 void RestoreTab(int expected_window_index,
85 int expected_tabstrip_index) {
86 int window_count = static_cast<int>(native_browser_list->size());
87 ASSERT_GT(window_count, 0);
89 bool expect_new_window = (expected_window_index == window_count);
91 Browser* browser;
92 if (expect_new_window) {
93 browser = native_browser_list->get(0);
94 } else {
95 browser = GetBrowser(expected_window_index);
97 int tab_count = browser->tab_strip_model()->count();
98 ASSERT_GT(tab_count, 0);
100 // Restore the tab.
101 content::WindowedNotificationObserver tab_added_observer(
102 chrome::NOTIFICATION_TAB_PARENTED,
103 content::NotificationService::AllSources());
104 content::WindowedNotificationObserver tab_loaded_observer(
105 content::NOTIFICATION_LOAD_STOP,
106 content::NotificationService::AllSources());
107 chrome::RestoreTab(browser);
108 tab_added_observer.Wait();
109 tab_loaded_observer.Wait();
111 if (expect_new_window) {
112 int new_window_count = static_cast<int>(native_browser_list->size());
113 EXPECT_EQ(++window_count, new_window_count);
114 browser = GetBrowser(expected_window_index);
115 } else {
116 EXPECT_EQ(++tab_count, browser->tab_strip_model()->count());
119 // Get a handle to the restored tab.
120 ASSERT_GT(browser->tab_strip_model()->count(), expected_tabstrip_index);
122 // Ensure that the tab and window are active.
123 EXPECT_EQ(expected_tabstrip_index,
124 browser->tab_strip_model()->active_index());
127 void GoBack(Browser* browser) {
128 content::WindowedNotificationObserver observer(
129 content::NOTIFICATION_LOAD_STOP,
130 content::NotificationService::AllSources());
131 chrome::GoBack(browser, CURRENT_TAB);
132 observer.Wait();
135 void EnsureTabFinishedRestoring(content::WebContents* tab) {
136 content::NavigationController* controller = &tab->GetController();
137 if (!controller->NeedsReload() && !controller->GetPendingEntry() &&
138 !controller->GetWebContents()->IsLoading())
139 return;
141 content::WindowedNotificationObserver observer(
142 content::NOTIFICATION_LOAD_STOP,
143 content::Source<content::NavigationController>(controller));
144 observer.Wait();
147 GURL url1_;
148 GURL url2_;
150 // The TabRestore browser tests only uses the native desktop for now.
151 const BrowserList* native_browser_list;
153 private:
154 DISALLOW_COPY_AND_ASSIGN(TabRestoreTest);
157 // Close the end tab in the current window, then restore it. The tab should be
158 // in its original position, and active.
159 IN_PROC_BROWSER_TEST_F(TabRestoreTest, Basic) {
160 int starting_tab_count = browser()->tab_strip_model()->count();
161 int tab_count = AddSomeTabs(browser(), 1);
163 int closed_tab_index = tab_count - 1;
164 CloseTab(closed_tab_index);
165 EXPECT_EQ(starting_tab_count, browser()->tab_strip_model()->count());
167 ASSERT_NO_FATAL_FAILURE(RestoreTab(0, closed_tab_index));
169 // And make sure everything looks right.
170 EXPECT_EQ(starting_tab_count + 1, browser()->tab_strip_model()->count());
171 EXPECT_EQ(closed_tab_index, browser()->tab_strip_model()->active_index());
172 EXPECT_EQ(url1_,
173 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
176 // Close a tab not at the end of the current window, then restore it. The tab
177 // should be in its original position, and active.
178 IN_PROC_BROWSER_TEST_F(TabRestoreTest, MiddleTab) {
179 int starting_tab_count = browser()->tab_strip_model()->count();
180 AddSomeTabs(browser(), 3);
182 // Close one in the middle
183 int closed_tab_index = starting_tab_count + 1;
184 CloseTab(closed_tab_index);
185 EXPECT_EQ(starting_tab_count + 2, browser()->tab_strip_model()->count());
187 ASSERT_NO_FATAL_FAILURE(RestoreTab(0, closed_tab_index));
189 // And make sure everything looks right.
190 EXPECT_EQ(starting_tab_count + 3, browser()->tab_strip_model()->count());
191 EXPECT_EQ(closed_tab_index, browser()->tab_strip_model()->active_index());
192 EXPECT_EQ(url1_,
193 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
196 // Close a tab, switch windows, then restore the tab. The tab should be in its
197 // original window and position, and active.
198 IN_PROC_BROWSER_TEST_F(TabRestoreTest, RestoreToDifferentWindow) {
199 int starting_tab_count = browser()->tab_strip_model()->count();
200 AddSomeTabs(browser(), 3);
202 // Close one in the middle
203 int closed_tab_index = starting_tab_count + 1;
204 CloseTab(closed_tab_index);
205 EXPECT_EQ(starting_tab_count + 2, browser()->tab_strip_model()->count());
207 // Create a new browser.
208 ui_test_utils::NavigateToURLWithDisposition(
209 browser(), GURL(chrome::kChromeUINewTabURL), NEW_WINDOW,
210 ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER);
211 EXPECT_EQ(2u, native_browser_list->size());
213 // Restore tab into original browser.
214 ASSERT_NO_FATAL_FAILURE(RestoreTab(0, closed_tab_index));
216 // And make sure everything looks right.
217 EXPECT_EQ(starting_tab_count + 3, browser()->tab_strip_model()->count());
218 EXPECT_EQ(closed_tab_index, browser()->tab_strip_model()->active_index());
219 EXPECT_EQ(url1_,
220 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
223 // Close a tab, open a new window, close the first window, then restore the
224 // tab. It should be in a new window.
225 // If this becomes flaky, use http://crbug.com/14774
226 IN_PROC_BROWSER_TEST_F(TabRestoreTest, DISABLED_BasicRestoreFromClosedWindow) {
227 // Navigate to url1 then url2.
228 ui_test_utils::NavigateToURL(browser(), url1_);
229 ui_test_utils::NavigateToURL(browser(), url2_);
231 // Create a new browser.
232 ui_test_utils::NavigateToURLWithDisposition(
233 browser(), GURL(chrome::kChromeUINewTabURL), NEW_WINDOW,
234 ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER);
235 EXPECT_EQ(2u, native_browser_list->size());
237 // Close the final tab in the first browser.
238 content::WindowedNotificationObserver window_observer(
239 chrome::NOTIFICATION_BROWSER_CLOSED,
240 content::NotificationService::AllSources());
241 CloseTab(0);
242 window_observer.Wait();
244 ASSERT_NO_FATAL_FAILURE(RestoreTab(1, 0));
246 // Tab should be in a new window.
247 Browser* browser = GetBrowser(1);
248 content::WebContents* web_contents =
249 browser->tab_strip_model()->GetActiveWebContents();
250 // And make sure the URLs match.
251 EXPECT_EQ(url2_, web_contents->GetURL());
252 GoBack(browser);
253 EXPECT_EQ(url1_, web_contents->GetURL());
256 #if defined(OS_WIN)
257 // Flakily times out: http://crbug.com/171503
258 #define MAYBE_DontLoadRestoredTab DISABLED_DontLoadRestoredTab
259 #else
260 #define MAYBE_DontLoadRestoredTab DontLoadRestoredTab
261 #endif
263 // Restore a tab then make sure it doesn't restore again.
264 IN_PROC_BROWSER_TEST_F(TabRestoreTest, MAYBE_DontLoadRestoredTab) {
265 // Add two tabs
266 int starting_tab_count = browser()->tab_strip_model()->count();
267 AddSomeTabs(browser(), 2);
268 ASSERT_EQ(browser()->tab_strip_model()->count(), starting_tab_count + 2);
270 // Close one of them.
271 CloseTab(0);
272 ASSERT_EQ(browser()->tab_strip_model()->count(), starting_tab_count + 1);
274 // Restore it.
275 ASSERT_NO_FATAL_FAILURE(RestoreTab(0, 0));
276 ASSERT_EQ(browser()->tab_strip_model()->count(), starting_tab_count + 2);
278 // Make sure that there's nothing else to restore.
279 ASSERT_EQ(chrome::GetRestoreTabType(browser()),
280 TabStripModelDelegate::RESTORE_NONE);
283 // Open a window with multiple tabs, close a tab, then close the window.
284 // Restore both and make sure the tab goes back into the window.
285 IN_PROC_BROWSER_TEST_F(TabRestoreTest, RestoreWindowAndTab) {
286 int starting_tab_count = browser()->tab_strip_model()->count();
287 AddSomeTabs(browser(), 3);
289 // Close one in the middle
290 int closed_tab_index = starting_tab_count + 1;
291 CloseTab(closed_tab_index);
292 EXPECT_EQ(starting_tab_count + 2, browser()->tab_strip_model()->count());
294 // Create a new browser.
295 ui_test_utils::NavigateToURLWithDisposition(
296 browser(), GURL(chrome::kChromeUINewTabURL), NEW_WINDOW,
297 ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER);
298 EXPECT_EQ(2u, native_browser_list->size());
300 // Close the first browser.
301 content::WindowedNotificationObserver observer(
302 chrome::NOTIFICATION_BROWSER_CLOSED,
303 content::NotificationService::AllSources());
304 chrome::CloseWindow(browser());
305 observer.Wait();
306 EXPECT_EQ(1u, native_browser_list->size());
308 // Restore the first window. The expected_tabstrip_index (second argument)
309 // indicates the expected active tab.
310 ASSERT_NO_FATAL_FAILURE(RestoreTab(1, starting_tab_count + 1));
311 Browser* browser = GetBrowser(1);
312 EXPECT_EQ(starting_tab_count + 2, browser->tab_strip_model()->count());
314 // Restore the closed tab.
315 ASSERT_NO_FATAL_FAILURE(RestoreTab(1, closed_tab_index));
316 EXPECT_EQ(starting_tab_count + 3, browser->tab_strip_model()->count());
317 EXPECT_EQ(url1_,
318 browser->tab_strip_model()->GetActiveWebContents()->GetURL());
321 // Open a window with two tabs, close both (closing the window), then restore
322 // both. Make sure both restored tabs are in the same window.
323 IN_PROC_BROWSER_TEST_F(TabRestoreTest, RestoreIntoSameWindow) {
324 ui_test_utils::NavigateToURLWithDisposition(
325 browser(), url1_, NEW_FOREGROUND_TAB,
326 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
327 // Navigate the rightmost one to url2_ for easier identification.
328 ui_test_utils::NavigateToURLWithDisposition(
329 browser(), url2_, NEW_FOREGROUND_TAB,
330 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
332 // Create a new browser.
333 ui_test_utils::NavigateToURLWithDisposition(
334 browser(), GURL(chrome::kChromeUINewTabURL), NEW_WINDOW,
335 ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER);
336 EXPECT_EQ(2u, native_browser_list->size());
338 // Close all but one tab in the first browser, left to right.
339 while (browser()->tab_strip_model()->count() > 1)
340 CloseTab(0);
342 // Close the last tab, closing the browser.
343 content::WindowedNotificationObserver observer(
344 chrome::NOTIFICATION_BROWSER_CLOSED,
345 content::NotificationService::AllSources());
346 CloseTab(0);
347 observer.Wait();
348 EXPECT_EQ(1u, native_browser_list->size());
350 // Restore the last-closed tab into a new window.
351 ASSERT_NO_FATAL_FAILURE(RestoreTab(1, 0));
352 Browser* browser = GetBrowser(1);
353 EXPECT_EQ(1, browser->tab_strip_model()->count());
354 EXPECT_EQ(url2_,
355 browser->tab_strip_model()->GetActiveWebContents()->GetURL());
357 // Restore the next-to-last-closed tab into the same window.
358 ASSERT_NO_FATAL_FAILURE(RestoreTab(1, 0));
359 EXPECT_EQ(2, browser->tab_strip_model()->count());
360 EXPECT_EQ(url1_,
361 browser->tab_strip_model()->GetActiveWebContents()->GetURL());
364 // Tests that a duplicate history entry is not created when we restore a page
365 // to an existing SiteInstance. (Bug 1230446)
366 IN_PROC_BROWSER_TEST_F(TabRestoreTest, RestoreWithExistingSiteInstance) {
367 ASSERT_TRUE(test_server()->Start());
369 GURL http_url1(test_server()->GetURL("files/title1.html"));
370 GURL http_url2(test_server()->GetURL("files/title2.html"));
371 int tab_count = browser()->tab_strip_model()->count();
373 // Add a tab
374 ui_test_utils::NavigateToURLWithDisposition(
375 browser(), http_url1, NEW_FOREGROUND_TAB,
376 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
377 EXPECT_EQ(++tab_count, browser()->tab_strip_model()->count());
379 // Navigate to another same-site URL.
380 content::WebContents* tab =
381 browser()->tab_strip_model()->GetWebContentsAt(tab_count - 1);
382 content::WindowedNotificationObserver observer(
383 content::NOTIFICATION_LOAD_STOP,
384 content::NotificationService::AllSources());
385 static_cast<content::WebContentsDelegate*>(browser())->OpenURLFromTab(
386 tab,
387 content::OpenURLParams(http_url2, content::Referrer(), CURRENT_TAB,
388 content::PAGE_TRANSITION_TYPED, false));
389 observer.Wait();
391 // Close the tab.
392 CloseTab(1);
394 // Create a new tab to the original site. Assuming process-per-site is
395 // enabled, this will ensure that the SiteInstance used by the restored tab
396 // will already exist when the restore happens.
397 ui_test_utils::NavigateToURLWithDisposition(
398 browser(), http_url2, NEW_FOREGROUND_TAB,
399 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
401 // Restore the closed tab.
402 ASSERT_NO_FATAL_FAILURE(RestoreTab(0, tab_count - 1));
404 // And make sure the URLs match.
405 EXPECT_EQ(http_url2,
406 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
407 GoBack(browser());
408 EXPECT_EQ(http_url1,
409 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
412 // Tests that the SiteInstances used for entries in a restored tab's history
413 // are given appropriate max page IDs, even if the renderer for the entry
414 // already exists. (Bug 1204135)
415 IN_PROC_BROWSER_TEST_F(TabRestoreTest,
416 RestoreCrossSiteWithExistingSiteInstance) {
417 ASSERT_TRUE(test_server()->Start());
419 GURL http_url1(test_server()->GetURL("files/title1.html"));
420 GURL http_url2(test_server()->GetURL("files/title2.html"));
422 int tab_count = browser()->tab_strip_model()->count();
424 // Add a tab
425 ui_test_utils::NavigateToURLWithDisposition(
426 browser(), http_url1, NEW_FOREGROUND_TAB,
427 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
428 EXPECT_EQ(++tab_count, browser()->tab_strip_model()->count());
430 // Navigate to more URLs, then a cross-site URL.
431 ui_test_utils::NavigateToURLWithDisposition(
432 browser(), http_url2, CURRENT_TAB,
433 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
434 ui_test_utils::NavigateToURLWithDisposition(
435 browser(), http_url1, CURRENT_TAB,
436 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
437 ui_test_utils::NavigateToURLWithDisposition(
438 browser(), url1_, CURRENT_TAB,
439 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
441 // Close the tab.
442 CloseTab(1);
444 // Create a new tab to the original site. Assuming process-per-site is
445 // enabled, this will ensure that the SiteInstance will already exist when
446 // the user clicks Back in the restored tab.
447 ui_test_utils::NavigateToURLWithDisposition(
448 browser(), http_url2, NEW_FOREGROUND_TAB,
449 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
451 // Restore the closed tab.
452 ASSERT_NO_FATAL_FAILURE(RestoreTab(0, tab_count - 1));
454 // And make sure the URLs match.
455 EXPECT_EQ(url1_,
456 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
457 GoBack(browser());
458 EXPECT_EQ(http_url1,
459 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
461 // Navigating to a new URL should clear the forward list, because the max
462 // page ID of the renderer should have been updated when we restored the tab.
463 ui_test_utils::NavigateToURLWithDisposition(
464 browser(), http_url2, CURRENT_TAB,
465 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
466 EXPECT_FALSE(chrome::CanGoForward(browser()));
467 EXPECT_EQ(http_url2,
468 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
471 IN_PROC_BROWSER_TEST_F(TabRestoreTest, RestoreWindow) {
472 // Create a new window.
473 size_t window_count = native_browser_list->size();
474 ui_test_utils::NavigateToURLWithDisposition(
475 browser(), GURL(chrome::kChromeUINewTabURL), NEW_WINDOW,
476 ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER);
477 EXPECT_EQ(++window_count, native_browser_list->size());
479 // Create two more tabs, one with url1, the other url2.
480 int initial_tab_count = browser()->tab_strip_model()->count();
481 ui_test_utils::NavigateToURLWithDisposition(
482 browser(), url1_, NEW_FOREGROUND_TAB,
483 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
484 ui_test_utils::NavigateToURLWithDisposition(
485 browser(), url2_, NEW_FOREGROUND_TAB,
486 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
488 // Close the window.
489 content::WindowedNotificationObserver close_window_observer(
490 chrome::NOTIFICATION_BROWSER_CLOSED,
491 content::NotificationService::AllSources());
492 chrome::CloseWindow(browser());
493 close_window_observer.Wait();
494 EXPECT_EQ(window_count - 1, native_browser_list->size());
496 // Restore the window.
497 content::WindowedNotificationObserver open_window_observer(
498 chrome::NOTIFICATION_BROWSER_OPENED,
499 content::NotificationService::AllSources());
500 content::WindowedNotificationObserver load_stop_observer(
501 content::NOTIFICATION_LOAD_STOP,
502 content::NotificationService::AllSources());
503 chrome::RestoreTab(native_browser_list->get(0));
504 open_window_observer.Wait();
505 EXPECT_EQ(window_count, native_browser_list->size());
507 Browser* browser = GetBrowser(1);
508 EXPECT_EQ(initial_tab_count + 2, browser->tab_strip_model()->count());
509 load_stop_observer.Wait();
511 content::WebContents* restored_tab =
512 browser->tab_strip_model()->GetWebContentsAt(initial_tab_count);
513 EnsureTabFinishedRestoring(restored_tab);
514 EXPECT_EQ(url1_, restored_tab->GetURL());
516 restored_tab =
517 browser->tab_strip_model()->GetWebContentsAt(initial_tab_count + 1);
518 EnsureTabFinishedRestoring(restored_tab);
519 EXPECT_EQ(url2_, restored_tab->GetURL());
522 // Restore tab with special URL chrome://credits/ and make sure the page loads
523 // properly after restore. See http://crbug.com/31905.
524 IN_PROC_BROWSER_TEST_F(TabRestoreTest, RestoreTabWithSpecialURL) {
525 // Navigate new tab to a special URL.
526 ui_test_utils::NavigateToURLWithDisposition(
527 browser(), GURL(chrome::kChromeUICreditsURL), NEW_FOREGROUND_TAB,
528 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
530 // Close the tab.
531 CloseTab(1);
533 // Restore the closed tab.
534 ASSERT_NO_FATAL_FAILURE(RestoreTab(0, 1));
535 content::WebContents* tab = browser()->tab_strip_model()->GetWebContentsAt(1);
536 EnsureTabFinishedRestoring(tab);
538 // See if content is as expected.
539 EXPECT_GT(
540 ui_test_utils::FindInPage(tab, ASCIIToUTF16("webkit"), true, false, NULL,
541 NULL),
545 // Restore tab with special URL in its navigation history, go back to that
546 // entry and see that it loads properly. See http://crbug.com/31905
547 IN_PROC_BROWSER_TEST_F(TabRestoreTest, RestoreTabWithSpecialURLOnBack) {
548 ASSERT_TRUE(test_server()->Start());
550 const GURL http_url(test_server()->GetURL("files/title1.html"));
552 // Navigate new tab to a special URL.
553 ui_test_utils::NavigateToURLWithDisposition(
554 browser(), GURL(chrome::kChromeUICreditsURL), NEW_FOREGROUND_TAB,
555 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
557 // Then navigate to a normal URL.
558 ui_test_utils::NavigateToURL(browser(), http_url);
560 // Close the tab.
561 CloseTab(1);
563 // Restore the closed tab.
564 ASSERT_NO_FATAL_FAILURE(RestoreTab(0, 1));
565 content::WebContents* tab = browser()->tab_strip_model()->GetWebContentsAt(1);
566 EnsureTabFinishedRestoring(tab);
567 ASSERT_EQ(http_url, tab->GetURL());
569 // Go back, and see if content is as expected.
570 GoBack(browser());
571 EXPECT_GT(
572 ui_test_utils::FindInPage(tab, ASCIIToUTF16("webkit"), true, false, NULL,
573 NULL),