Chromium Code Reviews| Index: chrome/browser/sessions/persistent_tab_restore_service_unittest.cc |
| diff --git a/chrome/browser/sessions/persistent_tab_restore_service_unittest.cc b/chrome/browser/sessions/persistent_tab_restore_service_unittest.cc |
| index 215cd32b3235cdd5cfd7b8d9cb760ec1e441a74b..ea8b3e83c48de447ed948662884cc090b2ecb5fe 100644 |
| --- a/chrome/browser/sessions/persistent_tab_restore_service_unittest.cc |
| +++ b/chrome/browser/sessions/persistent_tab_restore_service_unittest.cc |
| @@ -78,6 +78,9 @@ class PersistentTabRestoreServiceTest : public ChromeRenderViewHostTestHarness { |
| ~PersistentTabRestoreServiceTest() override {} |
| + SessionID tab_id() { return tab_id_; } |
|
sky
2017/06/28 22:38:00
const on both these. That is:
SessionID tab_id() c
chrisha
2017/06/30 15:42:12
Done.
|
| + SessionID window_id() { return window_id_; } |
| + |
| protected: |
| enum { |
| kMaxEntries = sessions::TabRestoreServiceHelper::kMaxEntries, |
| @@ -139,20 +142,17 @@ class PersistentTabRestoreServiceTest : public ChromeRenderViewHostTestHarness { |
| void AddWindowWithOneTabToSessionService(bool pinned) { |
| SessionService* session_service = |
| SessionServiceFactory::GetForProfile(profile()); |
| - SessionID tab_id; |
| - SessionID window_id; |
| - session_service->SetWindowType(window_id, |
| - Browser::TYPE_TABBED, |
| + session_service->SetWindowType(window_id(), Browser::TYPE_TABBED, |
| SessionService::TYPE_NORMAL); |
| - session_service->SetTabWindow(window_id, tab_id); |
| - session_service->SetTabIndexInWindow(window_id, tab_id, 0); |
| - session_service->SetSelectedTabInWindow(window_id, 0); |
| + session_service->SetTabWindow(window_id(), tab_id()); |
| + session_service->SetTabIndexInWindow(window_id(), tab_id(), 0); |
| + session_service->SetSelectedTabInWindow(window_id(), 0); |
| if (pinned) |
| - session_service->SetPinnedState(window_id, tab_id, true); |
| + session_service->SetPinnedState(window_id(), tab_id(), true); |
| session_service->UpdateTabNavigation( |
| - window_id, tab_id, |
| - SerializedNavigationEntryTestHelper::CreateNavigation( |
| - url1_.spec(), "title")); |
| + window_id(), tab_id(), |
| + SerializedNavigationEntryTestHelper::CreateNavigation(url1_.spec(), |
| + "title")); |
| } |
| // Creates a SessionService and assigns it to the Profile. The SessionService |
| @@ -186,6 +186,8 @@ class PersistentTabRestoreServiceTest : public ChromeRenderViewHostTestHarness { |
| std::unique_ptr<sessions::LiveTab> live_tab_; |
| std::unique_ptr<sessions::PersistentTabRestoreService> service_; |
| PersistentTabRestoreTimeFactory* time_factory_; |
| + SessionID window_id_; |
| + SessionID tab_id_; |
| }; |
| namespace { |
| @@ -488,6 +490,60 @@ TEST_F(PersistentTabRestoreServiceTest, LoadPreviousSessionAndTabs) { |
| EXPECT_TRUE(url3_ == tab->navigations[2].virtual_url()); |
| } |
| +// Make sure window bounds and workspace are properly loaded from the session |
| +// service. |
| +TEST_F(PersistentTabRestoreServiceTest, LoadWindowBoundsAndWorkspace) { |
| + static constexpr gfx::Rect kBounds(10, 20, 640, 480); |
|
sky
2017/06/28 22:38:00
Remove static from these.
chrisha
2017/06/30 15:42:12
Done.
|
| + static constexpr ui::WindowShowState kShowState = ui::SHOW_STATE_MINIMIZED; |
| + static constexpr char kWorkspace[] = "workspace"; |
| + |
| + CreateSessionServiceWithOneWindow(false); |
| + |
| + // Set the bounds, show state and workspace. |
| + SessionService* session_service = |
| + SessionServiceFactory::GetForProfile(profile()); |
| + session_service->SetWindowBounds(window_id(), kBounds, kShowState); |
| + session_service->SetWindowWorkspace(window_id(), kWorkspace); |
| + |
| + session_service->MoveCurrentSessionToLastSession(); |
| + |
| + AddThreeNavigations(); |
| + |
| + service_->CreateHistoricalTab(live_tab(), -1); |
| + |
| + RecreateService(); |
| + |
| + // We should get back two entries, one from the previous session and one from |
| + // the tab restore service. The previous session entry should be first. |
| + ASSERT_EQ(2U, service_->entries().size()); |
| + |
| + // The first entry should come from the session service. |
| + sessions::TabRestoreService::Entry* entry = service_->entries().front().get(); |
| + ASSERT_EQ(sessions::TabRestoreService::WINDOW, entry->type); |
| + sessions::TabRestoreService::Window* window = |
| + static_cast<sessions::TabRestoreService::Window*>(entry); |
| + ASSERT_EQ(kBounds, window->bounds); |
| + ASSERT_EQ(kShowState, window->show_state); |
| + ASSERT_EQ(kWorkspace, window->workspace); |
| + ASSERT_EQ(1U, window->tabs.size()); |
| + EXPECT_EQ(0, window->selected_tab_index); |
| + EXPECT_FALSE(window->tabs[0]->pinned); |
| + ASSERT_EQ(1U, window->tabs[0]->navigations.size()); |
| + EXPECT_EQ(0, window->tabs[0]->current_navigation_index); |
| + EXPECT_TRUE(url1_ == window->tabs[0]->navigations[0].virtual_url()); |
| + |
| + // Then the closed tab. |
| + entry = (++service_->entries().begin())->get(); |
| + ASSERT_EQ(sessions::TabRestoreService::TAB, entry->type); |
| + Tab* tab = static_cast<Tab*>(entry); |
| + ASSERT_FALSE(tab->pinned); |
| + ASSERT_EQ(3U, tab->navigations.size()); |
| + EXPECT_EQ(2, tab->current_navigation_index); |
| + EXPECT_TRUE(url1_ == tab->navigations[0].virtual_url()); |
| + EXPECT_TRUE(url2_ == tab->navigations[1].virtual_url()); |
| + EXPECT_TRUE(url3_ == tab->navigations[2].virtual_url()); |
| +} |
| + |
| // Make sure pinned state is correctly loaded from session service. |
| TEST_F(PersistentTabRestoreServiceTest, LoadPreviousSessionAndTabsPinned) { |
| CreateSessionServiceWithOneWindow(true); |