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

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

Issue 2713913002: [sync] Add Sessions integration tests (Closed)
Patch Set: Update commit message Created 3 years, 10 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 (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::OpenTabAndGetLocalWindows;
24 using sessions_helper::OpenTab;
25 using sessions_helper::OpenTabAtIndex;
23 using sessions_helper::ScopedWindowMap; 26 using sessions_helper::ScopedWindowMap;
24 using sessions_helper::SessionWindowMap; 27 using sessions_helper::SessionWindowMap;
25 using sessions_helper::SyncedSessionVector; 28 using sessions_helper::SyncedSessionVector;
26 using sessions_helper::WindowsMatch; 29 using sessions_helper::WindowsMatch;
27 30
28 class TwoClientSessionsSyncTest : public SyncTest { 31 class TwoClientSessionsSyncTest : public SyncTest {
29 public: 32 public:
30 TwoClientSessionsSyncTest() : SyncTest(TWO_CLIENT) {} 33 TwoClientSessionsSyncTest() : SyncTest(TWO_CLIENT) {}
31 ~TwoClientSessionsSyncTest() override {} 34 ~TwoClientSessionsSyncTest() override {}
32 35
36 void WaitForWindowsInForeignSession(int profile_index,
37 ScopedWindowMap windows) {
38 std::vector<ScopedWindowMap> expected_windows(1);
skym 2017/02/24 00:14:09 Wow, you really seem to like reserving space. What
Patrick Noland 2017/02/27 18:53:26 I actually tried this. You can't (trivially) put u
skym 2017/02/27 19:12:27 Why?
skym 2017/02/27 19:42:49 Okay, you're right, and things get confusing reall
Patrick Noland 2017/02/27 19:44:50 initializer lists don't work with move only types.
39 expected_windows[0] = std::move(windows);
40 ASSERT_TRUE(
skym 2017/02/24 00:14:09 EXPECT_TRUE?
Patrick Noland 2017/02/27 18:53:26 Done.
41 ForeignSessionsMatchChecker(profile_index, expected_windows).Wait());
42 }
43
33 private: 44 private:
34 DISALLOW_COPY_AND_ASSIGN(TwoClientSessionsSyncTest); 45 DISALLOW_COPY_AND_ASSIGN(TwoClientSessionsSyncTest);
35 }; 46 };
36 47
37 static const char* kURL1 = "http://127.0.0.1/bubba1"; 48 static const char* kURL1 = "http://127.0.0.1/bubba1";
38 static const char* kURL2 = "http://127.0.0.1/bubba2"; 49 static const char* kURL2 = "http://127.0.0.1/bubba2";
50 static const char* kURL3 = "http://127.0.0.1/foobar";
51 static const char* kURL4 = "http://127.0.0.1/barbaz";
39 52
40 // TODO(zea): Test each individual session command we care about separately. 53 // TODO(zea): Test each individual session command we care about separately.
41 // (as well as multi-window). We're currently only checking basic single-window/ 54 // (as well as multi-window). We're currently only checking basic single-window/
42 // single-tab functionality. 55 // single-tab functionality.
43 56
44 57
45 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, 58 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest,
46 E2E_ENABLED(SingleClientChanged)) { 59 E2E_ENABLED(SingleClientChanged)) {
47 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; 60 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
48 61
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 } 147 }
135 148
136 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, BothChanged) { 149 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, BothChanged) {
137 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; 150 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
138 151
139 ASSERT_TRUE(CheckInitialState(0)); 152 ASSERT_TRUE(CheckInitialState(0));
140 ASSERT_TRUE(CheckInitialState(1)); 153 ASSERT_TRUE(CheckInitialState(1));
141 154
142 // Open tabs on both clients and retain window information. 155 // Open tabs on both clients and retain window information.
143 ScopedWindowMap client0_windows; 156 ScopedWindowMap client0_windows;
144 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(kURL2), &client0_windows)); 157 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(kURL2), &client0_windows));
skym 2017/02/24 00:14:09 This pattern seems fairly awkward. It shows up ove
Patrick Noland 2017/02/27 18:53:26 I've gone ahead and added a helper to do this, alt
skym 2017/02/27 19:12:27 So, we have a problem with our integ test checkers
145 ScopedWindowMap client1_windows; 158 ScopedWindowMap client1_windows;
146 ASSERT_TRUE(OpenTabAndGetLocalWindows(1, GURL(kURL1), &client1_windows)); 159 ASSERT_TRUE(OpenTabAndGetLocalWindows(1, GURL(kURL1), &client1_windows));
147 160
148 // Wait for sync. 161 WaitForWindowsInForeignSession(1, std::move(client0_windows));
149 ASSERT_TRUE(AwaitQuiescence()); 162 WaitForWindowsInForeignSession(0, std::move(client0_windows));
skym 2017/02/24 00:14:09 You're moving client0_windows twice.
Patrick Noland 2017/02/27 18:53:26 Done.
150 163
151 // Get foreign session data from client 0 and 1. 164 // Check that a navigation is reflected on the other client.
152 SyncedSessionVector sessions0; 165 NavigateTab(0, GURL(kURL3));
153 SyncedSessionVector sessions1; 166 ASSERT_TRUE(GetLocalWindows(0, &client0_windows));
154 ASSERT_TRUE(GetSessionData(0, &sessions0)); 167 WaitForWindowsInForeignSession(1, std::move(client0_windows));
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));
163 } 168 }
164 169
165 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, DeleteIdleSession) { 170 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, DeleteIdleSession) {
166 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; 171 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
167 172
168 ASSERT_TRUE(CheckInitialState(0)); 173 ASSERT_TRUE(CheckInitialState(0));
169 ASSERT_TRUE(CheckInitialState(1)); 174 ASSERT_TRUE(CheckInitialState(1));
170 175
171 // Client 0 opened some tabs then went idle. 176 // Client 0 opened some tabs then went idle.
172 ScopedWindowMap client0_windows; 177 ScopedWindowMap client0_windows;
173 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(kURL1), &client0_windows)); 178 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(kURL1), &client0_windows));
174 179
175 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); 180 WaitForWindowsInForeignSession(1, std::move(client0_windows));
176 181
177 // Get foreign session data from client 1. 182 // Get foreign session data from client 1.
178 SyncedSessionVector sessions1; 183 SyncedSessionVector sessions1;
179 ASSERT_TRUE(GetSessionData(1, &sessions1)); 184 ASSERT_TRUE(GetSessionData(1, &sessions1));
180 185
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
185 // Client 1 now deletes client 0's tabs. This frees the memory of sessions1. 186 // Client 1 now deletes client 0's tabs. This frees the memory of sessions1.
186 DeleteForeignSession(1, sessions1[0]->session_tag); 187 DeleteForeignSession(1, sessions1[0]->session_tag);
187 ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0))); 188 ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0)));
188 ASSERT_FALSE(GetSessionData(1, &sessions1)); 189 ASSERT_FALSE(GetSessionData(1, &sessions1));
189 } 190 }
190 191
191 // Fails all release trybots. crbug.com/263369. 192 // Fails all release trybots. crbug.com/263369.
192 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, 193 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest,
193 DeleteActiveSession) { 194 DeleteActiveSession) {
194 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; 195 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
195 196
196 ASSERT_TRUE(CheckInitialState(0)); 197 ASSERT_TRUE(CheckInitialState(0));
197 ASSERT_TRUE(CheckInitialState(1)); 198 ASSERT_TRUE(CheckInitialState(1));
198 199
199 // Client 0 opened some tabs then went idle. 200 // Client 0 opened some tabs then went idle.
200 ScopedWindowMap client0_windows; 201 ScopedWindowMap client0_windows;
201 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(kURL1), &client0_windows)); 202 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(kURL1), &client0_windows));
202 203
203 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); 204 WaitForWindowsInForeignSession(1, std::move(client0_windows));
205
204 SyncedSessionVector sessions1; 206 SyncedSessionVector sessions1;
205 ASSERT_TRUE(GetSessionData(1, &sessions1)); 207 ASSERT_TRUE(GetSessionData(1, &sessions1));
206 ASSERT_EQ(1U, sessions1.size()); 208 ASSERT_EQ(1U, sessions1.size());
207 ASSERT_TRUE(WindowsMatch(sessions1[0]->windows, client0_windows));
208 209
209 // Client 1 now deletes client 0's tabs. This frees the memory of sessions1. 210 // Client 1 now deletes client 0's tabs. This frees the memory of sessions1.
210 DeleteForeignSession(1, sessions1[0]->session_tag); 211 DeleteForeignSession(1, sessions1[0]->session_tag);
211 ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0))); 212 ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0)));
212 ASSERT_FALSE(GetSessionData(1, &sessions1)); 213 ASSERT_FALSE(GetSessionData(1, &sessions1));
213 214
214 // Client 0 becomes active again with a new tab. 215 // Client 0 becomes active again with a new tab.
215 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(kURL2), &client0_windows)); 216 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(kURL2), &client0_windows));
216 ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); 217 WaitForWindowsInForeignSession(1, std::move(client0_windows));
217 ASSERT_TRUE(GetSessionData(1, &sessions1));
218 ASSERT_EQ(1U, sessions1.size());
219 ASSERT_TRUE(WindowsMatch(sessions1[0]->windows, client0_windows));
220 } 218 }
219
220 IN_PROC_BROWSER_TEST_F(TwoClientSessionsSyncTest, MultipleWindowsMultipleTabs) {
221 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
222
223 ASSERT_TRUE(CheckInitialState(0));
224 ASSERT_TRUE(CheckInitialState(1));
225
226 ASSERT_TRUE(OpenTab(0, GURL(kURL1)));
227 ASSERT_TRUE(OpenTabAtIndex(0, 1, GURL(kURL2)));
228
229 // Add a second browser for profile 0. This browser ends up in index 2.
230 AddBrowser(0);
231 ASSERT_TRUE(OpenTab(2, GURL(kURL3)));
232 ASSERT_TRUE(OpenTabAtIndex(2, 2, GURL(kURL4)));
233
234 ScopedWindowMap client0_windows;
235 ASSERT_TRUE(GetLocalWindows(2, &client0_windows));
236 EXPECT_EQ(client0_windows.size(), 2u);
skym 2017/02/24 00:14:09 https://github.com/google/googletest/blob/master/g
237
238 WaitForWindowsInForeignSession(1, std::move(client0_windows));
239 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698