OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/memory/scoped_vector.h" | |
6 #include "chrome/browser/sessions/session_service.h" | |
7 #include "chrome/browser/sync/profile_sync_service_harness.h" | |
8 #include "chrome/browser/sync/sessions/session_state.h" | |
9 #include "chrome/test/live_sync/live_sync_test.h" | |
10 #include "chrome/test/live_sync/sessions_helper.h" | |
11 | |
12 using sessions_helper::CheckInitialState; | |
13 using sessions_helper::GetLocalWindows; | |
14 using sessions_helper::GetSessionData; | |
15 using sessions_helper::OpenTabAndGetLocalWindows; | |
16 using sessions_helper::WindowsMatch; | |
17 | |
18 class TwoClientSessionsSyncTest : public LiveSyncTest { | |
19 public: | |
20 TwoClientSessionsSyncTest() : LiveSyncTest(TWO_CLIENT) {} | |
21 virtual ~TwoClientSessionsSyncTest() {} | |
22 | |
23 private: | |
24 DISALLOW_COPY_AND_ASSIGN(TwoClientSessionsSyncTest); | |
25 }; | |
26 | |
27 static const char* kValidPassphrase = "passphrase!"; | |
28 static const char* kURL1 = "chrome://sync"; | |
29 static const char* kURL2 = "chrome://version"; | |
30 | |
31 // TODO(zea): Test each individual session command we care about separately. | |
32 // (as well as multi-window). We're currently only checking basic single-window/ | |
33 // single-tab functionality. | |
34 | |
35 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, SingleClientChanged) { | |
36 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
37 | |
38 ASSERT_TRUE(CheckInitialState(0)); | |
39 ASSERT_TRUE(CheckInitialState(1)); | |
40 | |
41 ScopedVector<SessionWindow> client0_windows; | |
42 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(kURL1), client0_windows.get())); | |
43 | |
44 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | |
45 | |
46 // Get foreign session data from client 1. | |
47 SyncedSessionVector sessions1; | |
48 ASSERT_TRUE(GetSessionData(1, &sessions1)); | |
49 | |
50 // Verify client 1's foreign session matches client 0 current window. | |
51 ASSERT_EQ(1U, sessions1.size()); | |
52 ASSERT_TRUE(WindowsMatch(sessions1[0]->windows, client0_windows.get())); | |
53 } | |
54 | |
55 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, | |
56 SingleClientEnabledEncryption) { | |
57 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
58 | |
59 ASSERT_TRUE(CheckInitialState(0)); | |
60 ASSERT_TRUE(CheckInitialState(1)); | |
61 | |
62 ASSERT_TRUE(EnableEncryption(0, syncable::SESSIONS)); | |
63 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | |
64 ASSERT_TRUE(IsEncrypted(0, syncable::SESSIONS)); | |
65 ASSERT_TRUE(IsEncrypted(1, syncable::SESSIONS)); | |
66 } | |
67 | |
68 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, | |
69 SingleClientEnabledEncryptionAndChanged) { | |
70 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
71 | |
72 ASSERT_TRUE(CheckInitialState(0)); | |
73 ASSERT_TRUE(CheckInitialState(1)); | |
74 | |
75 ScopedVector<SessionWindow> client0_windows; | |
76 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(kURL1), client0_windows.get())); | |
77 ASSERT_TRUE(EnableEncryption(0, syncable::SESSIONS)); | |
78 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | |
79 | |
80 // Get foreign session data from client 1. | |
81 ASSERT_TRUE(IsEncrypted(1, syncable::SESSIONS)); | |
82 SyncedSessionVector sessions1; | |
83 ASSERT_TRUE(GetSessionData(1, &sessions1)); | |
84 | |
85 // Verify client 1's foreign session matches client 0 current window. | |
86 ASSERT_EQ(1U, sessions1.size()); | |
87 ASSERT_TRUE(WindowsMatch(sessions1[0]->windows, client0_windows.get())); | |
88 } | |
89 | |
90 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, | |
91 BothClientsEnabledEncryption) { | |
92 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
93 | |
94 ASSERT_TRUE(CheckInitialState(0)); | |
95 ASSERT_TRUE(CheckInitialState(1)); | |
96 | |
97 ASSERT_TRUE(EnableEncryption(0, syncable::SESSIONS)); | |
98 ASSERT_TRUE(EnableEncryption(1, syncable::SESSIONS)); | |
99 ASSERT_TRUE(AwaitQuiescence()); | |
100 ASSERT_TRUE(IsEncrypted(0, syncable::SESSIONS)); | |
101 ASSERT_TRUE(IsEncrypted(1, syncable::SESSIONS)); | |
102 } | |
103 | |
104 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, BothChanged) { | |
105 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
106 | |
107 ASSERT_TRUE(CheckInitialState(0)); | |
108 ASSERT_TRUE(CheckInitialState(1)); | |
109 | |
110 // Open tabs on both clients and retain window information. | |
111 ScopedVector<SessionWindow> client0_windows; | |
112 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(kURL2), client0_windows.get())); | |
113 ScopedVector<SessionWindow> client1_windows; | |
114 ASSERT_TRUE(OpenTabAndGetLocalWindows(1, GURL(kURL1), client1_windows.get())); | |
115 | |
116 // Wait for sync. | |
117 ASSERT_TRUE(AwaitQuiescence()); | |
118 | |
119 // Get foreign session data from client 0 and 1. | |
120 SyncedSessionVector sessions0; | |
121 SyncedSessionVector sessions1; | |
122 ASSERT_TRUE(GetSessionData(0, &sessions0)); | |
123 ASSERT_TRUE(GetSessionData(1, &sessions1)); | |
124 | |
125 // Verify client 1's foreign session matches client 0's current window and | |
126 // vice versa. | |
127 ASSERT_EQ(1U, sessions0.size()); | |
128 ASSERT_EQ(1U, sessions1.size()); | |
129 ASSERT_TRUE(WindowsMatch(sessions1[0]->windows, client0_windows.get())); | |
130 ASSERT_TRUE(WindowsMatch(sessions0[0]->windows, client1_windows.get())); | |
131 } | |
132 | |
133 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, | |
134 FirstChangesAndSetsPassphrase) { | |
135 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
136 | |
137 ASSERT_TRUE(CheckInitialState(0)); | |
138 ASSERT_TRUE(CheckInitialState(1)); | |
139 | |
140 ScopedVector<SessionWindow> client0_windows; | |
141 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(kURL1), client0_windows.get())); | |
142 | |
143 ASSERT_TRUE(EnableEncryption(0, syncable::SESSIONS)); | |
144 GetClient(0)->service()->SetPassphrase(kValidPassphrase, true, true); | |
145 ASSERT_TRUE(GetClient(0)->AwaitPassphraseAccepted()); | |
146 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | |
147 ASSERT_TRUE(GetClient(1)->AwaitPassphraseRequired()); | |
148 ASSERT_EQ(0, GetClient(1)->GetLastSessionSnapshot()-> | |
149 num_blocking_conflicting_updates); | |
150 // We have 3 non-blocking conflicts due to the two meta nodes (one for each | |
151 // client, and the one tab node). | |
152 ASSERT_EQ(3, GetClient(1)->GetLastSessionSnapshot()-> | |
153 num_conflicting_updates); // The encrypted nodes. | |
154 | |
155 GetClient(1)->service()->SetPassphrase(kValidPassphrase, true, true); | |
156 ASSERT_TRUE(GetClient(1)->AwaitPassphraseAccepted()); | |
157 ASSERT_TRUE(GetClient(1)->WaitForTypeEncryption(syncable::SESSIONS)); | |
158 | |
159 ASSERT_TRUE(IsEncrypted(0, syncable::SESSIONS)); | |
160 ASSERT_TRUE(IsEncrypted(1, syncable::SESSIONS)); | |
161 // Get foreign session data from client 0 and 1. | |
162 SyncedSessionVector sessions1; | |
163 ASSERT_TRUE(GetSessionData(1, &sessions1)); | |
164 | |
165 // Verify client 1's foreign session matches client 0's current window and | |
166 // vice versa. | |
167 ASSERT_EQ(1U, sessions1.size()); | |
168 ASSERT_TRUE(WindowsMatch(sessions1[0]->windows, client0_windows.get())); | |
169 } | |
170 | |
171 // Flaky (number of conflicting nodes is off). http://crbug.com/89604. | |
172 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, | |
173 FLAKY_FirstChangesWhileSecondWaitingForPassphrase) { | |
174 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
175 | |
176 ASSERT_TRUE(CheckInitialState(0)); | |
177 ASSERT_TRUE(CheckInitialState(1)); | |
178 | |
179 ASSERT_TRUE(EnableEncryption(0, syncable::SESSIONS)); | |
180 GetClient(0)->service()->SetPassphrase(kValidPassphrase, true, true); | |
181 ASSERT_TRUE(GetClient(0)->AwaitPassphraseAccepted()); | |
182 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | |
183 ASSERT_TRUE(GetClient(1)->AwaitPassphraseRequired()); | |
184 ASSERT_EQ(0, GetClient(1)->GetLastSessionSnapshot()-> | |
185 num_blocking_conflicting_updates); | |
186 // We have two non-blocking conflicts due to the two meta nodes (one for each | |
187 // client). | |
188 ASSERT_EQ(2, GetClient(1)->GetLastSessionSnapshot()-> | |
189 num_conflicting_updates); // The encrypted nodes. | |
190 | |
191 ScopedVector<SessionWindow> client0_windows; | |
192 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(kURL1), client0_windows.get())); | |
193 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | |
194 ASSERT_EQ(0, GetClient(1)->GetLastSessionSnapshot()-> | |
195 num_blocking_conflicting_updates); | |
196 ASSERT_EQ(3, GetClient(1)->GetLastSessionSnapshot()-> | |
197 num_conflicting_updates); // The encrypted nodes. | |
198 | |
199 GetClient(1)->service()->SetPassphrase(kValidPassphrase, true, true); | |
200 ASSERT_TRUE(GetClient(1)->AwaitPassphraseAccepted()); | |
201 ASSERT_TRUE(GetClient(1)->WaitForTypeEncryption(syncable::SESSIONS)); | |
202 | |
203 ASSERT_TRUE(IsEncrypted(0, syncable::SESSIONS)); | |
204 ASSERT_TRUE(IsEncrypted(1, syncable::SESSIONS)); | |
205 // Get foreign session data from client 0 and 1. | |
206 SyncedSessionVector sessions1; | |
207 ASSERT_TRUE(GetSessionData(1, &sessions1)); | |
208 | |
209 // Verify client 1's foreign session matches client 0's current window and | |
210 // vice versa. | |
211 ASSERT_EQ(1U, sessions1.size()); | |
212 ASSERT_TRUE(WindowsMatch(sessions1[0]->windows, client0_windows.get())); | |
213 } | |
214 | |
215 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, | |
216 SecondChangesAfterEncrAndPassphraseChange) { | |
217 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
218 | |
219 ASSERT_TRUE(CheckInitialState(0)); | |
220 ASSERT_TRUE(CheckInitialState(1)); | |
221 | |
222 ASSERT_TRUE(EnableEncryption(0, syncable::SESSIONS)); | |
223 GetClient(0)->service()->SetPassphrase(kValidPassphrase, true, true); | |
224 ASSERT_TRUE(GetClient(0)->AwaitPassphraseAccepted()); | |
225 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | |
226 ASSERT_TRUE(GetClient(1)->AwaitPassphraseRequired()); | |
227 ASSERT_EQ(0, GetClient(1)->GetLastSessionSnapshot()-> | |
228 num_blocking_conflicting_updates); | |
229 // We have two non-blocking conflicts due to the two meta nodes (one for each | |
230 // client). | |
231 ASSERT_EQ(2, GetClient(1)->GetLastSessionSnapshot()-> | |
232 num_conflicting_updates); // The encrypted nodes. | |
233 | |
234 // These changes are either made with the old passphrase or not encrypted at | |
235 // all depending on when client 0's changes are propagated. | |
236 ScopedVector<SessionWindow> client1_windows; | |
237 ASSERT_TRUE(OpenTabAndGetLocalWindows(1, GURL(kURL1), client1_windows.get())); | |
238 ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0))); | |
239 ASSERT_EQ(0, GetClient(1)->GetLastSessionSnapshot()-> | |
240 num_blocking_conflicting_updates); | |
241 ASSERT_EQ(2, GetClient(1)->GetLastSessionSnapshot()-> | |
242 num_conflicting_updates); // The same encrypted nodes. | |
243 | |
244 // At this point we enter the passphrase, triggering a resync, in which the | |
245 // local changes of client 1 get overwritten for now. | |
246 GetClient(1)->service()->SetPassphrase(kValidPassphrase, true, true); | |
247 ASSERT_TRUE(GetClient(1)->AwaitPassphraseAccepted()); | |
248 ASSERT_TRUE(GetClient(1)->WaitForTypeEncryption(syncable::SESSIONS)); | |
249 | |
250 ASSERT_TRUE(IsEncrypted(0, syncable::SESSIONS)); | |
251 ASSERT_TRUE(IsEncrypted(1, syncable::SESSIONS)); | |
252 // The session data from client 1 got overwritten. As a result, client 0 | |
253 // should have no foreign session data. | |
254 SyncedSessionVector sessions0; | |
255 SyncedSessionVector sessions1; | |
256 ASSERT_FALSE(GetSessionData(0, &sessions0)); | |
257 ASSERT_FALSE(GetSessionData(1, &sessions1)); | |
258 } | |
259 | |
260 // Flaky. http://crbug.com/85294 | |
261 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, | |
262 FLAKY_SecondChangesBeforeEncrAndPassphraseChange) { | |
263 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
264 | |
265 ASSERT_TRUE(CheckInitialState(0)); | |
266 ASSERT_TRUE(CheckInitialState(1)); | |
267 | |
268 // These changes are either made on client 1 without encryption. | |
269 ScopedVector<SessionWindow> client1_windows; | |
270 ASSERT_TRUE(OpenTabAndGetLocalWindows(1, GURL(kURL1), client1_windows.get())); | |
271 ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0))); | |
272 | |
273 // Turn encryption on client 0. Client 1's foreign will be encrypted with the | |
274 // new passphrase and synced back. It will be unable to decrypt it yet. | |
275 ASSERT_TRUE(EnableEncryption(0, syncable::SESSIONS)); | |
276 GetClient(0)->service()->SetPassphrase(kValidPassphrase, true, true); | |
277 ASSERT_TRUE(GetClient(0)->AwaitPassphraseAccepted()); | |
278 ASSERT_TRUE(AwaitQuiescence()); | |
279 ASSERT_TRUE(GetClient(1)->AwaitPassphraseRequired()); | |
280 ASSERT_EQ(0, GetClient(1)->GetLastSessionSnapshot()-> | |
281 num_blocking_conflicting_updates); | |
282 // We have three non-blocking conflicts due to the two meta nodes (one for | |
283 // each client) and the one tab node. | |
284 ASSERT_GE(3, GetClient(1)->GetLastSessionSnapshot()-> | |
285 num_conflicting_updates); // The encrypted nodes. | |
286 | |
287 // At this point we enter the passphrase, triggering a resync. | |
288 GetClient(1)->service()->SetPassphrase(kValidPassphrase, true, true); | |
289 ASSERT_TRUE(GetClient(1)->AwaitPassphraseAccepted()); | |
290 ASSERT_TRUE(GetClient(1)->WaitForTypeEncryption(syncable::SESSIONS)); | |
291 | |
292 ASSERT_TRUE(IsEncrypted(0, syncable::SESSIONS)); | |
293 ASSERT_TRUE(IsEncrypted(1, syncable::SESSIONS)); | |
294 // Client 0's foreign data should match client 1's local data. Client 1's | |
295 // foreign data is empty because client 0 did not open any tabs. | |
296 SyncedSessionVector sessions0; | |
297 SyncedSessionVector sessions1; | |
298 ASSERT_TRUE(GetSessionData(0, &sessions0)); | |
299 ASSERT_FALSE(GetSessionData(1, &sessions1)); | |
300 ASSERT_EQ(1U, sessions0.size()); | |
301 ASSERT_TRUE(WindowsMatch(sessions0[0]->windows, client1_windows.get())); | |
302 } | |
303 | |
304 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, | |
305 BothChangeWithEncryptionAndPassphrase) { | |
306 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
307 | |
308 ASSERT_TRUE(CheckInitialState(0)); | |
309 ASSERT_TRUE(CheckInitialState(1)); | |
310 | |
311 GetClient(0)->service()->SetPassphrase(kValidPassphrase, true, true); | |
312 ASSERT_TRUE(GetClient(0)->AwaitPassphraseAccepted()); | |
313 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | |
314 ASSERT_TRUE(GetClient(1)->AwaitPassphraseRequired()); | |
315 | |
316 // These changes will sync over to client 1, who will be unable to decrypt | |
317 // them due to the missing passphrase. | |
318 ScopedVector<SessionWindow> client0_windows; | |
319 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(kURL1), client0_windows.get())); | |
320 ASSERT_TRUE(EnableEncryption(0, syncable::SESSIONS)); | |
321 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); | |
322 ASSERT_EQ(0, GetClient(1)->GetLastSessionSnapshot()-> | |
323 num_blocking_conflicting_updates); | |
324 // We have three non-blocking conflicts due to the two meta nodes (one for | |
325 // each client) and the one tab node. | |
326 ASSERT_EQ(3, GetClient(1)->GetLastSessionSnapshot()-> | |
327 num_conflicting_updates); // The encrypted nodes. | |
328 | |
329 GetClient(1)->service()->SetPassphrase(kValidPassphrase, true, true); | |
330 ASSERT_TRUE(GetClient(1)->AwaitPassphraseAccepted()); | |
331 ASSERT_FALSE(GetClient(1)->service()->IsPassphraseRequired()); | |
332 ASSERT_TRUE(GetClient(1)->WaitForTypeEncryption(syncable::SESSIONS)); | |
333 | |
334 // Open windows on client 1, which should automatically be encrypted. | |
335 ScopedVector<SessionWindow> client1_windows; | |
336 ASSERT_TRUE(OpenTabAndGetLocalWindows(1, GURL(kURL2), client1_windows.get())); | |
337 ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0))); | |
338 | |
339 ASSERT_TRUE(IsEncrypted(0, syncable::SESSIONS)); | |
340 ASSERT_TRUE(IsEncrypted(1, syncable::SESSIONS)); | |
341 // Get foreign session data from client 0 and 1. | |
342 SyncedSessionVector sessions0; | |
343 SyncedSessionVector sessions1; | |
344 ASSERT_TRUE(GetSessionData(0, &sessions0)); | |
345 ASSERT_TRUE(GetSessionData(1, &sessions1)); | |
346 | |
347 // Verify client 1's foreign session matches client 0's current window and | |
348 // vice versa. | |
349 ASSERT_EQ(1U, sessions0.size()); | |
350 ASSERT_EQ(1U, sessions1.size()); | |
351 ASSERT_TRUE(WindowsMatch(sessions1[0]->windows, client0_windows.get())); | |
352 ASSERT_TRUE(WindowsMatch(sessions0[0]->windows, client1_windows.get())); | |
353 } | |
OLD | NEW |