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

Side by Side Diff: components/sync_sessions/sessions_sync_manager_unittest.cc

Issue 2868043003: Track task ids for navigations cross multiple tabs. (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/sync_sessions/sessions_sync_manager.h" 5 #include "components/sync_sessions/sessions_sync_manager.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 21 matching lines...) Expand all
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
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
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
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 NavigateTab(tabs_.back().get(), url, time);
706 return tabs_.back().get(); 714 return tabs_.back().get();
707 } 715 }
708 TestSyncedTabDelegate* AddTab(SessionID::id_type window_id, 716 TestSyncedTabDelegate* AddTab(SessionID::id_type window_id,
717 const std::string& url,
718 base::Time time) {
719 return AddTab(window_id, url, kInvalidTabID, time);
720 }
721 TestSyncedTabDelegate* AddTab(SessionID::id_type window_id,
722 const std::string& url,
723 SessionID::id_type source_tab_id) {
724 return AddTab(window_id, url, source_tab_id, base::Time::Now());
725 }
726 TestSyncedTabDelegate* AddTab(SessionID::id_type window_id,
709 const std::string& url) { 727 const std::string& url) {
710 return AddTab(window_id, url, base::Time::Now()); 728 return AddTab(window_id, url, kInvalidTabID);
711 } 729 }
712 730
713 void NavigateTab(TestSyncedTabDelegate* delegate, 731 void NavigateTab(TestSyncedTabDelegate* delegate,
714 const std::string& url, 732 const std::string& url,
715 base::Time time, 733 base::Time time,
716 ui::PageTransition transition) { 734 ui::PageTransition transition) {
717 auto entry = base::MakeUnique<sessions::SerializedNavigationEntry>( 735 auto entry = base::MakeUnique<sessions::SerializedNavigationEntry>(
718 SerializedNavigationEntryTestHelper::CreateNavigation(url, kTitle)); 736 SerializedNavigationEntryTestHelper::CreateNavigation(url, kTitle));
719 SerializedNavigationEntryTestHelper::SetTimestamp(time, entry.get()); 737 SerializedNavigationEntryTestHelper::SetTimestamp(time, entry.get());
720 SerializedNavigationEntryTestHelper::SetTransitionType(transition, 738 SerializedNavigationEntryTestHelper::SetTransitionType(transition,
(...skipping 1866 matching lines...) Expand 10 before | Expand all | Expand 10 after
2587 tab = SyncDataLocal(changes[3].sync_data()).GetSpecifics().session().tab(); 2605 tab = SyncDataLocal(changes[3].sync_data()).GetSpecifics().session().tab();
2588 EXPECT_EQ(tab.navigation_size(), 2); 2606 EXPECT_EQ(tab.navigation_size(), 2);
2589 EXPECT_EQ(tab.navigation(0).global_id(), tab.navigation(0).task_id()); 2607 EXPECT_EQ(tab.navigation(0).global_id(), tab.navigation(0).task_id());
2590 EXPECT_TRUE(tab.navigation(0).ancestor_task_id().empty()); 2608 EXPECT_TRUE(tab.navigation(0).ancestor_task_id().empty());
2591 EXPECT_EQ(tab.navigation(1).global_id(), tab.navigation(1).task_id()); 2609 EXPECT_EQ(tab.navigation(1).global_id(), tab.navigation(1).task_id());
2592 // navigation(1) is a subtask of navigation(0). 2610 // navigation(1) is a subtask of navigation(0).
2593 EXPECT_EQ(tab.navigation(1).ancestor_task_id_size(), 1); 2611 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()); 2612 EXPECT_EQ(tab.navigation(1).ancestor_task_id(0), tab.navigation(0).task_id());
2595 } 2613 }
2596 2614
2615 // Tests that task ids are generated for navigations on multiple local tabs.
2616 TEST_F(SessionsSyncManagerTest, TrackTasksOnMultipleTabs) {
2617 SyncChangeList changes;
2618 TestSyncedWindowDelegate* window = AddWindow();
2619 InitWithSyncDataTakeOutput(SyncDataList(), &changes);
2620 SessionID::id_type window_id = window->GetSessionId();
2621 ASSERT_FALSE(manager()->current_machine_tag().empty());
2622 changes.clear();
2623
2624 // Tab 1
2625 TestSyncedTabDelegate* tab1 = AddTab(window_id, kFoo1);
2626 NavigateTab(tab1, kFoo2, ui::PAGE_TRANSITION_LINK);
2627 // Tab 2 from Tab 1.
2628 TestSyncedTabDelegate* tab2 = AddTab(window_id, kBar1, tab1->GetSessionId());
2629 NavigateTab(tab2, kBar2, ui::PAGE_TRANSITION_LINK);
2630 // Tab 3 from Tab 2.
2631 TestSyncedTabDelegate* tab3 = AddTab(window_id, kBaz1, tab2->GetSessionId());
2632 NavigateTab(tab3, kBaz2, ui::PAGE_TRANSITION_LINK);
2633
2634 // We only test changes for tab add and tab update, and ignore header updates.
2635 FilterOutLocalHeaderChanges(&changes);
2636 // Sync data of updating Tab 1 change
2637 sync_pb::SessionTab sync_data_tab1 =
2638 SyncDataLocal(changes[1].sync_data()).GetSpecifics().session().tab();
2639 ASSERT_EQ(2, sync_data_tab1.navigation_size());
2640
2641 // Sync data of updating Tab 2 change
2642 sync_pb::SessionTab sync_data_tab2 =
2643 SyncDataLocal(changes[3].sync_data()).GetSpecifics().session().tab();
2644 ASSERT_EQ(2, sync_data_tab1.navigation_size());
2645
2646 // Sync data of adding Tab 3 change
2647 sync_pb::SessionTab sync_data_tab3 =
2648 SyncDataLocal(changes[4].sync_data()).GetSpecifics().session().tab();
2649 ASSERT_EQ(1, sync_data_tab3.navigation_size());
2650 EXPECT_EQ(sync_data_tab3.navigation(0).global_id(),
2651 sync_data_tab3.navigation(0).task_id());
2652 EXPECT_THAT(sync_data_tab3.navigation(0).ancestor_task_id(),
2653 ElementsAre(sync_data_tab1.navigation(0).task_id(),
2654 sync_data_tab1.navigation(1).task_id(),
2655 sync_data_tab2.navigation(0).task_id(),
2656 sync_data_tab2.navigation(1).task_id()));
2657
2658 // Sync data of adding Tab 3 change
2659 sync_data_tab3 =
2660 SyncDataLocal(changes[5].sync_data()).GetSpecifics().session().tab();
2661 ASSERT_EQ(2, sync_data_tab3.navigation_size());
2662 EXPECT_EQ(sync_data_tab3.navigation(0).global_id(),
2663 sync_data_tab3.navigation(0).task_id());
2664 EXPECT_THAT(sync_data_tab3.navigation(0).ancestor_task_id(),
2665 ElementsAre(sync_data_tab1.navigation(0).task_id(),
2666 sync_data_tab1.navigation(1).task_id(),
2667 sync_data_tab2.navigation(0).task_id(),
2668 sync_data_tab2.navigation(1).task_id()));
2669 EXPECT_EQ(sync_data_tab3.navigation(1).global_id(),
2670 sync_data_tab3.navigation(1).task_id());
2671 EXPECT_THAT(sync_data_tab3.navigation(1).ancestor_task_id(),
2672 ElementsAre(sync_data_tab1.navigation(0).task_id(),
2673 sync_data_tab1.navigation(1).task_id(),
2674 sync_data_tab2.navigation(0).task_id(),
2675 sync_data_tab2.navigation(1).task_id(),
2676 sync_data_tab3.navigation(0).task_id()));
2677 }
2678
2597 } // namespace sync_sessions 2679 } // namespace sync_sessions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698