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 "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 1912 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1923 SessionNotificationObserver observer; | 1923 SessionNotificationObserver observer; |
1924 ASSERT_FALSE(observer.notified_of_refresh()); | 1924 ASSERT_FALSE(observer.notified_of_refresh()); |
1925 InitWithNoSyncData(); | 1925 InitWithNoSyncData(); |
1926 AddTab(browser(), GURL("http://foo1")); | 1926 AddTab(browser(), GURL("http://foo1")); |
1927 EXPECT_FALSE(observer.notified_of_refresh()); | 1927 EXPECT_FALSE(observer.notified_of_refresh()); |
1928 NavigateAndCommitActiveTab(GURL("chrome://newtab/#open_tabs")); | 1928 NavigateAndCommitActiveTab(GURL("chrome://newtab/#open_tabs")); |
1929 EXPECT_TRUE(observer.notified_of_refresh()); | 1929 EXPECT_TRUE(observer.notified_of_refresh()); |
1930 } | 1930 } |
1931 #endif // defined(OS_ANDROID) || defined(OS_IOS) | 1931 #endif // defined(OS_ANDROID) || defined(OS_IOS) |
1932 | 1932 |
| 1933 // Tests receipt of duplicate tab IDs in the same window. This should never |
| 1934 // happen, but we want to make sure the client won't do anything bad if it does |
| 1935 // receive such garbage input data. |
| 1936 TEST_F(SessionsSyncManagerTest, ReceiveDuplicateTabInSameWindow) { |
| 1937 std::string tag = "tag1"; |
| 1938 |
| 1939 // Reuse tab ID 10 in an attempt to trigger bad behavior. |
| 1940 SessionID::id_type n1[] = {5, 10, 10, 17}; |
| 1941 std::vector<SessionID::id_type> tab_list1(n1, n1 + arraysize(n1)); |
| 1942 std::vector<sync_pb::SessionSpecifics> tabs1; |
| 1943 sync_pb::SessionSpecifics meta( |
| 1944 helper()->BuildForeignSession(tag, tab_list1, &tabs1)); |
| 1945 |
| 1946 // Set up initial data. |
| 1947 syncer::SyncDataList initial_data; |
| 1948 sync_pb::EntitySpecifics entity; |
| 1949 entity.mutable_session()->CopyFrom(meta); |
| 1950 initial_data.push_back(SyncData::CreateRemoteData( |
| 1951 1, |
| 1952 entity, |
| 1953 base::Time(), |
| 1954 syncer::AttachmentIdList(), |
| 1955 syncer::AttachmentServiceProxyForTest::Create())); |
| 1956 AddTabsToSyncDataList(tabs1, &initial_data); |
| 1957 |
| 1958 syncer::SyncChangeList output; |
| 1959 InitWithSyncDataTakeOutput(initial_data, &output); |
| 1960 } |
| 1961 |
| 1962 // Tests receipt of duplicate tab IDs for the same session. The duplicate tab |
| 1963 // ID is present in two different windows. A client can't be expected to do |
| 1964 // anything reasonable with this input, but we can expect that it doesn't |
| 1965 // crash. |
| 1966 TEST_F(SessionsSyncManagerTest, ReceiveDuplicateTabInOtherWindow) { |
| 1967 std::string tag = "tag1"; |
| 1968 |
| 1969 SessionID::id_type n1[] = {5, 10, 17}; |
| 1970 std::vector<SessionID::id_type> tab_list1(n1, n1 + arraysize(n1)); |
| 1971 std::vector<sync_pb::SessionSpecifics> tabs1; |
| 1972 sync_pb::SessionSpecifics meta( |
| 1973 helper()->BuildForeignSession(tag, tab_list1, &tabs1)); |
| 1974 |
| 1975 // Add a second window. Tab ID 10 is a duplicate. |
| 1976 SessionID::id_type n2[] = {10, 18, 20}; |
| 1977 std::vector<SessionID::id_type> tab_list2(n2, n2 + arraysize(n2)); |
| 1978 helper()->AddWindowSpecifics(1, tab_list2, &meta); |
| 1979 |
| 1980 // Set up initial data. |
| 1981 syncer::SyncDataList initial_data; |
| 1982 sync_pb::EntitySpecifics entity; |
| 1983 entity.mutable_session()->CopyFrom(meta); |
| 1984 initial_data.push_back(SyncData::CreateRemoteData( |
| 1985 1, |
| 1986 entity, |
| 1987 base::Time(), |
| 1988 syncer::AttachmentIdList(), |
| 1989 syncer::AttachmentServiceProxyForTest::Create())); |
| 1990 AddTabsToSyncDataList(tabs1, &initial_data); |
| 1991 |
| 1992 for (size_t i = 0; i < tab_list2.size(); ++i) { |
| 1993 sync_pb::EntitySpecifics entity; |
| 1994 helper()->BuildTabSpecifics(tag, 0, tab_list2[i], entity.mutable_session()); |
| 1995 initial_data.push_back(SyncData::CreateRemoteData( |
| 1996 i + 10, |
| 1997 entity, |
| 1998 base::Time(), |
| 1999 syncer::AttachmentIdList(), |
| 2000 syncer::AttachmentServiceProxyForTest::Create())); |
| 2001 } |
| 2002 |
| 2003 syncer::SyncChangeList output; |
| 2004 InitWithSyncDataTakeOutput(initial_data, &output); |
| 2005 } |
| 2006 |
1933 } // namespace browser_sync | 2007 } // namespace browser_sync |
OLD | NEW |