| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 chrome::CloseWindow(browser()); | 434 chrome::CloseWindow(browser()); |
| 435 close_window_observer.Wait(); | 435 close_window_observer.Wait(); |
| 436 EXPECT_EQ(1u, active_browser_list_->size()); | 436 EXPECT_EQ(1u, active_browser_list_->size()); |
| 437 | 437 |
| 438 // Check that the TabRestoreService has the contents of the closed window. | 438 // Check that the TabRestoreService has the contents of the closed window. |
| 439 Browser* browser = GetBrowser(0); | 439 Browser* browser = GetBrowser(0); |
| 440 sessions::TabRestoreService* service = | 440 sessions::TabRestoreService* service = |
| 441 TabRestoreServiceFactory::GetForProfile(browser->profile()); | 441 TabRestoreServiceFactory::GetForProfile(browser->profile()); |
| 442 const sessions::TabRestoreService::Entries& entries = service->entries(); | 442 const sessions::TabRestoreService::Entries& entries = service->entries(); |
| 443 EXPECT_EQ(1u, entries.size()); | 443 EXPECT_EQ(1u, entries.size()); |
| 444 sessions::TabRestoreService::Entry* entry = entries.front(); | 444 sessions::TabRestoreService::Entry* entry = entries.front().get(); |
| 445 ASSERT_EQ(sessions::TabRestoreService::WINDOW, entry->type); | 445 ASSERT_EQ(sessions::TabRestoreService::WINDOW, entry->type); |
| 446 sessions::TabRestoreService::Window* entry_win = | 446 sessions::TabRestoreService::Window* entry_win = |
| 447 static_cast<sessions::TabRestoreService::Window*>(entry); | 447 static_cast<sessions::TabRestoreService::Window*>(entry); |
| 448 std::vector<sessions::TabRestoreService::Tab>& tabs = entry_win->tabs; | 448 auto& tabs = entry_win->tabs; |
| 449 EXPECT_EQ(3u, tabs.size()); | 449 EXPECT_EQ(3u, tabs.size()); |
| 450 | 450 |
| 451 // Find the Tab to restore. | 451 // Find the Tab to restore. |
| 452 sessions::TabRestoreService::Tab tab_to_restore; | 452 SessionID::id_type tab_id_to_restore = 0; |
| 453 bool found_tab_to_restore = false; | 453 bool found_tab_to_restore = false; |
| 454 for (const auto& tab : tabs) { | 454 for (const auto& tab_ptr : tabs) { |
| 455 auto& tab = *tab_ptr; |
| 455 if (tab.navigations[tab.current_navigation_index].virtual_url() == url1_) { | 456 if (tab.navigations[tab.current_navigation_index].virtual_url() == url1_) { |
| 456 tab_to_restore = tab; | 457 tab_id_to_restore = tab.id; |
| 457 found_tab_to_restore = true; | 458 found_tab_to_restore = true; |
| 458 break; | 459 break; |
| 459 } | 460 } |
| 460 } | 461 } |
| 461 ASSERT_TRUE(found_tab_to_restore); | 462 ASSERT_TRUE(found_tab_to_restore); |
| 462 | 463 |
| 463 // Restore the tab into the current window. | 464 // Restore the tab into the current window. |
| 464 EXPECT_EQ(1, browser->tab_strip_model()->count()); | 465 EXPECT_EQ(1, browser->tab_strip_model()->count()); |
| 465 content::WindowedNotificationObserver tab_added_observer( | 466 content::WindowedNotificationObserver tab_added_observer( |
| 466 chrome::NOTIFICATION_TAB_PARENTED, | 467 chrome::NOTIFICATION_TAB_PARENTED, |
| 467 content::NotificationService::AllSources()); | 468 content::NotificationService::AllSources()); |
| 468 content::WindowedNotificationObserver tab_loaded_observer( | 469 content::WindowedNotificationObserver tab_loaded_observer( |
| 469 content::NOTIFICATION_LOAD_STOP, | 470 content::NOTIFICATION_LOAD_STOP, |
| 470 content::NotificationService::AllSources()); | 471 content::NotificationService::AllSources()); |
| 471 service->RestoreEntryById(browser->live_tab_context(), tab_to_restore.id, | 472 service->RestoreEntryById(browser->live_tab_context(), tab_id_to_restore, |
| 472 NEW_FOREGROUND_TAB); | 473 NEW_FOREGROUND_TAB); |
| 473 tab_added_observer.Wait(); | 474 tab_added_observer.Wait(); |
| 474 tab_loaded_observer.Wait(); | 475 tab_loaded_observer.Wait(); |
| 475 | 476 |
| 476 // Check that the tab was correctly restored. | 477 // Check that the tab was correctly restored. |
| 477 EXPECT_EQ(2, browser->tab_strip_model()->count()); | 478 EXPECT_EQ(2, browser->tab_strip_model()->count()); |
| 478 EXPECT_EQ(url1_, | 479 EXPECT_EQ(url1_, |
| 479 browser->tab_strip_model()->GetActiveWebContents()->GetURL()); | 480 browser->tab_strip_model()->GetActiveWebContents()->GetURL()); |
| 480 } | 481 } |
| 481 | 482 |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 700 while (browser()->tab_strip_model()->count()) | 701 while (browser()->tab_strip_model()->count()) |
| 701 CloseTab(0); | 702 CloseTab(0); |
| 702 } | 703 } |
| 703 | 704 |
| 704 // Verifies restoring a tab works on startup. | 705 // Verifies restoring a tab works on startup. |
| 705 IN_PROC_BROWSER_TEST_F(TabRestoreTest, RestoreOnStartup) { | 706 IN_PROC_BROWSER_TEST_F(TabRestoreTest, RestoreOnStartup) { |
| 706 ASSERT_NO_FATAL_FAILURE(RestoreTab(0, 1)); | 707 ASSERT_NO_FATAL_FAILURE(RestoreTab(0, 1)); |
| 707 EXPECT_EQ(url1_, | 708 EXPECT_EQ(url1_, |
| 708 browser()->tab_strip_model()->GetWebContentsAt(1)->GetURL()); | 709 browser()->tab_strip_model()->GetWebContentsAt(1)->GetURL()); |
| 709 } | 710 } |
| OLD | NEW |