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

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

Issue 2791183003: [Sync] Restore previous session if no tabbed windows present (Closed)
Patch Set: Fix android compile Created 3 years, 8 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 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 236
237 void reset() { 237 void reset() {
238 current_entry_index_ = 0; 238 current_entry_index_ = 0;
239 sync_id_ = TabNodePool::kInvalidTabNodeID; 239 sync_id_ = TabNodePool::kInvalidTabNodeID;
240 entries_.clear(); 240 entries_.clear();
241 } 241 }
242 242
243 private: 243 private:
244 int current_entry_index_ = -1; 244 int current_entry_index_ = -1;
245 bool is_supervised_ = false; 245 bool is_supervised_ = false;
246 int sync_id_ = -1; 246 int sync_id_ = kInvalidTabID;
247 SessionID tab_id_; 247 SessionID tab_id_;
248 SessionID window_id_; 248 SessionID window_id_;
249 std::vector<std::unique_ptr<const sessions::SerializedNavigationEntry>> 249 std::vector<std::unique_ptr<const sessions::SerializedNavigationEntry>>
250 blocked_navigations_; 250 blocked_navigations_;
251 std::vector<std::unique_ptr<const sessions::SerializedNavigationEntry>> 251 std::vector<std::unique_ptr<const sessions::SerializedNavigationEntry>>
252 entries_; 252 entries_;
253 }; 253 };
254 254
255 // A placeholder delegate. These delegates have no WebContents, simulating a tab 255 // A placeholder delegate. These delegates have no WebContents, simulating a tab
256 // 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
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 } 321 }
322 bool ShouldSync(SyncSessionsClient* sessions_client) override { 322 bool ShouldSync(SyncSessionsClient* sessions_client) override {
323 NOTREACHED(); 323 NOTREACHED();
324 return false; 324 return false;
325 } 325 }
326 326
327 SessionID::id_type GetSourceTabID() const override { return kInvalidTabID; } 327 SessionID::id_type GetSourceTabID() const override { return kInvalidTabID; }
328 328
329 private: 329 private:
330 SessionID::id_type session_id_; 330 SessionID::id_type session_id_;
331 int sync_id_; 331 int sync_id_ = kInvalidTabID;
332 }; 332 };
333 333
334 class TestSyncedWindowDelegate : public SyncedWindowDelegate { 334 class TestSyncedWindowDelegate : public SyncedWindowDelegate {
335 public: 335 public:
336 TestSyncedWindowDelegate() {} 336 TestSyncedWindowDelegate() {}
337 ~TestSyncedWindowDelegate() override {} 337 ~TestSyncedWindowDelegate() override {}
338 338
339 bool HasWindow() const override { return true; } 339 bool HasWindow() const override { return true; }
340 340
341 SessionID::id_type GetSessionId() const override { return window_id_.id(); } 341 SessionID::id_type GetSessionId() const override { return window_id_.id(); }
342 342
343 int GetTabCount() const override { return tab_delegates_.size(); } 343 int GetTabCount() const override { return tab_delegates_.size(); }
344 344
345 int GetActiveIndex() const override { return 0; } 345 int GetActiveIndex() const override { return 0; }
346 346
347 bool IsApp() const override { return false; } 347 bool IsApp() const override { return false; }
348 348
349 bool IsTypeTabbed() const override { 349 bool IsTypeTabbed() const override {
350 return window_type_ == sync_pb::SessionWindow_BrowserType_TYPE_TABBED; 350 return window_type_ == sync_pb::SessionWindow_BrowserType_TYPE_TABBED;
351 } 351 }
352 352
353 bool IsTypePopup() const override { 353 bool IsTypePopup() const override {
354 return window_type_ == sync_pb::SessionWindow_BrowserType_TYPE_POPUP; 354 return window_type_ == sync_pb::SessionWindow_BrowserType_TYPE_POPUP;
355 } 355 }
356 356
357 bool IsTabPinned(const SyncedTabDelegate* tab) const override { 357 bool IsTabPinned(const SyncedTabDelegate* tab) const override {
358 return false; 358 return false;
359 } 359 }
360 360
361 void OverrideWindowTypeToCustomTab() {
362 window_type_ = sync_pb::SessionWindow_BrowserType_TYPE_CUSTOM_TAB;
363 }
364
361 SyncedTabDelegate* GetTabAt(int index) const override { 365 SyncedTabDelegate* GetTabAt(int index) const override {
362 if (tab_delegates_.find(index) != tab_delegates_.end()) 366 if (tab_delegates_.find(index) != tab_delegates_.end())
363 return tab_delegates_.find(index)->second; 367 return tab_delegates_.find(index)->second;
364 368
365 return nullptr; 369 return nullptr;
366 } 370 }
367 371
368 void OverrideWindowId(SessionID::id_type id) { window_id_.set_id(id); } 372 void OverrideWindowId(SessionID::id_type id) { window_id_.set_id(id); }
369 373
370 void OverrideTabAt(int index, SyncedTabDelegate* delegate) { 374 void OverrideTabAt(int index, SyncedTabDelegate* delegate) {
371 tab_delegates_[index] = delegate; 375 tab_delegates_[index] = delegate;
372 } 376 }
373 377
374 SessionID::id_type GetTabIdAt(int index) const override { 378 SessionID::id_type GetTabIdAt(int index) const override {
375 SyncedTabDelegate* delegate = GetTabAt(index); 379 SyncedTabDelegate* delegate = GetTabAt(index);
376 if (!delegate) 380 if (!delegate)
377 return kInvalidTabID; 381 return kInvalidTabID;
378 return delegate->GetSessionId(); 382 return delegate->GetSessionId();
379 } 383 }
380 384
381 bool IsSessionRestoreInProgress() const override { return false; } 385 bool IsSessionRestoreInProgress() const override { return false; }
382 386
383 bool ShouldSync() const override { return true; } 387 bool ShouldSync() const override { return true; }
384 388
385 private: 389 private:
386 std::map<int, SyncedTabDelegate*> tab_delegates_; 390 std::map<int, SyncedTabDelegate*> tab_delegates_;
387 SessionID window_id_; 391 SessionID window_id_;
388 sync_pb::SessionWindow_BrowserType window_type_ = 392 sync_pb::SessionWindow_BrowserType window_type_ =
389 sync_pb::SessionWindow_BrowserType_TYPE_TABBED; 393 sync_pb::SessionWindow_BrowserType_TYPE_TABBED;
394 std::map<int, SyncedTabDelegate*> tab_overrides_;
395 std::map<int, SessionID::id_type> tab_id_overrides_;
390 }; 396 };
391 397
392 class TestSyncedWindowDelegatesGetter : public SyncedWindowDelegatesGetter { 398 class TestSyncedWindowDelegatesGetter : public SyncedWindowDelegatesGetter {
393 public: 399 public:
394 TestSyncedWindowDelegatesGetter() {} 400 TestSyncedWindowDelegatesGetter() {}
395 ~TestSyncedWindowDelegatesGetter() override {} 401 ~TestSyncedWindowDelegatesGetter() override {}
396 402
397 SyncedWindowDelegateMap GetSyncedWindowDelegates() override { 403 SyncedWindowDelegateMap GetSyncedWindowDelegates() override {
398 return delegates_; 404 return delegates_;
399 } 405 }
400 406
401 const SyncedWindowDelegate* FindById(SessionID::id_type id) override { 407 const SyncedWindowDelegate* FindById(SessionID::id_type id) override {
402 for (auto window_iter_pair : delegates_) { 408 for (auto window_iter_pair : delegates_) {
403 if (window_iter_pair.second->GetSessionId() == id) 409 if (window_iter_pair.second->GetSessionId() == id)
404 return window_iter_pair.second; 410 return window_iter_pair.second;
405 } 411 }
406 return nullptr; 412 return nullptr;
407 } 413 }
408 414
409 void AddSyncedWindowDelegate(const SyncedWindowDelegate* delegate) { 415 void AddSyncedWindowDelegate(const SyncedWindowDelegate* delegate) {
410 delegates_[delegate->GetSessionId()] = delegate; 416 delegates_[delegate->GetSessionId()] = delegate;
411 } 417 }
412 418
419 void ClearSyncedWindowDelegates() { delegates_.clear(); }
420
413 private: 421 private:
414 SyncedWindowDelegateMap delegates_; 422 SyncedWindowDelegateMap delegates_;
415 }; 423 };
416 424
417 class TestSyncChangeProcessor : public syncer::SyncChangeProcessor { 425 class TestSyncChangeProcessor : public syncer::SyncChangeProcessor {
418 public: 426 public:
419 explicit TestSyncChangeProcessor(SyncChangeList* output) : output_(output) {} 427 explicit TestSyncChangeProcessor(SyncChangeList* output) : output_(output) {}
420 SyncError ProcessSyncChanges(const tracked_objects::Location& from_here, 428 SyncError ProcessSyncChanges(const tracked_objects::Location& from_here,
421 const SyncChangeList& change_list) override { 429 const SyncChangeList& change_list) override {
422 if (error_.IsSet()) { 430 if (error_.IsSet()) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 SyncDataList sync_data_to_return_; 470 SyncDataList sync_data_to_return_;
463 base::ObserverList<syncer::LocalChangeObserver> local_change_observers_; 471 base::ObserverList<syncer::LocalChangeObserver> local_change_observers_;
464 }; 472 };
465 473
466 class DummyRouter : public LocalSessionEventRouter { 474 class DummyRouter : public LocalSessionEventRouter {
467 public: 475 public:
468 ~DummyRouter() override {} 476 ~DummyRouter() override {}
469 void StartRoutingTo(LocalSessionEventHandler* handler) override { 477 void StartRoutingTo(LocalSessionEventHandler* handler) override {
470 handler_ = handler; 478 handler_ = handler;
471 } 479 }
472 void Stop() override {} 480 void Stop() override { handler_ = nullptr; }
473 481
474 void NotifyNav(SyncedTabDelegate* tab) { 482 void NotifyNav(SyncedTabDelegate* tab) {
475 if (handler_) 483 if (handler_)
476 handler_->OnLocalTabModified(tab); 484 handler_->OnLocalTabModified(tab);
477 } 485 }
478 486
479 private: 487 private:
480 LocalSessionEventHandler* handler_ = nullptr; 488 LocalSessionEventHandler* handler_ = nullptr;
481 }; 489 };
482 490
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 SerializedNavigationEntryTestHelper::CreateNavigation(url, kTitle)); 717 SerializedNavigationEntryTestHelper::CreateNavigation(url, kTitle));
710 SerializedNavigationEntryTestHelper::SetTimestamp(time, entry.get()); 718 SerializedNavigationEntryTestHelper::SetTimestamp(time, entry.get());
711 delegate->AppendEntry(std::move(entry)); 719 delegate->AppendEntry(std::move(entry));
712 delegate->set_current_entry_index(delegate->GetCurrentEntryIndex() + 1); 720 delegate->set_current_entry_index(delegate->GetCurrentEntryIndex() + 1);
713 router_->NotifyNav(delegate); 721 router_->NotifyNav(delegate);
714 } 722 }
715 void NavigateTab(TestSyncedTabDelegate* delegate, const std::string& url) { 723 void NavigateTab(TestSyncedTabDelegate* delegate, const std::string& url) {
716 NavigateTab(delegate, url, base::Time()); 724 NavigateTab(delegate, url, base::Time());
717 } 725 }
718 726
727 void ResetWindows() {
728 window_getter_.ClearSyncedWindowDelegates();
729 windows_.clear();
730 }
731
719 TestSyncedWindowDelegate* AddWindow() { 732 TestSyncedWindowDelegate* AddWindow() {
720 windows_.push_back(base::MakeUnique<TestSyncedWindowDelegate>()); 733 windows_.push_back(base::MakeUnique<TestSyncedWindowDelegate>());
721 window_getter_.AddSyncedWindowDelegate(windows_.back().get()); 734 window_getter_.AddSyncedWindowDelegate(windows_.back().get());
722 return windows_.back().get(); 735 return windows_.back().get();
723 } 736 }
724 737
738 syncer::SyncDataList GetDataFromChanges(
739 const syncer::SyncChangeList& changes) {
740 syncer::SyncDataList data_list;
741 for (auto& change : changes) {
742 syncer::SyncDataLocal change_data(change.sync_data());
743 bool found = false;
744 for (auto&& data : data_list) {
745 syncer::SyncDataLocal local_data(data);
746 if (local_data.GetTag() == change_data.GetTag()) {
747 data = change.sync_data();
748 found = true;
749 break;
750 }
751 }
752 if (!found)
753 data_list.push_back(change_data);
754 }
755 return data_list;
756 }
757
758 syncer::SyncDataList ConvertToRemote(const syncer::SyncDataList& in) {
759 syncer::SyncDataList out;
760 for (auto& data : in) {
761 out.push_back(CreateRemoteData(data.GetSpecifics()));
762 }
763 return out;
764 }
765
725 private: 766 private:
726 std::unique_ptr<syncer::FakeSyncClient> sync_client_; 767 std::unique_ptr<syncer::FakeSyncClient> sync_client_;
727 std::unique_ptr<SyncSessionsClientShim> sessions_client_shim_; 768 std::unique_ptr<SyncSessionsClientShim> sessions_client_shim_;
728 std::unique_ptr<syncer::SyncPrefs> sync_prefs_; 769 std::unique_ptr<syncer::SyncPrefs> sync_prefs_;
729 SessionNotificationObserver observer_; 770 SessionNotificationObserver observer_;
730 std::unique_ptr<DummyRouter> router_; 771 std::unique_ptr<DummyRouter> router_;
731 std::unique_ptr<SessionsSyncManager> manager_; 772 std::unique_ptr<SessionsSyncManager> manager_;
732 SessionSyncTestHelper helper_; 773 SessionSyncTestHelper helper_;
733 TestSyncChangeProcessor* test_processor_ = nullptr; 774 TestSyncChangeProcessor* test_processor_ = nullptr;
734 TestSyncedWindowDelegatesGetter window_getter_; 775 TestSyncedWindowDelegatesGetter window_getter_;
735 std::vector<std::unique_ptr<TestSyncedWindowDelegate>> windows_; 776 std::vector<std::unique_ptr<TestSyncedWindowDelegate>> windows_;
736 std::vector<std::unique_ptr<TestSyncedTabDelegate>> tabs_; 777 std::vector<std::unique_ptr<TestSyncedTabDelegate>> tabs_;
737 std::unique_ptr<LocalDeviceInfoProviderMock> local_device_; 778 std::unique_ptr<LocalDeviceInfoProviderMock> local_device_;
738 }; 779 };
739 780
740 // Test that the SyncSessionManager can properly fill in a SessionHeader.
741 TEST_F(SessionsSyncManagerTest, PopulateSessionHeader) {
742 sync_pb::SessionHeader header_s;
743 header_s.set_client_name("Client 1");
744 header_s.set_device_type(sync_pb::SyncEnums_DeviceType_TYPE_WIN);
745
746 SyncedSession session;
747 base::Time time = base::Time::Now();
748 SessionsSyncManager::PopulateSessionHeaderFromSpecifics(header_s, time,
749 &session);
750 ASSERT_EQ("Client 1", session.session_name);
751 ASSERT_EQ(SyncedSession::TYPE_WIN, session.device_type);
752 ASSERT_EQ(time, session.modified_time);
753 }
754
755 // Test translation between protobuf types and chrome session types.
756 TEST_F(SessionsSyncManagerTest, PopulateSessionWindow) {
757 sync_pb::SessionWindow window_s;
758 window_s.add_tab(0);
759 window_s.set_browser_type(sync_pb::SessionWindow_BrowserType_TYPE_TABBED);
760 window_s.set_selected_tab_index(1);
761
762 SyncedSession* session = manager()->session_tracker_.GetSession(kTag1);
763 manager()->session_tracker_.PutWindowInSession(kTag1, 0);
764 manager()->BuildSyncedSessionFromSpecifics(kTag1, window_s, base::Time(),
765 session->windows[0].get());
766 ASSERT_EQ(1U, session->windows[0]->wrapped_window.tabs.size());
767 ASSERT_EQ(1, session->windows[0]->wrapped_window.selected_tab_index);
768 ASSERT_EQ(sessions::SessionWindow::TYPE_TABBED,
769 session->windows[0]->wrapped_window.type);
770 ASSERT_EQ(1U, manager()->session_tracker_.num_synced_sessions());
771 ASSERT_EQ(1U, manager()->session_tracker_.num_synced_tabs(kTag1));
772 }
773
774 // Populate the fake tab delegate with some data and navigation
775 // entries and make sure that setting a SessionTab from it preserves 781 // entries and make sure that setting a SessionTab from it preserves
776 // those entries (and clobbers any existing data). 782 // those entries (and clobbers any existing data).
777 TEST_F(SessionsSyncManagerTest, SetSessionTabFromDelegate) { 783 TEST_F(SessionsSyncManagerTest, SetSessionTabFromDelegate) {
778 // Create a tab with three valid entries. 784 // Create a tab with three valid entries.
779 TestSyncedTabDelegate* tab = 785 TestSyncedTabDelegate* tab =
780 AddTab(AddWindow()->GetSessionId(), kFoo1, kTime1); 786 AddTab(AddWindow()->GetSessionId(), kFoo1, kTime1);
781 NavigateTab(tab, kBar1, kTime2); 787 NavigateTab(tab, kBar1, kTime2);
782 NavigateTab(tab, kBaz1, kTime3); 788 NavigateTab(tab, kBaz1, kTime3);
783 789
784 sessions::SessionTab session_tab; 790 sessions::SessionTab session_tab;
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
945 SyncData d = CreateRemoteData(out[1].sync_data().GetSpecifics()); 951 SyncData d = CreateRemoteData(out[1].sync_data().GetSpecifics());
946 SyncDataList in = {d}; 952 SyncDataList in = {d};
947 out.clear(); 953 out.clear();
948 manager()->StopSyncing(syncer::SESSIONS); 954 manager()->StopSyncing(syncer::SESSIONS);
949 InitWithSyncDataTakeOutput(in, &out); 955 InitWithSyncDataTakeOutput(in, &out);
950 956
951 ASSERT_TRUE(ChangeTypeMatches(out, {SyncChange::ACTION_UPDATE})); 957 ASSERT_TRUE(ChangeTypeMatches(out, {SyncChange::ACTION_UPDATE}));
952 EXPECT_TRUE(out[0].sync_data().GetSpecifics().session().has_header()); 958 EXPECT_TRUE(out[0].sync_data().GetSpecifics().session().has_header());
953 } 959 }
954 960
961 // Ensure that tabbed windows from a previous session are preserved if no
962 // windows are present on startup.
963 TEST_F(SessionsSyncManagerTest, PreserveTabbedDataNoWindows) {
964 syncer::SyncDataList in;
965 syncer::SyncChangeList out;
966
967 // Set up one tab and start sync with it.
968 TestSyncedTabDelegate* tab = AddTab(AddWindow()->GetSessionId(), kFoo1);
969 NavigateTab(tab, kFoo2);
970 InitWithSyncDataTakeOutput(in, &out);
971
972 // There should be two entities, a header and a tab.
973 in = GetDataFromChanges(out);
974 out.clear();
975 ASSERT_EQ(2U, in.size());
976
977 // Resync, using the previous sync data, but with no windows open now.
978 manager()->StopSyncing(syncer::SESSIONS);
979 ResetWindows();
980 InitWithSyncDataTakeOutput(ConvertToRemote(in), &out);
981
982 // There should be two changes: the rewritten tab (to update the tab id), and
983 // the rewritten header.
984 ASSERT_TRUE(ChangeTypeMatches(
985 out, {SyncChange::ACTION_UPDATE, SyncChange::ACTION_UPDATE}));
986 VerifyLocalTabChange(out[0], 2, kFoo2);
987 VerifyLocalHeaderChange(out[1], 1, 1);
988
989 // Verify the tab id of the restored tab is updated and consistent.
990 int restored_tab_id =
991 out[0].sync_data().GetSpecifics().session().tab().tab_id();
992 // SessionId should be rewritten on restore.
993 ASSERT_NE(tab->GetSessionId(), restored_tab_id);
994 ASSERT_EQ(
995 restored_tab_id,
996 out[1].sync_data().GetSpecifics().session().header().window(0).tab(0));
997 }
998
999 // Ensure that tabbed windows from a previous session are preserved if only
1000 // transient windows are present at startup.
1001 TEST_F(SessionsSyncManagerTest, PreserveTabbedDataCustomTab) {
1002 syncer::SyncDataList in;
1003 syncer::SyncChangeList out;
1004
1005 // Set up one tab and start sync with it.
1006 TestSyncedWindowDelegate* window = AddWindow();
1007 TestSyncedTabDelegate* tab = AddTab(window->GetSessionId(), kFoo1);
1008 NavigateTab(tab, kFoo2);
1009 InitWithSyncDataTakeOutput(in, &out);
1010
1011 // There should be two entities, a header and a tab.
1012 in = GetDataFromChanges(out);
1013 out.clear();
1014 ASSERT_EQ(2U, in.size());
1015
1016 // Resync, using the previous sync data, but with only a custom tab open.
1017 manager()->StopSyncing(syncer::SESSIONS);
1018 window->OverrideWindowTypeToCustomTab();
1019 SessionID new_window_id;
1020 window->OverrideWindowId(new_window_id.id());
1021 std::unique_ptr<TestSyncedTabDelegate> custom_tab =
1022 base::MakeUnique<TestSyncedTabDelegate>();
1023 NavigateTab(custom_tab.get(), kBar1);
1024 window->OverrideTabAt(0, custom_tab.get());
1025 InitWithSyncDataTakeOutput(ConvertToRemote(in), &out);
1026
1027 // The previous session should be preserved, and the transient window should
1028 // be synced as a new transient window. This means that the original tab
1029 // node will be updated with its new tab id, a new tab node will be created,
1030 // and the header will be updated to reflect the two windows and two tabs.
1031 ASSERT_TRUE(
1032 ChangeTypeMatches(out, {SyncChange::ACTION_UPDATE, SyncChange::ACTION_ADD,
1033 SyncChange::ACTION_UPDATE}));
1034 VerifyLocalTabChange(out[0], 2, kFoo2);
1035 VerifyLocalTabChange(out[1], 1, kBar1);
1036 VerifyLocalHeaderChange(out[2], 2, 2);
1037
1038 // The two windows should have different window types.
1039 ASSERT_EQ(sync_pb::SessionWindow::TYPE_CUSTOM_TAB, out[2]
1040 .sync_data()
1041 .GetSpecifics()
1042 .session()
1043 .header()
1044 .window(0)
1045 .browser_type());
1046 ASSERT_EQ(sync_pb::SessionWindow::TYPE_TABBED, out[2]
1047 .sync_data()
1048 .GetSpecifics()
1049 .session()
1050 .header()
1051 .window(1)
1052 .browser_type());
1053
1054 // Verify the tab id of the restored tab is updated and consistent.
1055 int restored_tab_id =
1056 out[0].sync_data().GetSpecifics().session().tab().tab_id();
1057 // SessionId should be rewritten on restore.
1058 ASSERT_NE(tab->GetSessionId(), restored_tab_id);
1059 ASSERT_EQ(
1060 restored_tab_id,
1061 out[2].sync_data().GetSpecifics().session().header().window(1).tab(0));
1062
1063 // Verify the tab id of the custom tab is consistent.
1064 int custom_tab_id =
1065 out[1].sync_data().GetSpecifics().session().tab().tab_id();
1066 ASSERT_EQ(custom_tab->GetSessionId(), custom_tab_id);
1067 ASSERT_EQ(
1068 custom_tab_id,
1069 out[2].sync_data().GetSpecifics().session().header().window(0).tab(0));
1070 }
1071
955 // Tests MergeDataAndStartSyncing with sync data but no local data. 1072 // Tests MergeDataAndStartSyncing with sync data but no local data.
956 TEST_F(SessionsSyncManagerTest, MergeWithInitialForeignSession) { 1073 TEST_F(SessionsSyncManagerTest, MergeWithInitialForeignSession) {
957 std::vector<SessionID::id_type> tab_list1(std::begin(kTabIds1), 1074 std::vector<SessionID::id_type> tab_list1(std::begin(kTabIds1),
958 std::end(kTabIds1)); 1075 std::end(kTabIds1));
959 std::vector<sync_pb::SessionSpecifics> tabs1; 1076 std::vector<sync_pb::SessionSpecifics> tabs1;
960 sync_pb::SessionSpecifics meta( 1077 sync_pb::SessionSpecifics meta(
961 helper()->BuildForeignSession(kTag1, tab_list1, &tabs1)); 1078 helper()->BuildForeignSession(kTag1, tab_list1, &tabs1));
962 // Add a second window. 1079 // Add a second window.
963 std::vector<SessionID::id_type> tab_list2(std::begin(kTabIds2), 1080 std::vector<SessionID::id_type> tab_list2(std::begin(kTabIds2),
964 std::end(kTabIds2)); 1081 std::end(kTabIds2));
(...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after
1575 changes[1].sync_data().GetSpecifics().session().tab_node_id(); 1692 changes[1].sync_data().GetSpecifics().session().tab_node_id();
1576 1693
1577 // Pass back the previous tab and header nodes at association, along with a 1694 // Pass back the previous tab and header nodes at association, along with a
1578 // second tab node (with a rewritten tab node id). 1695 // second tab node (with a rewritten tab node id).
1579 SyncDataList in; 1696 SyncDataList in;
1580 in.push_back( 1697 in.push_back(
1581 CreateRemoteData(changes[2].sync_data().GetSpecifics())); // Header node. 1698 CreateRemoteData(changes[2].sync_data().GetSpecifics())); // Header node.
1582 sync_pb::SessionSpecifics new_tab( 1699 sync_pb::SessionSpecifics new_tab(
1583 changes[1].sync_data().GetSpecifics().session()); 1700 changes[1].sync_data().GetSpecifics().session());
1584 new_tab.set_tab_node_id(tab_node_id + 1); 1701 new_tab.set_tab_node_id(tab_node_id + 1);
1585 in.push_back(CreateRemoteData(new_tab)); // New tab node.
1586 in.push_back(CreateRemoteData( 1702 in.push_back(CreateRemoteData(
1587 changes[1].sync_data().GetSpecifics())); // Old tab node. 1703 changes[1].sync_data().GetSpecifics())); // Old tab node.
1704 in.push_back(CreateRemoteData(new_tab)); // New tab node.
1588 changes.clear(); 1705 changes.clear();
1589 1706
1590 // Reassociate (with the same single tab/window open). 1707 // Reassociate (with the same single tab/window open).
1591 manager()->StopSyncing(syncer::SESSIONS); 1708 manager()->StopSyncing(syncer::SESSIONS);
1592 InitWithSyncDataTakeOutput(in, &changes); 1709 InitWithSyncDataTakeOutput(in, &changes);
1593 1710
1594 // No tab entities should be deleted. The original (lower) tab node id should 1711 // No tab entities should be deleted. The original (lower) tab node id should
1595 // be reused for association. 1712 // be reused for association.
1596 FilterOutLocalHeaderChanges(&changes); 1713 FilterOutLocalHeaderChanges(&changes);
1597 ASSERT_TRUE(ChangeTypeMatches(changes, {SyncChange::ACTION_UPDATE})); 1714 ASSERT_TRUE(ChangeTypeMatches(changes, {SyncChange::ACTION_UPDATE}));
(...skipping 791 matching lines...) Expand 10 before | Expand all | Expand 10 after
2389 window2->OverrideTabAt(0, &tab2); 2506 window2->OverrideTabAt(0, &tab2);
2390 2507
2391 // Resync, reusing the old sync data. 2508 // Resync, reusing the old sync data.
2392 in.push_back(CreateRemoteData(out[0].sync_data().GetSpecifics())); 2509 in.push_back(CreateRemoteData(out[0].sync_data().GetSpecifics()));
2393 in.push_back(CreateRemoteData(out[1].sync_data().GetSpecifics())); 2510 in.push_back(CreateRemoteData(out[1].sync_data().GetSpecifics()));
2394 out.clear(); 2511 out.clear();
2395 InitWithSyncDataTakeOutput(in, &out); 2512 InitWithSyncDataTakeOutput(in, &out);
2396 2513
2397 // The tab entity will be overwritten twice. Once with the information for 2514 // The tab entity will be overwritten twice. Once with the information for
2398 // tab 1 and then again with the information for tab 2. This will be followed 2515 // tab 1 and then again with the information for tab 2. This will be followed
2399 // by a header change reflecting both tabs. 2516 // by a header change reflecting only the final tab.
2400 ASSERT_TRUE( 2517 ASSERT_TRUE(
2401 ChangeTypeMatches(out, 2518 ChangeTypeMatches(out,
2402 {SyncChange::ACTION_UPDATE, SyncChange::ACTION_UPDATE, 2519 {SyncChange::ACTION_UPDATE, SyncChange::ACTION_UPDATE,
2403 SyncChange::ACTION_UPDATE})); 2520 SyncChange::ACTION_UPDATE}));
2404 VerifyLocalHeaderChange(out[2], 2, 2); 2521 VerifyLocalHeaderChange(out[2], 2, 1);
2405 VerifyLocalTabChange(out[0], 1, kFoo1); 2522 VerifyLocalTabChange(out[0], 1, kFoo1);
2406 EXPECT_EQ(sync_id, out[0].sync_data().GetSpecifics().session().tab_node_id()); 2523 EXPECT_EQ(sync_id, out[0].sync_data().GetSpecifics().session().tab_node_id());
2407 EXPECT_EQ(tab1->GetSessionId(), 2524 EXPECT_EQ(tab1->GetSessionId(),
2408 out[0].sync_data().GetSpecifics().session().tab().tab_id()); 2525 out[0].sync_data().GetSpecifics().session().tab().tab_id());
2409 // Because tab 2 is a placeholder, tab 1's URL will be preserved. 2526 // Because tab 2 is a placeholder, tab 1's URL will be preserved.
2410 VerifyLocalTabChange(out[1], 1, kFoo1); 2527 VerifyLocalTabChange(out[1], 1, kFoo1);
2411 EXPECT_EQ(sync_id, out[1].sync_data().GetSpecifics().session().tab_node_id()); 2528 EXPECT_EQ(sync_id, out[1].sync_data().GetSpecifics().session().tab_node_id());
2412 EXPECT_EQ(tab2.GetSessionId(), 2529 EXPECT_EQ(tab2.GetSessionId(),
2413 out[1].sync_data().GetSpecifics().session().tab().tab_id()); 2530 out[1].sync_data().GetSpecifics().session().tab().tab_id());
2414 EXPECT_EQ(window2->GetSessionId(), 2531 EXPECT_EQ(window2->GetSessionId(),
2415 out[1].sync_data().GetSpecifics().session().tab().window_id()); 2532 out[1].sync_data().GetSpecifics().session().tab().window_id());
2416 } 2533 }
2417 2534
2418 } // namespace sync_sessions 2535 } // namespace sync_sessions
OLDNEW
« no previous file with comments | « components/sync_sessions/sessions_sync_manager.cc ('k') | components/sync_sessions/synced_session_tracker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698