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

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

Issue 1321713005: Abstract WebContents/NavigationController from core TabRestore code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Response to review Created 5 years, 3 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 "chrome/browser/sessions/persistent_tab_restore_service.h" 5 #include "chrome/browser/sessions/persistent_tab_restore_service.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "base/threading/sequenced_worker_pool.h" 13 #include "base/threading/sequenced_worker_pool.h"
14 #include "chrome/browser/chrome_notification_types.h" 14 #include "chrome/browser/chrome_notification_types.h"
15 #include "chrome/browser/sessions/chrome_tab_restore_service_client.h" 15 #include "chrome/browser/sessions/chrome_tab_restore_service_client.h"
16 #include "chrome/browser/sessions/session_service.h" 16 #include "chrome/browser/sessions/session_service.h"
17 #include "chrome/browser/sessions/session_service_factory.h" 17 #include "chrome/browser/sessions/session_service_factory.h"
18 #include "chrome/browser/sessions/session_service_utils.h" 18 #include "chrome/browser/sessions/session_service_utils.h"
19 #include "chrome/browser/sessions/tab_restore_service_factory.h" 19 #include "chrome/browser/sessions/tab_restore_service_factory.h"
20 #include "chrome/browser/sessions/tab_restore_service_observer.h" 20 #include "chrome/browser/sessions/tab_restore_service_observer.h"
21 #include "chrome/common/url_constants.h" 21 #include "chrome/common/url_constants.h"
22 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 22 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
23 #include "chrome/test/base/chrome_render_view_test.h" 23 #include "chrome/test/base/chrome_render_view_test.h"
24 #include "chrome/test/base/testing_profile.h" 24 #include "chrome/test/base/testing_profile.h"
25 #include "components/sessions/content/content_live_tab.h"
25 #include "components/sessions/serialized_navigation_entry_test_helper.h" 26 #include "components/sessions/serialized_navigation_entry_test_helper.h"
26 #include "components/sessions/session_types.h" 27 #include "components/sessions/session_types.h"
27 #include "content/public/browser/browser_thread.h" 28 #include "content/public/browser/browser_thread.h"
28 #include "content/public/browser/navigation_controller.h" 29 #include "content/public/browser/navigation_controller.h"
29 #include "content/public/browser/navigation_entry.h" 30 #include "content/public/browser/navigation_entry.h"
30 #include "content/public/browser/notification_service.h" 31 #include "content/public/browser/notification_service.h"
31 #include "content/public/browser/notification_types.h" 32 #include "content/public/browser/notification_types.h"
32 #include "content/public/browser/web_contents.h" 33 #include "content/public/browser/web_contents.h"
33 #include "content/public/test/render_view_test.h" 34 #include "content/public/test/render_view_test.h"
34 #include "content/public/test/test_utils.h" 35 #include "content/public/test/test_utils.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 ~PersistentTabRestoreServiceTest() override {} 73 ~PersistentTabRestoreServiceTest() override {}
73 74
74 protected: 75 protected:
75 enum { 76 enum {
76 kMaxEntries = TabRestoreServiceHelper::kMaxEntries, 77 kMaxEntries = TabRestoreServiceHelper::kMaxEntries,
77 }; 78 };
78 79
79 // testing::Test: 80 // testing::Test:
80 void SetUp() override { 81 void SetUp() override {
81 ChromeRenderViewHostTestHarness::SetUp(); 82 ChromeRenderViewHostTestHarness::SetUp();
83 live_tab_ = make_scoped_ptr(new sessions::ContentLiveTab(web_contents()));
82 time_factory_ = new PersistentTabRestoreTimeFactory(); 84 time_factory_ = new PersistentTabRestoreTimeFactory();
83 service_.reset(new PersistentTabRestoreService( 85 service_.reset(new PersistentTabRestoreService(
84 make_scoped_ptr(new ChromeTabRestoreServiceClient(profile())), 86 make_scoped_ptr(new ChromeTabRestoreServiceClient(profile())),
85 time_factory_)); 87 time_factory_));
86 } 88 }
87 89
88 void TearDown() override { 90 void TearDown() override {
89 service_->Shutdown(); 91 service_->Shutdown();
90 service_.reset(); 92 service_.reset();
91 delete time_factory_; 93 delete time_factory_;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 // Set this, otherwise previous session won't be loaded. 162 // Set this, otherwise previous session won't be loaded.
161 profile()->set_last_session_exited_cleanly(false); 163 profile()->set_last_session_exited_cleanly(false);
162 } 164 }
163 165
164 void SynchronousLoadTabsFromLastSession() { 166 void SynchronousLoadTabsFromLastSession() {
165 // Ensures that the load is complete before continuing. 167 // Ensures that the load is complete before continuing.
166 service_->LoadTabsFromLastSession(); 168 service_->LoadTabsFromLastSession();
167 content::RunAllBlockingPoolTasksUntilIdle(); 169 content::RunAllBlockingPoolTasksUntilIdle();
168 } 170 }
169 171
172 sessions::LiveTab* live_tab() { return live_tab_.get(); }
173
170 GURL url1_; 174 GURL url1_;
171 GURL url2_; 175 GURL url2_;
172 GURL url3_; 176 GURL url3_;
173 std::string user_agent_override_; 177 std::string user_agent_override_;
178 scoped_ptr<sessions::LiveTab> live_tab_;
174 scoped_ptr<PersistentTabRestoreService> service_; 179 scoped_ptr<PersistentTabRestoreService> service_;
175 PersistentTabRestoreTimeFactory* time_factory_; 180 PersistentTabRestoreTimeFactory* time_factory_;
176 }; 181 };
177 182
178 namespace { 183 namespace {
179 184
180 class TestTabRestoreServiceObserver : public TabRestoreServiceObserver { 185 class TestTabRestoreServiceObserver : public TabRestoreServiceObserver {
181 public: 186 public:
182 TestTabRestoreServiceObserver() : got_loaded_(false) {} 187 TestTabRestoreServiceObserver() : got_loaded_(false) {}
183 188
(...skipping 13 matching lines...) Expand all
197 202
198 DISALLOW_COPY_AND_ASSIGN(TestTabRestoreServiceObserver); 203 DISALLOW_COPY_AND_ASSIGN(TestTabRestoreServiceObserver);
199 }; 204 };
200 205
201 } // namespace 206 } // namespace
202 207
203 TEST_F(PersistentTabRestoreServiceTest, Basic) { 208 TEST_F(PersistentTabRestoreServiceTest, Basic) {
204 AddThreeNavigations(); 209 AddThreeNavigations();
205 210
206 // Have the service record the tab. 211 // Have the service record the tab.
207 service_->CreateHistoricalTab(web_contents(), -1); 212 service_->CreateHistoricalTab(live_tab(), -1);
208 213
209 // Make sure an entry was created. 214 // Make sure an entry was created.
210 ASSERT_EQ(1U, service_->entries().size()); 215 ASSERT_EQ(1U, service_->entries().size());
211 216
212 // Make sure the entry matches. 217 // Make sure the entry matches.
213 TabRestoreService::Entry* entry = service_->entries().front(); 218 TabRestoreService::Entry* entry = service_->entries().front();
214 ASSERT_EQ(TabRestoreService::TAB, entry->type); 219 ASSERT_EQ(TabRestoreService::TAB, entry->type);
215 Tab* tab = static_cast<Tab*>(entry); 220 Tab* tab = static_cast<Tab*>(entry);
216 EXPECT_FALSE(tab->pinned); 221 EXPECT_FALSE(tab->pinned);
217 EXPECT_TRUE(tab->extension_app_id.empty()); 222 EXPECT_TRUE(tab->extension_app_id.empty());
218 ASSERT_EQ(3U, tab->navigations.size()); 223 ASSERT_EQ(3U, tab->navigations.size());
219 EXPECT_TRUE(url1_ == tab->navigations[0].virtual_url()); 224 EXPECT_TRUE(url1_ == tab->navigations[0].virtual_url());
220 EXPECT_TRUE(url2_ == tab->navigations[1].virtual_url()); 225 EXPECT_TRUE(url2_ == tab->navigations[1].virtual_url());
221 EXPECT_TRUE(url3_ == tab->navigations[2].virtual_url()); 226 EXPECT_TRUE(url3_ == tab->navigations[2].virtual_url());
222 EXPECT_EQ("", tab->user_agent_override); 227 EXPECT_EQ("", tab->user_agent_override);
223 EXPECT_EQ(2, tab->current_navigation_index); 228 EXPECT_EQ(2, tab->current_navigation_index);
224 EXPECT_EQ(time_factory_->TimeNow().ToInternalValue(), 229 EXPECT_EQ(time_factory_->TimeNow().ToInternalValue(),
225 tab->timestamp.ToInternalValue()); 230 tab->timestamp.ToInternalValue());
226 231
227 NavigateToIndex(1); 232 NavigateToIndex(1);
228 233
229 // And check again, but set the user agent override this time. 234 // And check again, but set the user agent override this time.
230 web_contents()->SetUserAgentOverride(user_agent_override_); 235 web_contents()->SetUserAgentOverride(user_agent_override_);
231 service_->CreateHistoricalTab(web_contents(), -1); 236 service_->CreateHistoricalTab(live_tab(), -1);
232 237
233 // There should be two entries now. 238 // There should be two entries now.
234 ASSERT_EQ(2U, service_->entries().size()); 239 ASSERT_EQ(2U, service_->entries().size());
235 240
236 // Make sure the entry matches. 241 // Make sure the entry matches.
237 entry = service_->entries().front(); 242 entry = service_->entries().front();
238 ASSERT_EQ(TabRestoreService::TAB, entry->type); 243 ASSERT_EQ(TabRestoreService::TAB, entry->type);
239 tab = static_cast<Tab*>(entry); 244 tab = static_cast<Tab*>(entry);
240 EXPECT_FALSE(tab->pinned); 245 EXPECT_FALSE(tab->pinned);
241 ASSERT_EQ(3U, tab->navigations.size()); 246 ASSERT_EQ(3U, tab->navigations.size());
242 EXPECT_EQ(url1_, tab->navigations[0].virtual_url()); 247 EXPECT_EQ(url1_, tab->navigations[0].virtual_url());
243 EXPECT_EQ(url2_, tab->navigations[1].virtual_url()); 248 EXPECT_EQ(url2_, tab->navigations[1].virtual_url());
244 EXPECT_EQ(url3_, tab->navigations[2].virtual_url()); 249 EXPECT_EQ(url3_, tab->navigations[2].virtual_url());
245 EXPECT_EQ(user_agent_override_, tab->user_agent_override); 250 EXPECT_EQ(user_agent_override_, tab->user_agent_override);
246 EXPECT_EQ(1, tab->current_navigation_index); 251 EXPECT_EQ(1, tab->current_navigation_index);
247 EXPECT_EQ(time_factory_->TimeNow().ToInternalValue(), 252 EXPECT_EQ(time_factory_->TimeNow().ToInternalValue(),
248 tab->timestamp.ToInternalValue()); 253 tab->timestamp.ToInternalValue());
249 } 254 }
250 255
251 // Make sure TabRestoreService doesn't create an entry for a tab with no 256 // Make sure TabRestoreService doesn't create an entry for a tab with no
252 // navigations. 257 // navigations.
253 TEST_F(PersistentTabRestoreServiceTest, DontCreateEmptyTab) { 258 TEST_F(PersistentTabRestoreServiceTest, DontCreateEmptyTab) {
254 service_->CreateHistoricalTab(web_contents(), -1); 259 service_->CreateHistoricalTab(live_tab(), -1);
255 EXPECT_TRUE(service_->entries().empty()); 260 EXPECT_TRUE(service_->entries().empty());
256 } 261 }
257 262
258 // Tests restoring a single tab. 263 // Tests restoring a single tab.
259 TEST_F(PersistentTabRestoreServiceTest, Restore) { 264 TEST_F(PersistentTabRestoreServiceTest, Restore) {
260 AddThreeNavigations(); 265 AddThreeNavigations();
261 266
262 // Have the service record the tab. 267 // Have the service record the tab.
263 service_->CreateHistoricalTab(web_contents(), -1); 268 service_->CreateHistoricalTab(live_tab(), -1);
264 269
265 // Recreate the service and have it load the tabs. 270 // Recreate the service and have it load the tabs.
266 RecreateService(); 271 RecreateService();
267 272
268 // One entry should be created. 273 // One entry should be created.
269 ASSERT_EQ(1U, service_->entries().size()); 274 ASSERT_EQ(1U, service_->entries().size());
270 275
271 // And verify the entry. 276 // And verify the entry.
272 PersistentTabRestoreService::Entry* entry = service_->entries().front(); 277 PersistentTabRestoreService::Entry* entry = service_->entries().front();
273 ASSERT_EQ(TabRestoreService::TAB, entry->type); 278 ASSERT_EQ(TabRestoreService::TAB, entry->type);
274 Tab* tab = static_cast<Tab*>(entry); 279 Tab* tab = static_cast<Tab*>(entry);
275 EXPECT_FALSE(tab->pinned); 280 EXPECT_FALSE(tab->pinned);
276 ASSERT_EQ(3U, tab->navigations.size()); 281 ASSERT_EQ(3U, tab->navigations.size());
277 EXPECT_TRUE(url1_ == tab->navigations[0].virtual_url()); 282 EXPECT_TRUE(url1_ == tab->navigations[0].virtual_url());
278 EXPECT_TRUE(url2_ == tab->navigations[1].virtual_url()); 283 EXPECT_TRUE(url2_ == tab->navigations[1].virtual_url());
279 EXPECT_TRUE(url3_ == tab->navigations[2].virtual_url()); 284 EXPECT_TRUE(url3_ == tab->navigations[2].virtual_url());
280 EXPECT_EQ(2, tab->current_navigation_index); 285 EXPECT_EQ(2, tab->current_navigation_index);
281 EXPECT_EQ(time_factory_->TimeNow().ToInternalValue(), 286 EXPECT_EQ(time_factory_->TimeNow().ToInternalValue(),
282 tab->timestamp.ToInternalValue()); 287 tab->timestamp.ToInternalValue());
283 } 288 }
284 289
285 // Tests restoring a single pinned tab. 290 // Tests restoring a single pinned tab.
286 TEST_F(PersistentTabRestoreServiceTest, RestorePinnedAndApp) { 291 TEST_F(PersistentTabRestoreServiceTest, RestorePinnedAndApp) {
287 AddThreeNavigations(); 292 AddThreeNavigations();
288 293
289 // Have the service record the tab. 294 // Have the service record the tab.
290 service_->CreateHistoricalTab(web_contents(), -1); 295 service_->CreateHistoricalTab(live_tab(), -1);
291 296
292 // One entry should be created. 297 // One entry should be created.
293 ASSERT_EQ(1U, service_->entries().size()); 298 ASSERT_EQ(1U, service_->entries().size());
294 299
295 // We have to explicitly mark the tab as pinned as there is no browser for 300 // We have to explicitly mark the tab as pinned as there is no browser for
296 // these tests. 301 // these tests.
297 TabRestoreService::Entry* entry = service_->entries().front(); 302 TabRestoreService::Entry* entry = service_->entries().front();
298 ASSERT_EQ(TabRestoreService::TAB, entry->type); 303 ASSERT_EQ(TabRestoreService::TAB, entry->type);
299 Tab* tab = static_cast<Tab*>(entry); 304 Tab* tab = static_cast<Tab*>(entry);
300 tab->pinned = true; 305 tab->pinned = true;
(...skipping 20 matching lines...) Expand all
321 } 326 }
322 327
323 // Make sure we persist entries to disk that have post data. 328 // Make sure we persist entries to disk that have post data.
324 TEST_F(PersistentTabRestoreServiceTest, DontPersistPostData) { 329 TEST_F(PersistentTabRestoreServiceTest, DontPersistPostData) {
325 AddThreeNavigations(); 330 AddThreeNavigations();
326 controller().GetEntryAtIndex(0)->SetHasPostData(true); 331 controller().GetEntryAtIndex(0)->SetHasPostData(true);
327 controller().GetEntryAtIndex(1)->SetHasPostData(true); 332 controller().GetEntryAtIndex(1)->SetHasPostData(true);
328 controller().GetEntryAtIndex(2)->SetHasPostData(true); 333 controller().GetEntryAtIndex(2)->SetHasPostData(true);
329 334
330 // Have the service record the tab. 335 // Have the service record the tab.
331 service_->CreateHistoricalTab(web_contents(), -1); 336 service_->CreateHistoricalTab(live_tab(), -1);
332 ASSERT_EQ(1U, service_->entries().size()); 337 ASSERT_EQ(1U, service_->entries().size());
333 338
334 // Recreate the service and have it load the tabs. 339 // Recreate the service and have it load the tabs.
335 RecreateService(); 340 RecreateService();
336 341
337 // One entry should be created. 342 // One entry should be created.
338 ASSERT_EQ(1U, service_->entries().size()); 343 ASSERT_EQ(1U, service_->entries().size());
339 344
340 const TabRestoreService::Entry* restored_entry = service_->entries().front(); 345 const TabRestoreService::Entry* restored_entry = service_->entries().front();
341 ASSERT_EQ(TabRestoreService::TAB, restored_entry->type); 346 ASSERT_EQ(TabRestoreService::TAB, restored_entry->type);
342 347
343 const Tab* restored_tab = 348 const Tab* restored_tab =
344 static_cast<const Tab*>(restored_entry); 349 static_cast<const Tab*>(restored_entry);
345 // There should be 3 navs. 350 // There should be 3 navs.
346 ASSERT_EQ(3U, restored_tab->navigations.size()); 351 ASSERT_EQ(3U, restored_tab->navigations.size());
347 EXPECT_EQ(time_factory_->TimeNow().ToInternalValue(), 352 EXPECT_EQ(time_factory_->TimeNow().ToInternalValue(),
348 restored_tab->timestamp.ToInternalValue()); 353 restored_tab->timestamp.ToInternalValue());
349 } 354 }
350 355
351 // Make sure we don't persist entries to disk that have post data. This 356 // Make sure we don't persist entries to disk that have post data. This
352 // differs from DontPersistPostData1 in that all the navigations have post 357 // differs from DontPersistPostData1 in that all the navigations have post
353 // data, so that nothing should be persisted. 358 // data, so that nothing should be persisted.
354 TEST_F(PersistentTabRestoreServiceTest, DontLoadTwice) { 359 TEST_F(PersistentTabRestoreServiceTest, DontLoadTwice) {
355 AddThreeNavigations(); 360 AddThreeNavigations();
356 361
357 // Have the service record the tab. 362 // Have the service record the tab.
358 service_->CreateHistoricalTab(web_contents(), -1); 363 service_->CreateHistoricalTab(live_tab(), -1);
359 ASSERT_EQ(1U, service_->entries().size()); 364 ASSERT_EQ(1U, service_->entries().size());
360 365
361 // Recreate the service and have it load the tabs. 366 // Recreate the service and have it load the tabs.
362 RecreateService(); 367 RecreateService();
363 368
364 SynchronousLoadTabsFromLastSession(); 369 SynchronousLoadTabsFromLastSession();
365 370
366 // There should only be one entry. 371 // There should only be one entry.
367 ASSERT_EQ(1U, service_->entries().size()); 372 ASSERT_EQ(1U, service_->entries().size());
368 } 373 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 } 433 }
429 434
430 TEST_F(PersistentTabRestoreServiceTest, LoadPreviousSessionAndTabs) { 435 TEST_F(PersistentTabRestoreServiceTest, LoadPreviousSessionAndTabs) {
431 CreateSessionServiceWithOneWindow(false); 436 CreateSessionServiceWithOneWindow(false);
432 437
433 SessionServiceFactory::GetForProfile(profile())-> 438 SessionServiceFactory::GetForProfile(profile())->
434 MoveCurrentSessionToLastSession(); 439 MoveCurrentSessionToLastSession();
435 440
436 AddThreeNavigations(); 441 AddThreeNavigations();
437 442
438 service_->CreateHistoricalTab(web_contents(), -1); 443 service_->CreateHistoricalTab(live_tab(), -1);
439 444
440 RecreateService(); 445 RecreateService();
441 446
442 // We should get back two entries, one from the previous session and one from 447 // We should get back two entries, one from the previous session and one from
443 // the tab restore service. The previous session entry should be first. 448 // the tab restore service. The previous session entry should be first.
444 ASSERT_EQ(2U, service_->entries().size()); 449 ASSERT_EQ(2U, service_->entries().size());
445 // The first entry should come from the session service. 450 // The first entry should come from the session service.
446 TabRestoreService::Entry* entry = service_->entries().front(); 451 TabRestoreService::Entry* entry = service_->entries().front();
447 ASSERT_EQ(TabRestoreService::WINDOW, entry->type); 452 ASSERT_EQ(TabRestoreService::WINDOW, entry->type);
448 TabRestoreService::Window* window = 453 TabRestoreService::Window* window =
(...skipping 22 matching lines...) Expand all
471 476
472 // Make sure pinned state is correctly loaded from session service. 477 // Make sure pinned state is correctly loaded from session service.
473 TEST_F(PersistentTabRestoreServiceTest, LoadPreviousSessionAndTabsPinned) { 478 TEST_F(PersistentTabRestoreServiceTest, LoadPreviousSessionAndTabsPinned) {
474 CreateSessionServiceWithOneWindow(true); 479 CreateSessionServiceWithOneWindow(true);
475 480
476 SessionServiceFactory::GetForProfile(profile())-> 481 SessionServiceFactory::GetForProfile(profile())->
477 MoveCurrentSessionToLastSession(); 482 MoveCurrentSessionToLastSession();
478 483
479 AddThreeNavigations(); 484 AddThreeNavigations();
480 485
481 service_->CreateHistoricalTab(web_contents(), -1); 486 service_->CreateHistoricalTab(live_tab(), -1);
482 487
483 RecreateService(); 488 RecreateService();
484 489
485 // We should get back two entries, one from the previous session and one from 490 // We should get back two entries, one from the previous session and one from
486 // the tab restore service. The previous session entry should be first. 491 // the tab restore service. The previous session entry should be first.
487 ASSERT_EQ(2U, service_->entries().size()); 492 ASSERT_EQ(2U, service_->entries().size());
488 // The first entry should come from the session service. 493 // The first entry should come from the session service.
489 TabRestoreService::Entry* entry = service_->entries().front(); 494 TabRestoreService::Entry* entry = service_->entries().front();
490 ASSERT_EQ(TabRestoreService::WINDOW, entry->type); 495 ASSERT_EQ(TabRestoreService::WINDOW, entry->type);
491 TabRestoreService::Window* window = 496 TabRestoreService::Window* window =
(...skipping 23 matching lines...) Expand all
515 CreateSessionServiceWithOneWindow(false); 520 CreateSessionServiceWithOneWindow(false);
516 521
517 for (size_t i = 0; i < kMaxEntries; ++i) 522 for (size_t i = 0; i < kMaxEntries; ++i)
518 AddWindowWithOneTabToSessionService(false); 523 AddWindowWithOneTabToSessionService(false);
519 524
520 SessionServiceFactory::GetForProfile(profile())-> 525 SessionServiceFactory::GetForProfile(profile())->
521 MoveCurrentSessionToLastSession(); 526 MoveCurrentSessionToLastSession();
522 527
523 AddThreeNavigations(); 528 AddThreeNavigations();
524 529
525 service_->CreateHistoricalTab(web_contents(), -1); 530 service_->CreateHistoricalTab(live_tab(), -1);
526 531
527 RecreateService(); 532 RecreateService();
528 533
529 // We should get back kMaxEntries entries. We added more, but 534 // We should get back kMaxEntries entries. We added more, but
530 // TabRestoreService only allows up to kMaxEntries. 535 // TabRestoreService only allows up to kMaxEntries.
531 ASSERT_EQ(kMaxEntries, service_->entries().size()); 536 ASSERT_EQ(kMaxEntries, service_->entries().size());
532 537
533 // The first entry should come from the session service. 538 // The first entry should come from the session service.
534 TabRestoreService::Entry* entry = service_->entries().front(); 539 TabRestoreService::Entry* entry = service_->entries().front();
535 ASSERT_EQ(TabRestoreService::WINDOW, entry->type); 540 ASSERT_EQ(TabRestoreService::WINDOW, entry->type);
536 TabRestoreService::Window* window = 541 TabRestoreService::Window* window =
537 static_cast<TabRestoreService::Window*>(entry); 542 static_cast<TabRestoreService::Window*>(entry);
538 ASSERT_EQ(1U, window->tabs.size()); 543 ASSERT_EQ(1U, window->tabs.size());
539 EXPECT_EQ(0, window->selected_tab_index); 544 EXPECT_EQ(0, window->selected_tab_index);
540 EXPECT_EQ(0, window->timestamp.ToInternalValue()); 545 EXPECT_EQ(0, window->timestamp.ToInternalValue());
541 ASSERT_EQ(1U, window->tabs[0].navigations.size()); 546 ASSERT_EQ(1U, window->tabs[0].navigations.size());
542 EXPECT_EQ(0, window->tabs[0].current_navigation_index); 547 EXPECT_EQ(0, window->tabs[0].current_navigation_index);
543 EXPECT_EQ(0, window->tabs[0].timestamp.ToInternalValue()); 548 EXPECT_EQ(0, window->tabs[0].timestamp.ToInternalValue());
544 EXPECT_TRUE(url1_ == window->tabs[0].navigations[0].virtual_url()); 549 EXPECT_TRUE(url1_ == window->tabs[0].navigations[0].virtual_url());
545 } 550 }
546 551
547 // Makes sure we restore timestamps correctly. 552 // Makes sure we restore timestamps correctly.
548 TEST_F(PersistentTabRestoreServiceTest, TimestampSurvivesRestore) { 553 TEST_F(PersistentTabRestoreServiceTest, TimestampSurvivesRestore) {
549 base::Time tab_timestamp(base::Time::FromInternalValue(123456789)); 554 base::Time tab_timestamp(base::Time::FromInternalValue(123456789));
550 555
551 AddThreeNavigations(); 556 AddThreeNavigations();
552 557
553 // Have the service record the tab. 558 // Have the service record the tab.
554 service_->CreateHistoricalTab(web_contents(), -1); 559 service_->CreateHistoricalTab(live_tab(), -1);
555 560
556 // Make sure an entry was created. 561 // Make sure an entry was created.
557 ASSERT_EQ(1U, service_->entries().size()); 562 ASSERT_EQ(1U, service_->entries().size());
558 563
559 // Make sure the entry matches. 564 // Make sure the entry matches.
560 std::vector<SerializedNavigationEntry> old_navigations; 565 std::vector<SerializedNavigationEntry> old_navigations;
561 { 566 {
562 // |entry|/|tab| doesn't survive after RecreateService(). 567 // |entry|/|tab| doesn't survive after RecreateService().
563 TabRestoreService::Entry* entry = service_->entries().front(); 568 TabRestoreService::Entry* entry = service_->entries().front();
564 ASSERT_EQ(TabRestoreService::TAB, entry->type); 569 ASSERT_EQ(TabRestoreService::TAB, entry->type);
(...skipping 27 matching lines...) Expand all
592 EXPECT_EQ(old_navigations[i].timestamp(), 597 EXPECT_EQ(old_navigations[i].timestamp(),
593 restored_tab->navigations[i].timestamp()); 598 restored_tab->navigations[i].timestamp());
594 } 599 }
595 } 600 }
596 601
597 // Makes sure we restore status codes correctly. 602 // Makes sure we restore status codes correctly.
598 TEST_F(PersistentTabRestoreServiceTest, StatusCodesSurviveRestore) { 603 TEST_F(PersistentTabRestoreServiceTest, StatusCodesSurviveRestore) {
599 AddThreeNavigations(); 604 AddThreeNavigations();
600 605
601 // Have the service record the tab. 606 // Have the service record the tab.
602 service_->CreateHistoricalTab(web_contents(), -1); 607 service_->CreateHistoricalTab(live_tab(), -1);
603 608
604 // Make sure an entry was created. 609 // Make sure an entry was created.
605 ASSERT_EQ(1U, service_->entries().size()); 610 ASSERT_EQ(1U, service_->entries().size());
606 611
607 // Make sure the entry matches. 612 // Make sure the entry matches.
608 std::vector<sessions::SerializedNavigationEntry> old_navigations; 613 std::vector<sessions::SerializedNavigationEntry> old_navigations;
609 { 614 {
610 // |entry|/|tab| doesn't survive after RecreateService(). 615 // |entry|/|tab| doesn't survive after RecreateService().
611 TabRestoreService::Entry* entry = service_->entries().front(); 616 TabRestoreService::Entry* entry = service_->entries().front();
612 ASSERT_EQ(TabRestoreService::TAB, entry->type); 617 ASSERT_EQ(TabRestoreService::TAB, entry->type);
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
732 737
733 SessionServiceFactory::GetForProfile(profile())-> 738 SessionServiceFactory::GetForProfile(profile())->
734 MoveCurrentSessionToLastSession(); 739 MoveCurrentSessionToLastSession();
735 740
736 profile()->set_restored_last_session(true); 741 profile()->set_restored_last_session(true);
737 742
738 const size_t max_entries = kMaxEntries; 743 const size_t max_entries = kMaxEntries;
739 for (size_t i = 0; i < max_entries + 5; i++) { 744 for (size_t i = 0; i < max_entries + 5; i++) {
740 NavigateAndCommit( 745 NavigateAndCommit(
741 GURL(base::StringPrintf("http://%d", static_cast<int>(i)))); 746 GURL(base::StringPrintf("http://%d", static_cast<int>(i))));
742 service_->CreateHistoricalTab(web_contents(), -1); 747 service_->CreateHistoricalTab(live_tab(), -1);
743 } 748 }
744 749
745 EXPECT_EQ(max_entries, service_->entries().size()); 750 EXPECT_EQ(max_entries, service_->entries().size());
746 // This should not crash. 751 // This should not crash.
747 SynchronousLoadTabsFromLastSession(); 752 SynchronousLoadTabsFromLastSession();
748 EXPECT_EQ(max_entries, service_->entries().size()); 753 EXPECT_EQ(max_entries, service_->entries().size());
749 } 754 }
750 755
751 // Makes sure invoking LoadTabsFromLastSession() when the max number of entries 756 // Makes sure invoking LoadTabsFromLastSession() when the max number of entries
752 // have been added results in IsLoaded() returning true and notifies observers. 757 // have been added results in IsLoaded() returning true and notifies observers.
753 TEST_F(PersistentTabRestoreServiceTest, GoToLoadedWhenHaveMaxEntries) { 758 TEST_F(PersistentTabRestoreServiceTest, GoToLoadedWhenHaveMaxEntries) {
754 const size_t max_entries = kMaxEntries; 759 const size_t max_entries = kMaxEntries;
755 for (size_t i = 0; i < max_entries + 5; i++) { 760 for (size_t i = 0; i < max_entries + 5; i++) {
756 NavigateAndCommit( 761 NavigateAndCommit(
757 GURL(base::StringPrintf("http://%d", static_cast<int>(i)))); 762 GURL(base::StringPrintf("http://%d", static_cast<int>(i))));
758 service_->CreateHistoricalTab(web_contents(), -1); 763 service_->CreateHistoricalTab(live_tab(), -1);
759 } 764 }
760 765
761 EXPECT_FALSE(service_->IsLoaded()); 766 EXPECT_FALSE(service_->IsLoaded());
762 TestTabRestoreServiceObserver observer; 767 TestTabRestoreServiceObserver observer;
763 service_->AddObserver(&observer); 768 service_->AddObserver(&observer);
764 EXPECT_EQ(max_entries, service_->entries().size()); 769 EXPECT_EQ(max_entries, service_->entries().size());
765 SynchronousLoadTabsFromLastSession(); 770 SynchronousLoadTabsFromLastSession();
766 EXPECT_TRUE(observer.got_loaded()); 771 EXPECT_TRUE(observer.got_loaded());
767 EXPECT_TRUE(service_->IsLoaded()); 772 EXPECT_TRUE(service_->IsLoaded());
768 service_->RemoveObserver(&observer); 773 service_->RemoveObserver(&observer);
769 } 774 }
OLDNEW
« no previous file with comments | « chrome/browser/sessions/persistent_tab_restore_service.cc ('k') | chrome/browser/sessions/session_restore_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698