Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(253)

Side by Side Diff: chrome/browser/sessions/persistent_tab_restore_service_unittest.cc

Issue 2868983003: Ensure History > Recent Tabs restore preserves window disposition. (Closed)
Patch Set: Minor cleanup. Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "components/sessions/core/persistent_tab_restore_service.h" 5 #include "components/sessions/core/persistent_tab_restore_service.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 url2_("http://2"), 71 url2_("http://2"),
72 url3_("http://3"), 72 url3_("http://3"),
73 user_agent_override_( 73 user_agent_override_(
74 "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.19" 74 "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.19"
75 " (KHTML, like Gecko) Chrome/18.0.1025.45 Safari/535.19"), 75 " (KHTML, like Gecko) Chrome/18.0.1025.45 Safari/535.19"),
76 time_factory_(NULL) { 76 time_factory_(NULL) {
77 } 77 }
78 78
79 ~PersistentTabRestoreServiceTest() override {} 79 ~PersistentTabRestoreServiceTest() override {}
80 80
81 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.
82 SessionID window_id() { return window_id_; }
83
81 protected: 84 protected:
82 enum { 85 enum {
83 kMaxEntries = sessions::TabRestoreServiceHelper::kMaxEntries, 86 kMaxEntries = sessions::TabRestoreServiceHelper::kMaxEntries,
84 }; 87 };
85 88
86 // testing::Test: 89 // testing::Test:
87 void SetUp() override { 90 void SetUp() override {
88 ChromeRenderViewHostTestHarness::SetUp(); 91 ChromeRenderViewHostTestHarness::SetUp();
89 live_tab_ = base::WrapUnique(new sessions::ContentLiveTab(web_contents())); 92 live_tab_ = base::WrapUnique(new sessions::ContentLiveTab(web_contents()));
90 time_factory_ = new PersistentTabRestoreTimeFactory(); 93 time_factory_ = new PersistentTabRestoreTimeFactory();
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 base::MakeUnique<ChromeTabRestoreServiceClient>(profile()), 135 base::MakeUnique<ChromeTabRestoreServiceClient>(profile()),
133 time_factory_)); 136 time_factory_));
134 SynchronousLoadTabsFromLastSession(); 137 SynchronousLoadTabsFromLastSession();
135 } 138 }
136 139
137 // Adds a window with one tab and url to the profile's session service. 140 // Adds a window with one tab and url to the profile's session service.
138 // If |pinned| is true, the tab is marked as pinned in the session service. 141 // If |pinned| is true, the tab is marked as pinned in the session service.
139 void AddWindowWithOneTabToSessionService(bool pinned) { 142 void AddWindowWithOneTabToSessionService(bool pinned) {
140 SessionService* session_service = 143 SessionService* session_service =
141 SessionServiceFactory::GetForProfile(profile()); 144 SessionServiceFactory::GetForProfile(profile());
142 SessionID tab_id; 145 session_service->SetWindowType(window_id(), Browser::TYPE_TABBED,
143 SessionID window_id;
144 session_service->SetWindowType(window_id,
145 Browser::TYPE_TABBED,
146 SessionService::TYPE_NORMAL); 146 SessionService::TYPE_NORMAL);
147 session_service->SetTabWindow(window_id, tab_id); 147 session_service->SetTabWindow(window_id(), tab_id());
148 session_service->SetTabIndexInWindow(window_id, tab_id, 0); 148 session_service->SetTabIndexInWindow(window_id(), tab_id(), 0);
149 session_service->SetSelectedTabInWindow(window_id, 0); 149 session_service->SetSelectedTabInWindow(window_id(), 0);
150 if (pinned) 150 if (pinned)
151 session_service->SetPinnedState(window_id, tab_id, true); 151 session_service->SetPinnedState(window_id(), tab_id(), true);
152 session_service->UpdateTabNavigation( 152 session_service->UpdateTabNavigation(
153 window_id, tab_id, 153 window_id(), tab_id(),
154 SerializedNavigationEntryTestHelper::CreateNavigation( 154 SerializedNavigationEntryTestHelper::CreateNavigation(url1_.spec(),
155 url1_.spec(), "title")); 155 "title"));
156 } 156 }
157 157
158 // Creates a SessionService and assigns it to the Profile. The SessionService 158 // Creates a SessionService and assigns it to the Profile. The SessionService
159 // is configured with a single window with a single tab pointing at url1_ by 159 // is configured with a single window with a single tab pointing at url1_ by
160 // way of AddWindowWithOneTabToSessionService. If |pinned| is true, the 160 // way of AddWindowWithOneTabToSessionService. If |pinned| is true, the
161 // tab is marked as pinned in the session service. 161 // tab is marked as pinned in the session service.
162 void CreateSessionServiceWithOneWindow(bool pinned) { 162 void CreateSessionServiceWithOneWindow(bool pinned) {
163 std::unique_ptr<SessionService> session_service( 163 std::unique_ptr<SessionService> session_service(
164 new SessionService(profile())); 164 new SessionService(profile()));
165 SessionServiceFactory::SetForTestProfile(profile(), 165 SessionServiceFactory::SetForTestProfile(profile(),
(...skipping 13 matching lines...) Expand all
179 179
180 sessions::LiveTab* live_tab() { return live_tab_.get(); } 180 sessions::LiveTab* live_tab() { return live_tab_.get(); }
181 181
182 GURL url1_; 182 GURL url1_;
183 GURL url2_; 183 GURL url2_;
184 GURL url3_; 184 GURL url3_;
185 std::string user_agent_override_; 185 std::string user_agent_override_;
186 std::unique_ptr<sessions::LiveTab> live_tab_; 186 std::unique_ptr<sessions::LiveTab> live_tab_;
187 std::unique_ptr<sessions::PersistentTabRestoreService> service_; 187 std::unique_ptr<sessions::PersistentTabRestoreService> service_;
188 PersistentTabRestoreTimeFactory* time_factory_; 188 PersistentTabRestoreTimeFactory* time_factory_;
189 SessionID window_id_;
190 SessionID tab_id_;
189 }; 191 };
190 192
191 namespace { 193 namespace {
192 194
193 class TestTabRestoreServiceObserver 195 class TestTabRestoreServiceObserver
194 : public sessions::TabRestoreServiceObserver { 196 : public sessions::TabRestoreServiceObserver {
195 public: 197 public:
196 TestTabRestoreServiceObserver() : got_loaded_(false) {} 198 TestTabRestoreServiceObserver() : got_loaded_(false) {}
197 199
198 void clear_got_loaded() { got_loaded_ = false; } 200 void clear_got_loaded() { got_loaded_ = false; }
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 ASSERT_FALSE(tab->pinned); 483 ASSERT_FALSE(tab->pinned);
482 ASSERT_EQ(3U, tab->navigations.size()); 484 ASSERT_EQ(3U, tab->navigations.size());
483 EXPECT_EQ(2, tab->current_navigation_index); 485 EXPECT_EQ(2, tab->current_navigation_index);
484 EXPECT_EQ(time_factory_->TimeNow().ToInternalValue(), 486 EXPECT_EQ(time_factory_->TimeNow().ToInternalValue(),
485 tab->timestamp.ToInternalValue()); 487 tab->timestamp.ToInternalValue());
486 EXPECT_TRUE(url1_ == tab->navigations[0].virtual_url()); 488 EXPECT_TRUE(url1_ == tab->navigations[0].virtual_url());
487 EXPECT_TRUE(url2_ == tab->navigations[1].virtual_url()); 489 EXPECT_TRUE(url2_ == tab->navigations[1].virtual_url());
488 EXPECT_TRUE(url3_ == tab->navigations[2].virtual_url()); 490 EXPECT_TRUE(url3_ == tab->navigations[2].virtual_url());
489 } 491 }
490 492
493 // Make sure window bounds and workspace are properly loaded from the session
494 // service.
495 TEST_F(PersistentTabRestoreServiceTest, LoadWindowBoundsAndWorkspace) {
496 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.
497 static constexpr ui::WindowShowState kShowState = ui::SHOW_STATE_MINIMIZED;
498 static constexpr char kWorkspace[] = "workspace";
499
500 CreateSessionServiceWithOneWindow(false);
501
502 // Set the bounds, show state and workspace.
503 SessionService* session_service =
504 SessionServiceFactory::GetForProfile(profile());
505 session_service->SetWindowBounds(window_id(), kBounds, kShowState);
506 session_service->SetWindowWorkspace(window_id(), kWorkspace);
507
508 session_service->MoveCurrentSessionToLastSession();
509
510 AddThreeNavigations();
511
512 service_->CreateHistoricalTab(live_tab(), -1);
513
514 RecreateService();
515
516 // We should get back two entries, one from the previous session and one from
517 // the tab restore service. The previous session entry should be first.
518 ASSERT_EQ(2U, service_->entries().size());
519
520 // The first entry should come from the session service.
521 sessions::TabRestoreService::Entry* entry = service_->entries().front().get();
522 ASSERT_EQ(sessions::TabRestoreService::WINDOW, entry->type);
523 sessions::TabRestoreService::Window* window =
524 static_cast<sessions::TabRestoreService::Window*>(entry);
525 ASSERT_EQ(kBounds, window->bounds);
526 ASSERT_EQ(kShowState, window->show_state);
527 ASSERT_EQ(kWorkspace, window->workspace);
528 ASSERT_EQ(1U, window->tabs.size());
529 EXPECT_EQ(0, window->selected_tab_index);
530 EXPECT_FALSE(window->tabs[0]->pinned);
531 ASSERT_EQ(1U, window->tabs[0]->navigations.size());
532 EXPECT_EQ(0, window->tabs[0]->current_navigation_index);
533 EXPECT_TRUE(url1_ == window->tabs[0]->navigations[0].virtual_url());
534
535 // Then the closed tab.
536 entry = (++service_->entries().begin())->get();
537 ASSERT_EQ(sessions::TabRestoreService::TAB, entry->type);
538 Tab* tab = static_cast<Tab*>(entry);
539 ASSERT_FALSE(tab->pinned);
540 ASSERT_EQ(3U, tab->navigations.size());
541 EXPECT_EQ(2, tab->current_navigation_index);
542 EXPECT_TRUE(url1_ == tab->navigations[0].virtual_url());
543 EXPECT_TRUE(url2_ == tab->navigations[1].virtual_url());
544 EXPECT_TRUE(url3_ == tab->navigations[2].virtual_url());
545 }
546
491 // Make sure pinned state is correctly loaded from session service. 547 // Make sure pinned state is correctly loaded from session service.
492 TEST_F(PersistentTabRestoreServiceTest, LoadPreviousSessionAndTabsPinned) { 548 TEST_F(PersistentTabRestoreServiceTest, LoadPreviousSessionAndTabsPinned) {
493 CreateSessionServiceWithOneWindow(true); 549 CreateSessionServiceWithOneWindow(true);
494 550
495 SessionServiceFactory::GetForProfile(profile())-> 551 SessionServiceFactory::GetForProfile(profile())->
496 MoveCurrentSessionToLastSession(); 552 MoveCurrentSessionToLastSession();
497 553
498 AddThreeNavigations(); 554 AddThreeNavigations();
499 555
500 service_->CreateHistoricalTab(live_tab(), -1); 556 service_->CreateHistoricalTab(live_tab(), -1);
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 840
785 EXPECT_FALSE(service_->IsLoaded()); 841 EXPECT_FALSE(service_->IsLoaded());
786 TestTabRestoreServiceObserver observer; 842 TestTabRestoreServiceObserver observer;
787 service_->AddObserver(&observer); 843 service_->AddObserver(&observer);
788 EXPECT_EQ(max_entries, service_->entries().size()); 844 EXPECT_EQ(max_entries, service_->entries().size());
789 SynchronousLoadTabsFromLastSession(); 845 SynchronousLoadTabsFromLastSession();
790 EXPECT_TRUE(observer.got_loaded()); 846 EXPECT_TRUE(observer.got_loaded());
791 EXPECT_TRUE(service_->IsLoaded()); 847 EXPECT_TRUE(service_->IsLoaded());
792 service_->RemoveObserver(&observer); 848 service_->RemoveObserver(&observer);
793 } 849 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698