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

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

Issue 2901533003: Revert of 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;
43 42
44 namespace sync_sessions { 43 namespace sync_sessions {
45 44
46 namespace { 45 namespace {
47 46
48 const char kTitle[] = "title"; 47 const char kTitle[] = "title";
49 const char kFoo1[] = "http://foo1/"; 48 const char kFoo1[] = "http://foo1/";
50 const char kFoo2[] = "http://foo2/"; 49 const char kFoo2[] = "http://foo2/";
51 const char kBar1[] = "http://bar1/"; 50 const char kBar1[] = "http://bar1/";
52 const char kBar2[] = "http://bar2/"; 51 const char kBar2[] = "http://bar2/";
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 int http_count = 0; 204 int http_count = 0;
206 for (auto& entry : entries_) { 205 for (auto& entry : entries_) {
207 if (!entry->virtual_url().is_valid()) 206 if (!entry->virtual_url().is_valid())
208 return false; 207 return false;
209 if (entry->virtual_url().SchemeIsHTTPOrHTTPS()) 208 if (entry->virtual_url().SchemeIsHTTPOrHTTPS())
210 http_count++; 209 http_count++;
211 } 210 }
212 return http_count > 0; 211 return http_count > 0;
213 } 212 }
214 213
215 SessionID::id_type GetSourceTabID() const override { return source_tab_id_; } 214 SessionID::id_type GetSourceTabID() const override { return kInvalidTabID; }
216 void SetSourceTabID(SessionID::id_type source_tab_id) {
217 source_tab_id_ = source_tab_id;
218 }
219 215
220 void AppendEntry(std::unique_ptr<sessions::SerializedNavigationEntry> entry) { 216 void AppendEntry(std::unique_ptr<sessions::SerializedNavigationEntry> entry) {
221 entries_.push_back(std::move(entry)); 217 entries_.push_back(std::move(entry));
222 } 218 }
223 219
224 void set_current_entry_index(int i) { current_entry_index_ = i; } 220 void set_current_entry_index(int i) { current_entry_index_ = i; }
225 221
226 void SetWindowId(SessionID::id_type window_id) { 222 void SetWindowId(SessionID::id_type window_id) {
227 window_id_.set_id(window_id); 223 window_id_.set_id(window_id);
228 } 224 }
(...skipping 13 matching lines...) Expand all
242 current_entry_index_ = 0; 238 current_entry_index_ = 0;
243 sync_id_ = TabNodePool::kInvalidTabNodeID; 239 sync_id_ = TabNodePool::kInvalidTabNodeID;
244 entries_.clear(); 240 entries_.clear();
245 } 241 }
246 242
247 private: 243 private:
248 int current_entry_index_ = -1; 244 int current_entry_index_ = -1;
249 bool is_supervised_ = false; 245 bool is_supervised_ = false;
250 int sync_id_ = kInvalidTabID; 246 int sync_id_ = kInvalidTabID;
251 SessionID tab_id_; 247 SessionID tab_id_;
252 SessionID::id_type source_tab_id_ = kInvalidTabID;
253 SessionID window_id_; 248 SessionID window_id_;
254 std::vector<std::unique_ptr<const sessions::SerializedNavigationEntry>> 249 std::vector<std::unique_ptr<const sessions::SerializedNavigationEntry>>
255 blocked_navigations_; 250 blocked_navigations_;
256 std::vector<std::unique_ptr<const sessions::SerializedNavigationEntry>> 251 std::vector<std::unique_ptr<const sessions::SerializedNavigationEntry>>
257 entries_; 252 entries_;
258 }; 253 };
259 254
260 // A placeholder delegate. These delegates have no WebContents, simulating a tab 255 // A placeholder delegate. These delegates have no WebContents, simulating a tab
261 // that has been restored without bringing its state fully into memory (for 256 // that has been restored without bringing its state fully into memory (for
262 // example on Android), or where the tab's contents have been evicted from 257 // 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
682 677
683 SyncData CreateRemoteData(const sync_pb::EntitySpecifics& entity, 678 SyncData CreateRemoteData(const sync_pb::EntitySpecifics& entity,
684 base::Time mtime = base::Time()) const { 679 base::Time mtime = base::Time()) const {
685 // The server ID is never relevant to these tests, so just use 1. 680 // The server ID is never relevant to these tests, so just use 1.
686 return SyncData::CreateRemoteData( 681 return SyncData::CreateRemoteData(
687 1, entity, mtime, syncer::AttachmentIdList(), 682 1, entity, mtime, syncer::AttachmentIdList(),
688 syncer::AttachmentServiceProxyForTest::Create(), 683 syncer::AttachmentServiceProxyForTest::Create(),
689 SessionsSyncManager::TagHashFromSpecifics(entity.session())); 684 SessionsSyncManager::TagHashFromSpecifics(entity.session()));
690 } 685 }
691 686
692 // Creates a new tab within the window specified by |window_id| and from the 687 // Creates a new tab within the window specified by |window_id|, and points it
693 // source tab |source_tab_id|, and points it at |url|. Returns the newly 688 // at |url|. Returns the newly created TestSyncedTabDelegate (not owned).
694 // created TestSyncedTabDelegate (not owned).
695 TestSyncedTabDelegate* AddTab(SessionID::id_type window_id, 689 TestSyncedTabDelegate* AddTab(SessionID::id_type window_id,
696 const std::string& url, 690 const std::string& url,
697 SessionID::id_type source_tab_id,
698 base::Time time) { 691 base::Time time) {
699 tabs_.push_back(base::MakeUnique<TestSyncedTabDelegate>()); 692 tabs_.push_back(base::MakeUnique<TestSyncedTabDelegate>());
700 for (auto& window : windows_) { 693 for (auto& window : windows_) {
701 if (window->GetSessionId() == window_id) { 694 if (window->GetSessionId() == window_id) {
702 int tab_index = window->GetTabCount(); 695 int tab_index = window->GetTabCount();
703 window->OverrideTabAt(tab_index, tabs_.back().get()); 696 window->OverrideTabAt(tab_index, tabs_.back().get());
704 } 697 }
705 } 698 }
706 tabs_.back()->SetSourceTabID(source_tab_id);
707 699
708 // Simulate the browser firing a tab parented notification, ahead of the 700 // Simulate the browser firing a tab parented notification, ahead of the
709 // actual navigation. 701 // actual navigation.
710 router_->NotifyNav(tabs_.back().get()); 702 router_->NotifyNav(tabs_.back().get());
711 703
712 // Now do the actual navigation. 704 // Now do the actual navigation.
713 if (source_tab_id != kInvalidTabID) { 705 NavigateTab(tabs_.back().get(), url, time);
714 NavigateTab(tabs_.back().get(), url, time, ui::PAGE_TRANSITION_LINK);
715 } else {
716 NavigateTab(tabs_.back().get(), url, time);
717 }
718 return tabs_.back().get(); 706 return tabs_.back().get();
719 } 707 }
720 TestSyncedTabDelegate* AddTab(SessionID::id_type window_id, 708 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,
731 const std::string& url) { 709 const std::string& url) {
732 return AddTab(window_id, url, kInvalidTabID); 710 return AddTab(window_id, url, base::Time::Now());
733 } 711 }
734 712
735 void NavigateTab(TestSyncedTabDelegate* delegate, 713 void NavigateTab(TestSyncedTabDelegate* delegate,
736 const std::string& url, 714 const std::string& url,
737 base::Time time, 715 base::Time time,
738 ui::PageTransition transition) { 716 ui::PageTransition transition) {
739 auto entry = base::MakeUnique<sessions::SerializedNavigationEntry>( 717 auto entry = base::MakeUnique<sessions::SerializedNavigationEntry>(
740 SerializedNavigationEntryTestHelper::CreateNavigation(url, kTitle)); 718 SerializedNavigationEntryTestHelper::CreateNavigation(url, kTitle));
741 SerializedNavigationEntryTestHelper::SetTimestamp(time, entry.get()); 719 SerializedNavigationEntryTestHelper::SetTimestamp(time, entry.get());
742 SerializedNavigationEntryTestHelper::SetTransitionType(transition, 720 SerializedNavigationEntryTestHelper::SetTransitionType(transition,
(...skipping 1866 matching lines...) Expand 10 before | Expand all | Expand 10 after
2609 tab = SyncDataLocal(changes[3].sync_data()).GetSpecifics().session().tab(); 2587 tab = SyncDataLocal(changes[3].sync_data()).GetSpecifics().session().tab();
2610 EXPECT_EQ(tab.navigation_size(), 2); 2588 EXPECT_EQ(tab.navigation_size(), 2);
2611 EXPECT_EQ(tab.navigation(0).global_id(), tab.navigation(0).task_id()); 2589 EXPECT_EQ(tab.navigation(0).global_id(), tab.navigation(0).task_id());
2612 EXPECT_TRUE(tab.navigation(0).ancestor_task_id().empty()); 2590 EXPECT_TRUE(tab.navigation(0).ancestor_task_id().empty());
2613 EXPECT_EQ(tab.navigation(1).global_id(), tab.navigation(1).task_id()); 2591 EXPECT_EQ(tab.navigation(1).global_id(), tab.navigation(1).task_id());
2614 // navigation(1) is a subtask of navigation(0). 2592 // navigation(1) is a subtask of navigation(0).
2615 EXPECT_EQ(tab.navigation(1).ancestor_task_id_size(), 1); 2593 EXPECT_EQ(tab.navigation(1).ancestor_task_id_size(), 1);
2616 EXPECT_EQ(tab.navigation(1).ancestor_task_id(0), tab.navigation(0).task_id()); 2594 EXPECT_EQ(tab.navigation(1).ancestor_task_id(0), tab.navigation(0).task_id());
2617 } 2595 }
2618 2596
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
2683 } // namespace sync_sessions 2597 } // namespace sync_sessions
OLDNEW
« no previous file with comments | « components/sync_sessions/sessions_sync_manager.cc ('k') | components/sync_sessions/task_tracker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698