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 727 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
738 } | 738 } |
739 void NavigateTab(TestSyncedTabDelegate* delegate, const std::string& url) { | 739 void NavigateTab(TestSyncedTabDelegate* delegate, const std::string& url) { |
740 NavigateTab(delegate, url, base::Time::Now()); | 740 NavigateTab(delegate, url, base::Time::Now()); |
741 } | 741 } |
742 void NavigateTab(TestSyncedTabDelegate* delegate, | 742 void NavigateTab(TestSyncedTabDelegate* delegate, |
743 const std::string& url, | 743 const std::string& url, |
744 ui::PageTransition transition) { | 744 ui::PageTransition transition) { |
745 NavigateTab(delegate, url, base::Time::Now(), transition); | 745 NavigateTab(delegate, url, base::Time::Now(), transition); |
746 } | 746 } |
747 | 747 |
748 void ReloadTab(TestSyncedTabDelegate* delegate, base::Time time) { | |
749 sessions::SerializedNavigationEntry old_entry; | |
750 delegate->GetSerializedNavigationAtIndex(delegate->GetCurrentEntryIndex(), | |
751 &old_entry); | |
752 | |
753 auto new_entry = | |
754 base::MakeUnique<sessions::SerializedNavigationEntry>(old_entry); | |
755 SerializedNavigationEntryTestHelper::SetTimestamp(time, new_entry.get()); | |
756 | |
757 delegate->reset(); | |
758 delegate->AppendEntry(std::move(new_entry)); | |
759 router_->NotifyNav(delegate); | |
760 } | |
761 | |
748 void ResetWindows() { | 762 void ResetWindows() { |
749 window_getter_.ClearSyncedWindowDelegates(); | 763 window_getter_.ClearSyncedWindowDelegates(); |
750 windows_.clear(); | 764 windows_.clear(); |
751 } | 765 } |
752 | 766 |
753 TestSyncedWindowDelegate* AddWindow() { | 767 TestSyncedWindowDelegate* AddWindow() { |
754 windows_.push_back(base::MakeUnique<TestSyncedWindowDelegate>()); | 768 windows_.push_back(base::MakeUnique<TestSyncedWindowDelegate>()); |
755 window_getter_.AddSyncedWindowDelegate(windows_.back().get()); | 769 window_getter_.AddSyncedWindowDelegate(windows_.back().get()); |
756 return windows_.back().get(); | 770 return windows_.back().get(); |
757 } | 771 } |
(...skipping 1856 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2614 tab = SyncDataLocal(changes[3].sync_data()).GetSpecifics().session().tab(); | 2628 tab = SyncDataLocal(changes[3].sync_data()).GetSpecifics().session().tab(); |
2615 EXPECT_EQ(tab.navigation_size(), 2); | 2629 EXPECT_EQ(tab.navigation_size(), 2); |
2616 EXPECT_EQ(tab.navigation(0).global_id(), tab.navigation(0).task_id()); | 2630 EXPECT_EQ(tab.navigation(0).global_id(), tab.navigation(0).task_id()); |
2617 EXPECT_TRUE(tab.navigation(0).ancestor_task_id().empty()); | 2631 EXPECT_TRUE(tab.navigation(0).ancestor_task_id().empty()); |
2618 EXPECT_EQ(tab.navigation(1).global_id(), tab.navigation(1).task_id()); | 2632 EXPECT_EQ(tab.navigation(1).global_id(), tab.navigation(1).task_id()); |
2619 // navigation(1) is a subtask of navigation(0). | 2633 // navigation(1) is a subtask of navigation(0). |
2620 EXPECT_EQ(tab.navigation(1).ancestor_task_id_size(), 1); | 2634 EXPECT_EQ(tab.navigation(1).ancestor_task_id_size(), 1); |
2621 EXPECT_EQ(tab.navigation(1).ancestor_task_id(0), tab.navigation(0).task_id()); | 2635 EXPECT_EQ(tab.navigation(1).ancestor_task_id(0), tab.navigation(0).task_id()); |
2622 } | 2636 } |
2623 | 2637 |
2638 void CaptureGlobalIdChange(int64_t* old_ptr, | |
2639 int64_t* new_ptr, | |
2640 int64_t old_id, | |
2641 int64_t new_id) { | |
2642 *old_ptr = old_id; | |
2643 *new_ptr = new_id; | |
2644 } | |
2645 | |
2646 // Tests that subscribers to AddGlobalIdChangeObserver are notified when a | |
2647 // global_id is noticed to have been changed. | |
2648 TEST_F(SessionsSyncManagerTest, AddGlobalIdChangeObserver) { | |
2649 TestSyncedWindowDelegate* window = AddWindow(); | |
2650 SessionID::id_type window_id = window->GetSessionId(); | |
2651 SyncChangeList out; | |
2652 InitWithSyncDataTakeOutput(SyncDataList(), &out); | |
2653 | |
2654 int64_t old_id = -1; | |
2655 int64_t new_id = -1; | |
2656 manager()->AddGlobalIdChangeObserver( | |
2657 base::Bind(&CaptureGlobalIdChange, &old_id, &new_id)); | |
2658 | |
2659 TestSyncedTabDelegate* tab = AddTab(window_id, kFoo1, kTime1); | |
2660 EXPECT_EQ(-1, old_id); | |
2661 EXPECT_EQ(-1, new_id); | |
2662 | |
2663 ReloadTab(tab, kTime2); | |
2664 EXPECT_EQ(kTime1.ToInternalValue(), old_id); | |
2665 EXPECT_EQ(kTime2.ToInternalValue(), new_id); | |
2666 } | |
2667 | |
2668 // Tests that GetLatestGlobalId returns correct mappings for updated global_ids. | |
2669 TEST_F(SessionsSyncManagerTest, GetLatestGlobalId) { | |
2670 TestSyncedWindowDelegate* window = AddWindow(); | |
2671 SessionID::id_type window_id = window->GetSessionId(); | |
2672 SyncChangeList out; | |
2673 InitWithSyncDataTakeOutput(SyncDataList(), &out); | |
2674 | |
2675 TestSyncedTabDelegate* tab = AddTab(window_id, kFoo1, kTime1); | |
2676 ReloadTab(tab, kTime2); | |
2677 ReloadTab(tab, kTime3); | |
2678 | |
2679 EXPECT_EQ(kTime3.ToInternalValue(), | |
2680 manager()->GetLatestGlobalId(kTime1.ToInternalValue())); | |
2681 EXPECT_EQ(kTime3.ToInternalValue(), | |
2682 manager()->GetLatestGlobalId(kTime2.ToInternalValue())); | |
2683 EXPECT_EQ(kTime3.ToInternalValue(), | |
2684 manager()->GetLatestGlobalId(kTime3.ToInternalValue())); | |
2685 // kTime4 is not mapped, so itself should be returned. | |
2686 EXPECT_EQ(kTime4.ToInternalValue(), | |
2687 manager()->GetLatestGlobalId(kTime4.ToInternalValue())); | |
2688 } | |
2689 | |
2690 // Tests that the global_id mapping is eventually dropped after we reach out | |
2691 // threshold for the amount to remember. | |
2692 TEST_F(SessionsSyncManagerTest, GlobalIdMapperCleanup) { | |
2693 TestSyncedWindowDelegate* window = AddWindow(); | |
2694 SessionID::id_type window_id = window->GetSessionId(); | |
2695 SyncChangeList out; | |
2696 InitWithSyncDataTakeOutput(SyncDataList(), &out); | |
2697 | |
2698 base::Time current_time = kTime1; | |
2699 TestSyncedTabDelegate* tab = AddTab(window_id, kFoo1, current_time); | |
2700 | |
2701 for (int i = 0; i < 105; i++) { | |
Patrick Noland
2017/06/28 22:44:37
Can you reference the constant instead of 105 here
skym
2017/07/05 19:14:28
I'd prefer to not move to the constant's declarati
| |
2702 current_time = | |
2703 base::Time::FromInternalValue(current_time.ToInternalValue() + 1); | |
2704 ReloadTab(tab, current_time); | |
2705 } | |
2706 | |
2707 // Threshold is 100, kTime1 should be dropped, kTime1+10 should not. | |
2708 EXPECT_EQ(kTime1.ToInternalValue(), | |
2709 manager()->GetLatestGlobalId(kTime1.ToInternalValue())); | |
2710 EXPECT_EQ(current_time.ToInternalValue(), | |
2711 manager()->GetLatestGlobalId(10 + kTime1.ToInternalValue())); | |
2712 } | |
2713 | |
2624 } // namespace sync_sessions | 2714 } // namespace sync_sessions |
OLD | NEW |