OLD | NEW |
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 <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 30 matching lines...) Expand all Loading... |
41 using syncer::DeviceInfo; | 41 using syncer::DeviceInfo; |
42 using syncer::LocalDeviceInfoProvider; | 42 using syncer::LocalDeviceInfoProvider; |
43 using syncer::LocalDeviceInfoProviderMock; | 43 using syncer::LocalDeviceInfoProviderMock; |
44 using syncer::SyncChange; | 44 using syncer::SyncChange; |
45 using syncer::SyncData; | 45 using syncer::SyncData; |
46 | 46 |
47 namespace sync_sessions { | 47 namespace sync_sessions { |
48 | 48 |
49 namespace { | 49 namespace { |
50 | 50 |
51 const char kFoo1[] = "http://foo1/"; | |
52 const char kFoo2[] = "http://foo2/"; | |
53 const char kBar1[] = "http://bar1/"; | |
54 const char kBar2[] = "http://bar2/"; | |
55 const char kBaz1[] = "http://baz1/"; | |
56 const char kBaz2[] = "http://baz2/"; | |
57 | |
58 std::string TabNodeIdToTag(const std::string& machine_tag, int tab_node_id) { | |
59 return base::StringPrintf("%s %d", machine_tag.c_str(), tab_node_id); | |
60 } | |
61 | |
62 class SessionNotificationObserver { | 51 class SessionNotificationObserver { |
63 public: | 52 public: |
64 SessionNotificationObserver() | 53 SessionNotificationObserver() |
65 : notified_of_update_(false), notified_of_refresh_(false) {} | 54 : notified_of_update_(false), notified_of_refresh_(false) {} |
66 void NotifyOfUpdate() { notified_of_update_ = true; } | 55 void NotifyOfUpdate() { notified_of_update_ = true; } |
67 void NotifyOfRefresh() { notified_of_refresh_ = true; } | 56 void NotifyOfRefresh() { notified_of_refresh_ = true; } |
68 | 57 |
69 bool notified_of_update() const { return notified_of_update_; } | 58 bool notified_of_update() const { return notified_of_update_; } |
70 bool notified_of_refresh() const { return notified_of_refresh_; } | 59 bool notified_of_refresh() const { return notified_of_refresh_; } |
71 | 60 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 bool IsSessionRestoreInProgress() const override { | 121 bool IsSessionRestoreInProgress() const override { |
133 return wrapped_->IsSessionRestoreInProgress(); | 122 return wrapped_->IsSessionRestoreInProgress(); |
134 } | 123 } |
135 | 124 |
136 bool ShouldSync() const override { return wrapped_->ShouldSync(); } | 125 bool ShouldSync() const override { return wrapped_->ShouldSync(); } |
137 | 126 |
138 private: | 127 private: |
139 std::map<int, SyncedTabDelegate*> tab_overrides_; | 128 std::map<int, SyncedTabDelegate*> tab_overrides_; |
140 std::map<int, SessionID::id_type> tab_id_overrides_; | 129 std::map<int, SessionID::id_type> tab_id_overrides_; |
141 const SyncedWindowDelegate* const wrapped_; | 130 const SyncedWindowDelegate* const wrapped_; |
142 SessionID::id_type session_id_override_ = TabNodePool::kInvalidTabID; | 131 SessionID::id_type session_id_override_ = -1; |
143 }; | 132 }; |
144 | 133 |
145 class TestSyncedWindowDelegatesGetter : public SyncedWindowDelegatesGetter { | 134 class TestSyncedWindowDelegatesGetter : public SyncedWindowDelegatesGetter { |
146 public: | 135 public: |
147 TestSyncedWindowDelegatesGetter( | 136 TestSyncedWindowDelegatesGetter( |
148 const std::set<const SyncedWindowDelegate*>& delegates) | 137 const std::set<const SyncedWindowDelegate*>& delegates) |
149 : delegates_(delegates) {} | 138 : delegates_(delegates) {} |
150 | 139 |
151 std::set<const SyncedWindowDelegate*> GetSyncedWindowDelegates() override { | 140 std::set<const SyncedWindowDelegate*> GetSyncedWindowDelegates() override { |
152 return delegates_; | 141 return delegates_; |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 } | 392 } |
404 } | 393 } |
405 EXPECT_TRUE(found); | 394 EXPECT_TRUE(found); |
406 return list; | 395 return list; |
407 } | 396 } |
408 | 397 |
409 SyncSessionsClient* GetSyncSessionsClient() { | 398 SyncSessionsClient* GetSyncSessionsClient() { |
410 return sessions_client_shim_.get(); | 399 return sessions_client_shim_.get(); |
411 } | 400 } |
412 | 401 |
413 TabNodePool* GetTabPool() { | |
414 return &manager()->session_tracker_.local_tab_pool_; | |
415 } | |
416 | |
417 syncer::SyncPrefs* sync_prefs() { return sync_prefs_.get(); } | 402 syncer::SyncPrefs* sync_prefs() { return sync_prefs_.get(); } |
418 | 403 |
419 SyncedWindowDelegatesGetter* get_synced_window_getter() { | 404 SyncedWindowDelegatesGetter* get_synced_window_getter() { |
420 return manager()->synced_window_delegates_getter(); | 405 return manager()->synced_window_delegates_getter(); |
421 } | 406 } |
422 | 407 |
423 void set_synced_window_getter( | 408 void set_synced_window_getter( |
424 SyncedWindowDelegatesGetter* synced_window_getter) { | 409 SyncedWindowDelegatesGetter* synced_window_getter) { |
425 sessions_client_shim_->set_synced_window_getter(synced_window_getter); | 410 sessions_client_shim_->set_synced_window_getter(synced_window_getter); |
426 } | 411 } |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 ASSERT_EQ(1U, session->windows[0]->tabs.size()); | 495 ASSERT_EQ(1U, session->windows[0]->tabs.size()); |
511 ASSERT_EQ(1, session->windows[0]->selected_tab_index); | 496 ASSERT_EQ(1, session->windows[0]->selected_tab_index); |
512 ASSERT_EQ(sessions::SessionWindow::TYPE_TABBED, session->windows[0]->type); | 497 ASSERT_EQ(sessions::SessionWindow::TYPE_TABBED, session->windows[0]->type); |
513 ASSERT_EQ(1U, manager()->session_tracker_.num_synced_sessions()); | 498 ASSERT_EQ(1U, manager()->session_tracker_.num_synced_sessions()); |
514 ASSERT_EQ(1U, | 499 ASSERT_EQ(1U, |
515 manager()->session_tracker_.num_synced_tabs(std::string("tag"))); | 500 manager()->session_tracker_.num_synced_tabs(std::string("tag"))); |
516 } | 501 } |
517 | 502 |
518 namespace { | 503 namespace { |
519 | 504 |
520 // A SyncedTabDelegate fake for testing. It simulates a normal | |
521 // SyncedTabDelegate with a proper WebContents. For a SyncedTabDelegate without | |
522 // a WebContents, see PlaceholderTabDelegate below. | |
523 class SyncedTabDelegateFake : public SyncedTabDelegate { | 505 class SyncedTabDelegateFake : public SyncedTabDelegate { |
524 public: | 506 public: |
525 SyncedTabDelegateFake() {} | 507 SyncedTabDelegateFake() |
| 508 : current_entry_index_(0), is_supervised_(false), sync_id_(-1) {} |
526 ~SyncedTabDelegateFake() override {} | 509 ~SyncedTabDelegateFake() override {} |
527 | 510 |
528 // SyncedTabDelegate overrides. | |
529 bool IsInitialBlankNavigation() const override { | 511 bool IsInitialBlankNavigation() const override { |
530 // This differs from NavigationControllerImpl, which has an initial blank | 512 // This differs from NavigationControllerImpl, which has an initial blank |
531 // NavigationEntry. | 513 // NavigationEntry. |
532 return GetEntryCount() == 0; | 514 return GetEntryCount() == 0; |
533 } | 515 } |
534 int GetCurrentEntryIndex() const override { return current_entry_index_; } | 516 int GetCurrentEntryIndex() const override { return current_entry_index_; } |
| 517 void set_current_entry_index(int i) { |
| 518 current_entry_index_ = i; |
| 519 } |
| 520 |
| 521 void AppendEntry(std::unique_ptr<content::NavigationEntry> entry) { |
| 522 entries_.push_back(std::move(entry)); |
| 523 } |
| 524 |
535 GURL GetVirtualURLAtIndex(int i) const override { | 525 GURL GetVirtualURLAtIndex(int i) const override { |
536 if (static_cast<size_t>(i) >= entries_.size()) | 526 if (static_cast<size_t>(i) >= entries_.size()) |
537 return GURL(); | 527 return GURL(); |
538 return entries_[i]->GetVirtualURL(); | 528 return entries_[i]->GetVirtualURL(); |
539 } | 529 } |
| 530 |
540 GURL GetFaviconURLAtIndex(int i) const override { return GURL(); } | 531 GURL GetFaviconURLAtIndex(int i) const override { return GURL(); } |
| 532 |
541 ui::PageTransition GetTransitionAtIndex(int i) const override { | 533 ui::PageTransition GetTransitionAtIndex(int i) const override { |
542 if (static_cast<size_t>(i) >= entries_.size()) | 534 if (static_cast<size_t>(i) >= entries_.size()) |
543 return ui::PAGE_TRANSITION_LINK; | 535 return ui::PAGE_TRANSITION_LINK; |
544 return entries_[i]->GetTransitionType(); | 536 return entries_[i]->GetTransitionType(); |
545 } | 537 } |
| 538 |
546 void GetSerializedNavigationAtIndex( | 539 void GetSerializedNavigationAtIndex( |
547 int i, | 540 int i, |
548 sessions::SerializedNavigationEntry* serialized_entry) const override { | 541 sessions::SerializedNavigationEntry* serialized_entry) const override { |
549 if (static_cast<size_t>(i) >= entries_.size()) | 542 if (static_cast<size_t>(i) >= entries_.size()) |
550 return; | 543 return; |
551 *serialized_entry = | 544 *serialized_entry = |
552 sessions::ContentSerializedNavigationBuilder::FromNavigationEntry( | 545 sessions::ContentSerializedNavigationBuilder::FromNavigationEntry( |
553 i, *entries_[i]); | 546 i, *entries_[i]); |
554 } | 547 } |
| 548 |
555 int GetEntryCount() const override { return entries_.size(); } | 549 int GetEntryCount() const override { return entries_.size(); } |
556 SessionID::id_type GetWindowId() const override { return window_id_; } | 550 |
557 SessionID::id_type GetSessionId() const override { return tab_id_; } | 551 SessionID::id_type GetWindowId() const override { |
| 552 return SessionID::id_type(); |
| 553 } |
| 554 |
| 555 SessionID::id_type GetSessionId() const override { |
| 556 return SessionID::id_type(); |
| 557 } |
| 558 |
558 bool IsBeingDestroyed() const override { return false; } | 559 bool IsBeingDestroyed() const override { return false; } |
559 std::string GetExtensionAppId() const override { return std::string(); } | 560 std::string GetExtensionAppId() const override { return std::string(); } |
560 bool ProfileIsSupervised() const override { return is_supervised_; } | 561 bool ProfileIsSupervised() const override { return is_supervised_; } |
561 void set_is_supervised(bool is_supervised) { is_supervised_ = is_supervised; } | 562 void set_is_supervised(bool is_supervised) { is_supervised_ = is_supervised; } |
562 const std::vector<std::unique_ptr<const sessions::SerializedNavigationEntry>>* | 563 const std::vector<std::unique_ptr<const sessions::SerializedNavigationEntry>>* |
563 GetBlockedNavigations() const override { | 564 GetBlockedNavigations() const override { |
564 return &blocked_navigations_; | 565 return &blocked_navigations_; |
565 } | 566 } |
566 bool IsPlaceholderTab() const override { return false; } | |
567 int GetSyncId() const override { return sync_id_; } | |
568 void SetSyncId(int sync_id) override { sync_id_ = sync_id; } | |
569 bool ShouldSync(SyncSessionsClient* sessions_client) override { | |
570 return false; | |
571 } | |
572 | |
573 void AppendEntry(std::unique_ptr<content::NavigationEntry> entry) { | |
574 entries_.push_back(std::move(entry)); | |
575 } | |
576 | |
577 void set_current_entry_index(int i) { current_entry_index_ = i; } | |
578 | |
579 void SetWindowId(SessionID::id_type window_id) { window_id_ = window_id; } | |
580 | |
581 void SetSessionId(SessionID::id_type id) { tab_id_ = id; } | |
582 | |
583 void set_blocked_navigations( | 567 void set_blocked_navigations( |
584 std::vector<const content::NavigationEntry*>* navs) { | 568 std::vector<const content::NavigationEntry*>* navs) { |
585 for (auto* entry : *navs) { | 569 for (auto* entry : *navs) { |
586 auto serialized_entry = | 570 auto serialized_entry = |
587 base::MakeUnique<sessions::SerializedNavigationEntry>( | 571 base::MakeUnique<sessions::SerializedNavigationEntry>( |
588 sessions::ContentSerializedNavigationBuilder::FromNavigationEntry( | 572 sessions::ContentSerializedNavigationBuilder::FromNavigationEntry( |
589 blocked_navigations_.size(), *entry)); | 573 blocked_navigations_.size(), *entry)); |
590 blocked_navigations_.push_back(std::move(serialized_entry)); | 574 blocked_navigations_.push_back(std::move(serialized_entry)); |
591 } | 575 } |
592 } | 576 } |
| 577 bool IsPlaceholderTab() const override { return true; } |
| 578 |
| 579 // Session sync related methods. |
| 580 int GetSyncId() const override { return sync_id_; } |
| 581 void SetSyncId(int sync_id) override { sync_id_ = sync_id; } |
| 582 |
| 583 bool ShouldSync(SyncSessionsClient* sessions_client) override { |
| 584 return false; |
| 585 } |
593 | 586 |
594 void reset() { | 587 void reset() { |
595 current_entry_index_ = 0; | 588 current_entry_index_ = 0; |
596 sync_id_ = TabNodePool::kInvalidTabNodeID; | 589 sync_id_ = -1; |
597 entries_.clear(); | 590 entries_.clear(); |
598 } | 591 } |
599 | 592 |
600 private: | 593 private: |
601 int current_entry_index_ = 0; | 594 int current_entry_index_; |
602 bool is_supervised_ = false; | 595 bool is_supervised_; |
603 int sync_id_ = -1; | 596 int sync_id_; |
604 SessionID::id_type tab_id_ = 0; | |
605 SessionID::id_type window_id_ = 0; | |
606 std::vector<std::unique_ptr<const sessions::SerializedNavigationEntry>> | 597 std::vector<std::unique_ptr<const sessions::SerializedNavigationEntry>> |
607 blocked_navigations_; | 598 blocked_navigations_; |
608 std::vector<std::unique_ptr<content::NavigationEntry>> entries_; | 599 std::vector<std::unique_ptr<content::NavigationEntry>> entries_; |
609 }; | 600 }; |
610 | 601 |
611 // A placeholder delegate. These delegates have no WebContents, simulating a tab | |
612 // that has been restored without bringing its state fully into memory (for | |
613 // example on Android), or where the tab's contents have been evicted from | |
614 // memory. See SyncedTabDelegate::IsPlaceHolderTab for more info. | |
615 class PlaceholderTabDelegate : public SyncedTabDelegate { | |
616 public: | |
617 PlaceholderTabDelegate(SessionID::id_type session_id, int sync_id) | |
618 : session_id_(session_id), sync_id_(sync_id) {} | |
619 ~PlaceholderTabDelegate() override {} | |
620 | |
621 // SyncedTabDelegate overrides. | |
622 SessionID::id_type GetSessionId() const override { return session_id_; } | |
623 int GetSyncId() const override { return sync_id_; } | |
624 void SetSyncId(int sync_id) override { sync_id_ = sync_id; } | |
625 bool IsPlaceholderTab() const override { return true; } | |
626 | |
627 // Everything else is invalid to invoke as it depends on a valid WebContents. | |
628 SessionID::id_type GetWindowId() const override { | |
629 NOTREACHED(); | |
630 return 0; | |
631 } | |
632 bool IsBeingDestroyed() const override { | |
633 NOTREACHED(); | |
634 return false; | |
635 } | |
636 std::string GetExtensionAppId() const override { | |
637 NOTREACHED(); | |
638 return ""; | |
639 } | |
640 bool IsInitialBlankNavigation() const override { | |
641 NOTREACHED(); | |
642 return false; | |
643 } | |
644 int GetCurrentEntryIndex() const override { | |
645 NOTREACHED(); | |
646 return 0; | |
647 } | |
648 int GetEntryCount() const override { | |
649 NOTREACHED(); | |
650 return 0; | |
651 } | |
652 GURL GetVirtualURLAtIndex(int i) const override { | |
653 NOTREACHED(); | |
654 return GURL(); | |
655 } | |
656 GURL GetFaviconURLAtIndex(int i) const override { | |
657 NOTREACHED(); | |
658 return GURL(); | |
659 } | |
660 ui::PageTransition GetTransitionAtIndex(int i) const override { | |
661 NOTREACHED(); | |
662 return ui::PageTransition(); | |
663 } | |
664 void GetSerializedNavigationAtIndex( | |
665 int i, | |
666 sessions::SerializedNavigationEntry* serialized_entry) const override { | |
667 NOTREACHED(); | |
668 } | |
669 bool ProfileIsSupervised() const override { | |
670 NOTREACHED(); | |
671 return false; | |
672 } | |
673 const std::vector<std::unique_ptr<const sessions::SerializedNavigationEntry>>* | |
674 GetBlockedNavigations() const override { | |
675 NOTREACHED(); | |
676 return nullptr; | |
677 } | |
678 bool ShouldSync(SyncSessionsClient* sessions_client) override { | |
679 NOTREACHED(); | |
680 return false; | |
681 } | |
682 | |
683 private: | |
684 SessionID::id_type session_id_; | |
685 int sync_id_; | |
686 }; | |
687 | |
688 } // namespace | 602 } // namespace |
689 | 603 |
690 static const base::Time kTime0 = base::Time::FromInternalValue(100); | 604 static const base::Time kTime0 = base::Time::FromInternalValue(100); |
691 static const base::Time kTime1 = base::Time::FromInternalValue(110); | 605 static const base::Time kTime1 = base::Time::FromInternalValue(110); |
692 static const base::Time kTime2 = base::Time::FromInternalValue(120); | 606 static const base::Time kTime2 = base::Time::FromInternalValue(120); |
693 static const base::Time kTime3 = base::Time::FromInternalValue(130); | 607 static const base::Time kTime3 = base::Time::FromInternalValue(130); |
694 static const base::Time kTime4 = base::Time::FromInternalValue(140); | 608 static const base::Time kTime4 = base::Time::FromInternalValue(140); |
695 static const base::Time kTime5 = base::Time::FromInternalValue(150); | 609 static const base::Time kTime5 = base::Time::FromInternalValue(150); |
696 static const base::Time kTime6 = base::Time::FromInternalValue(160); | 610 static const base::Time kTime6 = base::Time::FromInternalValue(160); |
697 static const base::Time kTime7 = base::Time::FromInternalValue(170); | 611 static const base::Time kTime7 = base::Time::FromInternalValue(170); |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1032 new syncer::SyncErrorFactoryMock())); | 946 new syncer::SyncErrorFactoryMock())); |
1033 ASSERT_FALSE(result.error().IsSet()); | 947 ASSERT_FALSE(result.error().IsSet()); |
1034 | 948 |
1035 EXPECT_EQ(1U, out.size()); | 949 EXPECT_EQ(1U, out.size()); |
1036 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[0].change_type()); | 950 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[0].change_type()); |
1037 EXPECT_TRUE(out[0].sync_data().GetSpecifics().session().has_header()); | 951 EXPECT_TRUE(out[0].sync_data().GetSpecifics().session().has_header()); |
1038 } | 952 } |
1039 | 953 |
1040 // Ensure model association associates the pre-existing tabs. | 954 // Ensure model association associates the pre-existing tabs. |
1041 TEST_F(SessionsSyncManagerTest, SwappedOutOnRestore) { | 955 TEST_F(SessionsSyncManagerTest, SwappedOutOnRestore) { |
| 956 AddTab(browser(), GURL("http://foo1")); |
| 957 NavigateAndCommitActiveTab(GURL("http://foo2")); |
| 958 AddTab(browser(), GURL("http://bar1")); |
| 959 NavigateAndCommitActiveTab(GURL("http://bar2")); |
| 960 AddTab(browser(), GURL("http://baz1")); |
| 961 NavigateAndCommitActiveTab(GURL("http://baz2")); |
1042 const int kRestoredTabId = 1337; | 962 const int kRestoredTabId = 1337; |
1043 const int kNewTabId = 2468; | 963 const int kNewTabId = 2468; |
1044 | 964 |
1045 // AddTab inserts at index 0, so go in reverse order (tab 3 -> tab 1). | |
1046 AddTab(browser(), GURL(kBaz1)); | |
1047 NavigateAndCommitActiveTab(GURL(kBaz2)); | |
1048 AddTab(browser(), GURL(kBar1)); | |
1049 NavigateAndCommitActiveTab(GURL(kBar2)); | |
1050 AddTab(browser(), GURL(kFoo1)); | |
1051 NavigateAndCommitActiveTab(GURL(kFoo2)); | |
1052 | |
1053 syncer::SyncDataList in; | 965 syncer::SyncDataList in; |
1054 syncer::SyncChangeList out; | 966 syncer::SyncChangeList out; |
1055 InitWithSyncDataTakeOutput(in, &out); | 967 InitWithSyncDataTakeOutput(in, &out); |
1056 | 968 |
1057 // Should be one header add, 3 tab adds, one header update. | 969 // Should be one header add, 3 tab add/update pairs, one header update. |
1058 ASSERT_EQ(5U, out.size()); | 970 ASSERT_EQ(8U, out.size()); |
1059 | 971 |
1060 // For input, we set up: | 972 // For input, we set up: |
1061 // * one "normal" fully loaded tab | 973 // * one "normal" fully loaded tab |
1062 // * one placeholder tab with no WebContents and a tab_id change | 974 // * one "frozen" tab with no WebContents and a tab_id change |
1063 // * one placeholder tab with no WebContents and no tab_id change | 975 // * one "frozen" tab with no WebContents and no tab_id change |
1064 sync_pb::EntitySpecifics t0_entity = out[1].sync_data().GetSpecifics(); | 976 sync_pb::EntitySpecifics t0_entity = out[2].sync_data().GetSpecifics(); |
1065 sync_pb::EntitySpecifics t1_entity = out[2].sync_data().GetSpecifics(); | 977 sync_pb::EntitySpecifics t1_entity = out[4].sync_data().GetSpecifics(); |
1066 sync_pb::EntitySpecifics t2_entity = out[3].sync_data().GetSpecifics(); | 978 sync_pb::EntitySpecifics t2_entity = out[6].sync_data().GetSpecifics(); |
1067 t1_entity.mutable_session()->mutable_tab()->set_tab_id(kRestoredTabId); | 979 t1_entity.mutable_session()->mutable_tab()->set_tab_id(kRestoredTabId); |
1068 in.push_back(CreateRemoteData(t0_entity)); | 980 in.push_back(CreateRemoteData(t0_entity)); |
1069 in.push_back(CreateRemoteData(t1_entity)); | 981 in.push_back(CreateRemoteData(t1_entity)); |
1070 in.push_back(CreateRemoteData(t2_entity)); | 982 in.push_back(CreateRemoteData(t2_entity)); |
1071 out.clear(); | 983 out.clear(); |
1072 manager()->StopSyncing(syncer::SESSIONS); | 984 manager()->StopSyncing(syncer::SESSIONS); |
1073 | 985 |
1074 const std::set<const SyncedWindowDelegate*>& windows = | 986 const std::set<const SyncedWindowDelegate*>& windows = |
1075 manager()->synced_window_delegates_getter()->GetSyncedWindowDelegates(); | 987 manager()->synced_window_delegates_getter()->GetSyncedWindowDelegates(); |
1076 ASSERT_EQ(1U, windows.size()); | 988 ASSERT_EQ(1U, windows.size()); |
1077 PlaceholderTabDelegate t1_override(kNewTabId, 1); | 989 SyncedTabDelegateFake t1_override, t2_override; |
1078 PlaceholderTabDelegate t2_override(t2_entity.session().tab().tab_id(), 2); | 990 t1_override.SetSyncId(1); // No WebContents by default. |
| 991 t2_override.SetSyncId(2); // No WebContents by default. |
1079 SyncedWindowDelegateOverride window_override(*windows.begin()); | 992 SyncedWindowDelegateOverride window_override(*windows.begin()); |
1080 window_override.OverrideTabAt(1, &t1_override, kNewTabId); | 993 window_override.OverrideTabAt(1, &t1_override, kNewTabId); |
1081 window_override.OverrideTabAt(2, &t2_override, | 994 window_override.OverrideTabAt(2, &t2_override, |
1082 t2_entity.session().tab().tab_id()); | 995 t2_entity.session().tab().tab_id()); |
1083 std::set<const SyncedWindowDelegate*> delegates; | 996 std::set<const SyncedWindowDelegate*> delegates; |
1084 delegates.insert(&window_override); | 997 delegates.insert(&window_override); |
1085 std::unique_ptr<TestSyncedWindowDelegatesGetter> getter( | 998 std::unique_ptr<TestSyncedWindowDelegatesGetter> getter( |
1086 new TestSyncedWindowDelegatesGetter(delegates)); | 999 new TestSyncedWindowDelegatesGetter(delegates)); |
1087 set_synced_window_getter(getter.get()); | 1000 set_synced_window_getter(getter.get()); |
1088 | 1001 |
1089 syncer::SyncMergeResult result = manager()->MergeDataAndStartSyncing( | 1002 syncer::SyncMergeResult result = manager()->MergeDataAndStartSyncing( |
1090 syncer::SESSIONS, in, std::unique_ptr<syncer::SyncChangeProcessor>( | 1003 syncer::SESSIONS, in, std::unique_ptr<syncer::SyncChangeProcessor>( |
1091 new TestSyncProcessorStub(&out)), | 1004 new TestSyncProcessorStub(&out)), |
1092 std::unique_ptr<syncer::SyncErrorFactory>( | 1005 std::unique_ptr<syncer::SyncErrorFactory>( |
1093 new syncer::SyncErrorFactoryMock())); | 1006 new syncer::SyncErrorFactoryMock())); |
1094 | 1007 |
1095 // There should be three changes, one for the fully associated tab, and | 1008 // There should be two changes, one for the fully associated tab, and |
1096 // one each for the tab_id updates to t1 and t2. | 1009 // one for the tab_id update to t1. t2 shouldn't need to be updated. |
1097 ASSERT_EQ(3U, FilterOutLocalHeaderChanges(&out)->size()); | 1010 ASSERT_EQ(2U, FilterOutLocalHeaderChanges(&out)->size()); |
1098 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[0].change_type()); | 1011 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[0].change_type()); |
1099 EXPECT_EQ(kFoo2, out[0] | |
1100 .sync_data() | |
1101 .GetSpecifics() | |
1102 .session() | |
1103 .tab() | |
1104 .navigation(1) | |
1105 .virtual_url()); | |
1106 | |
1107 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[1].change_type()); | 1012 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[1].change_type()); |
1108 EXPECT_EQ(kNewTabId, | 1013 EXPECT_EQ(kNewTabId, |
1109 out[1].sync_data().GetSpecifics().session().tab().tab_id()); | 1014 out[1].sync_data().GetSpecifics().session().tab().tab_id()); |
1110 EXPECT_EQ(kBar2, out[1] | |
1111 .sync_data() | |
1112 .GetSpecifics() | |
1113 .session() | |
1114 .tab() | |
1115 .navigation(1) | |
1116 .virtual_url()); | |
1117 | 1015 |
1118 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[2].change_type()); | 1016 // Verify TabLinks. |
1119 EXPECT_EQ(t2_entity.session().tab().tab_id(), | 1017 SessionsSyncManager::TabLinksMap tab_map = manager()->local_tab_map_; |
1120 out[2].sync_data().GetSpecifics().session().tab().tab_id()); | 1018 ASSERT_EQ(3U, tab_map.size()); |
1121 EXPECT_EQ(kBaz2, out[2] | 1019 int t2_tab_id = t2_entity.session().tab().tab_id(); |
1122 .sync_data() | 1020 EXPECT_EQ(2, tab_map.find(t2_tab_id)->second->tab_node_id()); |
1123 .GetSpecifics() | 1021 EXPECT_EQ(1, tab_map.find(kNewTabId)->second->tab_node_id()); |
1124 .session() | 1022 int t0_tab_id = out[0].sync_data().GetSpecifics().session().tab().tab_id(); |
1125 .tab() | 1023 EXPECT_EQ(0, tab_map.find(t0_tab_id)->second->tab_node_id()); |
1126 .navigation(1) | 1024 // TODO(tim): Once bug 337057 is fixed, we can issue an OnLocalTabModified |
1127 .virtual_url()); | 1025 // from here (using an override similar to above) to return a new tab id |
| 1026 // and verify that we don't see any node creations in the SyncChangeProcessor |
| 1027 // (similar to how SessionsSyncManagerTest.OnLocalTabModified works.) |
1128 } | 1028 } |
1129 | 1029 |
1130 // Ensure model association updates the window ID for tabs whose window's ID has | 1030 // Ensure model association updates the window ID for tabs whose window's ID has |
1131 // changed. | 1031 // changed. |
1132 TEST_F(SessionsSyncManagerTest, WindowIdUpdatedOnRestore) { | 1032 TEST_F(SessionsSyncManagerTest, WindowIdUpdatedOnRestore) { |
1133 const int kNewWindowId = 1337; | 1033 const int kNewWindowId = 1337; |
1134 syncer::SyncDataList in; | 1034 syncer::SyncDataList in; |
1135 syncer::SyncChangeList out; | 1035 syncer::SyncChangeList out; |
1136 | 1036 |
1137 // Set up one tab and start sync with it. | 1037 // Set up one tab and start sync with it. |
1138 AddTab(browser(), GURL(kFoo1)); | 1038 AddTab(browser(), GURL("http://foo1")); |
1139 NavigateAndCommitActiveTab(GURL(kFoo2)); | 1039 NavigateAndCommitActiveTab(GURL("http://foo2")); |
1140 InitWithSyncDataTakeOutput(in, &out); | 1040 InitWithSyncDataTakeOutput(in, &out); |
1141 | 1041 |
1142 // Should be one header add, 1 tab add, and one header update. | 1042 // Should be one header add, 1 tab add/update pair, and one header update. |
1143 ASSERT_EQ(3U, out.size()); | 1043 ASSERT_EQ(4U, out.size()); |
1144 const sync_pb::EntitySpecifics t0_entity = out[1].sync_data().GetSpecifics(); | 1044 const sync_pb::EntitySpecifics t0_entity = out[2].sync_data().GetSpecifics(); |
1145 ASSERT_TRUE(t0_entity.session().has_tab()); | |
1146 | 1045 |
1147 in.push_back(CreateRemoteData(t0_entity)); | 1046 in.push_back(CreateRemoteData(t0_entity)); |
1148 out.clear(); | 1047 out.clear(); |
1149 manager()->StopSyncing(syncer::SESSIONS); | 1048 manager()->StopSyncing(syncer::SESSIONS); |
1150 | 1049 |
1151 // Override the tab with a placeholder tab delegate. | 1050 // SyncedTabDelegateFake is a placeholder (no WebContents) by default. |
1152 PlaceholderTabDelegate t0_override(t0_entity.session().tab().tab_id(), | 1051 SyncedTabDelegateFake t0_override; |
1153 t0_entity.session().tab_node_id()); | 1052 t0_override.SetSyncId(t0_entity.session().tab_node_id()); |
1154 | 1053 |
1155 // Set up the window override with the new window ID and placeholder tab. | 1054 // Set up the window override with the new window ID and placeholder tab. |
1156 const std::set<const SyncedWindowDelegate*>& windows = | 1055 const std::set<const SyncedWindowDelegate*>& windows = |
1157 get_synced_window_getter()->GetSyncedWindowDelegates(); | 1056 get_synced_window_getter()->GetSyncedWindowDelegates(); |
1158 ASSERT_EQ(1U, windows.size()); | 1057 ASSERT_EQ(1U, windows.size()); |
1159 SyncedWindowDelegateOverride window_override(*windows.begin()); | 1058 SyncedWindowDelegateOverride window_override(*windows.begin()); |
1160 window_override.OverrideSessionId(kNewWindowId); | 1059 window_override.OverrideSessionId(kNewWindowId); |
1161 window_override.OverrideTabAt(0, &t0_override, | 1060 window_override.OverrideTabAt(0, &t0_override, |
1162 t0_entity.session().tab().tab_id()); | 1061 t0_entity.session().tab().tab_id()); |
1163 | 1062 |
1164 // Inject the window override. | 1063 // Inject the window override. |
1165 std::set<const SyncedWindowDelegate*> delegates; | 1064 std::set<const SyncedWindowDelegate*> delegates; |
1166 delegates.insert(&window_override); | 1065 delegates.insert(&window_override); |
1167 std::unique_ptr<TestSyncedWindowDelegatesGetter> getter( | 1066 std::unique_ptr<TestSyncedWindowDelegatesGetter> getter( |
1168 new TestSyncedWindowDelegatesGetter(delegates)); | 1067 new TestSyncedWindowDelegatesGetter(delegates)); |
1169 set_synced_window_getter(getter.get()); | 1068 set_synced_window_getter(getter.get()); |
1170 | 1069 |
1171 syncer::SyncMergeResult result = manager()->MergeDataAndStartSyncing( | 1070 syncer::SyncMergeResult result = manager()->MergeDataAndStartSyncing( |
1172 syncer::SESSIONS, in, std::unique_ptr<syncer::SyncChangeProcessor>( | 1071 syncer::SESSIONS, in, std::unique_ptr<syncer::SyncChangeProcessor>( |
1173 new TestSyncProcessorStub(&out)), | 1072 new TestSyncProcessorStub(&out)), |
1174 std::unique_ptr<syncer::SyncErrorFactory>( | 1073 std::unique_ptr<syncer::SyncErrorFactory>( |
1175 new syncer::SyncErrorFactoryMock())); | 1074 new syncer::SyncErrorFactoryMock())); |
1176 | 1075 |
1177 // There should be one change for t0's window ID update. | 1076 // There should be one change for t0's window ID update. |
1178 ASSERT_EQ(1U, FilterOutLocalHeaderChanges(&out)->size()); | 1077 ASSERT_EQ(1U, FilterOutLocalHeaderChanges(&out)->size()); |
1179 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[0].change_type()); | 1078 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[0].change_type()); |
1180 EXPECT_EQ(kNewWindowId, | 1079 EXPECT_EQ(kNewWindowId, |
1181 out[0].sync_data().GetSpecifics().session().tab().window_id()); | 1080 out[0].sync_data().GetSpecifics().session().tab().window_id()); |
1182 EXPECT_EQ(kFoo2, out[0] | |
1183 .sync_data() | |
1184 .GetSpecifics() | |
1185 .session() | |
1186 .tab() | |
1187 .navigation(1) | |
1188 .virtual_url()); | |
1189 } | |
1190 | |
1191 // Ensure that the manager properly ignores a restored placeholder that refers | |
1192 // to a tab node that doesn't exist | |
1193 TEST_F(SessionsSyncManagerTest, RestoredPlacholderTabNodeDeleted) { | |
1194 const int kNewWindowId = 1337; | |
1195 syncer::SyncDataList in; | |
1196 syncer::SyncChangeList out; | |
1197 | |
1198 // Set up one tab and start sync with it. | |
1199 AddTab(browser(), GURL(kFoo1)); | |
1200 NavigateAndCommitActiveTab(GURL(kFoo2)); | |
1201 InitWithSyncDataTakeOutput(in, &out); | |
1202 | |
1203 // Should be one header add, 1 tab add, and one header update. | |
1204 ASSERT_EQ(3U, out.size()); | |
1205 const sync_pb::EntitySpecifics t0_entity = out[1].sync_data().GetSpecifics(); | |
1206 ASSERT_TRUE(t0_entity.session().has_tab()); | |
1207 | |
1208 out.clear(); | |
1209 manager()->StopSyncing(syncer::SESSIONS); | |
1210 | |
1211 // Override the tab with a placeholder tab delegate. | |
1212 PlaceholderTabDelegate t0_override(t0_entity.session().tab().tab_id(), | |
1213 t0_entity.session().tab_node_id()); | |
1214 | |
1215 // Set up the window override with the new window ID and placeholder tab. | |
1216 const std::set<const SyncedWindowDelegate*>& windows = | |
1217 get_synced_window_getter()->GetSyncedWindowDelegates(); | |
1218 ASSERT_EQ(1U, windows.size()); | |
1219 SyncedWindowDelegateOverride window_override(*windows.begin()); | |
1220 window_override.OverrideSessionId(kNewWindowId); | |
1221 window_override.OverrideTabAt(0, &t0_override, | |
1222 t0_entity.session().tab().tab_id()); | |
1223 | |
1224 // Inject the window override. | |
1225 std::set<const SyncedWindowDelegate*> delegates; | |
1226 delegates.insert(&window_override); | |
1227 std::unique_ptr<TestSyncedWindowDelegatesGetter> getter( | |
1228 new TestSyncedWindowDelegatesGetter(delegates)); | |
1229 set_synced_window_getter(getter.get()); | |
1230 | |
1231 syncer::SyncMergeResult result = manager()->MergeDataAndStartSyncing( | |
1232 syncer::SESSIONS, in, std::unique_ptr<syncer::SyncChangeProcessor>( | |
1233 new TestSyncProcessorStub(&out)), | |
1234 std::unique_ptr<syncer::SyncErrorFactory>( | |
1235 new syncer::SyncErrorFactoryMock())); | |
1236 | |
1237 // Because no entities were passed in at associate time, there should be no | |
1238 // tab changes. | |
1239 ASSERT_EQ(0U, FilterOutLocalHeaderChanges(&out)->size()); | |
1240 } | 1081 } |
1241 | 1082 |
1242 // Tests MergeDataAndStartSyncing with sync data but no local data. | 1083 // Tests MergeDataAndStartSyncing with sync data but no local data. |
1243 TEST_F(SessionsSyncManagerTest, MergeWithInitialForeignSession) { | 1084 TEST_F(SessionsSyncManagerTest, MergeWithInitialForeignSession) { |
1244 std::string tag = "tag1"; | 1085 std::string tag = "tag1"; |
1245 | 1086 |
1246 SessionID::id_type n1[] = {5, 10, 13, 17}; | 1087 SessionID::id_type n1[] = {5, 10, 13, 17}; |
1247 std::vector<SessionID::id_type> tab_list1(n1, n1 + arraysize(n1)); | 1088 std::vector<SessionID::id_type> tab_list1(n1, n1 + arraysize(n1)); |
1248 std::vector<sync_pb::SessionSpecifics> tabs1; | 1089 std::vector<sync_pb::SessionSpecifics> tabs1; |
1249 sync_pb::SessionSpecifics meta(helper()->BuildForeignSession( | 1090 sync_pb::SessionSpecifics meta(helper()->BuildForeignSession( |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1292 std::vector<SessionID::id_type> tab_list1(n1, n1 + arraysize(n1)); | 1133 std::vector<SessionID::id_type> tab_list1(n1, n1 + arraysize(n1)); |
1293 std::vector<sync_pb::SessionSpecifics> tabs1; | 1134 std::vector<sync_pb::SessionSpecifics> tabs1; |
1294 sync_pb::SessionSpecifics meta(helper()->BuildForeignSession( | 1135 sync_pb::SessionSpecifics meta(helper()->BuildForeignSession( |
1295 tag, tab_list1, &tabs1)); | 1136 tag, tab_list1, &tabs1)); |
1296 syncer::SyncDataList foreign_data; | 1137 syncer::SyncDataList foreign_data; |
1297 foreign_data.push_back(CreateRemoteData(meta)); | 1138 foreign_data.push_back(CreateRemoteData(meta)); |
1298 AddTabsToSyncDataList(tabs1, &foreign_data); | 1139 AddTabsToSyncDataList(tabs1, &foreign_data); |
1299 | 1140 |
1300 syncer::SyncChangeList output; | 1141 syncer::SyncChangeList output; |
1301 InitWithSyncDataTakeOutput(foreign_data, &output); | 1142 InitWithSyncDataTakeOutput(foreign_data, &output); |
1302 // Should be one header add, 1 tab add, and one header update. | 1143 ASSERT_EQ(4U, output.size()); |
1303 ASSERT_EQ(3U, output.size()); | |
1304 | 1144 |
1305 // Verify the local header. | 1145 // Verify the local header. |
1306 EXPECT_TRUE(output[0].IsValid()); | 1146 EXPECT_TRUE(output[0].IsValid()); |
1307 EXPECT_EQ(SyncChange::ACTION_ADD, output[0].change_type()); | 1147 EXPECT_EQ(SyncChange::ACTION_ADD, output[0].change_type()); |
1308 const SyncData data(output[0].sync_data()); | 1148 const SyncData data(output[0].sync_data()); |
1309 EXPECT_EQ(manager()->current_machine_tag(), | 1149 EXPECT_EQ(manager()->current_machine_tag(), |
1310 syncer::SyncDataLocal(data).GetTag()); | 1150 syncer::SyncDataLocal(data).GetTag()); |
1311 const sync_pb::SessionSpecifics& specifics(data.GetSpecifics().session()); | 1151 const sync_pb::SessionSpecifics& specifics(data.GetSpecifics().session()); |
1312 EXPECT_EQ(manager()->current_machine_tag(), specifics.session_tag()); | 1152 EXPECT_EQ(manager()->current_machine_tag(), specifics.session_tag()); |
1313 EXPECT_TRUE(specifics.has_header()); | 1153 EXPECT_TRUE(specifics.has_header()); |
1314 const sync_pb::SessionHeader& header_s = specifics.header(); | 1154 const sync_pb::SessionHeader& header_s = specifics.header(); |
1315 EXPECT_TRUE(header_s.has_device_type()); | 1155 EXPECT_TRUE(header_s.has_device_type()); |
1316 EXPECT_EQ(GetLocalDeviceInfo()->client_name(), header_s.client_name()); | 1156 EXPECT_EQ(GetLocalDeviceInfo()->client_name(), header_s.client_name()); |
1317 EXPECT_EQ(0, header_s.window_size()); | 1157 EXPECT_EQ(0, header_s.window_size()); |
1318 | 1158 |
1319 // Verify the tab node creations and updates with content. | 1159 // Verify the tab node creations and updates with content. |
1320 for (int i = 1; i < 3; i++) { | 1160 for (int i = 1; i < 3; i++) { |
1321 EXPECT_TRUE(output[i].IsValid()); | 1161 EXPECT_TRUE(output[i].IsValid()); |
1322 const SyncData data(output[i].sync_data()); | 1162 const SyncData data(output[i].sync_data()); |
1323 EXPECT_TRUE(base::StartsWith(syncer::SyncDataLocal(data).GetTag(), | 1163 EXPECT_TRUE(base::StartsWith(syncer::SyncDataLocal(data).GetTag(), |
1324 manager()->current_machine_tag(), | 1164 manager()->current_machine_tag(), |
1325 base::CompareCase::SENSITIVE)); | 1165 base::CompareCase::SENSITIVE)); |
1326 const sync_pb::SessionSpecifics& specifics(data.GetSpecifics().session()); | 1166 const sync_pb::SessionSpecifics& specifics(data.GetSpecifics().session()); |
1327 EXPECT_EQ(manager()->current_machine_tag(), specifics.session_tag()); | 1167 EXPECT_EQ(manager()->current_machine_tag(), specifics.session_tag()); |
1328 } | 1168 } |
1329 EXPECT_EQ(SyncChange::ACTION_ADD, output[1].change_type()); | 1169 EXPECT_EQ(SyncChange::ACTION_ADD, output[1].change_type()); |
1330 EXPECT_EQ(SyncChange::ACTION_UPDATE, output[2].change_type()); | 1170 EXPECT_EQ(SyncChange::ACTION_UPDATE, output[2].change_type()); |
1331 EXPECT_TRUE(output[1].sync_data().GetSpecifics().session().has_tab()); | 1171 EXPECT_TRUE(output[2].sync_data().GetSpecifics().session().has_tab()); |
1332 | 1172 |
1333 // Verify the header was updated to reflect window state. | 1173 // Verify the header was updated to reflect window state. |
1334 EXPECT_TRUE(output[2].IsValid()); | 1174 EXPECT_TRUE(output[3].IsValid()); |
1335 EXPECT_EQ(SyncChange::ACTION_UPDATE, output[2].change_type()); | 1175 EXPECT_EQ(SyncChange::ACTION_UPDATE, output[3].change_type()); |
1336 const SyncData data_2(output[2].sync_data()); | 1176 const SyncData data_2(output[3].sync_data()); |
1337 EXPECT_EQ(manager()->current_machine_tag(), | 1177 EXPECT_EQ(manager()->current_machine_tag(), |
1338 syncer::SyncDataLocal(data_2).GetTag()); | 1178 syncer::SyncDataLocal(data_2).GetTag()); |
1339 const sync_pb::SessionSpecifics& specifics2(data_2.GetSpecifics().session()); | 1179 const sync_pb::SessionSpecifics& specifics2(data_2.GetSpecifics().session()); |
1340 EXPECT_EQ(manager()->current_machine_tag(), specifics2.session_tag()); | 1180 EXPECT_EQ(manager()->current_machine_tag(), specifics2.session_tag()); |
1341 EXPECT_TRUE(specifics2.has_header()); | 1181 EXPECT_TRUE(specifics2.has_header()); |
1342 const sync_pb::SessionHeader& header_s2 = specifics2.header(); | 1182 const sync_pb::SessionHeader& header_s2 = specifics2.header(); |
1343 EXPECT_EQ(1, header_s2.window_size()); | 1183 EXPECT_EQ(1, header_s2.window_size()); |
1344 | 1184 |
1345 // Verify foreign data. | 1185 // Verify foreign data. |
1346 std::vector<const SyncedSession*> foreign_sessions; | 1186 std::vector<const SyncedSession*> foreign_sessions; |
(...skipping 22 matching lines...) Expand all Loading... |
1369 SessionID::id_type n1[] = {5, 10, 13, 17}; | 1209 SessionID::id_type n1[] = {5, 10, 13, 17}; |
1370 std::vector<SessionID::id_type> tab_list1(n1, n1 + arraysize(n1)); | 1210 std::vector<SessionID::id_type> tab_list1(n1, n1 + arraysize(n1)); |
1371 meta1_reference.push_back(tab_list1); | 1211 meta1_reference.push_back(tab_list1); |
1372 std::vector<sync_pb::SessionSpecifics> tabs1; | 1212 std::vector<sync_pb::SessionSpecifics> tabs1; |
1373 meta1 = helper()->BuildForeignSession(tag1, tab_list1, &tabs1); | 1213 meta1 = helper()->BuildForeignSession(tag1, tab_list1, &tabs1); |
1374 foreign_data1.push_back(CreateRemoteData(meta1)); | 1214 foreign_data1.push_back(CreateRemoteData(meta1)); |
1375 AddTabsToSyncDataList(tabs1, &foreign_data1); | 1215 AddTabsToSyncDataList(tabs1, &foreign_data1); |
1376 | 1216 |
1377 syncer::SyncChangeList output1; | 1217 syncer::SyncChangeList output1; |
1378 InitWithSyncDataTakeOutput(foreign_data1, &output1); | 1218 InitWithSyncDataTakeOutput(foreign_data1, &output1); |
1379 | 1219 ASSERT_EQ(4U, output1.size()); |
1380 // 1 header add, one tab add, one header update. | |
1381 ASSERT_EQ(3U, output1.size()); | |
1382 | 1220 |
1383 // Add a second window to the foreign session. | 1221 // Add a second window to the foreign session. |
1384 // TODO(tim): Bug 98892. Add local window too when observers are hooked up. | 1222 // TODO(tim): Bug 98892. Add local window too when observers are hooked up. |
1385 SessionID::id_type tab_nums2[] = {7, 15, 18, 20}; | 1223 SessionID::id_type tab_nums2[] = {7, 15, 18, 20}; |
1386 std::vector<SessionID::id_type> tab_list2( | 1224 std::vector<SessionID::id_type> tab_list2( |
1387 tab_nums2, tab_nums2 + arraysize(tab_nums2)); | 1225 tab_nums2, tab_nums2 + arraysize(tab_nums2)); |
1388 meta1_reference.push_back(tab_list2); | 1226 meta1_reference.push_back(tab_list2); |
1389 helper()->AddWindowSpecifics(1, tab_list2, &meta1); | 1227 helper()->AddWindowSpecifics(1, tab_list2, &meta1); |
1390 std::vector<sync_pb::SessionSpecifics> tabs2; | 1228 std::vector<sync_pb::SessionSpecifics> tabs2; |
1391 tabs2.resize(tab_list2.size()); | 1229 tabs2.resize(tab_list2.size()); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1462 EXPECT_TRUE(changes.empty()); | 1300 EXPECT_TRUE(changes.empty()); |
1463 | 1301 |
1464 // Fill an instance of session specifics with a foreign session's data. | 1302 // Fill an instance of session specifics with a foreign session's data. |
1465 std::vector<sync_pb::SessionSpecifics> tabs; | 1303 std::vector<sync_pb::SessionSpecifics> tabs; |
1466 SessionID::id_type n1[] = {5, 10, 13, 17}; | 1304 SessionID::id_type n1[] = {5, 10, 13, 17}; |
1467 std::vector<SessionID::id_type> tab_nums1(n1, n1 + arraysize(n1)); | 1305 std::vector<SessionID::id_type> tab_nums1(n1, n1 + arraysize(n1)); |
1468 sync_pb::SessionSpecifics meta(helper()->BuildForeignSession( | 1306 sync_pb::SessionSpecifics meta(helper()->BuildForeignSession( |
1469 tag, tab_nums1, &tabs)); | 1307 tag, tab_nums1, &tabs)); |
1470 | 1308 |
1471 // Update associator with the session's meta node, window, and tabs. | 1309 // Update associator with the session's meta node, window, and tabs. |
1472 manager()->UpdateTrackerWithSpecifics(meta, base::Time()); | 1310 manager()->UpdateTrackerWithForeignSession(meta, base::Time()); |
1473 for (std::vector<sync_pb::SessionSpecifics>::iterator iter = tabs.begin(); | 1311 for (std::vector<sync_pb::SessionSpecifics>::iterator iter = tabs.begin(); |
1474 iter != tabs.end(); ++iter) { | 1312 iter != tabs.end(); ++iter) { |
1475 manager()->UpdateTrackerWithSpecifics(*iter, base::Time()); | 1313 manager()->UpdateTrackerWithForeignSession(*iter, base::Time()); |
1476 } | 1314 } |
1477 ASSERT_TRUE(manager()->GetAllForeignSessions(&foreign_sessions)); | 1315 ASSERT_TRUE(manager()->GetAllForeignSessions(&foreign_sessions)); |
1478 ASSERT_EQ(1U, foreign_sessions.size()); | 1316 ASSERT_EQ(1U, foreign_sessions.size()); |
1479 | 1317 |
1480 // Now delete the foreign session. | 1318 // Now delete the foreign session. |
1481 manager()->DeleteForeignSessionInternal(tag, &changes); | 1319 manager()->DeleteForeignSessionInternal(tag, &changes); |
1482 EXPECT_FALSE(manager()->GetAllForeignSessions(&foreign_sessions)); | 1320 EXPECT_FALSE(manager()->GetAllForeignSessions(&foreign_sessions)); |
1483 | 1321 |
1484 EXPECT_EQ(5U, changes.size()); | 1322 EXPECT_EQ(5U, changes.size()); |
1485 std::set<std::string> expected_tags(&tag, &tag + 1); | 1323 std::set<std::string> expected_tags(&tag, &tag + 1); |
1486 for (int i = 0; i < 5; i++) | 1324 for (int i = 0; i < 5; i++) |
1487 expected_tags.insert(TabNodeIdToTag(tag, i)); | 1325 expected_tags.insert(TabNodePool::TabIdToTag(tag, i)); |
1488 | 1326 |
1489 for (int i = 0; i < 5; i++) { | 1327 for (int i = 0; i < 5; i++) { |
1490 SCOPED_TRACE(changes[i].ToString()); | 1328 SCOPED_TRACE(changes[i].ToString()); |
1491 EXPECT_TRUE(changes[i].IsValid()); | 1329 EXPECT_TRUE(changes[i].IsValid()); |
1492 EXPECT_EQ(SyncChange::ACTION_DELETE, changes[i].change_type()); | 1330 EXPECT_EQ(SyncChange::ACTION_DELETE, changes[i].change_type()); |
1493 EXPECT_TRUE(changes[i].sync_data().IsValid()); | 1331 EXPECT_TRUE(changes[i].sync_data().IsValid()); |
1494 EXPECT_EQ(1U, | 1332 EXPECT_EQ(1U, |
1495 expected_tags.erase( | 1333 expected_tags.erase( |
1496 syncer::SyncDataLocal(changes[i].sync_data()).GetTag())); | 1334 syncer::SyncDataLocal(changes[i].sync_data()).GetTag())); |
1497 } | 1335 } |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1600 | 1438 |
1601 // This should trigger repair of the TabNodePool. | 1439 // This should trigger repair of the TabNodePool. |
1602 const GURL foo1("http://foo/1"); | 1440 const GURL foo1("http://foo/1"); |
1603 AddTab(browser(), foo1); | 1441 AddTab(browser(), foo1); |
1604 EXPECT_FALSE(manager()->local_tab_pool_out_of_sync_); | 1442 EXPECT_FALSE(manager()->local_tab_pool_out_of_sync_); |
1605 | 1443 |
1606 // AddTab triggers two notifications, one for the tab insertion and one for | 1444 // AddTab triggers two notifications, one for the tab insertion and one for |
1607 // committing the NavigationEntry. The first notification results in a tab | 1445 // committing the NavigationEntry. The first notification results in a tab |
1608 // we don't associate although we do update the header node. The second | 1446 // we don't associate although we do update the header node. The second |
1609 // notification triggers association of the tab, and the subsequent window | 1447 // notification triggers association of the tab, and the subsequent window |
1610 // update. So we should see 3 changes at the SyncChangeProcessor. | 1448 // update. So we should see 4 changes at the SyncChangeProcessor. |
1611 ASSERT_EQ(3U, out.size()); | 1449 ASSERT_EQ(4U, out.size()); |
1612 | 1450 |
1613 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[0].change_type()); | 1451 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[0].change_type()); |
1614 ASSERT_TRUE(out[0].sync_data().GetSpecifics().session().has_header()); | 1452 ASSERT_TRUE(out[0].sync_data().GetSpecifics().session().has_header()); |
1615 EXPECT_EQ(SyncChange::ACTION_ADD, out[1].change_type()); | 1453 EXPECT_EQ(SyncChange::ACTION_ADD, out[1].change_type()); |
1616 int tab_node_id = out[1].sync_data().GetSpecifics().session().tab_node_id(); | 1454 int tab_node_id = out[1].sync_data().GetSpecifics().session().tab_node_id(); |
1617 EXPECT_EQ(TabNodeIdToTag(manager()->current_machine_tag(), tab_node_id), | 1455 EXPECT_EQ(TabNodePool::TabIdToTag( |
| 1456 manager()->current_machine_tag(), tab_node_id), |
1618 syncer::SyncDataLocal(out[1].sync_data()).GetTag()); | 1457 syncer::SyncDataLocal(out[1].sync_data()).GetTag()); |
1619 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[2].change_type()); | 1458 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[2].change_type()); |
1620 ASSERT_TRUE(out[2].sync_data().GetSpecifics().session().has_header()); | 1459 ASSERT_TRUE(out[2].sync_data().GetSpecifics().session().has_tab()); |
| 1460 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[3].change_type()); |
| 1461 ASSERT_TRUE(out[3].sync_data().GetSpecifics().session().has_header()); |
1621 | 1462 |
1622 // Verify the actual content. | 1463 // Verify the actual content. |
1623 const sync_pb::SessionHeader& session_header = | 1464 const sync_pb::SessionHeader& session_header = |
1624 out[2].sync_data().GetSpecifics().session().header(); | 1465 out[3].sync_data().GetSpecifics().session().header(); |
1625 ASSERT_EQ(1, session_header.window_size()); | 1466 ASSERT_EQ(1, session_header.window_size()); |
1626 EXPECT_EQ(1, session_header.window(0).tab_size()); | 1467 EXPECT_EQ(1, session_header.window(0).tab_size()); |
1627 const sync_pb::SessionTab& tab1 = | 1468 const sync_pb::SessionTab& tab1 = |
1628 out[1].sync_data().GetSpecifics().session().tab(); | 1469 out[2].sync_data().GetSpecifics().session().tab(); |
1629 ASSERT_EQ(1, tab1.navigation_size()); | 1470 ASSERT_EQ(1, tab1.navigation_size()); |
1630 EXPECT_EQ(foo1.spec(), tab1.navigation(0).virtual_url()); | 1471 EXPECT_EQ(foo1.spec(), tab1.navigation(0).virtual_url()); |
1631 | 1472 |
1632 // Verify TabNodePool integrity. | 1473 // Verify TabNodePool integrity. |
1633 EXPECT_EQ(1U, GetTabPool()->Capacity()); | 1474 EXPECT_EQ(1U, manager()->local_tab_pool_.Capacity()); |
1634 EXPECT_TRUE(GetTabPool()->Empty()); | 1475 EXPECT_TRUE(manager()->local_tab_pool_.Empty()); |
| 1476 |
| 1477 // Verify TabLinks. |
| 1478 SessionsSyncManager::TabLinksMap tab_map = manager()->local_tab_map_; |
| 1479 ASSERT_EQ(1U, tab_map.size()); |
| 1480 int tab_id = out[2].sync_data().GetSpecifics().session().tab().tab_id(); |
| 1481 EXPECT_EQ(tab_node_id, tab_map.find(tab_id)->second->tab_node_id()); |
1635 } | 1482 } |
1636 | 1483 |
1637 // Test that receiving a session delete from sync removes the session | 1484 // Test that receiving a session delete from sync removes the session |
1638 // from tracking. | 1485 // from tracking. |
1639 TEST_F(SessionsSyncManagerTest, ProcessForeignDelete) { | 1486 TEST_F(SessionsSyncManagerTest, ProcessForeignDelete) { |
1640 InitWithNoSyncData(); | 1487 InitWithNoSyncData(); |
1641 SessionID::id_type n[] = {5}; | 1488 SessionID::id_type n[] = {5}; |
1642 std::vector<sync_pb::SessionSpecifics> tabs1; | 1489 std::vector<sync_pb::SessionSpecifics> tabs1; |
1643 std::vector<SessionID::id_type> tab_list(n, n + arraysize(n)); | 1490 std::vector<SessionID::id_type> tab_list(n, n + arraysize(n)); |
1644 sync_pb::SessionSpecifics meta(helper()->BuildForeignSession( | 1491 sync_pb::SessionSpecifics meta(helper()->BuildForeignSession( |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1768 output.clear(); | 1615 output.clear(); |
1769 | 1616 |
1770 // Verify that cleanup post-merge cleanup correctly removes all tabs objects. | 1617 // Verify that cleanup post-merge cleanup correctly removes all tabs objects. |
1771 const sessions::SessionTab* tab; | 1618 const sessions::SessionTab* tab; |
1772 ASSERT_FALSE( | 1619 ASSERT_FALSE( |
1773 manager()->session_tracker_.LookupSessionTab(session_tag, 1, &tab)); | 1620 manager()->session_tracker_.LookupSessionTab(session_tag, 1, &tab)); |
1774 ASSERT_FALSE( | 1621 ASSERT_FALSE( |
1775 manager()->session_tracker_.LookupSessionTab(session_tag, 2, &tab)); | 1622 manager()->session_tracker_.LookupSessionTab(session_tag, 2, &tab)); |
1776 | 1623 |
1777 std::set<int> tab_node_ids; | 1624 std::set<int> tab_node_ids; |
1778 manager()->session_tracker_.LookupForeignTabNodeIds(session_tag, | 1625 manager()->session_tracker_.LookupTabNodeIds(session_tag, &tab_node_ids); |
1779 &tab_node_ids); | |
1780 EXPECT_EQ(6U, tab_node_ids.size()); | 1626 EXPECT_EQ(6U, tab_node_ids.size()); |
1781 EXPECT_TRUE(tab_node_ids.find(tab1A.tab_node_id()) != tab_node_ids.end()); | 1627 EXPECT_TRUE(tab_node_ids.find(tab1A.tab_node_id()) != tab_node_ids.end()); |
1782 EXPECT_TRUE(tab_node_ids.find(tab1B.tab_node_id()) != tab_node_ids.end()); | 1628 EXPECT_TRUE(tab_node_ids.find(tab1B.tab_node_id()) != tab_node_ids.end()); |
1783 EXPECT_TRUE(tab_node_ids.find(tab1C.tab_node_id()) != tab_node_ids.end()); | 1629 EXPECT_TRUE(tab_node_ids.find(tab1C.tab_node_id()) != tab_node_ids.end()); |
1784 EXPECT_TRUE(tab_node_ids.find(tab2A.tab_node_id()) != tab_node_ids.end()); | 1630 EXPECT_TRUE(tab_node_ids.find(tab2A.tab_node_id()) != tab_node_ids.end()); |
1785 EXPECT_TRUE(tab_node_ids.find(tab2B.tab_node_id()) != tab_node_ids.end()); | 1631 EXPECT_TRUE(tab_node_ids.find(tab2B.tab_node_id()) != tab_node_ids.end()); |
1786 EXPECT_TRUE(tab_node_ids.find(tab2C.tab_node_id()) != tab_node_ids.end()); | 1632 EXPECT_TRUE(tab_node_ids.find(tab2C.tab_node_id()) != tab_node_ids.end()); |
1787 | 1633 |
1788 syncer::SyncChangeList changes; | 1634 syncer::SyncChangeList changes; |
1789 changes.push_back(MakeRemoteChange(tab1A, SyncChange::ACTION_DELETE)); | 1635 changes.push_back(MakeRemoteChange(tab1A, SyncChange::ACTION_DELETE)); |
1790 changes.push_back(MakeRemoteChange(tab1B, SyncChange::ACTION_DELETE)); | 1636 changes.push_back(MakeRemoteChange(tab1B, SyncChange::ACTION_DELETE)); |
1791 changes.push_back(MakeRemoteChange(tab2C, SyncChange::ACTION_DELETE)); | 1637 changes.push_back(MakeRemoteChange(tab2C, SyncChange::ACTION_DELETE)); |
1792 manager()->ProcessSyncChanges(FROM_HERE, changes); | 1638 manager()->ProcessSyncChanges(FROM_HERE, changes); |
1793 | 1639 |
1794 tab_node_ids.clear(); | 1640 tab_node_ids.clear(); |
1795 manager()->session_tracker_.LookupForeignTabNodeIds(session_tag, | 1641 manager()->session_tracker_.LookupTabNodeIds(session_tag, &tab_node_ids); |
1796 &tab_node_ids); | |
1797 EXPECT_EQ(3U, tab_node_ids.size()); | 1642 EXPECT_EQ(3U, tab_node_ids.size()); |
1798 EXPECT_TRUE(tab_node_ids.find(tab1C.tab_node_id()) != tab_node_ids.end()); | 1643 EXPECT_TRUE(tab_node_ids.find(tab1C.tab_node_id()) != tab_node_ids.end()); |
1799 EXPECT_TRUE(tab_node_ids.find(tab2A.tab_node_id()) != tab_node_ids.end()); | 1644 EXPECT_TRUE(tab_node_ids.find(tab2A.tab_node_id()) != tab_node_ids.end()); |
1800 EXPECT_TRUE(tab_node_ids.find(tab2B.tab_node_id()) != tab_node_ids.end()); | 1645 EXPECT_TRUE(tab_node_ids.find(tab2B.tab_node_id()) != tab_node_ids.end()); |
1801 | 1646 |
1802 manager()->DoGarbageCollection(); | 1647 manager()->DoGarbageCollection(); |
1803 ASSERT_EQ(3U, output.size()); | 1648 ASSERT_EQ(3U, output.size()); |
1804 } | 1649 } |
1805 | 1650 |
1806 TEST_F(SessionsSyncManagerTest, ProcessForeignDeleteTabsWithReusedNodeIds) { | 1651 TEST_F(SessionsSyncManagerTest, ProcessForeignDeleteTabsWithReusedNodeIds) { |
(...skipping 17 matching lines...) Expand all Loading... |
1824 helper()->BuildTabSpecifics(session_tag, 0, 2, tab_node_id_shared, &tab2A); | 1669 helper()->BuildTabSpecifics(session_tag, 0, 2, tab_node_id_shared, &tab2A); |
1825 AddToSyncDataList(tab2A, &foreign_data, | 1670 AddToSyncDataList(tab2A, &foreign_data, |
1826 stale_mtime + base::TimeDelta::FromMinutes(1)); | 1671 stale_mtime + base::TimeDelta::FromMinutes(1)); |
1827 | 1672 |
1828 syncer::SyncChangeList output; | 1673 syncer::SyncChangeList output; |
1829 InitWithSyncDataTakeOutput(foreign_data, &output); | 1674 InitWithSyncDataTakeOutput(foreign_data, &output); |
1830 ASSERT_EQ(2U, output.size()); | 1675 ASSERT_EQ(2U, output.size()); |
1831 output.clear(); | 1676 output.clear(); |
1832 | 1677 |
1833 std::set<int> tab_node_ids; | 1678 std::set<int> tab_node_ids; |
1834 manager()->session_tracker_.LookupForeignTabNodeIds(session_tag, | 1679 manager()->session_tracker_.LookupTabNodeIds(session_tag, &tab_node_ids); |
1835 &tab_node_ids); | |
1836 EXPECT_EQ(2U, tab_node_ids.size()); | 1680 EXPECT_EQ(2U, tab_node_ids.size()); |
1837 EXPECT_TRUE(tab_node_ids.find(tab_node_id_shared) != tab_node_ids.end()); | 1681 EXPECT_TRUE(tab_node_ids.find(tab_node_id_shared) != tab_node_ids.end()); |
1838 EXPECT_TRUE(tab_node_ids.find(tab_node_id_unique) != tab_node_ids.end()); | 1682 EXPECT_TRUE(tab_node_ids.find(tab_node_id_unique) != tab_node_ids.end()); |
1839 | 1683 |
1840 syncer::SyncChangeList changes; | 1684 syncer::SyncChangeList changes; |
1841 changes.push_back(MakeRemoteChange(tab1A, SyncChange::ACTION_DELETE)); | 1685 changes.push_back(MakeRemoteChange(tab1A, SyncChange::ACTION_DELETE)); |
1842 manager()->ProcessSyncChanges(FROM_HERE, changes); | 1686 manager()->ProcessSyncChanges(FROM_HERE, changes); |
1843 | 1687 |
1844 tab_node_ids.clear(); | 1688 tab_node_ids.clear(); |
1845 manager()->session_tracker_.LookupForeignTabNodeIds(session_tag, | 1689 manager()->session_tracker_.LookupTabNodeIds(session_tag, &tab_node_ids); |
1846 &tab_node_ids); | |
1847 EXPECT_EQ(1U, tab_node_ids.size()); | 1690 EXPECT_EQ(1U, tab_node_ids.size()); |
1848 EXPECT_TRUE(tab_node_ids.find(tab_node_id_unique) != tab_node_ids.end()); | 1691 EXPECT_TRUE(tab_node_ids.find(tab_node_id_unique) != tab_node_ids.end()); |
1849 | 1692 |
1850 manager()->DoGarbageCollection(); | 1693 manager()->DoGarbageCollection(); |
1851 EXPECT_EQ(1U, output.size()); | 1694 EXPECT_EQ(1U, output.size()); |
1852 } | 1695 } |
1853 | 1696 |
1854 TEST_F(SessionsSyncManagerTest, AssociationReusesNodes) { | 1697 // TODO(shashishekhar): "Move this to TabNodePool unittests." |
| 1698 TEST_F(SessionsSyncManagerTest, SaveUnassociatedNodesForReassociation) { |
1855 syncer::SyncChangeList changes; | 1699 syncer::SyncChangeList changes; |
1856 AddTab(browser(), GURL("http://foo1")); | 1700 InitWithNoSyncData(); |
1857 InitWithSyncDataTakeOutput(syncer::SyncDataList(), &changes); | |
1858 ASSERT_EQ(3U, changes.size()); // Header add, tab add, header update. | |
1859 ASSERT_TRUE(changes[1].sync_data().GetSpecifics().session().has_tab()); | |
1860 int tab_node_id = | |
1861 changes[1].sync_data().GetSpecifics().session().tab_node_id(); | |
1862 | 1701 |
1863 // Pass back the previous tab and header nodes at association, along with a | 1702 std::string local_tag = manager()->current_machine_tag(); |
1864 // second tab node (with a rewritten tab node id). | 1703 // Create a free node and then dissassociate sessions so that it ends up |
1865 syncer::SyncDataList in; | 1704 // unassociated. |
1866 in.push_back( | 1705 manager()->local_tab_pool_.GetFreeTabNode(&changes); |
1867 CreateRemoteData(changes[2].sync_data().GetSpecifics())); // Header node. | 1706 |
1868 sync_pb::SessionSpecifics new_tab( | 1707 // Update the tab_id of the node, so that it is considered a valid |
1869 changes[1].sync_data().GetSpecifics().session()); | 1708 // unassociated node otherwise it will be mistaken for a corrupted node and |
1870 new_tab.set_tab_node_id(tab_node_id + 1); | 1709 // will be deleted before being added to the tab node pool. |
1871 in.push_back(CreateRemoteData(new_tab)); // New tab node. | 1710 sync_pb::EntitySpecifics entity(changes[0].sync_data().GetSpecifics()); |
1872 in.push_back(CreateRemoteData( | 1711 entity.mutable_session()->mutable_tab()->set_tab_id(1); |
1873 changes[1].sync_data().GetSpecifics())); // Old tab node. | 1712 SyncData d = CreateRemoteData(entity); |
| 1713 syncer::SyncDataList in(&d, &d + 1); |
1874 changes.clear(); | 1714 changes.clear(); |
1875 | 1715 SessionsSyncManager manager2(GetSyncSessionsClient(), sync_prefs(), |
1876 // Reassociate (with the same single tab/window open). | 1716 local_device(), NewDummyRouter(), |
1877 manager()->StopSyncing(syncer::SESSIONS); | 1717 base::Closure(), base::Closure()); |
1878 syncer::SyncMergeResult result = manager()->MergeDataAndStartSyncing( | 1718 syncer::SyncMergeResult result = manager2.MergeDataAndStartSyncing( |
1879 syncer::SESSIONS, in, std::unique_ptr<syncer::SyncChangeProcessor>( | 1719 syncer::SESSIONS, in, std::unique_ptr<syncer::SyncChangeProcessor>( |
1880 new TestSyncProcessorStub(&changes)), | 1720 new TestSyncProcessorStub(&changes)), |
1881 std::unique_ptr<syncer::SyncErrorFactory>( | 1721 std::unique_ptr<syncer::SyncErrorFactory>( |
1882 new syncer::SyncErrorFactoryMock())); | 1722 new syncer::SyncErrorFactoryMock())); |
1883 ASSERT_FALSE(result.error().IsSet()); | 1723 ASSERT_FALSE(result.error().IsSet()); |
1884 | 1724 EXPECT_TRUE(FilterOutLocalHeaderChanges(&changes)->empty()); |
1885 // No tab entities should be deleted. The original (lower) tab node id should | |
1886 // be reused for association. | |
1887 FilterOutLocalHeaderChanges(&changes); | |
1888 ASSERT_EQ(1U, changes.size()); | |
1889 EXPECT_EQ(SyncChange::ACTION_UPDATE, changes[0].change_type()); | |
1890 EXPECT_TRUE(changes[0].sync_data().GetSpecifics().session().has_tab()); | |
1891 EXPECT_EQ(tab_node_id, | |
1892 changes[0].sync_data().GetSpecifics().session().tab_node_id()); | |
1893 } | 1725 } |
1894 | 1726 |
1895 TEST_F(SessionsSyncManagerTest, MergeDeletesCorruptNode) { | 1727 TEST_F(SessionsSyncManagerTest, MergeDeletesCorruptNode) { |
1896 syncer::SyncChangeList changes; | 1728 syncer::SyncChangeList changes; |
1897 InitWithNoSyncData(); | 1729 InitWithNoSyncData(); |
1898 | 1730 |
1899 std::string local_tag = manager()->current_machine_tag(); | 1731 std::string local_tag = manager()->current_machine_tag(); |
1900 int tab_node_id = TabNodePool::kInvalidTabNodeID; | 1732 int tab_node_id = manager()->local_tab_pool_.GetFreeTabNode(&changes); |
1901 GetTabPool()->GetTabNodeForTab(0, &tab_node_id); | 1733 SyncData d = CreateRemoteData(changes[0].sync_data().GetSpecifics()); |
1902 sync_pb::SessionSpecifics specifics; | |
1903 specifics.set_session_tag(local_tag); | |
1904 specifics.set_tab_node_id(tab_node_id); | |
1905 SyncData d = CreateRemoteData(specifics); | |
1906 syncer::SyncDataList in(&d, &d + 1); | 1734 syncer::SyncDataList in(&d, &d + 1); |
| 1735 changes.clear(); |
1907 TearDown(); | 1736 TearDown(); |
1908 SetUp(); | 1737 SetUp(); |
1909 InitWithSyncDataTakeOutput(in, &changes); | 1738 InitWithSyncDataTakeOutput(in, &changes); |
1910 EXPECT_EQ(1U, FilterOutLocalHeaderChanges(&changes)->size()); | 1739 EXPECT_EQ(1U, FilterOutLocalHeaderChanges(&changes)->size()); |
1911 EXPECT_EQ(SyncChange::ACTION_DELETE, changes[0].change_type()); | 1740 EXPECT_EQ(SyncChange::ACTION_DELETE, changes[0].change_type()); |
1912 EXPECT_EQ(TabNodeIdToTag(local_tag, tab_node_id), | 1741 EXPECT_EQ(TabNodePool::TabIdToTag(local_tag, tab_node_id), |
1913 syncer::SyncDataLocal(changes[0].sync_data()).GetTag()); | 1742 syncer::SyncDataLocal(changes[0].sync_data()).GetTag()); |
1914 } | 1743 } |
1915 | 1744 |
1916 // Verifies that we drop both headers and tabs during merge if their stored tag | 1745 // Verifies that we drop both headers and tabs during merge if their stored tag |
1917 // hash doesn't match a computer tag hash. This mitigates potential failures | 1746 // hash doesn't match a computer tag hash. This mitigates potential failures |
1918 // while cleaning up bad foreign data, see crbug.com/604657. | 1747 // while cleaning up bad foreign data, see crbug.com/604657. |
1919 TEST_F(SessionsSyncManagerTest, MergeDeletesBadHash) { | 1748 TEST_F(SessionsSyncManagerTest, MergeDeletesBadHash) { |
1920 syncer::SyncDataList foreign_data; | 1749 syncer::SyncDataList foreign_data; |
1921 std::vector<SessionID::id_type> empty_ids; | 1750 std::vector<SessionID::id_type> empty_ids; |
1922 std::vector<sync_pb::SessionSpecifics> empty_tabs; | 1751 std::vector<sync_pb::SessionSpecifics> empty_tabs; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1971 InitWithSyncDataTakeOutput(syncer::SyncDataList(), &out); | 1800 InitWithSyncDataTakeOutput(syncer::SyncDataList(), &out); |
1972 ASSERT_EQ(2U, out.size()); // Header add and update. | 1801 ASSERT_EQ(2U, out.size()); // Header add and update. |
1973 EXPECT_EQ( | 1802 EXPECT_EQ( |
1974 0, | 1803 0, |
1975 out[1].sync_data().GetSpecifics().session().header().window_size()); | 1804 out[1].sync_data().GetSpecifics().session().header().window_size()); |
1976 out.clear(); | 1805 out.clear(); |
1977 | 1806 |
1978 // Go to a sync-interesting URL. | 1807 // Go to a sync-interesting URL. |
1979 NavigateAndCommitActiveTab(GURL("http://foo2")); | 1808 NavigateAndCommitActiveTab(GURL("http://foo2")); |
1980 | 1809 |
1981 EXPECT_EQ(2U, out.size()); // Tab add and header update. | 1810 EXPECT_EQ(3U, out.size()); // Tab add, update, and header update. |
1982 | 1811 |
1983 EXPECT_TRUE( | 1812 EXPECT_TRUE( |
1984 base::StartsWith(syncer::SyncDataLocal(out[0].sync_data()).GetTag(), | 1813 base::StartsWith(syncer::SyncDataLocal(out[0].sync_data()).GetTag(), |
1985 manager()->current_machine_tag(), | 1814 manager()->current_machine_tag(), |
1986 base::CompareCase::SENSITIVE)); | 1815 base::CompareCase::SENSITIVE)); |
1987 EXPECT_EQ(manager()->current_machine_tag(), | 1816 EXPECT_EQ(manager()->current_machine_tag(), |
1988 out[0].sync_data().GetSpecifics().session().session_tag()); | 1817 out[0].sync_data().GetSpecifics().session().session_tag()); |
1989 EXPECT_EQ(SyncChange::ACTION_ADD, out[0].change_type()); | 1818 EXPECT_EQ(SyncChange::ACTION_ADD, out[0].change_type()); |
1990 | 1819 |
1991 EXPECT_TRUE(out[1].IsValid()); | 1820 EXPECT_TRUE( |
| 1821 base::StartsWith(syncer::SyncDataLocal(out[1].sync_data()).GetTag(), |
| 1822 manager()->current_machine_tag(), |
| 1823 base::CompareCase::SENSITIVE)); |
| 1824 EXPECT_EQ(manager()->current_machine_tag(), |
| 1825 out[1].sync_data().GetSpecifics().session().session_tag()); |
| 1826 EXPECT_TRUE(out[1].sync_data().GetSpecifics().session().has_tab()); |
1992 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[1].change_type()); | 1827 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[1].change_type()); |
1993 const SyncData data(out[1].sync_data()); | 1828 |
| 1829 EXPECT_TRUE(out[2].IsValid()); |
| 1830 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[2].change_type()); |
| 1831 const SyncData data(out[2].sync_data()); |
1994 EXPECT_EQ(manager()->current_machine_tag(), | 1832 EXPECT_EQ(manager()->current_machine_tag(), |
1995 syncer::SyncDataLocal(data).GetTag()); | 1833 syncer::SyncDataLocal(data).GetTag()); |
1996 const sync_pb::SessionSpecifics& specifics(data.GetSpecifics().session()); | 1834 const sync_pb::SessionSpecifics& specifics(data.GetSpecifics().session()); |
1997 EXPECT_EQ(manager()->current_machine_tag(), specifics.session_tag()); | 1835 EXPECT_EQ(manager()->current_machine_tag(), specifics.session_tag()); |
1998 EXPECT_TRUE(specifics.has_header()); | 1836 EXPECT_TRUE(specifics.has_header()); |
1999 const sync_pb::SessionHeader& header_s = specifics.header(); | 1837 const sync_pb::SessionHeader& header_s = specifics.header(); |
2000 EXPECT_EQ(1, header_s.window_size()); | 1838 EXPECT_EQ(1, header_s.window_size()); |
2001 EXPECT_EQ(1, header_s.window(0).tab_size()); | 1839 EXPECT_EQ(1, header_s.window(0).tab_size()); |
2002 } | 1840 } |
2003 | 1841 |
(...skipping 11 matching lines...) Expand all Loading... |
2015 | 1853 |
2016 const GURL foo1("http://foo/1"); | 1854 const GURL foo1("http://foo/1"); |
2017 const GURL foo2("http://foo/2"); | 1855 const GURL foo2("http://foo/2"); |
2018 const GURL bar1("http://bar/1"); | 1856 const GURL bar1("http://bar/1"); |
2019 const GURL bar2("http://bar/2"); | 1857 const GURL bar2("http://bar/2"); |
2020 AddTab(browser(), foo1); | 1858 AddTab(browser(), foo1); |
2021 NavigateAndCommitActiveTab(foo2); | 1859 NavigateAndCommitActiveTab(foo2); |
2022 AddTab(browser(), bar1); | 1860 AddTab(browser(), bar1); |
2023 NavigateAndCommitActiveTab(bar2); | 1861 NavigateAndCommitActiveTab(bar2); |
2024 | 1862 |
2025 // Change type breakdown: | 1863 // One add, one update for each AddTab. |
2026 const size_t kChangesPerTabCreation = 3; // 1 tab add + 2 header updates. | 1864 // One update for each NavigateAndCommit. |
2027 const size_t kChangesPerTabNav = 2; // 1 tab update + 1 header update. | 1865 // = 6 total tab updates. |
2028 const size_t kChangesPerTab = kChangesPerTabNav + kChangesPerTabCreation; | 1866 // One header update corresponding to each of those. |
2029 const size_t kNumTabs = 2; | 1867 // = 6 total header updates. |
2030 const size_t kTotalUpdates = kChangesPerTab * kNumTabs; | 1868 // 12 total updates. |
2031 ASSERT_EQ(kTotalUpdates, out.size()); | 1869 ASSERT_EQ(12U, out.size()); |
2032 | 1870 |
2033 // Verify the tab node creations and updates to ensure the SyncProcessor | 1871 // Verify the tab node creations and updates to ensure the SyncProcessor |
2034 // sees the right operations. | 1872 // sees the right operations. |
2035 for (size_t i = 0; i < kTotalUpdates; i++) { | 1873 for (int i = 0; i < 12; i++) { |
2036 SCOPED_TRACE(i); | 1874 SCOPED_TRACE(i); |
2037 EXPECT_TRUE(out[i].IsValid()); | 1875 EXPECT_TRUE(out[i].IsValid()); |
2038 const SyncData data(out[i].sync_data()); | 1876 const SyncData data(out[i].sync_data()); |
2039 EXPECT_TRUE(base::StartsWith(syncer::SyncDataLocal(data).GetTag(), | 1877 EXPECT_TRUE(base::StartsWith(syncer::SyncDataLocal(data).GetTag(), |
2040 manager()->current_machine_tag(), | 1878 manager()->current_machine_tag(), |
2041 base::CompareCase::SENSITIVE)); | 1879 base::CompareCase::SENSITIVE)); |
2042 const sync_pb::SessionSpecifics& specifics(data.GetSpecifics().session()); | 1880 const sync_pb::SessionSpecifics& specifics(data.GetSpecifics().session()); |
2043 EXPECT_EQ(manager()->current_machine_tag(), specifics.session_tag()); | 1881 EXPECT_EQ(manager()->current_machine_tag(), specifics.session_tag()); |
2044 if (i % kChangesPerTab == 0) { | 1882 if (i % 6 == 0) { |
2045 // First thing on an AddTab is a no-op header update for parented tab. | 1883 // First thing on an AddTab is a no-op header update for parented tab. |
2046 EXPECT_EQ(header.SerializeAsString(), | 1884 EXPECT_EQ(header.SerializeAsString(), |
2047 data.GetSpecifics().SerializeAsString()); | 1885 data.GetSpecifics().SerializeAsString()); |
2048 EXPECT_EQ(manager()->current_machine_tag(), | 1886 EXPECT_EQ(manager()->current_machine_tag(), |
2049 syncer::SyncDataLocal(data).GetTag()); | 1887 syncer::SyncDataLocal(data).GetTag()); |
2050 } else if (i % kChangesPerTab == 1) { | 1888 } else if (i % 6 == 1) { |
2051 // Next, the tab should be added. | 1889 // Next, the TabNodePool should create the tab node. |
2052 EXPECT_EQ(SyncChange::ACTION_ADD, out[i].change_type()); | 1890 EXPECT_EQ(SyncChange::ACTION_ADD, out[i].change_type()); |
2053 EXPECT_EQ(TabNodeIdToTag(manager()->current_machine_tag(), | 1891 EXPECT_EQ(TabNodePool::TabIdToTag( |
2054 data.GetSpecifics().session().tab_node_id()), | 1892 manager()->current_machine_tag(), |
| 1893 data.GetSpecifics().session().tab_node_id()), |
2055 syncer::SyncDataLocal(data).GetTag()); | 1894 syncer::SyncDataLocal(data).GetTag()); |
2056 } else if (i % kChangesPerTab == 2) { | 1895 } else if (i % 6 == 2) { |
| 1896 // Then we see the tab update to the URL. |
| 1897 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[i].change_type()); |
| 1898 EXPECT_EQ(TabNodePool::TabIdToTag( |
| 1899 manager()->current_machine_tag(), |
| 1900 data.GetSpecifics().session().tab_node_id()), |
| 1901 syncer::SyncDataLocal(data).GetTag()); |
| 1902 ASSERT_TRUE(specifics.has_tab()); |
| 1903 } else if (i % 6 == 3) { |
2057 // The header needs to be updated to reflect the new window state. | 1904 // The header needs to be updated to reflect the new window state. |
2058 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[i].change_type()); | 1905 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[i].change_type()); |
2059 EXPECT_TRUE(specifics.has_header()); | 1906 EXPECT_TRUE(specifics.has_header()); |
2060 } else if (i % kChangesPerTab == 3) { | 1907 } else if (i % 6 == 4) { |
2061 // Now we move on to NavigateAndCommit. Update the tab. | 1908 // Now we move on to NavigateAndCommit. Update the tab. |
2062 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[i].change_type()); | 1909 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[i].change_type()); |
2063 EXPECT_EQ(TabNodeIdToTag(manager()->current_machine_tag(), | 1910 EXPECT_EQ(TabNodePool::TabIdToTag( |
2064 data.GetSpecifics().session().tab_node_id()), | 1911 manager()->current_machine_tag(), |
| 1912 data.GetSpecifics().session().tab_node_id()), |
2065 syncer::SyncDataLocal(data).GetTag()); | 1913 syncer::SyncDataLocal(data).GetTag()); |
2066 ASSERT_TRUE(specifics.has_tab()); | 1914 ASSERT_TRUE(specifics.has_tab()); |
2067 } else if (i % kChangesPerTab == 4) { | 1915 } else if (i % 6 == 5) { |
2068 // The header needs to be updated to reflect the new window state. | 1916 // The header needs to be updated to reflect the new window state. |
2069 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[i].change_type()); | 1917 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[i].change_type()); |
2070 ASSERT_TRUE(specifics.has_header()); | 1918 ASSERT_TRUE(specifics.has_header()); |
2071 header = data.GetSpecifics(); | 1919 header = data.GetSpecifics(); |
2072 } | 1920 } |
2073 } | 1921 } |
2074 | 1922 |
2075 // Verify the actual content to ensure sync sees the right data. | 1923 // Verify the actual content to ensure sync sees the right data. |
2076 // When it's all said and done, the header should reflect two tabs. | 1924 // When it's all said and done, the header should reflect two tabs. |
2077 const sync_pb::SessionHeader& session_header = header.session().header(); | 1925 const sync_pb::SessionHeader& session_header = header.session().header(); |
2078 ASSERT_EQ(1, session_header.window_size()); | 1926 ASSERT_EQ(1, session_header.window_size()); |
2079 EXPECT_EQ(2, session_header.window(0).tab_size()); | 1927 EXPECT_EQ(2, session_header.window(0).tab_size()); |
2080 | 1928 |
2081 // ASSERT_TRUEs above allow us to dive in freely here. | 1929 // ASSERT_TRUEs above allow us to dive in freely here. |
2082 // Verify first tab. | 1930 // Verify first tab. |
2083 const sync_pb::SessionTab& tab1_1 = | 1931 const sync_pb::SessionTab& tab1_1 = |
2084 out[1].sync_data().GetSpecifics().session().tab(); | 1932 out[2].sync_data().GetSpecifics().session().tab(); |
2085 ASSERT_EQ(1, tab1_1.navigation_size()); | 1933 ASSERT_EQ(1, tab1_1.navigation_size()); |
2086 EXPECT_EQ(foo1.spec(), tab1_1.navigation(0).virtual_url()); | 1934 EXPECT_EQ(foo1.spec(), tab1_1.navigation(0).virtual_url()); |
2087 const sync_pb::SessionTab& tab1_2 = | 1935 const sync_pb::SessionTab& tab1_2 = |
2088 out[3].sync_data().GetSpecifics().session().tab(); | 1936 out[4].sync_data().GetSpecifics().session().tab(); |
2089 ASSERT_EQ(2, tab1_2.navigation_size()); | 1937 ASSERT_EQ(2, tab1_2.navigation_size()); |
2090 EXPECT_EQ(foo1.spec(), tab1_2.navigation(0).virtual_url()); | 1938 EXPECT_EQ(foo1.spec(), tab1_2.navigation(0).virtual_url()); |
2091 EXPECT_EQ(foo2.spec(), tab1_2.navigation(1).virtual_url()); | 1939 EXPECT_EQ(foo2.spec(), tab1_2.navigation(1).virtual_url()); |
2092 | 1940 |
2093 // Verify second tab. | 1941 // Verify second tab. |
2094 const sync_pb::SessionTab& tab2_1 = | 1942 const sync_pb::SessionTab& tab2_1 = |
2095 out[6].sync_data().GetSpecifics().session().tab(); | 1943 out[8].sync_data().GetSpecifics().session().tab(); |
2096 ASSERT_EQ(1, tab2_1.navigation_size()); | 1944 ASSERT_EQ(1, tab2_1.navigation_size()); |
2097 EXPECT_EQ(bar1.spec(), tab2_1.navigation(0).virtual_url()); | 1945 EXPECT_EQ(bar1.spec(), tab2_1.navigation(0).virtual_url()); |
2098 const sync_pb::SessionTab& tab2_2 = | 1946 const sync_pb::SessionTab& tab2_2 = |
2099 out[8].sync_data().GetSpecifics().session().tab(); | 1947 out[10].sync_data().GetSpecifics().session().tab(); |
2100 ASSERT_EQ(2, tab2_2.navigation_size()); | 1948 ASSERT_EQ(2, tab2_2.navigation_size()); |
2101 EXPECT_EQ(bar1.spec(), tab2_2.navigation(0).virtual_url()); | 1949 EXPECT_EQ(bar1.spec(), tab2_2.navigation(0).virtual_url()); |
2102 EXPECT_EQ(bar2.spec(), tab2_2.navigation(1).virtual_url()); | 1950 EXPECT_EQ(bar2.spec(), tab2_2.navigation(1).virtual_url()); |
2103 | |
2104 // Verify tab delegates have Sync ids. | |
2105 std::set<const SyncedWindowDelegate*> window_delegates = | |
2106 get_synced_window_getter()->GetSyncedWindowDelegates(); | |
2107 // Sync ids are in reverse order because tabs are inserted at the beginning | |
2108 // of the tab list. | |
2109 EXPECT_EQ(1, (*window_delegates.begin())->GetTabAt(0)->GetSyncId()); | |
2110 EXPECT_EQ(0, (*window_delegates.begin())->GetTabAt(1)->GetSyncId()); | |
2111 } | 1951 } |
2112 | 1952 |
2113 // Check that if a tab becomes uninteresting (for example no syncable URLs), | 1953 // Check that if a tab becomes uninteresting (for example no syncable URLs), |
2114 // we correctly remove it from the header node. | 1954 // we correctly remove it from the header node. |
2115 TEST_F(SessionsSyncManagerTest, TabBecomesUninteresting) { | 1955 TEST_F(SessionsSyncManagerTest, TabBecomesUninteresting) { |
2116 syncer::SyncChangeList out; | 1956 syncer::SyncChangeList out; |
2117 // Init with no local data, relies on MergeLocalSessionNoTabs. | 1957 // Init with no local data, relies on MergeLocalSessionNoTabs. |
2118 InitWithSyncDataTakeOutput(syncer::SyncDataList(), &out); | 1958 InitWithSyncDataTakeOutput(syncer::SyncDataList(), &out); |
2119 ASSERT_FALSE(manager()->current_machine_tag().empty()); | 1959 ASSERT_FALSE(manager()->current_machine_tag().empty()); |
2120 ASSERT_EQ(2U, out.size()); | 1960 ASSERT_EQ(2U, out.size()); |
2121 out.clear(); | 1961 out.clear(); |
2122 | 1962 |
2123 const GURL kValidUrl("http://foo/1"); | 1963 const GURL kValidUrl("http://foo/1"); |
2124 const GURL kInternalUrl("chrome://internal"); | 1964 const GURL kInternalUrl("chrome://internal"); |
2125 | 1965 |
2126 // Add an interesting tab. | 1966 // Add an interesting tab. |
2127 AddTab(browser(), kValidUrl); | 1967 AddTab(browser(), kValidUrl); |
2128 // No-op header update, tab creation, header update. | 1968 // No-op header update, tab creation, tab update, header update. |
2129 ASSERT_EQ(3U, out.size()); | 1969 ASSERT_EQ(4U, out.size()); |
2130 // The last two are the interesting updates. | 1970 // The last two are the interesting updates. |
2131 ASSERT_TRUE(out[1].sync_data().GetSpecifics().session().has_tab()); | 1971 ASSERT_TRUE(out[2].sync_data().GetSpecifics().session().has_tab()); |
2132 EXPECT_EQ(kValidUrl.spec(), out[1] | 1972 EXPECT_EQ(kValidUrl.spec(), out[2] |
2133 .sync_data() | 1973 .sync_data() |
2134 .GetSpecifics() | 1974 .GetSpecifics() |
2135 .session() | 1975 .session() |
2136 .tab() | 1976 .tab() |
2137 .navigation(0) | 1977 .navigation(0) |
2138 .virtual_url()); | 1978 .virtual_url()); |
2139 ASSERT_TRUE(out[2].sync_data().GetSpecifics().session().has_header()); | 1979 ASSERT_TRUE(out[3].sync_data().GetSpecifics().session().has_header()); |
2140 ASSERT_EQ(1, | 1980 ASSERT_EQ(1, |
2141 out[2].sync_data().GetSpecifics().session().header().window_size()); | 1981 out[3].sync_data().GetSpecifics().session().header().window_size()); |
2142 ASSERT_EQ(1, out[2] | 1982 ASSERT_EQ(1, out[3] |
2143 .sync_data() | 1983 .sync_data() |
2144 .GetSpecifics() | 1984 .GetSpecifics() |
2145 .session() | 1985 .session() |
2146 .header() | 1986 .header() |
2147 .window(0) | 1987 .window(0) |
2148 .tab_size()); | 1988 .tab_size()); |
2149 | 1989 |
2150 // Navigate five times to uninteresting urls to push the interesting one off | 1990 // Navigate five times to uninteresting urls to push the interesting one off |
2151 // the back of the stack. | 1991 // the back of the stack. |
2152 NavigateAndCommitActiveTab(kInternalUrl); | 1992 NavigateAndCommitActiveTab(kInternalUrl); |
(...skipping 15 matching lines...) Expand all Loading... |
2168 | 2008 |
2169 // Ensure model association associates the pre-existing tabs. | 2009 // Ensure model association associates the pre-existing tabs. |
2170 TEST_F(SessionsSyncManagerTest, MergeLocalSessionExistingTabs) { | 2010 TEST_F(SessionsSyncManagerTest, MergeLocalSessionExistingTabs) { |
2171 AddTab(browser(), GURL("http://foo1")); | 2011 AddTab(browser(), GURL("http://foo1")); |
2172 NavigateAndCommitActiveTab(GURL("http://foo2")); // Adds back entry. | 2012 NavigateAndCommitActiveTab(GURL("http://foo2")); // Adds back entry. |
2173 AddTab(browser(), GURL("http://bar1")); | 2013 AddTab(browser(), GURL("http://bar1")); |
2174 NavigateAndCommitActiveTab(GURL("http://bar2")); // Adds back entry. | 2014 NavigateAndCommitActiveTab(GURL("http://bar2")); // Adds back entry. |
2175 | 2015 |
2176 syncer::SyncChangeList out; | 2016 syncer::SyncChangeList out; |
2177 InitWithSyncDataTakeOutput(syncer::SyncDataList(), &out); | 2017 InitWithSyncDataTakeOutput(syncer::SyncDataList(), &out); |
2178 ASSERT_EQ(4U, out.size()); // Header creation, add two tabs, header update | 2018 ASSERT_EQ(6U, out.size()); |
2179 | 2019 |
2180 // Check that this machine's data is not included in the foreign windows. | 2020 // Check that this machine's data is not included in the foreign windows. |
2181 std::vector<const SyncedSession*> foreign_sessions; | 2021 std::vector<const SyncedSession*> foreign_sessions; |
2182 ASSERT_FALSE(manager()->GetAllForeignSessions(&foreign_sessions)); | 2022 ASSERT_FALSE(manager()->GetAllForeignSessions(&foreign_sessions)); |
2183 | 2023 |
2184 // Verify the header. | 2024 // Verify the header. |
2185 EXPECT_TRUE(out[0].IsValid()); | 2025 EXPECT_TRUE(out[0].IsValid()); |
2186 EXPECT_EQ(SyncChange::ACTION_ADD, out[0].change_type()); | 2026 EXPECT_EQ(SyncChange::ACTION_ADD, out[0].change_type()); |
2187 const SyncData data(out[0].sync_data()); | 2027 const SyncData data(out[0].sync_data()); |
2188 EXPECT_EQ(manager()->current_machine_tag(), | 2028 EXPECT_EQ(manager()->current_machine_tag(), |
2189 syncer::SyncDataLocal(data).GetTag()); | 2029 syncer::SyncDataLocal(data).GetTag()); |
2190 const sync_pb::SessionSpecifics& specifics(data.GetSpecifics().session()); | 2030 const sync_pb::SessionSpecifics& specifics(data.GetSpecifics().session()); |
2191 EXPECT_EQ(manager()->current_machine_tag(), specifics.session_tag()); | 2031 EXPECT_EQ(manager()->current_machine_tag(), specifics.session_tag()); |
2192 EXPECT_TRUE(specifics.has_header()); | 2032 EXPECT_TRUE(specifics.has_header()); |
2193 const sync_pb::SessionHeader& header_s = specifics.header(); | 2033 const sync_pb::SessionHeader& header_s = specifics.header(); |
2194 EXPECT_TRUE(header_s.has_device_type()); | 2034 EXPECT_TRUE(header_s.has_device_type()); |
2195 EXPECT_EQ(GetLocalDeviceInfo()->client_name(), header_s.client_name()); | 2035 EXPECT_EQ(GetLocalDeviceInfo()->client_name(), header_s.client_name()); |
2196 EXPECT_EQ(0, header_s.window_size()); | 2036 EXPECT_EQ(0, header_s.window_size()); |
2197 | 2037 |
2198 // Verify the tab node creations and updates with content. | 2038 // Verify the tab node creations and updates with content. |
2199 for (int i = 1; i < 3; i++) { | 2039 for (int i = 1; i < 5; i++) { |
2200 EXPECT_TRUE(out[i].IsValid()); | 2040 EXPECT_TRUE(out[i].IsValid()); |
2201 const SyncData data(out[i].sync_data()); | 2041 const SyncData data(out[i].sync_data()); |
2202 EXPECT_TRUE(base::StartsWith(syncer::SyncDataLocal(data).GetTag(), | 2042 EXPECT_TRUE(base::StartsWith(syncer::SyncDataLocal(data).GetTag(), |
2203 manager()->current_machine_tag(), | 2043 manager()->current_machine_tag(), |
2204 base::CompareCase::SENSITIVE)); | 2044 base::CompareCase::SENSITIVE)); |
2205 const sync_pb::SessionSpecifics& specifics(data.GetSpecifics().session()); | 2045 const sync_pb::SessionSpecifics& specifics(data.GetSpecifics().session()); |
2206 EXPECT_EQ(manager()->current_machine_tag(), specifics.session_tag()); | 2046 EXPECT_EQ(manager()->current_machine_tag(), specifics.session_tag()); |
2207 EXPECT_EQ(SyncChange::ACTION_ADD, out[i].change_type()); | 2047 if (i % 2 == 1) { |
| 2048 EXPECT_EQ(SyncChange::ACTION_ADD, out[i].change_type()); |
| 2049 } else { |
| 2050 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[i].change_type()); |
| 2051 EXPECT_TRUE(specifics.has_tab()); |
| 2052 } |
2208 } | 2053 } |
2209 | 2054 |
2210 // Verify the header was updated to reflect new window state. | 2055 // Verify the header was updated to reflect new window state. |
2211 EXPECT_TRUE(out[3].IsValid()); | 2056 EXPECT_TRUE(out[5].IsValid()); |
2212 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[3].change_type()); | 2057 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[5].change_type()); |
2213 const SyncData data_2(out[3].sync_data()); | 2058 const SyncData data_2(out[5].sync_data()); |
2214 EXPECT_EQ(manager()->current_machine_tag(), | 2059 EXPECT_EQ(manager()->current_machine_tag(), |
2215 syncer::SyncDataLocal(data_2).GetTag()); | 2060 syncer::SyncDataLocal(data_2).GetTag()); |
2216 const sync_pb::SessionSpecifics& specifics2(data_2.GetSpecifics().session()); | 2061 const sync_pb::SessionSpecifics& specifics2(data_2.GetSpecifics().session()); |
2217 EXPECT_EQ(manager()->current_machine_tag(), specifics2.session_tag()); | 2062 EXPECT_EQ(manager()->current_machine_tag(), specifics2.session_tag()); |
2218 EXPECT_TRUE(specifics2.has_header()); | 2063 EXPECT_TRUE(specifics2.has_header()); |
2219 const sync_pb::SessionHeader& header_s2 = specifics2.header(); | 2064 const sync_pb::SessionHeader& header_s2 = specifics2.header(); |
2220 EXPECT_EQ(1, header_s2.window_size()); | 2065 EXPECT_EQ(1, header_s2.window_size()); |
2221 | 2066 |
2222 // Verify tab delegates have Sync ids. | 2067 // Verify TabLinks. |
2223 std::set<const SyncedWindowDelegate*> window_delegates = | 2068 SessionsSyncManager::TabLinksMap tab_map = manager()->local_tab_map_; |
2224 get_synced_window_getter()->GetSyncedWindowDelegates(); | 2069 ASSERT_EQ(2U, tab_map.size()); |
2225 // Sync ids are in same order as tabs because the association happens after | 2070 // Tabs are ordered by sessionid in tab_map, so should be able to traverse |
2226 // the tabs are opened (and therefore iterates through same order). | 2071 // the tree based on order of tabs created |
2227 EXPECT_EQ(0, (*window_delegates.begin())->GetTabAt(0)->GetSyncId()); | 2072 SessionsSyncManager::TabLinksMap::iterator iter = tab_map.begin(); |
2228 EXPECT_EQ(1, (*window_delegates.begin())->GetTabAt(1)->GetSyncId()); | 2073 ASSERT_EQ(2, iter->second->tab()->GetEntryCount()); |
| 2074 EXPECT_EQ(GURL("http://foo1"), iter->second->tab()->GetVirtualURLAtIndex(0)); |
| 2075 EXPECT_EQ(GURL("http://foo2"), iter->second->tab()->GetVirtualURLAtIndex(1)); |
| 2076 iter++; |
| 2077 ASSERT_EQ(2, iter->second->tab()->GetEntryCount()); |
| 2078 EXPECT_EQ(GURL("http://bar1"), iter->second->tab()->GetVirtualURLAtIndex(0)); |
| 2079 EXPECT_EQ(GURL("http://bar2"), iter->second->tab()->GetVirtualURLAtIndex(1)); |
2229 } | 2080 } |
2230 | 2081 |
2231 TEST_F(SessionsSyncManagerTest, ForeignSessionModifiedTime) { | 2082 TEST_F(SessionsSyncManagerTest, ForeignSessionModifiedTime) { |
2232 syncer::SyncDataList foreign_data; | 2083 syncer::SyncDataList foreign_data; |
2233 base::Time newest_time = base::Time::Now() - base::TimeDelta::FromDays(1); | 2084 base::Time newest_time = base::Time::Now() - base::TimeDelta::FromDays(1); |
2234 base::Time middle_time = base::Time::Now() - base::TimeDelta::FromDays(2); | 2085 base::Time middle_time = base::Time::Now() - base::TimeDelta::FromDays(2); |
2235 base::Time oldest_time = base::Time::Now() - base::TimeDelta::FromDays(3); | 2086 base::Time oldest_time = base::Time::Now() - base::TimeDelta::FromDays(3); |
2236 | 2087 |
2237 { | 2088 { |
2238 std::string session_tag = "tag1"; | 2089 std::string session_tag = "tag1"; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2321 | 2172 |
2322 // Now garbage collect and verify the non-stale session is still there. | 2173 // Now garbage collect and verify the non-stale session is still there. |
2323 manager()->DoGarbageCollection(); | 2174 manager()->DoGarbageCollection(); |
2324 ASSERT_EQ(5U, output.size()); | 2175 ASSERT_EQ(5U, output.size()); |
2325 EXPECT_EQ(SyncChange::ACTION_DELETE, output[0].change_type()); | 2176 EXPECT_EQ(SyncChange::ACTION_DELETE, output[0].change_type()); |
2326 const SyncData data(output[0].sync_data()); | 2177 const SyncData data(output[0].sync_data()); |
2327 EXPECT_EQ(tag1, syncer::SyncDataLocal(data).GetTag()); | 2178 EXPECT_EQ(tag1, syncer::SyncDataLocal(data).GetTag()); |
2328 for (int i = 1; i < 5; i++) { | 2179 for (int i = 1; i < 5; i++) { |
2329 EXPECT_EQ(SyncChange::ACTION_DELETE, output[i].change_type()); | 2180 EXPECT_EQ(SyncChange::ACTION_DELETE, output[i].change_type()); |
2330 const SyncData data(output[i].sync_data()); | 2181 const SyncData data(output[i].sync_data()); |
2331 EXPECT_EQ(TabNodeIdToTag(tag1, i), syncer::SyncDataLocal(data).GetTag()); | 2182 EXPECT_EQ(TabNodePool::TabIdToTag(tag1, i), |
| 2183 syncer::SyncDataLocal(data).GetTag()); |
2332 } | 2184 } |
2333 | 2185 |
2334 ASSERT_TRUE(manager()->GetAllForeignSessions(&foreign_sessions)); | 2186 ASSERT_TRUE(manager()->GetAllForeignSessions(&foreign_sessions)); |
2335 ASSERT_EQ(1U, foreign_sessions.size()); | 2187 ASSERT_EQ(1U, foreign_sessions.size()); |
2336 std::vector<std::vector<SessionID::id_type> > session_reference; | 2188 std::vector<std::vector<SessionID::id_type> > session_reference; |
2337 session_reference.push_back(tab_list2); | 2189 session_reference.push_back(tab_list2); |
2338 helper()->VerifySyncedSession(tag2, session_reference, | 2190 helper()->VerifySyncedSession(tag2, session_reference, |
2339 *(foreign_sessions[0])); | 2191 *(foreign_sessions[0])); |
2340 } | 2192 } |
2341 | 2193 |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2444 } | 2296 } |
2445 | 2297 |
2446 // Test that swapping WebContents for a tab is properly observed and handled | 2298 // Test that swapping WebContents for a tab is properly observed and handled |
2447 // by the SessionsSyncManager. | 2299 // by the SessionsSyncManager. |
2448 TEST_F(SessionsSyncManagerTest, CheckPrerenderedWebContentsSwap) { | 2300 TEST_F(SessionsSyncManagerTest, CheckPrerenderedWebContentsSwap) { |
2449 AddTab(browser(), GURL("http://foo1")); | 2301 AddTab(browser(), GURL("http://foo1")); |
2450 NavigateAndCommitActiveTab(GURL("http://foo2")); | 2302 NavigateAndCommitActiveTab(GURL("http://foo2")); |
2451 | 2303 |
2452 syncer::SyncChangeList out; | 2304 syncer::SyncChangeList out; |
2453 InitWithSyncDataTakeOutput(syncer::SyncDataList(), &out); | 2305 InitWithSyncDataTakeOutput(syncer::SyncDataList(), &out); |
2454 ASSERT_EQ(3U, out.size()); // Header ADD, tab ADD, header UPDATE. | 2306 ASSERT_EQ(4U, out.size()); // Header, tab ADD, tab UPDATE, header UPDATE. |
2455 out.clear(); | |
2456 | 2307 |
2457 // To simulate WebContents swap during prerendering, create new WebContents | 2308 // To simulate WebContents swap during prerendering, create new WebContents |
2458 // and swap with old WebContents. | 2309 // and swap with old WebContents. |
2459 std::unique_ptr<content::WebContents> old_web_contents; | 2310 std::unique_ptr<content::WebContents> old_web_contents; |
2460 old_web_contents.reset(browser()->tab_strip_model()->GetActiveWebContents()); | 2311 old_web_contents.reset(browser()->tab_strip_model()->GetActiveWebContents()); |
2461 | 2312 |
2462 // Create new WebContents, with the required tab helpers. | 2313 // Create new WebContents, with the required tab helpers. |
2463 WebContents* new_web_contents = WebContents::CreateWithSessionStorage( | 2314 WebContents* new_web_contents = WebContents::CreateWithSessionStorage( |
2464 WebContents::CreateParams(profile()), | 2315 WebContents::CreateParams(profile()), |
2465 old_web_contents->GetController().GetSessionStorageNamespaceMap()); | 2316 old_web_contents->GetController().GetSessionStorageNamespaceMap()); |
2466 SessionTabHelper::CreateForWebContents(new_web_contents); | 2317 SessionTabHelper::CreateForWebContents(new_web_contents); |
2467 TabContentsSyncedTabDelegate::CreateForWebContents(new_web_contents); | 2318 TabContentsSyncedTabDelegate::CreateForWebContents(new_web_contents); |
2468 new_web_contents->GetController() | 2319 new_web_contents->GetController() |
2469 .CopyStateFrom(old_web_contents->GetController()); | 2320 .CopyStateFrom(old_web_contents->GetController()); |
2470 | 2321 |
2471 // Swap the WebContents. | 2322 // Swap the WebContents. |
2472 int index = browser()->tab_strip_model()->GetIndexOfWebContents( | 2323 int index = browser()->tab_strip_model()->GetIndexOfWebContents( |
2473 old_web_contents.get()); | 2324 old_web_contents.get()); |
2474 browser()->tab_strip_model()->ReplaceWebContentsAt(index, new_web_contents); | 2325 browser()->tab_strip_model()->ReplaceWebContentsAt(index, new_web_contents); |
2475 | 2326 |
2476 ASSERT_EQ(4U, out.size()); | 2327 ASSERT_EQ(9U, out.size()); |
2477 EXPECT_EQ(SyncChange::ACTION_ADD, out[0].change_type()); | 2328 EXPECT_EQ(SyncChange::ACTION_ADD, out[4].change_type()); |
2478 out.clear(); | 2329 EXPECT_EQ(SyncChange::ACTION_UPDATE, out[5].change_type()); |
2479 | 2330 |
2480 // Navigate away. +1 tab updates, 1 header update. | 2331 // Navigate away. |
2481 NavigateAndCommitActiveTab(GURL("http://bar2")); | 2332 NavigateAndCommitActiveTab(GURL("http://bar2")); |
2482 | 2333 |
2483 // Delete old WebContents. This should not crash. | 2334 // Delete old WebContents. This should not crash. |
2484 // +1 no-op header update. | |
2485 old_web_contents.reset(); | 2335 old_web_contents.reset(); |
2486 | 2336 |
2487 // Try more navigations and verify output size. This can also reveal | 2337 // Try more navigations and verify output size. This can also reveal |
2488 // bugs (leaks) on memcheck bots if the SessionSyncManager | 2338 // bugs (leaks) on memcheck bots if the SessionSyncManager |
2489 // didn't properly clean up the tab pool or session tracker. | 2339 // didn't properly clean up the tab pool or session tracker. |
2490 // +1 tab updates, 1 header update. | |
2491 NavigateAndCommitActiveTab(GURL("http://bar3")); | 2340 NavigateAndCommitActiveTab(GURL("http://bar3")); |
2492 | 2341 |
2493 // +1 no-op header update, tab add, header update. | |
2494 AddTab(browser(), GURL("http://bar4")); | 2342 AddTab(browser(), GURL("http://bar4")); |
2495 // +1 tab update, header update. | |
2496 NavigateAndCommitActiveTab(GURL("http://bar5")); | 2343 NavigateAndCommitActiveTab(GURL("http://bar5")); |
2497 ASSERT_EQ(10U, out.size()); | 2344 ASSERT_EQ(19U, out.size()); |
2498 } | 2345 } |
2499 | 2346 |
2500 // Test that NOTIFICATION_FOREIGN_SESSION_UPDATED is sent when processing | 2347 // Test that NOTIFICATION_FOREIGN_SESSION_UPDATED is sent when processing |
2501 // sync changes. | 2348 // sync changes. |
2502 TEST_F(SessionsSyncManagerTest, NotifiedOfUpdates) { | 2349 TEST_F(SessionsSyncManagerTest, NotifiedOfUpdates) { |
2503 ASSERT_FALSE(observer()->notified_of_update()); | 2350 ASSERT_FALSE(observer()->notified_of_update()); |
2504 InitWithNoSyncData(); | 2351 InitWithNoSyncData(); |
2505 | 2352 |
2506 SessionID::id_type n[] = {5}; | 2353 SessionID::id_type n[] = {5}; |
2507 std::vector<sync_pb::SessionSpecifics> tabs1; | 2354 std::vector<sync_pb::SessionSpecifics> tabs1; |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2756 base::Time last_time; | 2603 base::Time last_time; |
2757 for (size_t i = 0; i < tabs.size(); ++i) { | 2604 for (size_t i = 0; i < tabs.size(); ++i) { |
2758 base::Time this_time = tabs[i]->timestamp; | 2605 base::Time this_time = tabs[i]->timestamp; |
2759 if (i > 0) | 2606 if (i > 0) |
2760 ASSERT_GE(last_time, this_time); | 2607 ASSERT_GE(last_time, this_time); |
2761 last_time = tabs[i]->timestamp; | 2608 last_time = tabs[i]->timestamp; |
2762 } | 2609 } |
2763 } | 2610 } |
2764 | 2611 |
2765 } // namespace sync_sessions | 2612 } // namespace sync_sessions |
OLD | NEW |