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

Side by Side Diff: chrome/browser/sync/sessions/sessions_sync_manager_unittest.cc

Issue 1882243004: Convert //chrome/browser/sync from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address feedback Created 4 years, 8 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/sync_sessions/sessions_sync_manager.h" 5 #include "components/sync_sessions/sessions_sync_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 base::FieldTrialList::FindFullName(trial_name); 254 base::FieldTrialList::FindFullName(trial_name);
255 } 255 }
256 256
257 class DummyRouter : public LocalSessionEventRouter { 257 class DummyRouter : public LocalSessionEventRouter {
258 public: 258 public:
259 ~DummyRouter() override {} 259 ~DummyRouter() override {}
260 void StartRoutingTo(LocalSessionEventHandler* handler) override {} 260 void StartRoutingTo(LocalSessionEventHandler* handler) override {}
261 void Stop() override {} 261 void Stop() override {}
262 }; 262 };
263 263
264 scoped_ptr<LocalSessionEventRouter> NewDummyRouter() { 264 std::unique_ptr<LocalSessionEventRouter> NewDummyRouter() {
265 return scoped_ptr<LocalSessionEventRouter>(new DummyRouter()); 265 return std::unique_ptr<LocalSessionEventRouter>(new DummyRouter());
266 } 266 }
267 267
268 // Provides ability to override SyncedWindowDelegatesGetter. 268 // Provides ability to override SyncedWindowDelegatesGetter.
269 // All other calls are passed through to the original SyncSessionsClient. 269 // All other calls are passed through to the original SyncSessionsClient.
270 class SyncSessionsClientShim : public sync_sessions::SyncSessionsClient { 270 class SyncSessionsClientShim : public sync_sessions::SyncSessionsClient {
271 public: 271 public:
272 SyncSessionsClientShim( 272 SyncSessionsClientShim(
273 sync_sessions::SyncSessionsClient* sync_sessions_client) 273 sync_sessions::SyncSessionsClient* sync_sessions_client)
274 : sync_sessions_client_(sync_sessions_client), 274 : sync_sessions_client_(sync_sessions_client),
275 synced_window_getter_(nullptr) {} 275 synced_window_getter_(nullptr) {}
(...skipping 19 matching lines...) Expand all
295 override { 295 override {
296 // The idea here is to allow the test code override the default 296 // The idea here is to allow the test code override the default
297 // SyncedWindowDelegatesGetter provided by |sync_sessions_client_|. 297 // SyncedWindowDelegatesGetter provided by |sync_sessions_client_|.
298 // If |synced_window_getter_| is explicitly set, return it; otherwise return 298 // If |synced_window_getter_| is explicitly set, return it; otherwise return
299 // the default one provided by |sync_sessions_client_|. 299 // the default one provided by |sync_sessions_client_|.
300 return synced_window_getter_ 300 return synced_window_getter_
301 ? synced_window_getter_ 301 ? synced_window_getter_
302 : sync_sessions_client_->GetSyncedWindowDelegatesGetter(); 302 : sync_sessions_client_->GetSyncedWindowDelegatesGetter();
303 } 303 }
304 304
305 scoped_ptr<browser_sync::LocalSessionEventRouter> GetLocalSessionEventRouter() 305 std::unique_ptr<browser_sync::LocalSessionEventRouter>
306 override { 306 GetLocalSessionEventRouter() override {
307 return sync_sessions_client_->GetLocalSessionEventRouter(); 307 return sync_sessions_client_->GetLocalSessionEventRouter();
308 } 308 }
309 309
310 void set_synced_window_getter( 310 void set_synced_window_getter(
311 browser_sync::SyncedWindowDelegatesGetter* synced_window_getter) { 311 browser_sync::SyncedWindowDelegatesGetter* synced_window_getter) {
312 synced_window_getter_ = synced_window_getter; 312 synced_window_getter_ = synced_window_getter;
313 } 313 }
314 314
315 private: 315 private:
316 sync_sessions::SyncSessionsClient* const sync_sessions_client_; 316 sync_sessions::SyncSessionsClient* const sync_sessions_client_;
(...skipping 21 matching lines...) Expand all
338 sync_client_.reset(new browser_sync::ChromeSyncClient(profile())); 338 sync_client_.reset(new browser_sync::ChromeSyncClient(profile()));
339 sessions_client_shim_.reset( 339 sessions_client_shim_.reset(
340 new SyncSessionsClientShim(sync_client_->GetSyncSessionsClient())); 340 new SyncSessionsClientShim(sync_client_->GetSyncSessionsClient()));
341 browser_sync::NotificationServiceSessionsRouter* router( 341 browser_sync::NotificationServiceSessionsRouter* router(
342 new browser_sync::NotificationServiceSessionsRouter( 342 new browser_sync::NotificationServiceSessionsRouter(
343 profile(), GetSyncSessionsClient(), 343 profile(), GetSyncSessionsClient(),
344 syncer::SyncableService::StartSyncFlare())); 344 syncer::SyncableService::StartSyncFlare()));
345 sync_prefs_.reset(new sync_driver::SyncPrefs(profile()->GetPrefs())); 345 sync_prefs_.reset(new sync_driver::SyncPrefs(profile()->GetPrefs()));
346 manager_.reset(new SessionsSyncManager( 346 manager_.reset(new SessionsSyncManager(
347 GetSyncSessionsClient(), sync_prefs_.get(), local_device_.get(), 347 GetSyncSessionsClient(), sync_prefs_.get(), local_device_.get(),
348 scoped_ptr<LocalSessionEventRouter>(router), 348 std::unique_ptr<LocalSessionEventRouter>(router),
349 base::Bind(&SessionNotificationObserver::NotifyOfUpdate, 349 base::Bind(&SessionNotificationObserver::NotifyOfUpdate,
350 base::Unretained(&observer_)), 350 base::Unretained(&observer_)),
351 base::Bind(&SessionNotificationObserver::NotifyOfRefresh, 351 base::Bind(&SessionNotificationObserver::NotifyOfRefresh,
352 base::Unretained(&observer_)))); 352 base::Unretained(&observer_))));
353 } 353 }
354 354
355 void TearDown() override { 355 void TearDown() override {
356 test_processor_ = NULL; 356 test_processor_ = NULL;
357 helper()->Reset(); 357 helper()->Reset();
358 sync_prefs_.reset(); 358 sync_prefs_.reset();
359 manager_.reset(); 359 manager_.reset();
360 BrowserWithTestWindowTest::TearDown(); 360 BrowserWithTestWindowTest::TearDown();
361 } 361 }
362 362
363 const DeviceInfo* GetLocalDeviceInfo() { 363 const DeviceInfo* GetLocalDeviceInfo() {
364 return local_device_->GetLocalDeviceInfo(); 364 return local_device_->GetLocalDeviceInfo();
365 } 365 }
366 366
367 SessionsSyncManager* manager() { return manager_.get(); } 367 SessionsSyncManager* manager() { return manager_.get(); }
368 SessionSyncTestHelper* helper() { return &helper_; } 368 SessionSyncTestHelper* helper() { return &helper_; }
369 LocalDeviceInfoProvider* local_device() { return local_device_.get(); } 369 LocalDeviceInfoProvider* local_device() { return local_device_.get(); }
370 SessionNotificationObserver* observer() { return &observer_; } 370 SessionNotificationObserver* observer() { return &observer_; }
371 371
372 void InitWithSyncDataTakeOutput(const syncer::SyncDataList& initial_data, 372 void InitWithSyncDataTakeOutput(const syncer::SyncDataList& initial_data,
373 syncer::SyncChangeList* output) { 373 syncer::SyncChangeList* output) {
374 test_processor_ = new TestSyncProcessorStub(output); 374 test_processor_ = new TestSyncProcessorStub(output);
375 syncer::SyncMergeResult result = manager_->MergeDataAndStartSyncing( 375 syncer::SyncMergeResult result = manager_->MergeDataAndStartSyncing(
376 syncer::SESSIONS, initial_data, 376 syncer::SESSIONS, initial_data,
377 scoped_ptr<syncer::SyncChangeProcessor>(test_processor_), 377 std::unique_ptr<syncer::SyncChangeProcessor>(test_processor_),
378 scoped_ptr<syncer::SyncErrorFactory>( 378 std::unique_ptr<syncer::SyncErrorFactory>(
379 new syncer::SyncErrorFactoryMock())); 379 new syncer::SyncErrorFactoryMock()));
380 EXPECT_FALSE(result.error().IsSet()); 380 EXPECT_FALSE(result.error().IsSet());
381 } 381 }
382 382
383 void InitWithNoSyncData() { 383 void InitWithNoSyncData() {
384 InitWithSyncDataTakeOutput(syncer::SyncDataList(), NULL); 384 InitWithSyncDataTakeOutput(syncer::SyncDataList(), NULL);
385 } 385 }
386 386
387 void TriggerProcessSyncChangesError() { 387 void TriggerProcessSyncChangesError() {
388 test_processor_->FailProcessSyncChangesWith(syncer::SyncError( 388 test_processor_->FailProcessSyncChangesWith(syncer::SyncError(
(...skipping 29 matching lines...) Expand all
418 } 418 }
419 419
420 sync_driver::SyncPrefs* sync_prefs() { return sync_prefs_.get(); } 420 sync_driver::SyncPrefs* sync_prefs() { return sync_prefs_.get(); }
421 421
422 void set_synced_window_getter( 422 void set_synced_window_getter(
423 browser_sync::SyncedWindowDelegatesGetter* synced_window_getter) { 423 browser_sync::SyncedWindowDelegatesGetter* synced_window_getter) {
424 sessions_client_shim_->set_synced_window_getter(synced_window_getter); 424 sessions_client_shim_->set_synced_window_getter(synced_window_getter);
425 } 425 }
426 426
427 private: 427 private:
428 scoped_ptr<browser_sync::ChromeSyncClient> sync_client_; 428 std::unique_ptr<browser_sync::ChromeSyncClient> sync_client_;
429 scoped_ptr<SyncSessionsClientShim> sessions_client_shim_; 429 std::unique_ptr<SyncSessionsClientShim> sessions_client_shim_;
430 scoped_ptr<sync_driver::SyncPrefs> sync_prefs_; 430 std::unique_ptr<sync_driver::SyncPrefs> sync_prefs_;
431 SessionNotificationObserver observer_; 431 SessionNotificationObserver observer_;
432 scoped_ptr<SessionsSyncManager> manager_; 432 std::unique_ptr<SessionsSyncManager> manager_;
433 SessionSyncTestHelper helper_; 433 SessionSyncTestHelper helper_;
434 TestSyncProcessorStub* test_processor_; 434 TestSyncProcessorStub* test_processor_;
435 scoped_ptr<LocalDeviceInfoProviderMock> local_device_; 435 std::unique_ptr<LocalDeviceInfoProviderMock> local_device_;
436 }; 436 };
437 437
438 // Test that the SyncSessionManager can properly fill in a SessionHeader. 438 // Test that the SyncSessionManager can properly fill in a SessionHeader.
439 TEST_F(SessionsSyncManagerTest, PopulateSessionHeader) { 439 TEST_F(SessionsSyncManagerTest, PopulateSessionHeader) {
440 sync_pb::SessionHeader header_s; 440 sync_pb::SessionHeader header_s;
441 header_s.set_client_name("Client 1"); 441 header_s.set_client_name("Client 1");
442 header_s.set_device_type(sync_pb::SyncEnums_DeviceType_TYPE_WIN); 442 header_s.set_device_type(sync_pb::SyncEnums_DeviceType_TYPE_WIN);
443 443
444 SyncedSession session; 444 SyncedSession session;
445 base::Time time = base::Time::Now(); 445 base::Time time = base::Time::Now();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 bool IsInitialBlankNavigation() const override { 481 bool IsInitialBlankNavigation() const override {
482 // This differs from NavigationControllerImpl, which has an initial blank 482 // This differs from NavigationControllerImpl, which has an initial blank
483 // NavigationEntry. 483 // NavigationEntry.
484 return GetEntryCount() == 0; 484 return GetEntryCount() == 0;
485 } 485 }
486 int GetCurrentEntryIndex() const override { return current_entry_index_; } 486 int GetCurrentEntryIndex() const override { return current_entry_index_; }
487 void set_current_entry_index(int i) { 487 void set_current_entry_index(int i) {
488 current_entry_index_ = i; 488 current_entry_index_ = i;
489 } 489 }
490 490
491 void AppendEntry(scoped_ptr<content::NavigationEntry> entry) { 491 void AppendEntry(std::unique_ptr<content::NavigationEntry> entry) {
492 entries_.push_back(std::move(entry)); 492 entries_.push_back(std::move(entry));
493 } 493 }
494 494
495 GURL GetVirtualURLAtIndex(int i) const override { 495 GURL GetVirtualURLAtIndex(int i) const override {
496 if (static_cast<size_t>(i) >= entries_.size()) 496 if (static_cast<size_t>(i) >= entries_.size())
497 return GURL(); 497 return GURL();
498 return entries_[i]->GetVirtualURL(); 498 return entries_[i]->GetVirtualURL();
499 } 499 }
500 500
501 GURL GetFaviconURLAtIndex(int i) const override { return GURL(); } 501 GURL GetFaviconURLAtIndex(int i) const override { return GURL(); }
(...skipping 28 matching lines...) Expand all
530 std::string GetExtensionAppId() const override { return std::string(); } 530 std::string GetExtensionAppId() const override { return std::string(); }
531 bool ProfileIsSupervised() const override { return is_supervised_; } 531 bool ProfileIsSupervised() const override { return is_supervised_; }
532 void set_is_supervised(bool is_supervised) { is_supervised_ = is_supervised; } 532 void set_is_supervised(bool is_supervised) { is_supervised_ = is_supervised; }
533 const std::vector<const sessions::SerializedNavigationEntry*>* 533 const std::vector<const sessions::SerializedNavigationEntry*>*
534 GetBlockedNavigations() const override { 534 GetBlockedNavigations() const override {
535 return &blocked_navigations_.get(); 535 return &blocked_navigations_.get();
536 } 536 }
537 void set_blocked_navigations( 537 void set_blocked_navigations(
538 std::vector<const content::NavigationEntry*>* navs) { 538 std::vector<const content::NavigationEntry*>* navs) {
539 for (auto* entry : *navs) { 539 for (auto* entry : *navs) {
540 scoped_ptr<sessions::SerializedNavigationEntry> serialized_entry( 540 std::unique_ptr<sessions::SerializedNavigationEntry> serialized_entry(
541 new sessions::SerializedNavigationEntry()); 541 new sessions::SerializedNavigationEntry());
542 *serialized_entry = 542 *serialized_entry =
543 sessions::ContentSerializedNavigationBuilder::FromNavigationEntry( 543 sessions::ContentSerializedNavigationBuilder::FromNavigationEntry(
544 blocked_navigations_.size(), *entry); 544 blocked_navigations_.size(), *entry);
545 blocked_navigations_.push_back(serialized_entry.release()); 545 blocked_navigations_.push_back(serialized_entry.release());
546 } 546 }
547 } 547 }
548 bool IsPlaceholderTab() const override { return true; } 548 bool IsPlaceholderTab() const override { return true; }
549 549
550 // Session sync related methods. 550 // Session sync related methods.
(...skipping 30 matching lines...) Expand all
581 static const base::Time kTime7 = base::Time::FromInternalValue(170); 581 static const base::Time kTime7 = base::Time::FromInternalValue(170);
582 static const base::Time kTime8 = base::Time::FromInternalValue(180); 582 static const base::Time kTime8 = base::Time::FromInternalValue(180);
583 static const base::Time kTime9 = base::Time::FromInternalValue(190); 583 static const base::Time kTime9 = base::Time::FromInternalValue(190);
584 584
585 // Populate the mock tab delegate with some data and navigation 585 // Populate the mock tab delegate with some data and navigation
586 // entries and make sure that setting a SessionTab from it preserves 586 // entries and make sure that setting a SessionTab from it preserves
587 // those entries (and clobbers any existing data). 587 // those entries (and clobbers any existing data).
588 TEST_F(SessionsSyncManagerTest, SetSessionTabFromDelegate) { 588 TEST_F(SessionsSyncManagerTest, SetSessionTabFromDelegate) {
589 // Create a tab with three valid entries. 589 // Create a tab with three valid entries.
590 SyncedTabDelegateFake tab; 590 SyncedTabDelegateFake tab;
591 scoped_ptr<content::NavigationEntry> entry1( 591 std::unique_ptr<content::NavigationEntry> entry1(
592 content::NavigationEntry::Create()); 592 content::NavigationEntry::Create());
593 GURL url1("http://www.google.com/"); 593 GURL url1("http://www.google.com/");
594 entry1->SetVirtualURL(url1); 594 entry1->SetVirtualURL(url1);
595 entry1->SetTimestamp(kTime1); 595 entry1->SetTimestamp(kTime1);
596 entry1->SetHttpStatusCode(200); 596 entry1->SetHttpStatusCode(200);
597 scoped_ptr<content::NavigationEntry> entry2( 597 std::unique_ptr<content::NavigationEntry> entry2(
598 content::NavigationEntry::Create()); 598 content::NavigationEntry::Create());
599 GURL url2("http://www.noodle.com/"); 599 GURL url2("http://www.noodle.com/");
600 entry2->SetVirtualURL(url2); 600 entry2->SetVirtualURL(url2);
601 entry2->SetTimestamp(kTime2); 601 entry2->SetTimestamp(kTime2);
602 entry2->SetHttpStatusCode(201); 602 entry2->SetHttpStatusCode(201);
603 scoped_ptr<content::NavigationEntry> entry3( 603 std::unique_ptr<content::NavigationEntry> entry3(
604 content::NavigationEntry::Create()); 604 content::NavigationEntry::Create());
605 GURL url3("http://www.doodle.com/"); 605 GURL url3("http://www.doodle.com/");
606 entry3->SetVirtualURL(url3); 606 entry3->SetVirtualURL(url3);
607 entry3->SetTimestamp(kTime3); 607 entry3->SetTimestamp(kTime3);
608 entry3->SetHttpStatusCode(202); 608 entry3->SetHttpStatusCode(202);
609 609
610 tab.AppendEntry(std::move(entry1)); 610 tab.AppendEntry(std::move(entry1));
611 tab.AppendEntry(std::move(entry2)); 611 tab.AppendEntry(std::move(entry2));
612 tab.AppendEntry(std::move(entry3)); 612 tab.AppendEntry(std::move(entry3));
613 tab.set_current_entry_index(2); 613 tab.set_current_entry_index(2);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
651 session_tab.navigations[1].blocked_state()); 651 session_tab.navigations[1].blocked_state());
652 EXPECT_EQ(SerializedNavigationEntry::STATE_INVALID, 652 EXPECT_EQ(SerializedNavigationEntry::STATE_INVALID,
653 session_tab.navigations[2].blocked_state()); 653 session_tab.navigations[2].blocked_state());
654 EXPECT_TRUE(session_tab.session_storage_persistent_id.empty()); 654 EXPECT_TRUE(session_tab.session_storage_persistent_id.empty());
655 } 655 }
656 656
657 // Ensure the current_navigation_index gets set properly when the navigation 657 // Ensure the current_navigation_index gets set properly when the navigation
658 // stack gets trucated to +/- 6 entries. 658 // stack gets trucated to +/- 6 entries.
659 TEST_F(SessionsSyncManagerTest, SetSessionTabFromDelegateNavigationIndex) { 659 TEST_F(SessionsSyncManagerTest, SetSessionTabFromDelegateNavigationIndex) {
660 SyncedTabDelegateFake tab; 660 SyncedTabDelegateFake tab;
661 scoped_ptr<content::NavigationEntry> entry0( 661 std::unique_ptr<content::NavigationEntry> entry0(
662 content::NavigationEntry::Create()); 662 content::NavigationEntry::Create());
663 GURL url0("http://www.google.com/"); 663 GURL url0("http://www.google.com/");
664 entry0->SetVirtualURL(url0); 664 entry0->SetVirtualURL(url0);
665 entry0->SetTimestamp(kTime0); 665 entry0->SetTimestamp(kTime0);
666 entry0->SetHttpStatusCode(200); 666 entry0->SetHttpStatusCode(200);
667 scoped_ptr<content::NavigationEntry> entry1( 667 std::unique_ptr<content::NavigationEntry> entry1(
668 content::NavigationEntry::Create()); 668 content::NavigationEntry::Create());
669 GURL url1("http://www.zoogle.com/"); 669 GURL url1("http://www.zoogle.com/");
670 entry1->SetVirtualURL(url1); 670 entry1->SetVirtualURL(url1);
671 entry1->SetTimestamp(kTime1); 671 entry1->SetTimestamp(kTime1);
672 entry1->SetHttpStatusCode(200); 672 entry1->SetHttpStatusCode(200);
673 scoped_ptr<content::NavigationEntry> entry2( 673 std::unique_ptr<content::NavigationEntry> entry2(
674 content::NavigationEntry::Create()); 674 content::NavigationEntry::Create());
675 GURL url2("http://www.noogle.com/"); 675 GURL url2("http://www.noogle.com/");
676 entry2->SetVirtualURL(url2); 676 entry2->SetVirtualURL(url2);
677 entry2->SetTimestamp(kTime2); 677 entry2->SetTimestamp(kTime2);
678 entry2->SetHttpStatusCode(200); 678 entry2->SetHttpStatusCode(200);
679 scoped_ptr<content::NavigationEntry> entry3( 679 std::unique_ptr<content::NavigationEntry> entry3(
680 content::NavigationEntry::Create()); 680 content::NavigationEntry::Create());
681 GURL url3("http://www.doogle.com/"); 681 GURL url3("http://www.doogle.com/");
682 entry3->SetVirtualURL(url3); 682 entry3->SetVirtualURL(url3);
683 entry3->SetTimestamp(kTime3); 683 entry3->SetTimestamp(kTime3);
684 entry3->SetHttpStatusCode(200); 684 entry3->SetHttpStatusCode(200);
685 scoped_ptr<content::NavigationEntry> entry4( 685 std::unique_ptr<content::NavigationEntry> entry4(
686 content::NavigationEntry::Create()); 686 content::NavigationEntry::Create());
687 GURL url4("http://www.yoogle.com/"); 687 GURL url4("http://www.yoogle.com/");
688 entry4->SetVirtualURL(url4); 688 entry4->SetVirtualURL(url4);
689 entry4->SetTimestamp(kTime4); 689 entry4->SetTimestamp(kTime4);
690 entry4->SetHttpStatusCode(200); 690 entry4->SetHttpStatusCode(200);
691 scoped_ptr<content::NavigationEntry> entry5( 691 std::unique_ptr<content::NavigationEntry> entry5(
692 content::NavigationEntry::Create()); 692 content::NavigationEntry::Create());
693 GURL url5("http://www.foogle.com/"); 693 GURL url5("http://www.foogle.com/");
694 entry5->SetVirtualURL(url5); 694 entry5->SetVirtualURL(url5);
695 entry5->SetTimestamp(kTime5); 695 entry5->SetTimestamp(kTime5);
696 entry5->SetHttpStatusCode(200); 696 entry5->SetHttpStatusCode(200);
697 scoped_ptr<content::NavigationEntry> entry6( 697 std::unique_ptr<content::NavigationEntry> entry6(
698 content::NavigationEntry::Create()); 698 content::NavigationEntry::Create());
699 GURL url6("http://www.boogle.com/"); 699 GURL url6("http://www.boogle.com/");
700 entry6->SetVirtualURL(url6); 700 entry6->SetVirtualURL(url6);
701 entry6->SetTimestamp(kTime6); 701 entry6->SetTimestamp(kTime6);
702 entry6->SetHttpStatusCode(200); 702 entry6->SetHttpStatusCode(200);
703 scoped_ptr<content::NavigationEntry> entry7( 703 std::unique_ptr<content::NavigationEntry> entry7(
704 content::NavigationEntry::Create()); 704 content::NavigationEntry::Create());
705 GURL url7("http://www.moogle.com/"); 705 GURL url7("http://www.moogle.com/");
706 entry7->SetVirtualURL(url7); 706 entry7->SetVirtualURL(url7);
707 entry7->SetTimestamp(kTime7); 707 entry7->SetTimestamp(kTime7);
708 entry7->SetHttpStatusCode(200); 708 entry7->SetHttpStatusCode(200);
709 scoped_ptr<content::NavigationEntry> entry8( 709 std::unique_ptr<content::NavigationEntry> entry8(
710 content::NavigationEntry::Create()); 710 content::NavigationEntry::Create());
711 GURL url8("http://www.poogle.com/"); 711 GURL url8("http://www.poogle.com/");
712 entry8->SetVirtualURL(url8); 712 entry8->SetVirtualURL(url8);
713 entry8->SetTimestamp(kTime8); 713 entry8->SetTimestamp(kTime8);
714 entry8->SetHttpStatusCode(200); 714 entry8->SetHttpStatusCode(200);
715 scoped_ptr<content::NavigationEntry> entry9( 715 std::unique_ptr<content::NavigationEntry> entry9(
716 content::NavigationEntry::Create()); 716 content::NavigationEntry::Create());
717 GURL url9("http://www.roogle.com/"); 717 GURL url9("http://www.roogle.com/");
718 entry9->SetVirtualURL(url9); 718 entry9->SetVirtualURL(url9);
719 entry9->SetTimestamp(kTime9); 719 entry9->SetTimestamp(kTime9);
720 entry9->SetHttpStatusCode(200); 720 entry9->SetHttpStatusCode(200);
721 721
722 tab.AppendEntry(std::move(entry0)); 722 tab.AppendEntry(std::move(entry0));
723 tab.AppendEntry(std::move(entry1)); 723 tab.AppendEntry(std::move(entry1));
724 tab.AppendEntry(std::move(entry2)); 724 tab.AppendEntry(std::move(entry2));
725 tab.AppendEntry(std::move(entry3)); 725 tab.AppendEntry(std::move(entry3));
(...skipping 12 matching lines...) Expand all
738 ASSERT_EQ(8u, session_tab.navigations.size()); 738 ASSERT_EQ(8u, session_tab.navigations.size());
739 EXPECT_EQ(url2, session_tab.navigations[0].virtual_url()); 739 EXPECT_EQ(url2, session_tab.navigations[0].virtual_url());
740 EXPECT_EQ(url3, session_tab.navigations[1].virtual_url()); 740 EXPECT_EQ(url3, session_tab.navigations[1].virtual_url());
741 EXPECT_EQ(url4, session_tab.navigations[2].virtual_url()); 741 EXPECT_EQ(url4, session_tab.navigations[2].virtual_url());
742 } 742 }
743 743
744 // Ensure the current_navigation_index gets set to the end of the navigation 744 // Ensure the current_navigation_index gets set to the end of the navigation
745 // stack if the current navigation is invalid. 745 // stack if the current navigation is invalid.
746 TEST_F(SessionsSyncManagerTest, SetSessionTabFromDelegateCurrentInvalid) { 746 TEST_F(SessionsSyncManagerTest, SetSessionTabFromDelegateCurrentInvalid) {
747 SyncedTabDelegateFake tab; 747 SyncedTabDelegateFake tab;
748 scoped_ptr<content::NavigationEntry> entry0( 748 std::unique_ptr<content::NavigationEntry> entry0(
749 content::NavigationEntry::Create()); 749 content::NavigationEntry::Create());
750 entry0->SetVirtualURL(GURL("http://www.google.com")); 750 entry0->SetVirtualURL(GURL("http://www.google.com"));
751 entry0->SetTimestamp(kTime0); 751 entry0->SetTimestamp(kTime0);
752 entry0->SetHttpStatusCode(200); 752 entry0->SetHttpStatusCode(200);
753 scoped_ptr<content::NavigationEntry> entry1( 753 std::unique_ptr<content::NavigationEntry> entry1(
754 content::NavigationEntry::Create()); 754 content::NavigationEntry::Create());
755 entry1->SetVirtualURL(GURL("")); 755 entry1->SetVirtualURL(GURL(""));
756 entry1->SetTimestamp(kTime1); 756 entry1->SetTimestamp(kTime1);
757 entry1->SetHttpStatusCode(200); 757 entry1->SetHttpStatusCode(200);
758 scoped_ptr<content::NavigationEntry> entry2( 758 std::unique_ptr<content::NavigationEntry> entry2(
759 content::NavigationEntry::Create()); 759 content::NavigationEntry::Create());
760 entry2->SetVirtualURL(GURL("http://www.noogle.com")); 760 entry2->SetVirtualURL(GURL("http://www.noogle.com"));
761 entry2->SetTimestamp(kTime2); 761 entry2->SetTimestamp(kTime2);
762 entry2->SetHttpStatusCode(200); 762 entry2->SetHttpStatusCode(200);
763 scoped_ptr<content::NavigationEntry> entry3( 763 std::unique_ptr<content::NavigationEntry> entry3(
764 content::NavigationEntry::Create()); 764 content::NavigationEntry::Create());
765 entry3->SetVirtualURL(GURL("http://www.doogle.com")); 765 entry3->SetVirtualURL(GURL("http://www.doogle.com"));
766 entry3->SetTimestamp(kTime3); 766 entry3->SetTimestamp(kTime3);
767 entry3->SetHttpStatusCode(200); 767 entry3->SetHttpStatusCode(200);
768 768
769 tab.AppendEntry(std::move(entry0)); 769 tab.AppendEntry(std::move(entry0));
770 tab.AppendEntry(std::move(entry1)); 770 tab.AppendEntry(std::move(entry1));
771 tab.AppendEntry(std::move(entry2)); 771 tab.AppendEntry(std::move(entry2));
772 tab.AppendEntry(std::move(entry3)); 772 tab.AppendEntry(std::move(entry3));
773 tab.set_current_entry_index(1); 773 tab.set_current_entry_index(1);
(...skipping 26 matching lines...) Expand all
800 800
801 ASSERT_EQ(2u, session_tab.variation_ids.size()); 801 ASSERT_EQ(2u, session_tab.variation_ids.size());
802 EXPECT_EQ(kVariationId1, session_tab.variation_ids[0]); 802 EXPECT_EQ(kVariationId1, session_tab.variation_ids[0]);
803 EXPECT_EQ(kVariationId2, session_tab.variation_ids[1]); 803 EXPECT_EQ(kVariationId2, session_tab.variation_ids[1]);
804 } 804 }
805 805
806 // Tests that for supervised users blocked navigations are recorded and marked 806 // Tests that for supervised users blocked navigations are recorded and marked
807 // as such, while regular navigations are marked as allowed. 807 // as such, while regular navigations are marked as allowed.
808 TEST_F(SessionsSyncManagerTest, BlockedNavigations) { 808 TEST_F(SessionsSyncManagerTest, BlockedNavigations) {
809 SyncedTabDelegateFake tab; 809 SyncedTabDelegateFake tab;
810 scoped_ptr<content::NavigationEntry> entry1( 810 std::unique_ptr<content::NavigationEntry> entry1(
811 content::NavigationEntry::Create()); 811 content::NavigationEntry::Create());
812 GURL url1("http://www.google.com/"); 812 GURL url1("http://www.google.com/");
813 entry1->SetVirtualURL(url1); 813 entry1->SetVirtualURL(url1);
814 entry1->SetTimestamp(kTime1); 814 entry1->SetTimestamp(kTime1);
815 tab.AppendEntry(std::move(entry1)); 815 tab.AppendEntry(std::move(entry1));
816 816
817 scoped_ptr<content::NavigationEntry> entry2( 817 std::unique_ptr<content::NavigationEntry> entry2(
818 content::NavigationEntry::Create()); 818 content::NavigationEntry::Create());
819 GURL url2("http://blocked.com/foo"); 819 GURL url2("http://blocked.com/foo");
820 entry2->SetVirtualURL(url2); 820 entry2->SetVirtualURL(url2);
821 entry2->SetTimestamp(kTime2); 821 entry2->SetTimestamp(kTime2);
822 scoped_ptr<content::NavigationEntry> entry3( 822 std::unique_ptr<content::NavigationEntry> entry3(
823 content::NavigationEntry::Create()); 823 content::NavigationEntry::Create());
824 GURL url3("http://evil.com/"); 824 GURL url3("http://evil.com/");
825 entry3->SetVirtualURL(url3); 825 entry3->SetVirtualURL(url3);
826 entry3->SetTimestamp(kTime3); 826 entry3->SetTimestamp(kTime3);
827 ScopedVector<const content::NavigationEntry> blocked_navigations; 827 ScopedVector<const content::NavigationEntry> blocked_navigations;
828 blocked_navigations.push_back(std::move(entry2)); 828 blocked_navigations.push_back(std::move(entry2));
829 blocked_navigations.push_back(std::move(entry3)); 829 blocked_navigations.push_back(std::move(entry3));
830 830
831 tab.set_is_supervised(true); 831 tab.set_is_supervised(true);
832 tab.set_blocked_navigations(&blocked_navigations.get()); 832 tab.set_blocked_navigations(&blocked_navigations.get());
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
908 data.GetSpecifics(), 908 data.GetSpecifics(),
909 base::Time(), 909 base::Time(),
910 syncer::AttachmentIdList(), 910 syncer::AttachmentIdList(),
911 syncer::AttachmentServiceProxyForTest::Create())); 911 syncer::AttachmentServiceProxyForTest::Create()));
912 syncer::SyncDataList in(&d, &d + 1); 912 syncer::SyncDataList in(&d, &d + 1);
913 out.clear(); 913 out.clear();
914 SessionsSyncManager manager2(GetSyncSessionsClient(), sync_prefs(), 914 SessionsSyncManager manager2(GetSyncSessionsClient(), sync_prefs(),
915 local_device(), NewDummyRouter(), 915 local_device(), NewDummyRouter(),
916 base::Closure(), base::Closure()); 916 base::Closure(), base::Closure());
917 syncer::SyncMergeResult result = manager2.MergeDataAndStartSyncing( 917 syncer::SyncMergeResult result = manager2.MergeDataAndStartSyncing(
918 syncer::SESSIONS, in, 918 syncer::SESSIONS, in, std::unique_ptr<syncer::SyncChangeProcessor>(
919 scoped_ptr<syncer::SyncChangeProcessor>( 919 new TestSyncProcessorStub(&out)),
920 new TestSyncProcessorStub(&out)), 920 std::unique_ptr<syncer::SyncErrorFactory>(
921 scoped_ptr<syncer::SyncErrorFactory>(
922 new syncer::SyncErrorFactoryMock())); 921 new syncer::SyncErrorFactoryMock()));
923 ASSERT_FALSE(result.error().IsSet()); 922 ASSERT_FALSE(result.error().IsSet());
924 923
925 EXPECT_EQ(1U, out.size()); 924 EXPECT_EQ(1U, out.size());
926 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[0].change_type()); 925 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[0].change_type());
927 EXPECT_TRUE(out[0].sync_data().GetSpecifics().session().has_header()); 926 EXPECT_TRUE(out[0].sync_data().GetSpecifics().session().has_header());
928 } 927 }
929 928
930 // Ensure model association associates the pre-existing tabs. 929 // Ensure model association associates the pre-existing tabs.
931 TEST_F(SessionsSyncManagerTest, SwappedOutOnRestore) { 930 TEST_F(SessionsSyncManagerTest, SwappedOutOnRestore) {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
980 ASSERT_EQ(1U, windows.size()); 979 ASSERT_EQ(1U, windows.size());
981 SyncedTabDelegateFake t1_override, t2_override; 980 SyncedTabDelegateFake t1_override, t2_override;
982 t1_override.SetSyncId(1); // No WebContents by default. 981 t1_override.SetSyncId(1); // No WebContents by default.
983 t2_override.SetSyncId(2); // No WebContents by default. 982 t2_override.SetSyncId(2); // No WebContents by default.
984 SyncedWindowDelegateOverride window_override(*windows.begin()); 983 SyncedWindowDelegateOverride window_override(*windows.begin());
985 window_override.OverrideTabAt(1, &t1_override, kNewTabId); 984 window_override.OverrideTabAt(1, &t1_override, kNewTabId);
986 window_override.OverrideTabAt(2, &t2_override, 985 window_override.OverrideTabAt(2, &t2_override,
987 t2.GetSpecifics().session().tab().tab_id()); 986 t2.GetSpecifics().session().tab().tab_id());
988 std::set<const SyncedWindowDelegate*> delegates; 987 std::set<const SyncedWindowDelegate*> delegates;
989 delegates.insert(&window_override); 988 delegates.insert(&window_override);
990 scoped_ptr<TestSyncedWindowDelegatesGetter> getter( 989 std::unique_ptr<TestSyncedWindowDelegatesGetter> getter(
991 new TestSyncedWindowDelegatesGetter(delegates)); 990 new TestSyncedWindowDelegatesGetter(delegates));
992 set_synced_window_getter(getter.get()); 991 set_synced_window_getter(getter.get());
993 992
994 syncer::SyncMergeResult result = manager()->MergeDataAndStartSyncing( 993 syncer::SyncMergeResult result = manager()->MergeDataAndStartSyncing(
995 syncer::SESSIONS, in, 994 syncer::SESSIONS, in, std::unique_ptr<syncer::SyncChangeProcessor>(
996 scoped_ptr<syncer::SyncChangeProcessor>( 995 new TestSyncProcessorStub(&out)),
997 new TestSyncProcessorStub(&out)), 996 std::unique_ptr<syncer::SyncErrorFactory>(
998 scoped_ptr<syncer::SyncErrorFactory>(
999 new syncer::SyncErrorFactoryMock())); 997 new syncer::SyncErrorFactoryMock()));
1000 998
1001 // There should be two changes, one for the fully associated tab, and 999 // There should be two changes, one for the fully associated tab, and
1002 // one for the tab_id update to t1. t2 shouldn't need to be updated. 1000 // one for the tab_id update to t1. t2 shouldn't need to be updated.
1003 ASSERT_EQ(2U, FilterOutLocalHeaderChanges(&out)->size()); 1001 ASSERT_EQ(2U, FilterOutLocalHeaderChanges(&out)->size());
1004 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[0].change_type()); 1002 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[0].change_type());
1005 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[1].change_type()); 1003 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[1].change_type());
1006 EXPECT_EQ(kNewTabId, 1004 EXPECT_EQ(kNewTabId,
1007 out[1].sync_data().GetSpecifics().session().tab().tab_id()); 1005 out[1].sync_data().GetSpecifics().session().tab().tab_id());
1008 1006
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after
1499 entity, 1497 entity,
1500 base::Time(), 1498 base::Time(),
1501 syncer::AttachmentIdList(), 1499 syncer::AttachmentIdList(),
1502 syncer::AttachmentServiceProxyForTest::Create())); 1500 syncer::AttachmentServiceProxyForTest::Create()));
1503 syncer::SyncDataList in(&d, &d + 1); 1501 syncer::SyncDataList in(&d, &d + 1);
1504 changes.clear(); 1502 changes.clear();
1505 SessionsSyncManager manager2(GetSyncSessionsClient(), sync_prefs(), 1503 SessionsSyncManager manager2(GetSyncSessionsClient(), sync_prefs(),
1506 local_device(), NewDummyRouter(), 1504 local_device(), NewDummyRouter(),
1507 base::Closure(), base::Closure()); 1505 base::Closure(), base::Closure());
1508 syncer::SyncMergeResult result = manager2.MergeDataAndStartSyncing( 1506 syncer::SyncMergeResult result = manager2.MergeDataAndStartSyncing(
1509 syncer::SESSIONS, in, 1507 syncer::SESSIONS, in, std::unique_ptr<syncer::SyncChangeProcessor>(
1510 scoped_ptr<syncer::SyncChangeProcessor>( 1508 new TestSyncProcessorStub(&changes)),
1511 new TestSyncProcessorStub(&changes)), 1509 std::unique_ptr<syncer::SyncErrorFactory>(
1512 scoped_ptr<syncer::SyncErrorFactory>(
1513 new syncer::SyncErrorFactoryMock())); 1510 new syncer::SyncErrorFactoryMock()));
1514 ASSERT_FALSE(result.error().IsSet()); 1511 ASSERT_FALSE(result.error().IsSet());
1515 EXPECT_TRUE(FilterOutLocalHeaderChanges(&changes)->empty()); 1512 EXPECT_TRUE(FilterOutLocalHeaderChanges(&changes)->empty());
1516 } 1513 }
1517 1514
1518 TEST_F(SessionsSyncManagerTest, MergeDeletesCorruptNode) { 1515 TEST_F(SessionsSyncManagerTest, MergeDeletesCorruptNode) {
1519 syncer::SyncChangeList changes; 1516 syncer::SyncChangeList changes;
1520 InitWithNoSyncData(); 1517 InitWithNoSyncData();
1521 1518
1522 std::string local_tag = manager()->current_machine_tag(); 1519 std::string local_tag = manager()->current_machine_tag();
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after
1955 TEST_F(SessionsSyncManagerTest, CheckPrerenderedWebContentsSwap) { 1952 TEST_F(SessionsSyncManagerTest, CheckPrerenderedWebContentsSwap) {
1956 AddTab(browser(), GURL("http://foo1")); 1953 AddTab(browser(), GURL("http://foo1"));
1957 NavigateAndCommitActiveTab(GURL("http://foo2")); 1954 NavigateAndCommitActiveTab(GURL("http://foo2"));
1958 1955
1959 syncer::SyncChangeList out; 1956 syncer::SyncChangeList out;
1960 InitWithSyncDataTakeOutput(syncer::SyncDataList(), &out); 1957 InitWithSyncDataTakeOutput(syncer::SyncDataList(), &out);
1961 ASSERT_EQ(4U, out.size()); // Header, tab ADD, tab UPDATE, header UPDATE. 1958 ASSERT_EQ(4U, out.size()); // Header, tab ADD, tab UPDATE, header UPDATE.
1962 1959
1963 // To simulate WebContents swap during prerendering, create new WebContents 1960 // To simulate WebContents swap during prerendering, create new WebContents
1964 // and swap with old WebContents. 1961 // and swap with old WebContents.
1965 scoped_ptr<content::WebContents> old_web_contents; 1962 std::unique_ptr<content::WebContents> old_web_contents;
1966 old_web_contents.reset(browser()->tab_strip_model()->GetActiveWebContents()); 1963 old_web_contents.reset(browser()->tab_strip_model()->GetActiveWebContents());
1967 1964
1968 // Create new WebContents, with the required tab helpers. 1965 // Create new WebContents, with the required tab helpers.
1969 WebContents* new_web_contents = WebContents::CreateWithSessionStorage( 1966 WebContents* new_web_contents = WebContents::CreateWithSessionStorage(
1970 WebContents::CreateParams(profile()), 1967 WebContents::CreateParams(profile()),
1971 old_web_contents->GetController().GetSessionStorageNamespaceMap()); 1968 old_web_contents->GetController().GetSessionStorageNamespaceMap());
1972 SessionTabHelper::CreateForWebContents(new_web_contents); 1969 SessionTabHelper::CreateForWebContents(new_web_contents);
1973 TabContentsSyncedTabDelegate::CreateForWebContents(new_web_contents); 1970 TabContentsSyncedTabDelegate::CreateForWebContents(new_web_contents);
1974 new_web_contents->GetController() 1971 new_web_contents->GetController()
1975 .CopyStateFrom(old_web_contents->GetController()); 1972 .CopyStateFrom(old_web_contents->GetController());
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
2316 base::Time last_time; 2313 base::Time last_time;
2317 for (size_t i = 0; i < tabs.size(); ++i) { 2314 for (size_t i = 0; i < tabs.size(); ++i) {
2318 base::Time this_time = tabs[i]->timestamp; 2315 base::Time this_time = tabs[i]->timestamp;
2319 if (i > 0) 2316 if (i > 0)
2320 ASSERT_GE(last_time, this_time); 2317 ASSERT_GE(last_time, this_time);
2321 last_time = tabs[i]->timestamp; 2318 last_time = tabs[i]->timestamp;
2322 } 2319 }
2323 } 2320 }
2324 2321
2325 } // namespace browser_sync 2322 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698