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 21 matching lines...) Expand all Loading... |
32 using sessions::SerializedNavigationEntryTestHelper; | 32 using sessions::SerializedNavigationEntryTestHelper; |
33 using syncer::DeviceInfo; | 33 using syncer::DeviceInfo; |
34 using syncer::LocalDeviceInfoProvider; | 34 using syncer::LocalDeviceInfoProvider; |
35 using syncer::LocalDeviceInfoProviderMock; | 35 using syncer::LocalDeviceInfoProviderMock; |
36 using syncer::SyncChange; | 36 using syncer::SyncChange; |
37 using syncer::SyncChangeList; | 37 using syncer::SyncChangeList; |
38 using syncer::SyncData; | 38 using syncer::SyncData; |
39 using syncer::SyncDataList; | 39 using syncer::SyncDataList; |
40 using syncer::SyncDataLocal; | 40 using syncer::SyncDataLocal; |
41 using syncer::SyncError; | 41 using syncer::SyncError; |
| 42 using testing::ElementsAre; |
42 | 43 |
43 namespace sync_sessions { | 44 namespace sync_sessions { |
44 | 45 |
45 namespace { | 46 namespace { |
46 | 47 |
47 const char kTitle[] = "title"; | 48 const char kTitle[] = "title"; |
48 const char kFoo1[] = "http://foo1/"; | 49 const char kFoo1[] = "http://foo1/"; |
49 const char kFoo2[] = "http://foo2/"; | 50 const char kFoo2[] = "http://foo2/"; |
50 const char kBar1[] = "http://bar1/"; | 51 const char kBar1[] = "http://bar1/"; |
51 const char kBar2[] = "http://bar2/"; | 52 const char kBar2[] = "http://bar2/"; |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 int http_count = 0; | 205 int http_count = 0; |
205 for (auto& entry : entries_) { | 206 for (auto& entry : entries_) { |
206 if (!entry->virtual_url().is_valid()) | 207 if (!entry->virtual_url().is_valid()) |
207 return false; | 208 return false; |
208 if (entry->virtual_url().SchemeIsHTTPOrHTTPS()) | 209 if (entry->virtual_url().SchemeIsHTTPOrHTTPS()) |
209 http_count++; | 210 http_count++; |
210 } | 211 } |
211 return http_count > 0; | 212 return http_count > 0; |
212 } | 213 } |
213 | 214 |
214 SessionID::id_type GetSourceTabID() const override { return kInvalidTabID; } | 215 SessionID::id_type GetSourceTabID() const override { return source_tab_id_; } |
| 216 void SetSourceTabID(SessionID::id_type source_tab_id) { |
| 217 source_tab_id_ = source_tab_id; |
| 218 } |
215 | 219 |
216 void AppendEntry(std::unique_ptr<sessions::SerializedNavigationEntry> entry) { | 220 void AppendEntry(std::unique_ptr<sessions::SerializedNavigationEntry> entry) { |
217 entries_.push_back(std::move(entry)); | 221 entries_.push_back(std::move(entry)); |
218 } | 222 } |
219 | 223 |
220 void set_current_entry_index(int i) { current_entry_index_ = i; } | 224 void set_current_entry_index(int i) { current_entry_index_ = i; } |
221 | 225 |
222 void SetWindowId(SessionID::id_type window_id) { | 226 void SetWindowId(SessionID::id_type window_id) { |
223 window_id_.set_id(window_id); | 227 window_id_.set_id(window_id); |
224 } | 228 } |
(...skipping 13 matching lines...) Expand all Loading... |
238 current_entry_index_ = 0; | 242 current_entry_index_ = 0; |
239 sync_id_ = TabNodePool::kInvalidTabNodeID; | 243 sync_id_ = TabNodePool::kInvalidTabNodeID; |
240 entries_.clear(); | 244 entries_.clear(); |
241 } | 245 } |
242 | 246 |
243 private: | 247 private: |
244 int current_entry_index_ = -1; | 248 int current_entry_index_ = -1; |
245 bool is_supervised_ = false; | 249 bool is_supervised_ = false; |
246 int sync_id_ = kInvalidTabID; | 250 int sync_id_ = kInvalidTabID; |
247 SessionID tab_id_; | 251 SessionID tab_id_; |
| 252 SessionID::id_type source_tab_id_ = kInvalidTabID; |
248 SessionID window_id_; | 253 SessionID window_id_; |
249 std::vector<std::unique_ptr<const sessions::SerializedNavigationEntry>> | 254 std::vector<std::unique_ptr<const sessions::SerializedNavigationEntry>> |
250 blocked_navigations_; | 255 blocked_navigations_; |
251 std::vector<std::unique_ptr<const sessions::SerializedNavigationEntry>> | 256 std::vector<std::unique_ptr<const sessions::SerializedNavigationEntry>> |
252 entries_; | 257 entries_; |
253 }; | 258 }; |
254 | 259 |
255 // A placeholder delegate. These delegates have no WebContents, simulating a tab | 260 // A placeholder delegate. These delegates have no WebContents, simulating a tab |
256 // that has been restored without bringing its state fully into memory (for | 261 // that has been restored without bringing its state fully into memory (for |
257 // example on Android), or where the tab's contents have been evicted from | 262 // example on Android), or where the tab's contents have been evicted from |
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
677 | 682 |
678 SyncData CreateRemoteData(const sync_pb::EntitySpecifics& entity, | 683 SyncData CreateRemoteData(const sync_pb::EntitySpecifics& entity, |
679 base::Time mtime = base::Time()) const { | 684 base::Time mtime = base::Time()) const { |
680 // The server ID is never relevant to these tests, so just use 1. | 685 // The server ID is never relevant to these tests, so just use 1. |
681 return SyncData::CreateRemoteData( | 686 return SyncData::CreateRemoteData( |
682 1, entity, mtime, syncer::AttachmentIdList(), | 687 1, entity, mtime, syncer::AttachmentIdList(), |
683 syncer::AttachmentServiceProxyForTest::Create(), | 688 syncer::AttachmentServiceProxyForTest::Create(), |
684 SessionsSyncManager::TagHashFromSpecifics(entity.session())); | 689 SessionsSyncManager::TagHashFromSpecifics(entity.session())); |
685 } | 690 } |
686 | 691 |
687 // Creates a new tab within the window specified by |window_id|, and points it | 692 // Creates a new tab within the window specified by |window_id| and from the |
688 // at |url|. Returns the newly created TestSyncedTabDelegate (not owned). | 693 // source tab |source_tab_id|, and points it at |url|. Returns the newly |
| 694 // created TestSyncedTabDelegate (not owned). |
689 TestSyncedTabDelegate* AddTab(SessionID::id_type window_id, | 695 TestSyncedTabDelegate* AddTab(SessionID::id_type window_id, |
690 const std::string& url, | 696 const std::string& url, |
| 697 SessionID::id_type source_tab_id, |
691 base::Time time) { | 698 base::Time time) { |
692 tabs_.push_back(base::MakeUnique<TestSyncedTabDelegate>()); | 699 tabs_.push_back(base::MakeUnique<TestSyncedTabDelegate>()); |
693 for (auto& window : windows_) { | 700 for (auto& window : windows_) { |
694 if (window->GetSessionId() == window_id) { | 701 if (window->GetSessionId() == window_id) { |
695 int tab_index = window->GetTabCount(); | 702 int tab_index = window->GetTabCount(); |
696 window->OverrideTabAt(tab_index, tabs_.back().get()); | 703 window->OverrideTabAt(tab_index, tabs_.back().get()); |
697 } | 704 } |
698 } | 705 } |
| 706 tabs_.back()->SetSourceTabID(source_tab_id); |
699 | 707 |
700 // Simulate the browser firing a tab parented notification, ahead of the | 708 // Simulate the browser firing a tab parented notification, ahead of the |
701 // actual navigation. | 709 // actual navigation. |
702 router_->NotifyNav(tabs_.back().get()); | 710 router_->NotifyNav(tabs_.back().get()); |
703 | 711 |
704 // Now do the actual navigation. | 712 // Now do the actual navigation. |
705 NavigateTab(tabs_.back().get(), url, time); | 713 if (source_tab_id != kInvalidTabID) { |
| 714 NavigateTab(tabs_.back().get(), url, time, ui::PAGE_TRANSITION_LINK); |
| 715 } else { |
| 716 NavigateTab(tabs_.back().get(), url, time); |
| 717 } |
706 return tabs_.back().get(); | 718 return tabs_.back().get(); |
707 } | 719 } |
708 TestSyncedTabDelegate* AddTab(SessionID::id_type window_id, | 720 TestSyncedTabDelegate* AddTab(SessionID::id_type window_id, |
| 721 const std::string& url, |
| 722 base::Time time) { |
| 723 return AddTab(window_id, url, kInvalidTabID, time); |
| 724 } |
| 725 TestSyncedTabDelegate* AddTab(SessionID::id_type window_id, |
| 726 const std::string& url, |
| 727 SessionID::id_type source_tab_id) { |
| 728 return AddTab(window_id, url, source_tab_id, base::Time::Now()); |
| 729 } |
| 730 TestSyncedTabDelegate* AddTab(SessionID::id_type window_id, |
709 const std::string& url) { | 731 const std::string& url) { |
710 return AddTab(window_id, url, base::Time::Now()); | 732 return AddTab(window_id, url, kInvalidTabID); |
711 } | 733 } |
712 | 734 |
713 void NavigateTab(TestSyncedTabDelegate* delegate, | 735 void NavigateTab(TestSyncedTabDelegate* delegate, |
714 const std::string& url, | 736 const std::string& url, |
715 base::Time time, | 737 base::Time time, |
716 ui::PageTransition transition) { | 738 ui::PageTransition transition) { |
717 auto entry = base::MakeUnique<sessions::SerializedNavigationEntry>( | 739 auto entry = base::MakeUnique<sessions::SerializedNavigationEntry>( |
718 SerializedNavigationEntryTestHelper::CreateNavigation(url, kTitle)); | 740 SerializedNavigationEntryTestHelper::CreateNavigation(url, kTitle)); |
719 SerializedNavigationEntryTestHelper::SetTimestamp(time, entry.get()); | 741 SerializedNavigationEntryTestHelper::SetTimestamp(time, entry.get()); |
720 SerializedNavigationEntryTestHelper::SetTransitionType(transition, | 742 SerializedNavigationEntryTestHelper::SetTransitionType(transition, |
(...skipping 1866 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2587 tab = SyncDataLocal(changes[3].sync_data()).GetSpecifics().session().tab(); | 2609 tab = SyncDataLocal(changes[3].sync_data()).GetSpecifics().session().tab(); |
2588 EXPECT_EQ(tab.navigation_size(), 2); | 2610 EXPECT_EQ(tab.navigation_size(), 2); |
2589 EXPECT_EQ(tab.navigation(0).global_id(), tab.navigation(0).task_id()); | 2611 EXPECT_EQ(tab.navigation(0).global_id(), tab.navigation(0).task_id()); |
2590 EXPECT_TRUE(tab.navigation(0).ancestor_task_id().empty()); | 2612 EXPECT_TRUE(tab.navigation(0).ancestor_task_id().empty()); |
2591 EXPECT_EQ(tab.navigation(1).global_id(), tab.navigation(1).task_id()); | 2613 EXPECT_EQ(tab.navigation(1).global_id(), tab.navigation(1).task_id()); |
2592 // navigation(1) is a subtask of navigation(0). | 2614 // navigation(1) is a subtask of navigation(0). |
2593 EXPECT_EQ(tab.navigation(1).ancestor_task_id_size(), 1); | 2615 EXPECT_EQ(tab.navigation(1).ancestor_task_id_size(), 1); |
2594 EXPECT_EQ(tab.navigation(1).ancestor_task_id(0), tab.navigation(0).task_id()); | 2616 EXPECT_EQ(tab.navigation(1).ancestor_task_id(0), tab.navigation(0).task_id()); |
2595 } | 2617 } |
2596 | 2618 |
| 2619 // Tests that task ids are generated for navigations on multiple local tabs. |
| 2620 TEST_F(SessionsSyncManagerTest, TrackTasksOnMultipleTabs) { |
| 2621 SyncChangeList changes; |
| 2622 TestSyncedWindowDelegate* window = AddWindow(); |
| 2623 InitWithSyncDataTakeOutput(SyncDataList(), &changes); |
| 2624 SessionID::id_type window_id = window->GetSessionId(); |
| 2625 ASSERT_FALSE(manager()->current_machine_tag().empty()); |
| 2626 changes.clear(); |
| 2627 |
| 2628 // Tab 1 |
| 2629 TestSyncedTabDelegate* tab1 = AddTab(window_id, kFoo1); |
| 2630 NavigateTab(tab1, kFoo2, ui::PAGE_TRANSITION_LINK); |
| 2631 // Tab 2 from Tab 1. |
| 2632 TestSyncedTabDelegate* tab2 = AddTab(window_id, kBar1, tab1->GetSessionId()); |
| 2633 NavigateTab(tab2, kBar2, ui::PAGE_TRANSITION_LINK); |
| 2634 // Tab 3 from Tab 2. |
| 2635 TestSyncedTabDelegate* tab3 = AddTab(window_id, kBaz1, tab2->GetSessionId()); |
| 2636 NavigateTab(tab3, kBaz2, ui::PAGE_TRANSITION_LINK); |
| 2637 |
| 2638 // We only test changes for tab add and tab update, and ignore header updates. |
| 2639 FilterOutLocalHeaderChanges(&changes); |
| 2640 // Sync data of updating Tab 1 change |
| 2641 sync_pb::SessionTab sync_data_tab1 = |
| 2642 SyncDataLocal(changes[1].sync_data()).GetSpecifics().session().tab(); |
| 2643 ASSERT_EQ(2, sync_data_tab1.navigation_size()); |
| 2644 |
| 2645 // Sync data of updating Tab 2 change |
| 2646 sync_pb::SessionTab sync_data_tab2 = |
| 2647 SyncDataLocal(changes[3].sync_data()).GetSpecifics().session().tab(); |
| 2648 ASSERT_EQ(2, sync_data_tab1.navigation_size()); |
| 2649 |
| 2650 // Sync data of adding Tab 3 change |
| 2651 sync_pb::SessionTab sync_data_tab3 = |
| 2652 SyncDataLocal(changes[4].sync_data()).GetSpecifics().session().tab(); |
| 2653 ASSERT_EQ(1, sync_data_tab3.navigation_size()); |
| 2654 EXPECT_EQ(sync_data_tab3.navigation(0).global_id(), |
| 2655 sync_data_tab3.navigation(0).task_id()); |
| 2656 EXPECT_THAT(sync_data_tab3.navigation(0).ancestor_task_id(), |
| 2657 ElementsAre(sync_data_tab1.navigation(0).task_id(), |
| 2658 sync_data_tab1.navigation(1).task_id(), |
| 2659 sync_data_tab2.navigation(0).task_id(), |
| 2660 sync_data_tab2.navigation(1).task_id())); |
| 2661 |
| 2662 // Sync data of adding Tab 3 change |
| 2663 sync_data_tab3 = |
| 2664 SyncDataLocal(changes[5].sync_data()).GetSpecifics().session().tab(); |
| 2665 ASSERT_EQ(2, sync_data_tab3.navigation_size()); |
| 2666 EXPECT_EQ(sync_data_tab3.navigation(0).global_id(), |
| 2667 sync_data_tab3.navigation(0).task_id()); |
| 2668 EXPECT_THAT(sync_data_tab3.navigation(0).ancestor_task_id(), |
| 2669 ElementsAre(sync_data_tab1.navigation(0).task_id(), |
| 2670 sync_data_tab1.navigation(1).task_id(), |
| 2671 sync_data_tab2.navigation(0).task_id(), |
| 2672 sync_data_tab2.navigation(1).task_id())); |
| 2673 EXPECT_EQ(sync_data_tab3.navigation(1).global_id(), |
| 2674 sync_data_tab3.navigation(1).task_id()); |
| 2675 EXPECT_THAT(sync_data_tab3.navigation(1).ancestor_task_id(), |
| 2676 ElementsAre(sync_data_tab1.navigation(0).task_id(), |
| 2677 sync_data_tab1.navigation(1).task_id(), |
| 2678 sync_data_tab2.navigation(0).task_id(), |
| 2679 sync_data_tab2.navigation(1).task_id(), |
| 2680 sync_data_tab3.navigation(0).task_id())); |
| 2681 } |
| 2682 |
2597 } // namespace sync_sessions | 2683 } // namespace sync_sessions |
OLD | NEW |