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

Side by Side Diff: chrome/browser/sync/sessions/sessions_sync_manager_unittest.cc

Issue 699033002: Sync: Handle duplicating tab IDs in foreign session data (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « chrome/browser/sync/sessions/sessions_sync_manager.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "chrome/browser/sync/sessions/sessions_sync_manager.h" 5 #include "chrome/browser/sync/sessions/sessions_sync_manager.h"
6 6
7 #include "base/strings/string_util.h" 7 #include "base/strings/string_util.h"
8 #include "chrome/browser/chrome_notification_types.h" 8 #include "chrome/browser/chrome_notification_types.h"
9 #include "chrome/browser/sessions/session_tab_helper.h" 9 #include "chrome/browser/sessions/session_tab_helper.h"
10 #include "chrome/browser/sessions/session_types.h" 10 #include "chrome/browser/sessions/session_types.h"
(...skipping 1951 matching lines...) Expand 10 before | Expand all | Expand 10 after
1962 entity, 1962 entity,
1963 base::Time(), 1963 base::Time(),
1964 syncer::AttachmentIdList(), 1964 syncer::AttachmentIdList(),
1965 syncer::AttachmentServiceProxyForTest::Create())); 1965 syncer::AttachmentServiceProxyForTest::Create()));
1966 } 1966 }
1967 1967
1968 syncer::SyncChangeList output; 1968 syncer::SyncChangeList output;
1969 InitWithSyncDataTakeOutput(initial_data, &output); 1969 InitWithSyncDataTakeOutput(initial_data, &output);
1970 } 1970 }
1971 1971
1972 // Tests receipt of multiple unassociated tabs and makes sure that
1973 // the ones with later timestamp win
1974 TEST_F(SessionsSyncManagerTest, ReceiveDuplicateUnassociatedTabs) {
1975 std::string tag = "tag1";
1976
1977 SessionID::id_type n1[] = {5, 10, 17};
1978 std::vector<SessionID::id_type> tab_list1(n1, n1 + arraysize(n1));
1979 std::vector<sync_pb::SessionSpecifics> tabs1;
1980 sync_pb::SessionSpecifics meta(
1981 helper()->BuildForeignSession(tag, tab_list1, &tabs1));
1982
1983 // Set up initial data.
1984 syncer::SyncDataList initial_data;
1985 sync_pb::EntitySpecifics entity;
1986 entity.mutable_session()->CopyFrom(meta);
1987 initial_data.push_back(SyncData::CreateRemoteData(
1988 1,
1989 entity,
1990 base::Time(),
1991 syncer::AttachmentIdList(),
1992 syncer::AttachmentServiceProxyForTest::Create()));
1993
1994 int node_id = 2;
1995
1996 for (size_t i = 0; i < tabs1.size(); i++) {
1997 entity.mutable_session()->CopyFrom(tabs1[i]);
1998 initial_data.push_back(SyncData::CreateRemoteData(
1999 node_id++,
2000 entity,
2001 base::Time::FromDoubleT(2000),
2002 syncer::AttachmentIdList(),
2003 syncer::AttachmentServiceProxyForTest::Create()));
2004 }
2005
2006 // Add two more tabs with duplicating IDs but with different modification
2007 // times, one before and one after the tabs above.
2008 // These two tabs get a different visual indices to distinguish them from the
2009 // tabs above that get visual index 1 by default.
2010 sync_pb::SessionSpecifics duplicating_tab1;
2011 helper()->BuildTabSpecifics(tag, 0, 10, &duplicating_tab1);
2012 duplicating_tab1.mutable_tab()->set_tab_visual_index(2);
2013 entity.mutable_session()->CopyFrom(duplicating_tab1);
2014 initial_data.push_back(SyncData::CreateRemoteData(
2015 node_id++,
2016 entity,
2017 base::Time::FromDoubleT(1000),
2018 syncer::AttachmentIdList(),
2019 syncer::AttachmentServiceProxyForTest::Create()));
2020
2021 sync_pb::SessionSpecifics duplicating_tab2;
2022 helper()->BuildTabSpecifics(tag, 0, 17, &duplicating_tab2);
2023 duplicating_tab2.mutable_tab()->set_tab_visual_index(3);
2024 entity.mutable_session()->CopyFrom(duplicating_tab2);
2025 initial_data.push_back(SyncData::CreateRemoteData(
2026 node_id++,
2027 entity,
2028 base::Time::FromDoubleT(3000),
2029 syncer::AttachmentIdList(),
2030 syncer::AttachmentServiceProxyForTest::Create()));
2031
2032 syncer::SyncChangeList output;
2033 InitWithSyncDataTakeOutput(initial_data, &output);
2034
2035 std::vector<const SyncedSession*> foreign_sessions;
2036 ASSERT_TRUE(manager()->GetAllForeignSessions(&foreign_sessions));
2037
2038 const std::vector<SessionTab*>& window_tabs =
2039 foreign_sessions[0]->windows.find(0)->second->tabs;
2040 ASSERT_EQ(3U, window_tabs.size());
2041 // The first one is from the original set of tabs.
2042 ASSERT_EQ(1, window_tabs[0]->tab_visual_index);
2043 // The one from the original set of tabs wins over duplicating_tab1.
2044 ASSERT_EQ(1, window_tabs[1]->tab_visual_index);
2045 // duplicating_tab2 wins due to the later timestamp.
2046 ASSERT_EQ(3, window_tabs[2]->tab_visual_index);
2047 }
2048
1972 } // namespace browser_sync 2049 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/sessions/sessions_sync_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698