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

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: Remove NOTREACHED(). Created 3 years, 4 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() const { return tab_id_; }
82 SessionID window_id() const { 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 service_.reset(); 133 service_.reset();
131 service_.reset(new sessions::PersistentTabRestoreService( 134 service_.reset(new sessions::PersistentTabRestoreService(
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) {
143 // Create new window / tab IDs so that these remain distinct.
144 window_id_ = SessionID();
145 tab_id_ = SessionID();
146
140 SessionService* session_service = 147 SessionService* session_service =
141 SessionServiceFactory::GetForProfile(profile()); 148 SessionServiceFactory::GetForProfile(profile());
142 SessionID tab_id; 149 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); 150 SessionService::TYPE_NORMAL);
147 session_service->SetTabWindow(window_id, tab_id); 151 session_service->SetTabWindow(window_id(), tab_id());
148 session_service->SetTabIndexInWindow(window_id, tab_id, 0); 152 session_service->SetTabIndexInWindow(window_id(), tab_id(), 0);
149 session_service->SetSelectedTabInWindow(window_id, 0); 153 session_service->SetSelectedTabInWindow(window_id(), 0);
150 if (pinned) 154 if (pinned)
151 session_service->SetPinnedState(window_id, tab_id, true); 155 session_service->SetPinnedState(window_id(), tab_id(), true);
152 session_service->UpdateTabNavigation( 156 session_service->UpdateTabNavigation(
153 window_id, tab_id, 157 window_id(), tab_id(),
154 SerializedNavigationEntryTestHelper::CreateNavigation( 158 SerializedNavigationEntryTestHelper::CreateNavigation(url1_.spec(),
155 url1_.spec(), "title")); 159 "title"));
156 } 160 }
157 161
158 // Creates a SessionService and assigns it to the Profile. The SessionService 162 // 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 163 // is configured with a single window with a single tab pointing at url1_ by
160 // way of AddWindowWithOneTabToSessionService. If |pinned| is true, the 164 // way of AddWindowWithOneTabToSessionService. If |pinned| is true, the
161 // tab is marked as pinned in the session service. 165 // tab is marked as pinned in the session service.
162 void CreateSessionServiceWithOneWindow(bool pinned) { 166 void CreateSessionServiceWithOneWindow(bool pinned) {
163 std::unique_ptr<SessionService> session_service( 167 std::unique_ptr<SessionService> session_service(
164 new SessionService(profile())); 168 new SessionService(profile()));
165 SessionServiceFactory::SetForTestProfile(profile(), 169 SessionServiceFactory::SetForTestProfile(profile(),
(...skipping 13 matching lines...) Expand all
179 183
180 sessions::LiveTab* live_tab() { return live_tab_.get(); } 184 sessions::LiveTab* live_tab() { return live_tab_.get(); }
181 185
182 GURL url1_; 186 GURL url1_;
183 GURL url2_; 187 GURL url2_;
184 GURL url3_; 188 GURL url3_;
185 std::string user_agent_override_; 189 std::string user_agent_override_;
186 std::unique_ptr<sessions::LiveTab> live_tab_; 190 std::unique_ptr<sessions::LiveTab> live_tab_;
187 std::unique_ptr<sessions::PersistentTabRestoreService> service_; 191 std::unique_ptr<sessions::PersistentTabRestoreService> service_;
188 PersistentTabRestoreTimeFactory* time_factory_; 192 PersistentTabRestoreTimeFactory* time_factory_;
193 SessionID window_id_;
194 SessionID tab_id_;
189 }; 195 };
190 196
191 namespace { 197 namespace {
192 198
193 class TestTabRestoreServiceObserver 199 class TestTabRestoreServiceObserver
194 : public sessions::TabRestoreServiceObserver { 200 : public sessions::TabRestoreServiceObserver {
195 public: 201 public:
196 TestTabRestoreServiceObserver() : got_loaded_(false) {} 202 TestTabRestoreServiceObserver() : got_loaded_(false) {}
197 203
198 void clear_got_loaded() { got_loaded_ = false; } 204 void clear_got_loaded() { got_loaded_ = false; }
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 ASSERT_FALSE(tab->pinned); 487 ASSERT_FALSE(tab->pinned);
482 ASSERT_EQ(3U, tab->navigations.size()); 488 ASSERT_EQ(3U, tab->navigations.size());
483 EXPECT_EQ(2, tab->current_navigation_index); 489 EXPECT_EQ(2, tab->current_navigation_index);
484 EXPECT_EQ(time_factory_->TimeNow().ToInternalValue(), 490 EXPECT_EQ(time_factory_->TimeNow().ToInternalValue(),
485 tab->timestamp.ToInternalValue()); 491 tab->timestamp.ToInternalValue());
486 EXPECT_TRUE(url1_ == tab->navigations[0].virtual_url()); 492 EXPECT_TRUE(url1_ == tab->navigations[0].virtual_url());
487 EXPECT_TRUE(url2_ == tab->navigations[1].virtual_url()); 493 EXPECT_TRUE(url2_ == tab->navigations[1].virtual_url());
488 EXPECT_TRUE(url3_ == tab->navigations[2].virtual_url()); 494 EXPECT_TRUE(url3_ == tab->navigations[2].virtual_url());
489 } 495 }
490 496
497 // Make sure window bounds and workspace are properly loaded from the session
498 // service.
499 TEST_F(PersistentTabRestoreServiceTest, LoadWindowBoundsAndWorkspace) {
500 constexpr gfx::Rect kBounds(10, 20, 640, 480);
501 constexpr ui::WindowShowState kShowState = ui::SHOW_STATE_MINIMIZED;
502 constexpr char kWorkspace[] = "workspace";
503
504 CreateSessionServiceWithOneWindow(false);
505
506 // Set the bounds, show state and workspace.
507 SessionService* session_service =
508 SessionServiceFactory::GetForProfile(profile());
509 session_service->SetWindowBounds(window_id(), kBounds, kShowState);
510 session_service->SetWindowWorkspace(window_id(), kWorkspace);
511
512 session_service->MoveCurrentSessionToLastSession();
513
514 AddThreeNavigations();
515
516 service_->CreateHistoricalTab(live_tab(), -1);
517
518 RecreateService();
519
520 // We should get back two entries, one from the previous session and one from
521 // the tab restore service. The previous session entry should be first.
522 ASSERT_EQ(2U, service_->entries().size());
523
524 // The first entry should come from the session service.
525 sessions::TabRestoreService::Entry* entry = service_->entries().front().get();
526 ASSERT_EQ(sessions::TabRestoreService::WINDOW, entry->type);
527 sessions::TabRestoreService::Window* window =
528 static_cast<sessions::TabRestoreService::Window*>(entry);
529 ASSERT_EQ(kBounds, window->bounds);
530 ASSERT_EQ(kShowState, window->show_state);
531 ASSERT_EQ(kWorkspace, window->workspace);
532 ASSERT_EQ(1U, window->tabs.size());
533 EXPECT_EQ(0, window->selected_tab_index);
534 EXPECT_FALSE(window->tabs[0]->pinned);
535 ASSERT_EQ(1U, window->tabs[0]->navigations.size());
536 EXPECT_EQ(0, window->tabs[0]->current_navigation_index);
537 EXPECT_TRUE(url1_ == window->tabs[0]->navigations[0].virtual_url());
538
539 // Then the closed tab.
540 entry = (++service_->entries().begin())->get();
541 ASSERT_EQ(sessions::TabRestoreService::TAB, entry->type);
542 Tab* tab = static_cast<Tab*>(entry);
543 ASSERT_FALSE(tab->pinned);
544 ASSERT_EQ(3U, tab->navigations.size());
545 EXPECT_EQ(2, tab->current_navigation_index);
546 EXPECT_TRUE(url1_ == tab->navigations[0].virtual_url());
547 EXPECT_TRUE(url2_ == tab->navigations[1].virtual_url());
548 EXPECT_TRUE(url3_ == tab->navigations[2].virtual_url());
549 }
550
491 // Make sure pinned state is correctly loaded from session service. 551 // Make sure pinned state is correctly loaded from session service.
492 TEST_F(PersistentTabRestoreServiceTest, LoadPreviousSessionAndTabsPinned) { 552 TEST_F(PersistentTabRestoreServiceTest, LoadPreviousSessionAndTabsPinned) {
493 CreateSessionServiceWithOneWindow(true); 553 CreateSessionServiceWithOneWindow(true);
494 554
495 SessionServiceFactory::GetForProfile(profile())-> 555 SessionServiceFactory::GetForProfile(profile())->
496 MoveCurrentSessionToLastSession(); 556 MoveCurrentSessionToLastSession();
497 557
498 AddThreeNavigations(); 558 AddThreeNavigations();
499 559
500 service_->CreateHistoricalTab(live_tab(), -1); 560 service_->CreateHistoricalTab(live_tab(), -1);
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 844
785 EXPECT_FALSE(service_->IsLoaded()); 845 EXPECT_FALSE(service_->IsLoaded());
786 TestTabRestoreServiceObserver observer; 846 TestTabRestoreServiceObserver observer;
787 service_->AddObserver(&observer); 847 service_->AddObserver(&observer);
788 EXPECT_EQ(max_entries, service_->entries().size()); 848 EXPECT_EQ(max_entries, service_->entries().size());
789 SynchronousLoadTabsFromLastSession(); 849 SynchronousLoadTabsFromLastSession();
790 EXPECT_TRUE(observer.got_loaded()); 850 EXPECT_TRUE(observer.got_loaded());
791 EXPECT_TRUE(service_->IsLoaded()); 851 EXPECT_TRUE(service_->IsLoaded());
792 service_->RemoveObserver(&observer); 852 service_->RemoveObserver(&observer);
793 } 853 }
OLDNEW
« no previous file with comments | « chrome/browser/sessions/chrome_tab_restore_service_client.cc ('k') | chrome/browser/sessions/tab_restore_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698