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 682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
693 // Simulate the browser firing a tab parented notification, ahead of the | 693 // Simulate the browser firing a tab parented notification, ahead of the |
694 // actual navigation. | 694 // actual navigation. |
695 router_->NotifyNav(tabs_.back().get()); | 695 router_->NotifyNav(tabs_.back().get()); |
696 | 696 |
697 // Now do the actual navigation. | 697 // Now do the actual navigation. |
698 NavigateTab(tabs_.back().get(), url, time); | 698 NavigateTab(tabs_.back().get(), url, time); |
699 return tabs_.back().get(); | 699 return tabs_.back().get(); |
700 } | 700 } |
701 TestSyncedTabDelegate* AddTab(SessionID::id_type window_id, | 701 TestSyncedTabDelegate* AddTab(SessionID::id_type window_id, |
702 const std::string& url) { | 702 const std::string& url) { |
703 return AddTab(window_id, url, base::Time()); | 703 return AddTab(window_id, url, base::Time::Now()); |
704 } | 704 } |
705 | 705 |
706 void NavigateTab(TestSyncedTabDelegate* delegate, | 706 void NavigateTab(TestSyncedTabDelegate* delegate, |
707 const std::string& url, | 707 const std::string& url, |
708 base::Time time) { | 708 base::Time time, |
709 ui::PageTransition transition) { | |
709 auto entry = base::MakeUnique<sessions::SerializedNavigationEntry>( | 710 auto entry = base::MakeUnique<sessions::SerializedNavigationEntry>( |
710 SerializedNavigationEntryTestHelper::CreateNavigation(url, kTitle)); | 711 SerializedNavigationEntryTestHelper::CreateNavigation(url, kTitle)); |
711 SerializedNavigationEntryTestHelper::SetTimestamp(time, entry.get()); | 712 SerializedNavigationEntryTestHelper::SetTimestamp(time, entry.get()); |
713 SerializedNavigationEntryTestHelper::SetTransitionType(transition, | |
714 entry.get()); | |
712 delegate->AppendEntry(std::move(entry)); | 715 delegate->AppendEntry(std::move(entry)); |
713 delegate->set_current_entry_index(delegate->GetCurrentEntryIndex() + 1); | 716 delegate->set_current_entry_index(delegate->GetCurrentEntryIndex() + 1); |
714 router_->NotifyNav(delegate); | 717 router_->NotifyNav(delegate); |
715 } | 718 } |
719 void NavigateTab(TestSyncedTabDelegate* delegate, | |
720 const std::string& url, | |
721 base::Time time) { | |
722 NavigateTab(delegate, url, time, ui::PAGE_TRANSITION_TYPED); | |
723 } | |
716 void NavigateTab(TestSyncedTabDelegate* delegate, const std::string& url) { | 724 void NavigateTab(TestSyncedTabDelegate* delegate, const std::string& url) { |
717 NavigateTab(delegate, url, base::Time()); | 725 NavigateTab(delegate, url, base::Time::Now()); |
726 } | |
727 void NavigateTab(TestSyncedTabDelegate* delegate, | |
728 const std::string& url, | |
729 ui::PageTransition transition) { | |
730 NavigateTab(delegate, url, base::Time::Now(), transition); | |
718 } | 731 } |
719 | 732 |
720 TestSyncedWindowDelegate* AddWindow() { | 733 TestSyncedWindowDelegate* AddWindow() { |
721 windows_.push_back(base::MakeUnique<TestSyncedWindowDelegate>()); | 734 windows_.push_back(base::MakeUnique<TestSyncedWindowDelegate>()); |
722 window_getter_.AddSyncedWindowDelegate(windows_.back().get()); | 735 window_getter_.AddSyncedWindowDelegate(windows_.back().get()); |
723 return windows_.back().get(); | 736 return windows_.back().get(); |
724 } | 737 } |
725 | 738 |
726 private: | 739 private: |
727 std::unique_ptr<syncer::FakeSyncClient> sync_client_; | 740 std::unique_ptr<syncer::FakeSyncClient> sync_client_; |
(...skipping 1668 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2396 out[0].sync_data().GetSpecifics().session().tab().tab_id()); | 2409 out[0].sync_data().GetSpecifics().session().tab().tab_id()); |
2397 // Because tab 2 is a placeholder, tab 1's URL will be preserved. | 2410 // Because tab 2 is a placeholder, tab 1's URL will be preserved. |
2398 VerifyLocalTabChange(out[1], 1, kFoo1); | 2411 VerifyLocalTabChange(out[1], 1, kFoo1); |
2399 EXPECT_EQ(sync_id, out[1].sync_data().GetSpecifics().session().tab_node_id()); | 2412 EXPECT_EQ(sync_id, out[1].sync_data().GetSpecifics().session().tab_node_id()); |
2400 EXPECT_EQ(tab2.GetSessionId(), | 2413 EXPECT_EQ(tab2.GetSessionId(), |
2401 out[1].sync_data().GetSpecifics().session().tab().tab_id()); | 2414 out[1].sync_data().GetSpecifics().session().tab().tab_id()); |
2402 EXPECT_EQ(window2->GetSessionId(), | 2415 EXPECT_EQ(window2->GetSessionId(), |
2403 out[1].sync_data().GetSpecifics().session().tab().window_id()); | 2416 out[1].sync_data().GetSpecifics().session().tab().window_id()); |
2404 } | 2417 } |
2405 | 2418 |
2419 // Tests that task ids are generated for navigations on local tabs. | |
2420 TEST_F(SessionsSyncManagerTest, TrackTasksOnLocalTabModified) { | |
2421 SyncChangeList out; | |
2422 TestSyncedWindowDelegate* window = AddWindow(); | |
2423 InitWithSyncDataTakeOutput(SyncDataList(), &out); | |
2424 SessionID::id_type window_id = window->GetSessionId(); | |
2425 ASSERT_FALSE(manager()->current_machine_tag().empty()); | |
2426 out.clear(); | |
2427 | |
2428 // Tab 1 | |
2429 NavigateTab(AddTab(window_id, kFoo1), kFoo2, ui::PAGE_TRANSITION_TYPED); | |
2430 // Tab 2 | |
2431 NavigateTab(AddTab(window_id, kBar1), kBar2, ui::PAGE_TRANSITION_LINK); | |
2432 | |
2433 // We only test changes for tab add and tab update, and ingore header updates. | |
Nicolas Zea
2017/04/17 23:18:46
nit: ingore -> ignore
shenchao
2017/04/19 22:10:01
Done.
| |
2434 // Sync data of adding Tab 1 change | |
2435 sync_pb::SessionTab tab = | |
2436 SyncDataLocal(out[1].sync_data()).GetSpecifics().session().tab(); | |
Nicolas Zea
2017/04/17 23:18:46
If you're ignoring header updates, you can use Fil
shenchao
2017/04/19 22:10:01
Done.
| |
2437 EXPECT_EQ(tab.navigation_size(), 1); | |
2438 EXPECT_EQ(tab.navigation(0).global_id(), tab.navigation(0).task_id()); | |
2439 EXPECT_TRUE(tab.navigation(0).ancestor_task_id().empty()); | |
2440 | |
2441 // Sync data of updating Tab 1 change | |
2442 tab = SyncDataLocal(out[3].sync_data()).GetSpecifics().session().tab(); | |
2443 EXPECT_EQ(tab.navigation_size(), 2); | |
2444 // navigation(0) and navigation(1) are two seperated tasks. | |
2445 EXPECT_EQ(tab.navigation(0).global_id(), tab.navigation(0).task_id()); | |
2446 EXPECT_TRUE(tab.navigation(0).ancestor_task_id().empty()); | |
2447 EXPECT_EQ(tab.navigation(1).global_id(), tab.navigation(1).task_id()); | |
2448 EXPECT_TRUE(tab.navigation(1).ancestor_task_id().empty()); | |
2449 | |
2450 // Sync data of adding Tab 2 change | |
2451 tab = SyncDataLocal(out[6].sync_data()).GetSpecifics().session().tab(); | |
2452 EXPECT_EQ(tab.navigation_size(), 1); | |
2453 EXPECT_EQ(tab.navigation(0).global_id(), tab.navigation(0).task_id()); | |
2454 EXPECT_TRUE(tab.navigation(0).ancestor_task_id().empty()); | |
2455 | |
2456 // Sync data of updating Tab 2 change | |
2457 tab = SyncDataLocal(out[8].sync_data()).GetSpecifics().session().tab(); | |
2458 EXPECT_EQ(tab.navigation_size(), 2); | |
2459 EXPECT_EQ(tab.navigation(0).global_id(), tab.navigation(0).task_id()); | |
2460 EXPECT_TRUE(tab.navigation(0).ancestor_task_id().empty()); | |
2461 EXPECT_EQ(tab.navigation(1).global_id(), tab.navigation(1).task_id()); | |
2462 // navigation(1) is a subtask of navigation(0). | |
2463 EXPECT_EQ(tab.navigation(1).ancestor_task_id_size(), 1); | |
2464 EXPECT_EQ(tab.navigation(1).ancestor_task_id(0), tab.navigation(0).task_id()); | |
2465 } | |
2466 | |
2406 } // namespace sync_sessions | 2467 } // namespace sync_sessions |
OLD | NEW |