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

Side by Side Diff: chrome/browser/sync/test/integration/single_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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 "base/macros.h" 5 #include "base/macros.h"
6 #include "base/test/histogram_tester.h" 6 #include "base/test/histogram_tester.h"
7 #include "chrome/browser/sessions/session_service.h" 7 #include "chrome/browser/sessions/session_service.h"
8 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h" 8 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h"
9 #include "chrome/browser/sync/test/integration/sessions_helper.h" 9 #include "chrome/browser/sync/test/integration/sessions_helper.h"
10 #include "chrome/browser/sync/test/integration/sync_test.h" 10 #include "chrome/browser/sync/test/integration/sync_test.h"
11 #include "chrome/browser/sync/test/integration/typed_urls_helper.h" 11 #include "chrome/browser/sync/test/integration/typed_urls_helper.h"
12 #include "chrome/browser/sync/test/integration/updated_progress_marker_checker.h " 12 #include "chrome/browser/sync/test/integration/updated_progress_marker_checker.h "
13 #include "chrome/common/chrome_switches.h" 13 #include "chrome/common/chrome_switches.h"
14 #include "chrome/common/url_constants.h" 14 #include "chrome/common/url_constants.h"
15 #include "components/browser_sync/profile_sync_service.h" 15 #include "components/browser_sync/profile_sync_service.h"
16 #include "components/history/core/browser/history_types.h" 16 #include "components/history/core/browser/history_types.h"
17 #include "components/sessions/core/session_types.h" 17 #include "components/sessions/core/session_types.h"
18 #include "components/sync/base/time.h" 18 #include "components/sync/base/time.h"
19 #include "components/sync/driver/sync_driver_switches.h" 19 #include "components/sync/driver/sync_driver_switches.h"
20 #include "components/sync/test/fake_server/fake_server_verifier.h"
21 #include "components/sync/test/fake_server/sessions_hierarchy.h" 20 #include "components/sync/test/fake_server/sessions_hierarchy.h"
22 21
23 #if defined(OS_CHROMEOS) 22 #if defined(OS_CHROMEOS)
24 #include "chromeos/chromeos_switches.h" 23 #include "chromeos/chromeos_switches.h"
25 #endif 24 #endif
26 25
27 using base::HistogramBase; 26 using base::HistogramBase;
28 using base::HistogramSamples; 27 using base::HistogramSamples;
29 using base::HistogramTester; 28 using base::HistogramTester;
30 using fake_server::SessionsHierarchy; 29 using fake_server::SessionsHierarchy;
31 using sessions_helper::CheckInitialState; 30 using sessions_helper::CheckInitialState;
32 using sessions_helper::GetLocalWindows; 31 using sessions_helper::GetLocalWindows;
33 using sessions_helper::GetSessionData; 32 using sessions_helper::GetSessionData;
34 using sessions_helper::ModelAssociatorHasTabWithUrl; 33 using sessions_helper::ModelAssociatorHasTabWithUrl;
34 using sessions_helper::MoveTab;
35 using sessions_helper::NavigateTab;
36 using sessions_helper::NavigateTabBack;
37 using sessions_helper::NavigateTabForward;
35 using sessions_helper::OpenTabAndGetLocalWindows; 38 using sessions_helper::OpenTabAndGetLocalWindows;
39 using sessions_helper::OpenTab;
40 using sessions_helper::OpenTabAtIndex;
36 using sessions_helper::ScopedWindowMap; 41 using sessions_helper::ScopedWindowMap;
37 using sessions_helper::SessionWindowMap; 42 using sessions_helper::SessionWindowMap;
38 using sessions_helper::SyncedSessionVector; 43 using sessions_helper::SyncedSessionVector;
39 using sessions_helper::WaitForTabsToLoad; 44 using sessions_helper::WaitForTabsToLoad;
40 using sessions_helper::WindowsMatch; 45 using sessions_helper::WindowsMatch;
41 using typed_urls_helper::GetUrlFromClient; 46 using typed_urls_helper::GetUrlFromClient;
42 47
43 namespace { 48 namespace {
44 49
45 void ExpectUniqueSampleGE(const HistogramTester& histogram_tester, 50 void ExpectUniqueSampleGE(const HistogramTester& histogram_tester,
(...skipping 28 matching lines...) Expand all
74 #if defined(OS_CHROMEOS) 79 #if defined(OS_CHROMEOS)
75 // kIgnoreUserProfileMappingForTests will let UserManager always return 80 // kIgnoreUserProfileMappingForTests will let UserManager always return
76 // active user. If this switch is not set, sync test's profile will not 81 // active user. If this switch is not set, sync test's profile will not
77 // match UserManager's active user, then UserManager won't return active 82 // match UserManager's active user, then UserManager won't return active
78 // user to our tests. 83 // user to our tests.
79 if (!cl->HasSwitch(chromeos::switches::kIgnoreUserProfileMappingForTests)) 84 if (!cl->HasSwitch(chromeos::switches::kIgnoreUserProfileMappingForTests))
80 cl->AppendSwitch(chromeos::switches::kIgnoreUserProfileMappingForTests); 85 cl->AppendSwitch(chromeos::switches::kIgnoreUserProfileMappingForTests);
81 #endif 86 #endif
82 } 87 }
83 88
89 void ExpectNavigationChain(int browser_index, const std::vector<GURL> urls) {
90 ScopedWindowMap windows;
91 ASSERT_TRUE(GetLocalWindows(browser_index, &windows));
skym 2017/02/24 00:14:09 GetLocalWindows takes a profile_index. This doesn'
Patrick Noland 2017/02/24 01:00:40 Good catch. This works in practice for reasons exp
Patrick Noland 2017/02/27 18:53:26 I ended up just removing this parameter, which is
92 ASSERT_EQ(windows.begin()->second->tabs.size(), 1u);
93 sessions::SessionTab* tab = windows.begin()->second->tabs[0].get();
94
95 int index = 0;
96 EXPECT_EQ(urls.size(), tab->navigations.size());
97 for (auto it = tab->navigations.begin(); it != tab->navigations.end();
98 ++it, ++index) {
99 EXPECT_EQ(urls[index], it->virtual_url());
100 }
101 }
102
103 // Block until the expected hierarchy is recorded on the FakeServer for the
104 // profile at |profile_index|. This will time out if the hierarchy is never
105 // recorded.
106 void WaitForHierarchyOnServer(
107 const fake_server::SessionsHierarchy& hierarchy) {
108 SessionHierarchyMatchChecker checker(GetSyncService(0), hierarchy,
109 GetFakeServer());
110 EXPECT_TRUE(checker.Wait());
111 }
112
113 // Shortcut to call WaitForHierarchyOnServer for only |url| in a single
114 // window.
115 void WaitForURLOnServer(const GURL& url) {
116 fake_server::SessionsHierarchy expected_hierarchy;
117 expected_hierarchy.AddWindow(url.spec());
118 WaitForHierarchyOnServer(expected_hierarchy);
119 }
120
84 private: 121 private:
85 DISALLOW_COPY_AND_ASSIGN(SingleClientSessionsSyncTest); 122 DISALLOW_COPY_AND_ASSIGN(SingleClientSessionsSyncTest);
86 }; 123 };
87 124
88 IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, Sanity) { 125 IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, Sanity) {
89 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; 126 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
90 127
91 ASSERT_TRUE(CheckInitialState(0)); 128 ASSERT_TRUE(CheckInitialState(0));
92 129
93 // Add a new session to client 0 and wait for it to sync. 130 // Add a new session to client 0 and wait for it to sync.
94 ScopedWindowMap old_windows; 131 ScopedWindowMap old_windows;
95 GURL url = GURL("http://127.0.0.1/bubba"); 132 GURL url = GURL("http://127.0.0.1/bubba");
96 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, url, &old_windows)); 133 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, url, &old_windows));
97 ASSERT_TRUE(UpdatedProgressMarkerChecker(GetSyncService(0)).Wait()); 134 ASSERT_TRUE(UpdatedProgressMarkerChecker(GetSyncService(0)).Wait());
98 135
99 // Get foreign session data from client 0. 136 // Get foreign session data from client 0.
100 SyncedSessionVector sessions; 137 SyncedSessionVector sessions;
101 ASSERT_FALSE(GetSessionData(0, &sessions)); 138 ASSERT_FALSE(GetSessionData(0, &sessions));
102 ASSERT_EQ(0U, sessions.size()); 139 ASSERT_EQ(0U, sessions.size());
103 140
104 // Verify client didn't change. 141 // Verify client didn't change.
105 ScopedWindowMap new_windows; 142 ScopedWindowMap new_windows;
106 ASSERT_TRUE(GetLocalWindows(0, &new_windows)); 143 ASSERT_TRUE(GetLocalWindows(0, &new_windows));
107 ASSERT_TRUE(WindowsMatch(old_windows, new_windows)); 144 ASSERT_TRUE(WindowsMatch(old_windows, new_windows));
108 145
109 fake_server::FakeServerVerifier fake_server_verifier(GetFakeServer()); 146 WaitForURLOnServer(url);
110 SessionsHierarchy expected_sessions;
111 expected_sessions.AddWindow(url.spec());
112 ASSERT_TRUE(fake_server_verifier.VerifySessions(expected_sessions));
113 } 147 }
114 148
115 IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, NoSessions) { 149 IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, NoSessions) {
116 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; 150 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
117 151
118 fake_server::FakeServerVerifier fake_server_verifier(GetFakeServer()); 152 WaitForHierarchyOnServer(SessionsHierarchy());
119 SessionsHierarchy expected_sessions;
120 ASSERT_TRUE(fake_server_verifier.VerifySessions(expected_sessions));
121 } 153 }
122 154
123 IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, ChromeHistory) { 155 IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, ChromeHistory) {
124 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; 156 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
125 157
126 ASSERT_TRUE(CheckInitialState(0)); 158 ASSERT_TRUE(CheckInitialState(0));
127 159
128 // Add a new session to client 0 and wait for it to sync. 160 // Add a new session to client 0 and wait for it to sync.
129 ScopedWindowMap old_windows; 161 ScopedWindowMap old_windows;
130 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(chrome::kChromeUIHistoryURL), 162 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(chrome::kChromeUIHistoryURL),
131 &old_windows)); 163 &old_windows));
132 std::vector<GURL> urls; 164 std::vector<GURL> urls({GURL(chrome::kChromeUIHistoryURL)});
133 urls.push_back(GURL(chrome::kChromeUIHistoryURL));
134 ASSERT_TRUE(WaitForTabsToLoad(0, urls)); 165 ASSERT_TRUE(WaitForTabsToLoad(0, urls));
skym 2017/02/24 00:14:09 Inline the whole thing!
Patrick Noland 2017/02/27 18:53:26 Done.
135 166
136 // Verify the chrome history page synced. 167 // Verify the chrome history page synced.
137 ASSERT_TRUE(ModelAssociatorHasTabWithUrl(0, 168 ASSERT_TRUE(ModelAssociatorHasTabWithUrl(0,
138 GURL(chrome::kChromeUIHistoryURL))); 169 GURL(chrome::kChromeUIHistoryURL)));
139 } 170 }
140 171
141 IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, TimestampMatchesHistory) { 172 IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, TimestampMatchesHistory) {
142 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; 173 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
143 174
144 ASSERT_TRUE(CheckInitialState(0)); 175 ASSERT_TRUE(CheckInitialState(0));
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 for (auto it3 = (*it2)->navigations.begin(); 218 for (auto it3 = (*it2)->navigations.begin();
188 it3 != (*it2)->navigations.end(); ++it3) { 219 it3 != (*it2)->navigations.end(); ++it3) {
189 EXPECT_EQ(200, it3->http_status_code()); 220 EXPECT_EQ(200, it3->http_status_code());
190 ++found_navigations; 221 ++found_navigations;
191 } 222 }
192 } 223 }
193 } 224 }
194 ASSERT_EQ(1, found_navigations); 225 ASSERT_EQ(1, found_navigations);
195 } 226 }
196 227
228 IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, FragmentURLNavigation) {
229 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
230 ASSERT_TRUE(CheckInitialState(0));
231
232 ScopedWindowMap windows;
233 GURL url = GURL("http://127.0.0.1/bubba");
234 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, url, &windows));
235 WaitForURLOnServer(url);
236
237 GURL fragment_url = GURL("http://127.0.0.1/bubba#fragment");
238 NavigateTab(0, fragment_url);
239 WaitForURLOnServer(fragment_url);
240 }
241
242 IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest,
243 NavigationChainForwardBack) {
244 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
245 ASSERT_TRUE(CheckInitialState(0));
246
247 ScopedWindowMap windows;
248 GURL first_url = GURL("http://127.0.0.1/foobar");
249 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, first_url, &windows));
250 WaitForURLOnServer(first_url);
251
252 GURL second_url = GURL("http://127.0.0.1/barbaz");
253 NavigateTab(0, second_url);
254 WaitForURLOnServer(second_url);
255
256 NavigateTabBack(0);
257 WaitForURLOnServer(first_url);
258
259 ExpectNavigationChain(0, {first_url, second_url});
260
261 NavigateTabForward(0);
262 WaitForURLOnServer(second_url);
263
264 ExpectNavigationChain(0, {first_url, second_url});
265 }
266
267 IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest,
268 NavigationChainAlteredDestructively) {
269 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
270 ASSERT_TRUE(CheckInitialState(0));
271
272 ScopedWindowMap windows;
273 GURL base_url = GURL("http://127.0.0.1/bubba");
274 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, base_url, &windows));
275 WaitForURLOnServer(base_url);
276
277 GURL first_url = GURL("http://127.0.0.1/foobar");
278 ASSERT_TRUE(NavigateTab(0, first_url));
279 WaitForURLOnServer(first_url);
280
281 // Check that the navigation chain matches the above sequence of {base_url,
282 // first_url}.
283 ExpectNavigationChain(0, {base_url, first_url});
284
285 NavigateTabBack(0);
286 WaitForURLOnServer(base_url);
287
288 GURL second_url = GURL("http://127.0.0.1/barbaz");
289 NavigateTab(0, second_url);
290 WaitForURLOnServer(second_url);
291
292 NavigateTabBack(0);
293 WaitForURLOnServer(base_url);
294
295 // Check that the navigation chain contains second_url where first_url was
296 // before.
297 ExpectNavigationChain(0, {base_url, second_url});
298 }
299
300 IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, OpenNewTab) {
301 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
302 ASSERT_TRUE(CheckInitialState(0));
303
304 GURL base_url = GURL("http://127.0.0.1/bubba");
305 ASSERT_TRUE(OpenTabAtIndex(0, 0, base_url));
306
307 SessionsHierarchy hierarchy;
308 hierarchy.AddWindow(base_url.spec());
309 WaitForHierarchyOnServer(hierarchy);
310
311 GURL new_tab_url = GURL("http://127.0.0.1/foobar");
312 ASSERT_TRUE(OpenTabAtIndex(0, 1, new_tab_url));
313
314 SessionsHierarchy new_hierarchy;
315 new_hierarchy.AddWindow(
316 std::multiset<std::string>({base_url.spec(), new_tab_url.spec()}));
skym 2017/02/24 00:14:09 Do you need to specify std::multiset<std::string>
Patrick Noland 2017/02/24 01:00:40 The compiler complains if you don't :/
skym 2017/02/24 16:20:17 But, why? Also, I don't think you need () and {} e
Patrick Noland 2017/02/27 18:53:26 This is replaced with the initializer_list now, al
317 WaitForHierarchyOnServer(new_hierarchy);
318 }
319
320 IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, OpenNewWindow) {
321 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
322 ASSERT_TRUE(CheckInitialState(0));
323
324 GURL base_url = GURL("http://127.0.0.1/bubba");
325 ASSERT_TRUE(OpenTab(0, base_url));
326
327 SessionsHierarchy hierarchy;
328 hierarchy.AddWindow(base_url.spec());
329 WaitForHierarchyOnServer(hierarchy);
330
331 GURL new_window_url = GURL("http://127.0.0.1/foobar");
332 AddBrowser(0);
333 ASSERT_TRUE(OpenTab(1, new_window_url));
334
335 SessionsHierarchy new_hierarchy;
336 new_hierarchy.AddWindow({base_url.spec()});
skym 2017/02/24 00:14:09 Why the {}? It seems like it should do the same th
Patrick Noland 2017/02/27 18:53:26 Done.
337 new_hierarchy.AddWindow({new_window_url.spec()});
338 WaitForHierarchyOnServer(new_hierarchy);
339 }
340
341 IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, TabMovedToOtherWindow) {
342 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
343 ASSERT_TRUE(CheckInitialState(0));
344
345 GURL base_url = GURL("http://127.0.0.1/bubba");
346 GURL moved_tab_url = GURL("http://127.0.0.1/foobar");
347
348 ASSERT_TRUE(OpenTab(0, base_url));
349 ASSERT_TRUE(OpenTabAtIndex(0, 1, moved_tab_url));
350
351 GURL new_window_url = GURL("http://127.0.0.1/barbaz");
352 AddBrowser(0);
353 ASSERT_TRUE(OpenTab(1, new_window_url));
354
355 SessionsHierarchy hierarchy;
356 hierarchy.AddWindow(
357 std::multiset<std::string>({base_url.spec(), moved_tab_url.spec()}));
358 hierarchy.AddWindow({new_window_url.spec()});
359 WaitForHierarchyOnServer(hierarchy);
360
361 // Move tab 1 in browser 0 to browser 1.
362 MoveTab(0, 1, 1);
363
364 SessionsHierarchy changed_hierarchy;
skym 2017/02/24 00:14:09 Doesn't this make you want to have a constructor f
Patrick Noland 2017/02/24 01:00:40 Yes it does, I'll just add that
skym 2017/02/24 16:20:17 Bonus points for making a fancy one that can take
Patrick Noland 2017/02/27 18:53:26 That requires a variadic template, which should be
365 changed_hierarchy.AddWindow({base_url.spec()});
366 changed_hierarchy.AddWindow(std::multiset<std::string>(
367 {new_window_url.spec(), moved_tab_url.spec()}));
368 WaitForHierarchyOnServer(changed_hierarchy);
369 }
370
197 IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, CookieJarMismatch) { 371 IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, CookieJarMismatch) {
198 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; 372 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
199 373
200 ASSERT_TRUE(CheckInitialState(0)); 374 ASSERT_TRUE(CheckInitialState(0));
201 375
202 ScopedWindowMap old_windows; 376 ScopedWindowMap old_windows;
203 sync_pb::ClientToServerMessage message; 377 sync_pb::ClientToServerMessage message;
204 378
205 // The HistogramTester objects are scoped to allow more precise verification. 379 // The HistogramTester objects are scoped to allow more precise verification.
206 { 380 {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 // Verify the cookie jar mismatch bool is set to false. 423 // Verify the cookie jar mismatch bool is set to false.
250 ASSERT_TRUE(GetFakeServer()->GetLastCommitMessage(&message)); 424 ASSERT_TRUE(GetFakeServer()->GetLastCommitMessage(&message));
251 ASSERT_FALSE(message.commit().config_params().cookie_jar_mismatch()); 425 ASSERT_FALSE(message.commit().config_params().cookie_jar_mismatch());
252 426
253 // Verify the histograms were recorded properly. 427 // Verify the histograms were recorded properly.
254 ExpectUniqueSampleGE(histogram_tester, "Sync.CookieJarMatchOnNavigation", 428 ExpectUniqueSampleGE(histogram_tester, "Sync.CookieJarMatchOnNavigation",
255 true, 1); 429 true, 1);
256 histogram_tester.ExpectTotalCount("Sync.CookieJarEmptyOnMismatch", 0); 430 histogram_tester.ExpectTotalCount("Sync.CookieJarEmptyOnMismatch", 0);
257 } 431 }
258 } 432 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698