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