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

Side by Side Diff: chrome/browser/sync/test/integration/two_client_sessions_sync_test.cc

Issue 2722953002: Revert of [sync] Add Sessions integration tests (Closed)
Patch Set: Created 3 years, 9 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
« no previous file with comments | « chrome/browser/sync/test/integration/sync_test.cc ('k') | chrome/test/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <string> 5 #include <string>
6 6
7 #include "base/guid.h" 7 #include "base/guid.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
11 #include "chrome/browser/sessions/session_service.h" 11 #include "chrome/browser/sessions/session_service.h"
12 #include "chrome/browser/sync/test/integration/passwords_helper.h" 12 #include "chrome/browser/sync/test/integration/passwords_helper.h"
13 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h" 13 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h"
14 #include "chrome/browser/sync/test/integration/sessions_helper.h" 14 #include "chrome/browser/sync/test/integration/sessions_helper.h"
15 #include "chrome/browser/sync/test/integration/sync_test.h" 15 #include "chrome/browser/sync/test/integration/sync_test.h"
16 #include "components/sync/engine/cycle/sync_cycle_snapshot.h" 16 #include "components/sync/engine/cycle/sync_cycle_snapshot.h"
17 17
18 using sessions_helper::CheckInitialState; 18 using sessions_helper::CheckInitialState;
19 using sessions_helper::DeleteForeignSession; 19 using sessions_helper::DeleteForeignSession;
20 using sessions_helper::GetLocalWindows; 20 using sessions_helper::GetLocalWindows;
21 using sessions_helper::GetSessionData; 21 using sessions_helper::GetSessionData;
22 using sessions_helper::NavigateTab; 22 using sessions_helper::OpenTabAndGetLocalWindows;
23 using sessions_helper::OpenTab;
24 using sessions_helper::OpenTabAtIndex;
25 using sessions_helper::ScopedWindowMap; 23 using sessions_helper::ScopedWindowMap;
26 using sessions_helper::SessionWindowMap; 24 using sessions_helper::SessionWindowMap;
27 using sessions_helper::SyncedSessionVector; 25 using sessions_helper::SyncedSessionVector;
28 using sessions_helper::WindowsMatch; 26 using sessions_helper::WindowsMatch;
29 27
30 class TwoClientSessionsSyncTest : public SyncTest { 28 class TwoClientSessionsSyncTest : public SyncTest {
31 public: 29 public:
32 TwoClientSessionsSyncTest() : SyncTest(TWO_CLIENT) {} 30 TwoClientSessionsSyncTest() : SyncTest(TWO_CLIENT) {}
33 ~TwoClientSessionsSyncTest() override {} 31 ~TwoClientSessionsSyncTest() override {}
34 32
35 void WaitForWindowsInForeignSession(int index, ScopedWindowMap windows) {
36 std::vector<ScopedWindowMap> expected_windows;
37 expected_windows.push_back(std::move(windows));
38 EXPECT_TRUE(ForeignSessionsMatchChecker(index, expected_windows).Wait());
39 }
40
41 void WaitForForeignSessionsToSync(int local_index, int non_local_index) {
42 ScopedWindowMap client_windows;
43 ASSERT_TRUE(GetLocalWindows(local_index, &client_windows));
44 WaitForWindowsInForeignSession(non_local_index, std::move(client_windows));
45 }
46
47 private: 33 private:
48 DISALLOW_COPY_AND_ASSIGN(TwoClientSessionsSyncTest); 34 DISALLOW_COPY_AND_ASSIGN(TwoClientSessionsSyncTest);
49 }; 35 };
50 36
51 static const char* kURL1 = "http://127.0.0.1/bubba1"; 37 static const char* kURL1 = "http://127.0.0.1/bubba1";
52 static const char* kURL2 = "http://127.0.0.1/bubba2"; 38 static const char* kURL2 = "http://127.0.0.1/bubba2";
53 static const char* kURL3 = "http://127.0.0.1/foobar";
54 static const char* kURL4 = "http://127.0.0.1/barbaz";
55 39
56 // TODO(zea): Test each individual session command we care about separately. 40 // TODO(zea): Test each individual session command we care about separately.
57 // (as well as multi-window). We're currently only checking basic single-window/ 41 // (as well as multi-window). We're currently only checking basic single-window/
58 // single-tab functionality. 42 // single-tab functionality.
59 43
60 44
61 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, 45 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest,
62 E2E_ENABLED(SingleClientChanged)) { 46 E2E_ENABLED(SingleClientChanged)) {
63 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; 47 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
64 48
65 // Open tab and access a url on client 0 49 // Open tab and access a url on client 0
66 ScopedWindowMap client0_windows; 50 ScopedWindowMap client0_windows;
67 std::string url = base::StringPrintf("http://127.0.0.1/bubba%s", 51 std::string url = base::StringPrintf("http://127.0.0.1/bubba%s",
68 base::GenerateGUID().c_str()); 52 base::GenerateGUID().c_str());
53 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(url), &client0_windows));
69 54
70 ASSERT_TRUE(OpenTab(0, GURL(url))); 55 // Retain the window information on client 0
71 WaitForForeignSessionsToSync(0, 1); 56 std::vector<ScopedWindowMap> expected_windows(1);
57 expected_windows[0] = std::move(client0_windows);
58
59 // Check the foreign windows on client 1
60 ASSERT_TRUE(ForeignSessionsMatchChecker(1, expected_windows).Wait());
72 } 61 }
73 62
74 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, 63 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest,
75 E2E_ENABLED(AllChanged)) { 64 E2E_ENABLED(AllChanged)) {
76 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; 65 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
77 66
78 // Open tabs on all clients and retain window information. 67 // Open tabs on all clients and retain window information.
79 std::vector<ScopedWindowMap> client_windows(num_clients()); 68 std::vector<ScopedWindowMap> client_windows(num_clients());
80 for (int i = 0; i < num_clients(); ++i) { 69 for (int i = 0; i < num_clients(); ++i) {
81 ScopedWindowMap windows; 70 ScopedWindowMap windows;
82 std::string url = base::StringPrintf("http://127.0.0.1/bubba%s", 71 std::string url = base::StringPrintf("http://127.0.0.1/bubba%s",
83 base::GenerateGUID().c_str()); 72 base::GenerateGUID().c_str());
84 ASSERT_TRUE(OpenTab(i, GURL(url))); 73 ASSERT_TRUE(OpenTabAndGetLocalWindows(i, GURL(url), &windows));
85 ASSERT_TRUE(GetLocalWindows(i, &windows));
86 client_windows[i] = std::move(windows); 74 client_windows[i] = std::move(windows);
87 } 75 }
88 76
89 // Get foreign session data from all clients and check it against all 77 // Get foreign session data from all clients and check it against all
90 // client_windows. 78 // client_windows.
91 for (int i = 0; i < num_clients(); ++i) { 79 for (int i = 0; i < num_clients(); ++i) {
92 ASSERT_TRUE(ForeignSessionsMatchChecker(i, client_windows).Wait()); 80 ASSERT_TRUE(ForeignSessionsMatchChecker(i, client_windows).Wait());
93 } 81 }
94 } 82 }
95 83
(...skipping 13 matching lines...) Expand all
109 // This test is flaky on several platforms: 97 // This test is flaky on several platforms:
110 // http://crbug.com/420979 98 // http://crbug.com/420979
111 // http://crbug.com/421167 99 // http://crbug.com/421167
112 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, 100 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest,
113 DISABLED_SingleClientEnabledEncryptionAndChanged) { 101 DISABLED_SingleClientEnabledEncryptionAndChanged) {
114 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; 102 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
115 103
116 ASSERT_TRUE(CheckInitialState(0)); 104 ASSERT_TRUE(CheckInitialState(0));
117 ASSERT_TRUE(CheckInitialState(1)); 105 ASSERT_TRUE(CheckInitialState(1));
118 106
119 ASSERT_TRUE(OpenTab(0, GURL(kURL1))); 107 ScopedWindowMap client0_windows;
108 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(kURL1), &client0_windows));
120 ASSERT_TRUE(EnableEncryption(0)); 109 ASSERT_TRUE(EnableEncryption(0));
121 WaitForForeignSessionsToSync(0, 1); 110 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
111
112 // Get foreign session data from client 1.
113 ASSERT_TRUE(IsEncryptionComplete(1));
114 SyncedSessionVector sessions1;
115 ASSERT_TRUE(GetSessionData(1, &sessions1));
116
117 // Verify client 1's foreign session matches client 0 current window.
118 ASSERT_EQ(1U, sessions1.size());
119 ASSERT_TRUE(WindowsMatch(sessions1[0]->windows, client0_windows));
122 } 120 }
123 121
124 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, 122 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest,
125 BothClientsEnabledEncryption) { 123 BothClientsEnabledEncryption) {
126 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; 124 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
127 125
128 ASSERT_TRUE(CheckInitialState(0)); 126 ASSERT_TRUE(CheckInitialState(0));
129 ASSERT_TRUE(CheckInitialState(1)); 127 ASSERT_TRUE(CheckInitialState(1));
130 128
131 ASSERT_TRUE(EnableEncryption(0)); 129 ASSERT_TRUE(EnableEncryption(0));
132 ASSERT_TRUE(EnableEncryption(1)); 130 ASSERT_TRUE(EnableEncryption(1));
133 ASSERT_TRUE(AwaitQuiescence()); 131 ASSERT_TRUE(AwaitQuiescence());
134 ASSERT_TRUE(IsEncryptionComplete(0)); 132 ASSERT_TRUE(IsEncryptionComplete(0));
135 ASSERT_TRUE(IsEncryptionComplete(1)); 133 ASSERT_TRUE(IsEncryptionComplete(1));
136 } 134 }
137 135
138 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, BothChanged) { 136 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, BothChanged) {
139 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; 137 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
140 138
141 ASSERT_TRUE(CheckInitialState(0)); 139 ASSERT_TRUE(CheckInitialState(0));
142 ASSERT_TRUE(CheckInitialState(1)); 140 ASSERT_TRUE(CheckInitialState(1));
143 141
144 ASSERT_TRUE(OpenTab(0, GURL(kURL1))); 142 // Open tabs on both clients and retain window information.
145 ASSERT_TRUE(OpenTab(1, GURL(kURL2))); 143 ScopedWindowMap client0_windows;
144 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(kURL2), &client0_windows));
145 ScopedWindowMap client1_windows;
146 ASSERT_TRUE(OpenTabAndGetLocalWindows(1, GURL(kURL1), &client1_windows));
146 147
147 WaitForForeignSessionsToSync(0, 1); 148 // Wait for sync.
148 WaitForForeignSessionsToSync(1, 0); 149 ASSERT_TRUE(AwaitQuiescence());
149 150
150 // Check that a navigation in client 0 is reflected on client 1. 151 // Get foreign session data from client 0 and 1.
151 NavigateTab(0, GURL(kURL3)); 152 SyncedSessionVector sessions0;
152 WaitForForeignSessionsToSync(0, 1); 153 SyncedSessionVector sessions1;
154 ASSERT_TRUE(GetSessionData(0, &sessions0));
155 ASSERT_TRUE(GetSessionData(1, &sessions1));
156
157 // Verify client 1's foreign session matches client 0's current window and
158 // vice versa.
159 ASSERT_EQ(1U, sessions0.size());
160 ASSERT_EQ(1U, sessions1.size());
161 ASSERT_TRUE(WindowsMatch(sessions1[0]->windows, client0_windows));
162 ASSERT_TRUE(WindowsMatch(sessions0[0]->windows, client1_windows));
153 } 163 }
154 164
155 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, DeleteIdleSession) { 165 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, DeleteIdleSession) {
156 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; 166 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
157 167
158 ASSERT_TRUE(CheckInitialState(0)); 168 ASSERT_TRUE(CheckInitialState(0));
159 ASSERT_TRUE(CheckInitialState(1)); 169 ASSERT_TRUE(CheckInitialState(1));
160 170
161 // Client 0 opened some tabs then went idle. 171 // Client 0 opened some tabs then went idle.
162 ASSERT_TRUE(OpenTab(0, GURL(kURL1))); 172 ScopedWindowMap client0_windows;
163 WaitForForeignSessionsToSync(0, 1); 173 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(kURL1), &client0_windows));
174
175 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
164 176
165 // Get foreign session data from client 1. 177 // Get foreign session data from client 1.
166 SyncedSessionVector sessions1; 178 SyncedSessionVector sessions1;
167 ASSERT_TRUE(GetSessionData(1, &sessions1)); 179 ASSERT_TRUE(GetSessionData(1, &sessions1));
168 180
181 // Verify client 1's foreign session matches client 0 current window.
182 ASSERT_EQ(1U, sessions1.size());
183 ASSERT_TRUE(WindowsMatch(sessions1[0]->windows, client0_windows));
184
169 // Client 1 now deletes client 0's tabs. This frees the memory of sessions1. 185 // Client 1 now deletes client 0's tabs. This frees the memory of sessions1.
170 DeleteForeignSession(1, sessions1[0]->session_tag); 186 DeleteForeignSession(1, sessions1[0]->session_tag);
171 ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0))); 187 ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0)));
172 ASSERT_FALSE(GetSessionData(1, &sessions1)); 188 ASSERT_FALSE(GetSessionData(1, &sessions1));
173 } 189 }
174 190
175 // Fails all release trybots. crbug.com/263369. 191 // Fails all release trybots. crbug.com/263369.
176 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, 192 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest,
177 DeleteActiveSession) { 193 DeleteActiveSession) {
178 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; 194 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
179 195
180 ASSERT_TRUE(CheckInitialState(0)); 196 ASSERT_TRUE(CheckInitialState(0));
181 ASSERT_TRUE(CheckInitialState(1)); 197 ASSERT_TRUE(CheckInitialState(1));
182 198
183 // Client 0 opened some tabs then went idle. 199 // Client 0 opened some tabs then went idle.
184 ASSERT_TRUE(OpenTab(0, GURL(kURL1))); 200 ScopedWindowMap client0_windows;
185 WaitForForeignSessionsToSync(0, 1); 201 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(kURL1), &client0_windows));
186 202
203 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
187 SyncedSessionVector sessions1; 204 SyncedSessionVector sessions1;
188 ASSERT_TRUE(GetSessionData(1, &sessions1)); 205 ASSERT_TRUE(GetSessionData(1, &sessions1));
189 ASSERT_EQ(1U, sessions1.size()); 206 ASSERT_EQ(1U, sessions1.size());
207 ASSERT_TRUE(WindowsMatch(sessions1[0]->windows, client0_windows));
190 208
191 // Client 1 now deletes client 0's tabs. This frees the memory of sessions1. 209 // Client 1 now deletes client 0's tabs. This frees the memory of sessions1.
192 DeleteForeignSession(1, sessions1[0]->session_tag); 210 DeleteForeignSession(1, sessions1[0]->session_tag);
193 ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0))); 211 ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0)));
194 ASSERT_FALSE(GetSessionData(1, &sessions1)); 212 ASSERT_FALSE(GetSessionData(1, &sessions1));
195 213
196 // Client 0 becomes active again with a new tab. 214 // Client 0 becomes active again with a new tab.
197 ASSERT_TRUE(OpenTab(0, GURL(kURL2))); 215 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(kURL2), &client0_windows));
198 WaitForForeignSessionsToSync(0, 1); 216 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1)));
217 ASSERT_TRUE(GetSessionData(1, &sessions1));
218 ASSERT_EQ(1U, sessions1.size());
219 ASSERT_TRUE(WindowsMatch(sessions1[0]->windows, client0_windows));
199 } 220 }
200
201 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, MultipleWindowsMultipleTabs) {
202 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
203
204 ASSERT_TRUE(CheckInitialState(0));
205 ASSERT_TRUE(CheckInitialState(1));
206
207 EXPECT_TRUE(OpenTab(0, GURL(kURL1)));
208 EXPECT_TRUE(OpenTabAtIndex(0, 1, GURL(kURL2)));
209
210 // Add a second browser for profile 0. This browser ends up in index 2.
211 AddBrowser(0);
212 EXPECT_TRUE(OpenTab(2, GURL(kURL3)));
213 EXPECT_TRUE(OpenTabAtIndex(2, 2, GURL(kURL4)));
214
215 WaitForForeignSessionsToSync(0, 1);
216 }
OLDNEW
« no previous file with comments | « chrome/browser/sync/test/integration/sync_test.cc ('k') | chrome/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698