OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
8 #include "base/test/test_timeouts.h" | 8 #include "base/test/test_timeouts.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/app/chrome_command_ids.h" | 10 #include "chrome/app/chrome_command_ids.h" |
11 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
12 #include "chrome/browser/ui/browser_commands.h" | 12 #include "chrome/browser/ui/browser_commands.h" |
13 #include "chrome/browser/ui/browser_list.h" | 13 #include "chrome/browser/ui/browser_list.h" |
| 14 #include "chrome/browser/ui/browser_tabstrip.h" |
14 #include "chrome/browser/ui/find_bar/find_notification_details.h" | 15 #include "chrome/browser/ui/find_bar/find_notification_details.h" |
15 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 16 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
16 #include "chrome/common/chrome_notification_types.h" | 17 #include "chrome/common/chrome_notification_types.h" |
17 #include "chrome/common/chrome_paths.h" | 18 #include "chrome/common/chrome_paths.h" |
18 #include "chrome/common/url_constants.h" | 19 #include "chrome/common/url_constants.h" |
19 #include "chrome/test/base/in_process_browser_test.h" | 20 #include "chrome/test/base/in_process_browser_test.h" |
20 #include "chrome/test/base/ui_test_utils.h" | 21 #include "chrome/test/base/ui_test_utils.h" |
21 #include "content/public/browser/navigation_controller.h" | 22 #include "content/public/browser/navigation_controller.h" |
22 #include "content/public/browser/notification_service.h" | 23 #include "content/public/browser/notification_service.h" |
23 #include "content/public/browser/notification_source.h" | 24 #include "content/public/browser/notification_source.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 ui_test_utils::NavigateToURLWithDisposition( | 57 ui_test_utils::NavigateToURLWithDisposition( |
57 browser, url1_, NEW_FOREGROUND_TAB, | 58 browser, url1_, NEW_FOREGROUND_TAB, |
58 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 59 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
59 } | 60 } |
60 int tab_count = browser->tab_count(); | 61 int tab_count = browser->tab_count(); |
61 EXPECT_EQ(starting_tab_count + how_many, tab_count); | 62 EXPECT_EQ(starting_tab_count + how_many, tab_count); |
62 return tab_count; | 63 return tab_count; |
63 } | 64 } |
64 | 65 |
65 void CloseTab(int index) { | 66 void CloseTab(int index) { |
66 content::WebContents* new_tab = browser()->GetWebContentsAt(index); | 67 content::WebContents* new_tab = chrome::GetWebContentsAt(browser(), index); |
67 ui_test_utils::WindowedNotificationObserver tab_close_observer( | 68 ui_test_utils::WindowedNotificationObserver tab_close_observer( |
68 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | 69 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
69 content::NotificationService::AllSources()); | 70 content::NotificationService::AllSources()); |
70 browser()->CloseTabContents(new_tab); | 71 chrome::CloseWebContents(browser(), new_tab); |
71 tab_close_observer.Wait(); | 72 tab_close_observer.Wait(); |
72 } | 73 } |
73 | 74 |
74 // Uses the undo-close-tab accelerator to undo a close-tab or close-window | 75 // Uses the undo-close-tab accelerator to undo a close-tab or close-window |
75 // operation. The newly restored tab is expected to appear in the | 76 // operation. The newly restored tab is expected to appear in the |
76 // window at index |expected_window_index|, at the |expected_tabstrip_index|, | 77 // window at index |expected_window_index|, at the |expected_tabstrip_index|, |
77 // and to be active. If |expected_window_index| is equal to the number of | 78 // and to be active. If |expected_window_index| is equal to the number of |
78 // current windows, the restored tab is expected to be created in a new | 79 // current windows, the restored tab is expected to be created in a new |
79 // window (since the index is 0-based). | 80 // window (since the index is 0-based). |
80 void RestoreTab(int expected_window_index, | 81 void RestoreTab(int expected_window_index, |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 | 155 |
155 int closed_tab_index = tab_count - 1; | 156 int closed_tab_index = tab_count - 1; |
156 CloseTab(closed_tab_index); | 157 CloseTab(closed_tab_index); |
157 EXPECT_EQ(starting_tab_count, browser()->tab_count()); | 158 EXPECT_EQ(starting_tab_count, browser()->tab_count()); |
158 | 159 |
159 ASSERT_NO_FATAL_FAILURE(RestoreTab(0, closed_tab_index)); | 160 ASSERT_NO_FATAL_FAILURE(RestoreTab(0, closed_tab_index)); |
160 | 161 |
161 // And make sure everything looks right. | 162 // And make sure everything looks right. |
162 EXPECT_EQ(starting_tab_count + 1, browser()->tab_count()); | 163 EXPECT_EQ(starting_tab_count + 1, browser()->tab_count()); |
163 EXPECT_EQ(closed_tab_index, browser()->active_index()); | 164 EXPECT_EQ(closed_tab_index, browser()->active_index()); |
164 EXPECT_EQ(url1_, browser()->GetActiveWebContents()->GetURL()); | 165 EXPECT_EQ(url1_, chrome::GetActiveWebContents(browser())->GetURL()); |
165 } | 166 } |
166 | 167 |
167 // Close a tab not at the end of the current window, then restore it. The tab | 168 // Close a tab not at the end of the current window, then restore it. The tab |
168 // should be in its original position, and active. | 169 // should be in its original position, and active. |
169 IN_PROC_BROWSER_TEST_F(TabRestoreTest, MiddleTab) { | 170 IN_PROC_BROWSER_TEST_F(TabRestoreTest, MiddleTab) { |
170 int starting_tab_count = browser()->tab_count(); | 171 int starting_tab_count = browser()->tab_count(); |
171 AddSomeTabs(browser(), 3); | 172 AddSomeTabs(browser(), 3); |
172 | 173 |
173 // Close one in the middle | 174 // Close one in the middle |
174 int closed_tab_index = starting_tab_count + 1; | 175 int closed_tab_index = starting_tab_count + 1; |
175 CloseTab(closed_tab_index); | 176 CloseTab(closed_tab_index); |
176 EXPECT_EQ(starting_tab_count + 2, browser()->tab_count()); | 177 EXPECT_EQ(starting_tab_count + 2, browser()->tab_count()); |
177 | 178 |
178 ASSERT_NO_FATAL_FAILURE(RestoreTab(0, closed_tab_index)); | 179 ASSERT_NO_FATAL_FAILURE(RestoreTab(0, closed_tab_index)); |
179 | 180 |
180 // And make sure everything looks right. | 181 // And make sure everything looks right. |
181 EXPECT_EQ(starting_tab_count + 3, browser()->tab_count()); | 182 EXPECT_EQ(starting_tab_count + 3, browser()->tab_count()); |
182 EXPECT_EQ(closed_tab_index, browser()->active_index()); | 183 EXPECT_EQ(closed_tab_index, browser()->active_index()); |
183 EXPECT_EQ(url1_, browser()->GetActiveWebContents()->GetURL()); | 184 EXPECT_EQ(url1_, chrome::GetActiveWebContents(browser())->GetURL()); |
184 } | 185 } |
185 | 186 |
186 // Close a tab, switch windows, then restore the tab. The tab should be in its | 187 // Close a tab, switch windows, then restore the tab. The tab should be in its |
187 // original window and position, and active. | 188 // original window and position, and active. |
188 IN_PROC_BROWSER_TEST_F(TabRestoreTest, RestoreToDifferentWindow) { | 189 IN_PROC_BROWSER_TEST_F(TabRestoreTest, RestoreToDifferentWindow) { |
189 int starting_tab_count = browser()->tab_count(); | 190 int starting_tab_count = browser()->tab_count(); |
190 AddSomeTabs(browser(), 3); | 191 AddSomeTabs(browser(), 3); |
191 | 192 |
192 // Close one in the middle | 193 // Close one in the middle |
193 int closed_tab_index = starting_tab_count + 1; | 194 int closed_tab_index = starting_tab_count + 1; |
194 CloseTab(closed_tab_index); | 195 CloseTab(closed_tab_index); |
195 EXPECT_EQ(starting_tab_count + 2, browser()->tab_count()); | 196 EXPECT_EQ(starting_tab_count + 2, browser()->tab_count()); |
196 | 197 |
197 // Create a new browser. | 198 // Create a new browser. |
198 ui_test_utils::NavigateToURLWithDisposition( | 199 ui_test_utils::NavigateToURLWithDisposition( |
199 browser(), GURL(chrome::kChromeUINewTabURL), NEW_WINDOW, | 200 browser(), GURL(chrome::kChromeUINewTabURL), NEW_WINDOW, |
200 ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER); | 201 ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER); |
201 EXPECT_EQ(2u, BrowserList::size()); | 202 EXPECT_EQ(2u, BrowserList::size()); |
202 | 203 |
203 // Restore tab into original browser. | 204 // Restore tab into original browser. |
204 ASSERT_NO_FATAL_FAILURE(RestoreTab(0, closed_tab_index)); | 205 ASSERT_NO_FATAL_FAILURE(RestoreTab(0, closed_tab_index)); |
205 | 206 |
206 // And make sure everything looks right. | 207 // And make sure everything looks right. |
207 EXPECT_EQ(starting_tab_count + 3, browser()->tab_count()); | 208 EXPECT_EQ(starting_tab_count + 3, browser()->tab_count()); |
208 EXPECT_EQ(closed_tab_index, browser()->active_index()); | 209 EXPECT_EQ(closed_tab_index, browser()->active_index()); |
209 EXPECT_EQ(url1_, browser()->GetActiveWebContents()->GetURL()); | 210 EXPECT_EQ(url1_, chrome::GetActiveWebContents(browser())->GetURL()); |
210 } | 211 } |
211 | 212 |
212 // Close a tab, open a new window, close the first window, then restore the | 213 // Close a tab, open a new window, close the first window, then restore the |
213 // tab. It should be in a new window. | 214 // tab. It should be in a new window. |
214 // If this becomes flaky, use http://crbug.com/14774 | 215 // If this becomes flaky, use http://crbug.com/14774 |
215 IN_PROC_BROWSER_TEST_F(TabRestoreTest, FLAKY_BasicRestoreFromClosedWindow) { | 216 IN_PROC_BROWSER_TEST_F(TabRestoreTest, FLAKY_BasicRestoreFromClosedWindow) { |
216 // Navigate to url1 then url2. | 217 // Navigate to url1 then url2. |
217 ui_test_utils::NavigateToURL(browser(), url1_); | 218 ui_test_utils::NavigateToURL(browser(), url1_); |
218 ui_test_utils::NavigateToURL(browser(), url2_); | 219 ui_test_utils::NavigateToURL(browser(), url2_); |
219 | 220 |
220 // Create a new browser. | 221 // Create a new browser. |
221 ui_test_utils::NavigateToURLWithDisposition( | 222 ui_test_utils::NavigateToURLWithDisposition( |
222 browser(), GURL(chrome::kChromeUINewTabURL), NEW_WINDOW, | 223 browser(), GURL(chrome::kChromeUINewTabURL), NEW_WINDOW, |
223 ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER); | 224 ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER); |
224 EXPECT_EQ(2u, BrowserList::size()); | 225 EXPECT_EQ(2u, BrowserList::size()); |
225 | 226 |
226 // Close the final tab in the first browser. | 227 // Close the final tab in the first browser. |
227 ui_test_utils::WindowedNotificationObserver window_observer( | 228 ui_test_utils::WindowedNotificationObserver window_observer( |
228 chrome::NOTIFICATION_BROWSER_CLOSED, | 229 chrome::NOTIFICATION_BROWSER_CLOSED, |
229 content::NotificationService::AllSources()); | 230 content::NotificationService::AllSources()); |
230 CloseTab(0); | 231 CloseTab(0); |
231 window_observer.Wait(); | 232 window_observer.Wait(); |
232 | 233 |
233 ASSERT_NO_FATAL_FAILURE(RestoreTab(1, 0)); | 234 ASSERT_NO_FATAL_FAILURE(RestoreTab(1, 0)); |
234 | 235 |
235 // Tab should be in a new window. | 236 // Tab should be in a new window. |
236 Browser* browser = GetBrowser(1); | 237 Browser* browser = GetBrowser(1); |
237 content::WebContents* web_contents = browser->GetActiveWebContents(); | 238 content::WebContents* web_contents = chrome::GetActiveWebContents(browser); |
238 // And make sure the URLs matches. | 239 // And make sure the URLs matches. |
239 EXPECT_EQ(url2_, web_contents->GetURL()); | 240 EXPECT_EQ(url2_, web_contents->GetURL()); |
240 GoBack(browser); | 241 GoBack(browser); |
241 EXPECT_EQ(url1_, web_contents->GetURL()); | 242 EXPECT_EQ(url1_, web_contents->GetURL()); |
242 } | 243 } |
243 | 244 |
244 // Restore a tab then make sure it doesn't restore again. | 245 // Restore a tab then make sure it doesn't restore again. |
245 IN_PROC_BROWSER_TEST_F(TabRestoreTest, DontLoadRestoredTab) { | 246 IN_PROC_BROWSER_TEST_F(TabRestoreTest, DontLoadRestoredTab) { |
246 // Add two tabs | 247 // Add two tabs |
247 int starting_tab_count = browser()->tab_count(); | 248 int starting_tab_count = browser()->tab_count(); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 | 288 |
288 // Restore the first window. The expected_tabstrip_index (second argument) | 289 // Restore the first window. The expected_tabstrip_index (second argument) |
289 // indicates the expected active tab. | 290 // indicates the expected active tab. |
290 ASSERT_NO_FATAL_FAILURE(RestoreTab(1, starting_tab_count + 1)); | 291 ASSERT_NO_FATAL_FAILURE(RestoreTab(1, starting_tab_count + 1)); |
291 Browser* browser = GetBrowser(1); | 292 Browser* browser = GetBrowser(1); |
292 EXPECT_EQ(starting_tab_count + 2, browser->tab_count()); | 293 EXPECT_EQ(starting_tab_count + 2, browser->tab_count()); |
293 | 294 |
294 // Restore the closed tab. | 295 // Restore the closed tab. |
295 ASSERT_NO_FATAL_FAILURE(RestoreTab(1, closed_tab_index)); | 296 ASSERT_NO_FATAL_FAILURE(RestoreTab(1, closed_tab_index)); |
296 EXPECT_EQ(starting_tab_count + 3, browser->tab_count()); | 297 EXPECT_EQ(starting_tab_count + 3, browser->tab_count()); |
297 EXPECT_EQ(url1_, browser->GetActiveWebContents()->GetURL()); | 298 EXPECT_EQ(url1_, chrome::GetActiveWebContents(browser)->GetURL()); |
298 } | 299 } |
299 | 300 |
300 // Open a window with two tabs, close both (closing the window), then restore | 301 // Open a window with two tabs, close both (closing the window), then restore |
301 // both. Make sure both restored tabs are in the same window. | 302 // both. Make sure both restored tabs are in the same window. |
302 IN_PROC_BROWSER_TEST_F(TabRestoreTest, RestoreIntoSameWindow) { | 303 IN_PROC_BROWSER_TEST_F(TabRestoreTest, RestoreIntoSameWindow) { |
303 ui_test_utils::NavigateToURLWithDisposition( | 304 ui_test_utils::NavigateToURLWithDisposition( |
304 browser(), url1_, NEW_FOREGROUND_TAB, | 305 browser(), url1_, NEW_FOREGROUND_TAB, |
305 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 306 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
306 // Navigate the rightmost one to url2_ for easier identification. | 307 // Navigate the rightmost one to url2_ for easier identification. |
307 ui_test_utils::NavigateToURLWithDisposition( | 308 ui_test_utils::NavigateToURLWithDisposition( |
(...skipping 15 matching lines...) Expand all Loading... |
323 chrome::NOTIFICATION_BROWSER_CLOSED, | 324 chrome::NOTIFICATION_BROWSER_CLOSED, |
324 content::NotificationService::AllSources()); | 325 content::NotificationService::AllSources()); |
325 CloseTab(0); | 326 CloseTab(0); |
326 observer.Wait(); | 327 observer.Wait(); |
327 EXPECT_EQ(1u, BrowserList::size()); | 328 EXPECT_EQ(1u, BrowserList::size()); |
328 | 329 |
329 // Restore the last-closed tab into a new window. | 330 // Restore the last-closed tab into a new window. |
330 ASSERT_NO_FATAL_FAILURE(RestoreTab(1, 0)); | 331 ASSERT_NO_FATAL_FAILURE(RestoreTab(1, 0)); |
331 Browser* browser = GetBrowser(1); | 332 Browser* browser = GetBrowser(1); |
332 EXPECT_EQ(1, browser->tab_count()); | 333 EXPECT_EQ(1, browser->tab_count()); |
333 EXPECT_EQ(url2_, browser->GetActiveWebContents()->GetURL()); | 334 EXPECT_EQ(url2_, chrome::GetActiveWebContents(browser)->GetURL()); |
334 | 335 |
335 // Restore the next-to-last-closed tab into the same window. | 336 // Restore the next-to-last-closed tab into the same window. |
336 ASSERT_NO_FATAL_FAILURE(RestoreTab(1, 0)); | 337 ASSERT_NO_FATAL_FAILURE(RestoreTab(1, 0)); |
337 EXPECT_EQ(2, browser->tab_count()); | 338 EXPECT_EQ(2, browser->tab_count()); |
338 EXPECT_EQ(url1_, browser->GetActiveWebContents()->GetURL()); | 339 EXPECT_EQ(url1_, chrome::GetActiveWebContents(browser)->GetURL()); |
339 } | 340 } |
340 | 341 |
341 // Tests that a duplicate history entry is not created when we restore a page | 342 // Tests that a duplicate history entry is not created when we restore a page |
342 // to an existing SiteInstance. (Bug 1230446) | 343 // to an existing SiteInstance. (Bug 1230446) |
343 IN_PROC_BROWSER_TEST_F(TabRestoreTest, RestoreWithExistingSiteInstance) { | 344 IN_PROC_BROWSER_TEST_F(TabRestoreTest, RestoreWithExistingSiteInstance) { |
344 ASSERT_TRUE(test_server()->Start()); | 345 ASSERT_TRUE(test_server()->Start()); |
345 | 346 |
346 GURL http_url1(test_server()->GetURL("files/title1.html")); | 347 GURL http_url1(test_server()->GetURL("files/title1.html")); |
347 GURL http_url2(test_server()->GetURL("files/title2.html")); | 348 GURL http_url2(test_server()->GetURL("files/title2.html")); |
348 int tab_count = browser()->tab_count(); | 349 int tab_count = browser()->tab_count(); |
349 | 350 |
350 // Add a tab | 351 // Add a tab |
351 ui_test_utils::NavigateToURLWithDisposition( | 352 ui_test_utils::NavigateToURLWithDisposition( |
352 browser(), http_url1, NEW_FOREGROUND_TAB, | 353 browser(), http_url1, NEW_FOREGROUND_TAB, |
353 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 354 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
354 EXPECT_EQ(++tab_count, browser()->tab_count()); | 355 EXPECT_EQ(++tab_count, browser()->tab_count()); |
355 | 356 |
356 // Navigate to another same-site URL. | 357 // Navigate to another same-site URL. |
357 content::WebContents* tab = browser()->GetWebContentsAt(tab_count - 1); | 358 content::WebContents* tab = |
| 359 chrome::GetWebContentsAt(browser(), tab_count - 1); |
358 ui_test_utils::WindowedNotificationObserver observer( | 360 ui_test_utils::WindowedNotificationObserver observer( |
359 content::NOTIFICATION_LOAD_STOP, | 361 content::NOTIFICATION_LOAD_STOP, |
360 content::NotificationService::AllSources()); | 362 content::NotificationService::AllSources()); |
361 static_cast<content::WebContentsDelegate*>(browser())->OpenURLFromTab( | 363 static_cast<content::WebContentsDelegate*>(browser())->OpenURLFromTab( |
362 tab, | 364 tab, |
363 content::OpenURLParams(http_url2, content::Referrer(), CURRENT_TAB, | 365 content::OpenURLParams(http_url2, content::Referrer(), CURRENT_TAB, |
364 content::PAGE_TRANSITION_TYPED, false)); | 366 content::PAGE_TRANSITION_TYPED, false)); |
365 observer.Wait(); | 367 observer.Wait(); |
366 | 368 |
367 // Close the tab. | 369 // Close the tab. |
368 CloseTab(1); | 370 CloseTab(1); |
369 | 371 |
370 // Create a new tab to the original site. Assuming process-per-site is | 372 // Create a new tab to the original site. Assuming process-per-site is |
371 // enabled, this will ensure that the SiteInstance used by the restored tab | 373 // enabled, this will ensure that the SiteInstance used by the restored tab |
372 // will already exist when the restore happens. | 374 // will already exist when the restore happens. |
373 ui_test_utils::NavigateToURLWithDisposition( | 375 ui_test_utils::NavigateToURLWithDisposition( |
374 browser(), http_url2, NEW_FOREGROUND_TAB, | 376 browser(), http_url2, NEW_FOREGROUND_TAB, |
375 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 377 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
376 | 378 |
377 // Restore the closed tab. | 379 // Restore the closed tab. |
378 ASSERT_NO_FATAL_FAILURE(RestoreTab(0, tab_count - 1)); | 380 ASSERT_NO_FATAL_FAILURE(RestoreTab(0, tab_count - 1)); |
379 | 381 |
380 // And make sure the URLs match. | 382 // And make sure the URLs match. |
381 EXPECT_EQ(http_url2, browser()->GetActiveWebContents()->GetURL()); | 383 EXPECT_EQ(http_url2, chrome::GetActiveWebContents(browser())->GetURL()); |
382 GoBack(browser()); | 384 GoBack(browser()); |
383 EXPECT_EQ(http_url1, browser()->GetActiveWebContents()->GetURL()); | 385 EXPECT_EQ(http_url1, chrome::GetActiveWebContents(browser())->GetURL()); |
384 } | 386 } |
385 | 387 |
386 // Tests that the SiteInstances used for entries in a restored tab's history | 388 // Tests that the SiteInstances used for entries in a restored tab's history |
387 // are given appropriate max page IDs, even if the renderer for the entry | 389 // are given appropriate max page IDs, even if the renderer for the entry |
388 // already exists. (Bug 1204135) | 390 // already exists. (Bug 1204135) |
389 IN_PROC_BROWSER_TEST_F(TabRestoreTest, | 391 IN_PROC_BROWSER_TEST_F(TabRestoreTest, |
390 RestoreCrossSiteWithExistingSiteInstance) { | 392 RestoreCrossSiteWithExistingSiteInstance) { |
391 ASSERT_TRUE(test_server()->Start()); | 393 ASSERT_TRUE(test_server()->Start()); |
392 | 394 |
393 GURL http_url1(test_server()->GetURL("files/title1.html")); | 395 GURL http_url1(test_server()->GetURL("files/title1.html")); |
(...skipping 25 matching lines...) Expand all Loading... |
419 // enabled, this will ensure that the SiteInstance will already exist when | 421 // enabled, this will ensure that the SiteInstance will already exist when |
420 // the user clicks Back in the restored tab. | 422 // the user clicks Back in the restored tab. |
421 ui_test_utils::NavigateToURLWithDisposition( | 423 ui_test_utils::NavigateToURLWithDisposition( |
422 browser(), http_url2, NEW_FOREGROUND_TAB, | 424 browser(), http_url2, NEW_FOREGROUND_TAB, |
423 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 425 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
424 | 426 |
425 // Restore the closed tab. | 427 // Restore the closed tab. |
426 ASSERT_NO_FATAL_FAILURE(RestoreTab(0, tab_count - 1)); | 428 ASSERT_NO_FATAL_FAILURE(RestoreTab(0, tab_count - 1)); |
427 | 429 |
428 // And make sure the URLs match. | 430 // And make sure the URLs match. |
429 EXPECT_EQ(url1_, browser()->GetActiveWebContents()->GetURL()); | 431 EXPECT_EQ(url1_, chrome::GetActiveWebContents(browser())->GetURL()); |
430 GoBack(browser()); | 432 GoBack(browser()); |
431 EXPECT_EQ(http_url1, browser()->GetActiveWebContents()->GetURL()); | 433 EXPECT_EQ(http_url1, chrome::GetActiveWebContents(browser())->GetURL()); |
432 | 434 |
433 // Navigating to a new URL should clear the forward list, because the max | 435 // Navigating to a new URL should clear the forward list, because the max |
434 // page ID of the renderer should have been updated when we restored the tab. | 436 // page ID of the renderer should have been updated when we restored the tab. |
435 ui_test_utils::NavigateToURLWithDisposition( | 437 ui_test_utils::NavigateToURLWithDisposition( |
436 browser(), http_url2, CURRENT_TAB, | 438 browser(), http_url2, CURRENT_TAB, |
437 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 439 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
438 EXPECT_FALSE(chrome::CanGoForward(browser())); | 440 EXPECT_FALSE(chrome::CanGoForward(browser())); |
439 EXPECT_EQ(http_url2, browser()->GetActiveWebContents()->GetURL()); | 441 EXPECT_EQ(http_url2, chrome::GetActiveWebContents(browser())->GetURL()); |
440 } | 442 } |
441 | 443 |
442 IN_PROC_BROWSER_TEST_F(TabRestoreTest, RestoreWindow) { | 444 IN_PROC_BROWSER_TEST_F(TabRestoreTest, RestoreWindow) { |
443 // Create a new window. | 445 // Create a new window. |
444 size_t window_count = BrowserList::size(); | 446 size_t window_count = BrowserList::size(); |
445 ui_test_utils::NavigateToURLWithDisposition( | 447 ui_test_utils::NavigateToURLWithDisposition( |
446 browser(), GURL(chrome::kChromeUINewTabURL), NEW_WINDOW, | 448 browser(), GURL(chrome::kChromeUINewTabURL), NEW_WINDOW, |
447 ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER); | 449 ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER); |
448 EXPECT_EQ(++window_count, BrowserList::size()); | 450 EXPECT_EQ(++window_count, BrowserList::size()); |
449 | 451 |
(...skipping 23 matching lines...) Expand all Loading... |
473 content::NotificationService::AllSources()); | 475 content::NotificationService::AllSources()); |
474 (*BrowserList::begin())->RestoreTab(); | 476 (*BrowserList::begin())->RestoreTab(); |
475 open_window_observer.Wait(); | 477 open_window_observer.Wait(); |
476 EXPECT_EQ(window_count, BrowserList::size()); | 478 EXPECT_EQ(window_count, BrowserList::size()); |
477 | 479 |
478 Browser* browser = GetBrowser(1); | 480 Browser* browser = GetBrowser(1); |
479 EXPECT_EQ(initial_tab_count + 2, browser->tab_count()); | 481 EXPECT_EQ(initial_tab_count + 2, browser->tab_count()); |
480 load_stop_observer.Wait(); | 482 load_stop_observer.Wait(); |
481 | 483 |
482 content::WebContents* restored_tab = | 484 content::WebContents* restored_tab = |
483 browser->GetWebContentsAt(initial_tab_count); | 485 chrome::GetWebContentsAt(browser, initial_tab_count); |
484 EnsureTabFinishedRestoring(restored_tab); | 486 EnsureTabFinishedRestoring(restored_tab); |
485 EXPECT_EQ(url1_, restored_tab->GetURL()); | 487 EXPECT_EQ(url1_, restored_tab->GetURL()); |
486 | 488 |
487 restored_tab = browser->GetWebContentsAt(initial_tab_count + 1); | 489 restored_tab = chrome::GetWebContentsAt(browser, initial_tab_count + 1); |
488 EnsureTabFinishedRestoring(restored_tab); | 490 EnsureTabFinishedRestoring(restored_tab); |
489 EXPECT_EQ(url2_, restored_tab->GetURL()); | 491 EXPECT_EQ(url2_, restored_tab->GetURL()); |
490 } | 492 } |
491 | 493 |
492 // Restore tab with special URL chrome://credits/ and make sure the page loads | 494 // Restore tab with special URL chrome://credits/ and make sure the page loads |
493 // properly after restore. See http://crbug.com/31905. | 495 // properly after restore. See http://crbug.com/31905. |
494 IN_PROC_BROWSER_TEST_F(TabRestoreTest, RestoreTabWithSpecialURL) { | 496 IN_PROC_BROWSER_TEST_F(TabRestoreTest, RestoreTabWithSpecialURL) { |
495 // Navigate new tab to a special URL. | 497 // Navigate new tab to a special URL. |
496 ui_test_utils::NavigateToURLWithDisposition( | 498 ui_test_utils::NavigateToURLWithDisposition( |
497 browser(), GURL(chrome::kChromeUICreditsURL), NEW_FOREGROUND_TAB, | 499 browser(), GURL(chrome::kChromeUICreditsURL), NEW_FOREGROUND_TAB, |
498 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 500 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
499 | 501 |
500 // Close the tab. | 502 // Close the tab. |
501 CloseTab(1); | 503 CloseTab(1); |
502 | 504 |
503 // Restore the closed tab. | 505 // Restore the closed tab. |
504 ASSERT_NO_FATAL_FAILURE(RestoreTab(0, 1)); | 506 ASSERT_NO_FATAL_FAILURE(RestoreTab(0, 1)); |
505 TabContents* tab = browser()->GetTabContentsAt(1); | 507 TabContents* tab = chrome::GetTabContentsAt(browser(), 1); |
506 EnsureTabFinishedRestoring(tab->web_contents()); | 508 EnsureTabFinishedRestoring(tab->web_contents()); |
507 | 509 |
508 // See if content is as expected. | 510 // See if content is as expected. |
509 EXPECT_GT( | 511 EXPECT_GT( |
510 ui_test_utils::FindInPage(tab, ASCIIToUTF16("webkit"), true, false, NULL), | 512 ui_test_utils::FindInPage(tab, ASCIIToUTF16("webkit"), true, false, NULL), |
511 0); | 513 0); |
512 } | 514 } |
513 | 515 |
514 // Restore tab with special URL in its navigation history, go back to that | 516 // Restore tab with special URL in its navigation history, go back to that |
515 // entry and see that it loads properly. See http://crbug.com/31905 | 517 // entry and see that it loads properly. See http://crbug.com/31905 |
516 IN_PROC_BROWSER_TEST_F(TabRestoreTest, RestoreTabWithSpecialURLOnBack) { | 518 IN_PROC_BROWSER_TEST_F(TabRestoreTest, RestoreTabWithSpecialURLOnBack) { |
517 ASSERT_TRUE(test_server()->Start()); | 519 ASSERT_TRUE(test_server()->Start()); |
518 | 520 |
519 const GURL http_url(test_server()->GetURL("files/title1.html")); | 521 const GURL http_url(test_server()->GetURL("files/title1.html")); |
520 | 522 |
521 // Navigate new tab to a special URL. | 523 // Navigate new tab to a special URL. |
522 ui_test_utils::NavigateToURLWithDisposition( | 524 ui_test_utils::NavigateToURLWithDisposition( |
523 browser(), GURL(chrome::kChromeUICreditsURL), NEW_FOREGROUND_TAB, | 525 browser(), GURL(chrome::kChromeUICreditsURL), NEW_FOREGROUND_TAB, |
524 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 526 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
525 | 527 |
526 // Then navigate to a normal URL. | 528 // Then navigate to a normal URL. |
527 ui_test_utils::NavigateToURL(browser(), http_url); | 529 ui_test_utils::NavigateToURL(browser(), http_url); |
528 | 530 |
529 // Close the tab. | 531 // Close the tab. |
530 CloseTab(1); | 532 CloseTab(1); |
531 | 533 |
532 // Restore the closed tab. | 534 // Restore the closed tab. |
533 ASSERT_NO_FATAL_FAILURE(RestoreTab(0, 1)); | 535 ASSERT_NO_FATAL_FAILURE(RestoreTab(0, 1)); |
534 TabContents* tab = browser()->GetTabContentsAt(1); | 536 TabContents* tab = chrome::GetTabContentsAt(browser(), 1); |
535 EnsureTabFinishedRestoring(tab->web_contents()); | 537 EnsureTabFinishedRestoring(tab->web_contents()); |
536 ASSERT_EQ(http_url, tab->web_contents()->GetURL()); | 538 ASSERT_EQ(http_url, tab->web_contents()->GetURL()); |
537 | 539 |
538 // Go back, and see if content is as expected. | 540 // Go back, and see if content is as expected. |
539 GoBack(browser()); | 541 GoBack(browser()); |
540 EXPECT_GT( | 542 EXPECT_GT( |
541 ui_test_utils::FindInPage(tab, ASCIIToUTF16("webkit"), true, false, NULL), | 543 ui_test_utils::FindInPage(tab, ASCIIToUTF16("webkit"), true, false, NULL), |
542 0); | 544 0); |
543 } | 545 } |
OLD | NEW |