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

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

Issue 2725813003: reland of [sync] Add Sessions integration tests (Closed)
Patch Set: Switch back to WaitForURLOnServer, make everything a constant 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
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/session_hierarchy_match_checker.h "
9 #include "chrome/browser/sync/test/integration/sessions_helper.h" 10 #include "chrome/browser/sync/test/integration/sessions_helper.h"
10 #include "chrome/browser/sync/test/integration/sync_test.h" 11 #include "chrome/browser/sync/test/integration/sync_test.h"
11 #include "chrome/browser/sync/test/integration/typed_urls_helper.h" 12 #include "chrome/browser/sync/test/integration/typed_urls_helper.h"
12 #include "chrome/browser/sync/test/integration/updated_progress_marker_checker.h " 13 #include "chrome/browser/sync/test/integration/updated_progress_marker_checker.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)
24 #include "chromeos/chromeos_switches.h"
25 #endif
26
27 using base::HistogramBase; 22 using base::HistogramBase;
28 using base::HistogramSamples; 23 using base::HistogramSamples;
29 using base::HistogramTester; 24 using base::HistogramTester;
30 using fake_server::SessionsHierarchy; 25 using fake_server::SessionsHierarchy;
31 using sessions_helper::CheckInitialState; 26 using sessions_helper::CheckInitialState;
32 using sessions_helper::GetLocalWindows; 27 using sessions_helper::GetLocalWindows;
33 using sessions_helper::GetSessionData; 28 using sessions_helper::GetSessionData;
34 using sessions_helper::ModelAssociatorHasTabWithUrl; 29 using sessions_helper::ModelAssociatorHasTabWithUrl;
35 using sessions_helper::OpenTabAndGetLocalWindows; 30 using sessions_helper::MoveTab;
31 using sessions_helper::NavigateTab;
32 using sessions_helper::NavigateTabBack;
33 using sessions_helper::NavigateTabForward;
34 using sessions_helper::OpenTab;
35 using sessions_helper::OpenTabAtIndex;
36 using sessions_helper::ScopedWindowMap; 36 using sessions_helper::ScopedWindowMap;
37 using sessions_helper::SessionWindowMap; 37 using sessions_helper::SessionWindowMap;
38 using sessions_helper::SyncedSessionVector; 38 using sessions_helper::SyncedSessionVector;
39 using sessions_helper::WaitForTabsToLoad; 39 using sessions_helper::WaitForTabsToLoad;
40 using sessions_helper::WindowsMatch; 40 using sessions_helper::WindowsMatch;
41 using typed_urls_helper::GetUrlFromClient; 41 using typed_urls_helper::GetUrlFromClient;
42 42
43 namespace { 43 namespace {
44 44
45 static const char* kURL1 = "data:text/html,<html><title>Test</title></html>";
46 static const char* kURL2 = "data:text/html,<html><title>Test2</title></html>";
47 static const char* kURL3 = "data:text/html,<html><title>Test3</title></html>";
48 static const char* kBaseFragmentURL =
49 "data:text/html,<html><title>Fragment</title><body></body></html>";
50 static const char* kSpecifiedFragmentURL =
51 "data:text/html,<html><title>Fragment</title><body></body></html>#fragment";
52
45 void ExpectUniqueSampleGE(const HistogramTester& histogram_tester, 53 void ExpectUniqueSampleGE(const HistogramTester& histogram_tester,
46 const std::string& name, 54 const std::string& name,
47 HistogramBase::Sample sample, 55 HistogramBase::Sample sample,
48 HistogramBase::Count expected_inclusive_lower_bound) { 56 HistogramBase::Count expected_inclusive_lower_bound) {
49 std::unique_ptr<HistogramSamples> samples = 57 std::unique_ptr<HistogramSamples> samples =
50 histogram_tester.GetHistogramSamplesSinceCreation(name); 58 histogram_tester.GetHistogramSamplesSinceCreation(name);
51 int sample_count = samples->GetCount(sample); 59 int sample_count = samples->GetCount(sample);
52 EXPECT_GE(expected_inclusive_lower_bound, sample_count); 60 EXPECT_GE(sample_count, expected_inclusive_lower_bound);
53 EXPECT_EQ(sample_count, samples->TotalCount()); 61 EXPECT_EQ(sample_count, samples->TotalCount());
54 } 62 }
55 63
56 } // namespace 64 } // namespace
57 65
58 class SingleClientSessionsSyncTest : public SyncTest { 66 class SingleClientSessionsSyncTest : public SyncTest {
59 public: 67 public:
60 SingleClientSessionsSyncTest() : SyncTest(SINGLE_CLIENT) {} 68 SingleClientSessionsSyncTest() : SyncTest(SINGLE_CLIENT) {}
61 ~SingleClientSessionsSyncTest() override {} 69 ~SingleClientSessionsSyncTest() override {}
62 70
63 void SetUpCommandLine(base::CommandLine* cl) override { 71 void ExpectNavigationChain(const std::vector<GURL>& urls) {
64 // This is a hacky override of the switches set in 72 ScopedWindowMap windows;
65 // SyncTest::SetUpCommandLine() to avoid the switch that speeds up nudge 73 ASSERT_TRUE(GetLocalWindows(0, &windows));
66 // delays. CookieJarMismatch asserts exact histogram counts assuming that 74 ASSERT_EQ(windows.begin()->second->tabs.size(), 1u);
67 // sync is relatively slow, so we preserve that assumption. 75 sessions::SessionTab* tab = windows.begin()->second->tabs[0].get();
68 if (!cl->HasSwitch(switches::kDisableBackgroundNetworking))
69 cl->AppendSwitch(switches::kDisableBackgroundNetworking);
70 76
71 if (!cl->HasSwitch(switches::kSyncShortInitialRetryOverride)) 77 int index = 0;
72 cl->AppendSwitch(switches::kSyncShortInitialRetryOverride); 78 EXPECT_EQ(urls.size(), tab->navigations.size());
79 for (auto it = tab->navigations.begin(); it != tab->navigations.end();
80 ++it, ++index) {
81 EXPECT_EQ(urls[index], it->virtual_url());
82 }
83 }
73 84
74 #if defined(OS_CHROMEOS) 85 // Block until the expected hierarchy is recorded on the FakeServer for
75 // kIgnoreUserProfileMappingForTests will let UserManager always return 86 // profile 0. This will time out if the hierarchy is never
76 // active user. If this switch is not set, sync test's profile will not 87 // recorded.
77 // match UserManager's active user, then UserManager won't return active 88 void WaitForHierarchyOnServer(
78 // user to our tests. 89 const fake_server::SessionsHierarchy& hierarchy) {
79 if (!cl->HasSwitch(chromeos::switches::kIgnoreUserProfileMappingForTests)) 90 SessionHierarchyMatchChecker checker(hierarchy, GetSyncService(0),
80 cl->AppendSwitch(chromeos::switches::kIgnoreUserProfileMappingForTests); 91 GetFakeServer());
81 #endif 92 EXPECT_TRUE(checker.Wait());
93 }
94
95 // Shortcut to call WaitForHierarchyOnServer for only |url| in a single
96 // window.
97 void WaitForURLOnServer(const GURL& url) {
98 WaitForHierarchyOnServer({{url.spec()}});
82 } 99 }
83 100
84 private: 101 private:
85 DISALLOW_COPY_AND_ASSIGN(SingleClientSessionsSyncTest); 102 DISALLOW_COPY_AND_ASSIGN(SingleClientSessionsSyncTest);
86 }; 103 };
87 104
88 IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, Sanity) { 105 IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, Sanity) {
89 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; 106 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
90 107
91 ASSERT_TRUE(CheckInitialState(0)); 108 ASSERT_TRUE(CheckInitialState(0));
92 109
93 // Add a new session to client 0 and wait for it to sync. 110 // Add a new session to client 0 and wait for it to sync.
94 ScopedWindowMap old_windows; 111 ScopedWindowMap old_windows;
95 GURL url = GURL("http://127.0.0.1/bubba"); 112 GURL url = GURL(kURL1);
96 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, url, &old_windows)); 113 ASSERT_TRUE(OpenTab(0, url));
114 ASSERT_TRUE(GetLocalWindows(0, &old_windows));
97 ASSERT_TRUE(UpdatedProgressMarkerChecker(GetSyncService(0)).Wait()); 115 ASSERT_TRUE(UpdatedProgressMarkerChecker(GetSyncService(0)).Wait());
98 116
99 // Get foreign session data from client 0. 117 // Get foreign session data from client 0.
100 SyncedSessionVector sessions; 118 SyncedSessionVector sessions;
101 ASSERT_FALSE(GetSessionData(0, &sessions)); 119 ASSERT_FALSE(GetSessionData(0, &sessions));
102 ASSERT_EQ(0U, sessions.size()); 120 ASSERT_EQ(0U, sessions.size());
103 121
104 // Verify client didn't change. 122 // Verify client didn't change.
105 ScopedWindowMap new_windows; 123 ScopedWindowMap new_windows;
106 ASSERT_TRUE(GetLocalWindows(0, &new_windows)); 124 ASSERT_TRUE(GetLocalWindows(0, &new_windows));
107 ASSERT_TRUE(WindowsMatch(old_windows, new_windows)); 125 ASSERT_TRUE(WindowsMatch(old_windows, new_windows));
108 126
109 fake_server::FakeServerVerifier fake_server_verifier(GetFakeServer()); 127 WaitForURLOnServer(url);
110 SessionsHierarchy expected_sessions;
111 expected_sessions.AddWindow(url.spec());
112 ASSERT_TRUE(fake_server_verifier.VerifySessions(expected_sessions));
113 } 128 }
114 129
115 IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, NoSessions) { 130 IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, NoSessions) {
116 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; 131 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
117 132
118 fake_server::FakeServerVerifier fake_server_verifier(GetFakeServer()); 133 WaitForHierarchyOnServer(SessionsHierarchy());
119 SessionsHierarchy expected_sessions;
120 ASSERT_TRUE(fake_server_verifier.VerifySessions(expected_sessions));
121 } 134 }
122 135
123 IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, ChromeHistory) { 136 IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, ChromeHistory) {
124 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; 137 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
125 138
126 ASSERT_TRUE(CheckInitialState(0)); 139 ASSERT_TRUE(CheckInitialState(0));
127 140
128 // Add a new session to client 0 and wait for it to sync. 141 ASSERT_TRUE(OpenTab(0, GURL(chrome::kChromeUIHistoryURL)));
129 ScopedWindowMap old_windows; 142 WaitForURLOnServer(GURL(chrome::kChromeUIHistoryURL));
130 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, GURL(chrome::kChromeUIHistoryURL),
131 &old_windows));
132 std::vector<GURL> urls;
133 urls.push_back(GURL(chrome::kChromeUIHistoryURL));
134 ASSERT_TRUE(WaitForTabsToLoad(0, urls));
135
136 // Verify the chrome history page synced.
137 ASSERT_TRUE(ModelAssociatorHasTabWithUrl(0,
138 GURL(chrome::kChromeUIHistoryURL)));
139 } 143 }
140 144
141 IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, TimestampMatchesHistory) { 145 IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, TimestampMatchesHistory) {
142 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; 146 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
143 147
144 ASSERT_TRUE(CheckInitialState(0)); 148 ASSERT_TRUE(CheckInitialState(0));
145 149
146 // We want a URL that doesn't 404 and has a non-empty title. 150 const GURL url(kURL1);
147 const GURL url("data:text/html,<html><title>Test</title></html>");
148 151
149 ScopedWindowMap windows; 152 ScopedWindowMap windows;
150 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, url, &windows)); 153 ASSERT_TRUE(OpenTab(0, url));
154 ASSERT_TRUE(GetLocalWindows(0, &windows));
151 155
152 int found_navigations = 0; 156 int found_navigations = 0;
153 for (auto it = windows.begin(); it != windows.end(); ++it) { 157 for (auto it = windows.begin(); it != windows.end(); ++it) {
154 for (auto it2 = it->second->tabs.begin(); it2 != it->second->tabs.end(); 158 for (auto it2 = it->second->tabs.begin(); it2 != it->second->tabs.end();
155 ++it2) { 159 ++it2) {
156 for (auto it3 = (*it2)->navigations.begin(); 160 for (auto it3 = (*it2)->navigations.begin();
157 it3 != (*it2)->navigations.end(); ++it3) { 161 it3 != (*it2)->navigations.end(); ++it3) {
158 const base::Time timestamp = it3->timestamp(); 162 const base::Time timestamp = it3->timestamp();
159 163
160 history::URLRow virtual_row; 164 history::URLRow virtual_row;
161 ASSERT_TRUE(GetUrlFromClient(0, it3->virtual_url(), &virtual_row)); 165 ASSERT_TRUE(GetUrlFromClient(0, it3->virtual_url(), &virtual_row));
162 const base::Time history_timestamp = virtual_row.last_visit(); 166 const base::Time history_timestamp = virtual_row.last_visit();
163 167
164 ASSERT_EQ(timestamp, history_timestamp); 168 ASSERT_EQ(timestamp, history_timestamp);
165 ++found_navigations; 169 ++found_navigations;
166 } 170 }
167 } 171 }
168 } 172 }
169 ASSERT_EQ(1, found_navigations); 173 ASSERT_EQ(1, found_navigations);
170 } 174 }
171 175
172 IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, ResponseCodeIsPreserved) { 176 IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, ResponseCodeIsPreserved) {
173 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; 177 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
174 178
175 ASSERT_TRUE(CheckInitialState(0)); 179 ASSERT_TRUE(CheckInitialState(0));
176 180
177 // We want a URL that doesn't 404 and has a non-empty title. 181 const GURL url(kURL1);
178 const GURL url("data:text/html,<html><title>Test</title></html>");
179
180 ScopedWindowMap windows; 182 ScopedWindowMap windows;
181 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, url, &windows)); 183 ASSERT_TRUE(OpenTab(0, url));
184 ASSERT_TRUE(GetLocalWindows(0, &windows));
182 185
183 int found_navigations = 0; 186 int found_navigations = 0;
184 for (auto it = windows.begin(); it != windows.end(); ++it) { 187 for (auto it = windows.begin(); it != windows.end(); ++it) {
185 for (auto it2 = it->second->tabs.begin(); it2 != it->second->tabs.end(); 188 for (auto it2 = it->second->tabs.begin(); it2 != it->second->tabs.end();
186 ++it2) { 189 ++it2) {
187 for (auto it3 = (*it2)->navigations.begin(); 190 for (auto it3 = (*it2)->navigations.begin();
188 it3 != (*it2)->navigations.end(); ++it3) { 191 it3 != (*it2)->navigations.end(); ++it3) {
189 EXPECT_EQ(200, it3->http_status_code()); 192 EXPECT_EQ(200, it3->http_status_code());
190 ++found_navigations; 193 ++found_navigations;
191 } 194 }
192 } 195 }
193 } 196 }
194 ASSERT_EQ(1, found_navigations); 197 ASSERT_EQ(1, found_navigations);
195 } 198 }
196 199
200 IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, FragmentURLNavigation) {
201 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
202 ASSERT_TRUE(CheckInitialState(0));
203
204 const GURL url(kBaseFragmentURL);
205 ASSERT_TRUE(OpenTab(0, url));
206 WaitForURLOnServer(url);
207
208 const GURL fragment_url(kSpecifiedFragmentURL);
209 NavigateTab(0, fragment_url);
210 WaitForURLOnServer(fragment_url);
211 }
212
213 IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest,
214 NavigationChainForwardBack) {
215 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
216 ASSERT_TRUE(CheckInitialState(0));
217
218 GURL first_url = GURL(kURL1);
219 ASSERT_TRUE(OpenTab(0, first_url));
220 WaitForURLOnServer(first_url);
221
222 GURL second_url = GURL(kURL2);
223 NavigateTab(0, second_url);
224 WaitForURLOnServer(second_url);
225
226 NavigateTabBack(0);
227 WaitForURLOnServer(first_url);
228
229 ExpectNavigationChain({first_url, second_url});
230
231 NavigateTabForward(0);
232 WaitForURLOnServer(second_url);
233
234 ExpectNavigationChain({first_url, second_url});
235 }
236
237 IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest,
238 NavigationChainAlteredDestructively) {
239 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
240 ASSERT_TRUE(CheckInitialState(0));
241
242 GURL base_url = GURL(kURL1);
243 ASSERT_TRUE(OpenTab(0, base_url));
244 WaitForURLOnServer(base_url);
245
246 GURL first_url = GURL(kURL2);
247 ASSERT_TRUE(NavigateTab(0, first_url));
248 WaitForURLOnServer(first_url);
249
250 // Check that the navigation chain matches the above sequence of {base_url,
251 // first_url}.
252 ExpectNavigationChain({base_url, first_url});
253
254 NavigateTabBack(0);
255 WaitForURLOnServer(base_url);
256
257 GURL second_url = GURL(kURL3);
258 NavigateTab(0, second_url);
259 WaitForURLOnServer(second_url);
260
261 NavigateTabBack(0);
262 WaitForURLOnServer(base_url);
263
264 // Check that the navigation chain contains second_url where first_url was
265 // before.
266 ExpectNavigationChain({base_url, second_url});
267 }
268
269 IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, OpenNewTab) {
270 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
271 ASSERT_TRUE(CheckInitialState(0));
272
273 GURL base_url = GURL(kURL1);
274 ASSERT_TRUE(OpenTabAtIndex(0, 0, base_url));
275
276 WaitForURLOnServer(base_url);
277
278 GURL new_tab_url = GURL(kURL2);
279 ASSERT_TRUE(OpenTabAtIndex(0, 1, new_tab_url));
280
281 WaitForHierarchyOnServer(
282 SessionsHierarchy({{base_url.spec(), new_tab_url.spec()}}));
283 }
284
285 IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, OpenNewWindow) {
286 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
287 ASSERT_TRUE(CheckInitialState(0));
288
289 GURL base_url = GURL(kURL1);
290 ASSERT_TRUE(OpenTab(0, base_url));
291
292 WaitForURLOnServer(base_url);
293
294 GURL new_window_url = GURL(kURL2);
295 AddBrowser(0);
296 ASSERT_TRUE(OpenTab(1, new_window_url));
297
298 WaitForHierarchyOnServer(
299 SessionsHierarchy({{base_url.spec()}, {new_window_url.spec()}}));
300 }
301
302 IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, TabMovedToOtherWindow) {
303 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
304 ASSERT_TRUE(CheckInitialState(0));
305
306 GURL base_url = GURL(kURL1);
307 GURL moved_tab_url = GURL(kURL2);
308
309 ASSERT_TRUE(OpenTab(0, base_url));
310 ASSERT_TRUE(OpenTabAtIndex(0, 1, moved_tab_url));
311
312 GURL new_window_url = GURL(kURL3);
313 AddBrowser(0);
314 ASSERT_TRUE(OpenTab(1, new_window_url));
315
316 WaitForHierarchyOnServer(SessionsHierarchy(
317 {{base_url.spec(), moved_tab_url.spec()}, {new_window_url.spec()}}));
318
319 // Move tab 1 in browser 0 to browser 1.
320 MoveTab(0, 1, 1);
321
322 WaitForHierarchyOnServer(SessionsHierarchy(
323 {{base_url.spec()}, {new_window_url.spec(), moved_tab_url.spec()}}));
324 }
325
197 IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, CookieJarMismatch) { 326 IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, CookieJarMismatch) {
198 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; 327 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
199 328
200 ASSERT_TRUE(CheckInitialState(0)); 329 ASSERT_TRUE(CheckInitialState(0));
201 330
202 ScopedWindowMap old_windows;
203 sync_pb::ClientToServerMessage message; 331 sync_pb::ClientToServerMessage message;
204 332
205 // The HistogramTester objects are scoped to allow more precise verification. 333 // The HistogramTester objects are scoped to allow more precise verification.
206 { 334 {
207 HistogramTester histogram_tester; 335 HistogramTester histogram_tester;
208 336
209 // Add a new session to client 0 and wait for it to sync. 337 // Add a new session to client 0 and wait for it to sync.
210 GURL url = GURL("http://127.0.0.1/bubba"); 338 GURL url = GURL(kURL1);
211 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, url, &old_windows)); 339 ASSERT_TRUE(OpenTab(0, url));
212 TriggerSyncForModelTypes(0, syncer::ModelTypeSet(syncer::SESSIONS)); 340 WaitForURLOnServer(url);
213 ASSERT_TRUE(UpdatedProgressMarkerChecker(GetSyncService(0)).Wait());
214 341
215 // The cookie jar mismatch value will be true by default due to 342 // The cookie jar mismatch value will be true by default due to
216 // the way integration tests trigger signin (which does not involve a normal 343 // the way integration tests trigger signin (which does not involve a normal
217 // web content signin flow). 344 // web content signin flow).
218 ASSERT_TRUE(GetFakeServer()->GetLastCommitMessage(&message)); 345 ASSERT_TRUE(GetFakeServer()->GetLastCommitMessage(&message));
219 ASSERT_TRUE(message.commit().config_params().cookie_jar_mismatch()); 346 ASSERT_TRUE(message.commit().config_params().cookie_jar_mismatch());
220 347
221 // It is possible that multiple sync cycles occured during the call to 348 // It is possible that multiple sync cycles occured during the call to
222 // OpenTabAndGetLocalWindows, which would cause multiple identical samples. 349 // OpenTab, which would cause multiple identical samples.
223 ExpectUniqueSampleGE(histogram_tester, "Sync.CookieJarMatchOnNavigation", 350 ExpectUniqueSampleGE(histogram_tester, "Sync.CookieJarMatchOnNavigation",
224 false, 1); 351 false, 1);
225 ExpectUniqueSampleGE(histogram_tester, "Sync.CookieJarEmptyOnMismatch", 352 ExpectUniqueSampleGE(histogram_tester, "Sync.CookieJarEmptyOnMismatch",
226 true, 1); 353 true, 1);
227 354
228 // Trigger a cookie jar change (user signing in to content area). 355 // Trigger a cookie jar change (user signing in to content area).
229 gaia::ListedAccount signed_in_account; 356 gaia::ListedAccount signed_in_account;
230 signed_in_account.id = 357 signed_in_account.id =
231 GetClient(0)->service()->signin()->GetAuthenticatedAccountId(); 358 GetClient(0)->service()->signin()->GetAuthenticatedAccountId();
232 std::vector<gaia::ListedAccount> accounts; 359 std::vector<gaia::ListedAccount> accounts;
233 std::vector<gaia::ListedAccount> signed_out_accounts; 360 std::vector<gaia::ListedAccount> signed_out_accounts;
234 accounts.push_back(signed_in_account); 361 accounts.push_back(signed_in_account);
235 GoogleServiceAuthError error(GoogleServiceAuthError::NONE); 362 GoogleServiceAuthError error(GoogleServiceAuthError::NONE);
236 GetClient(0)->service()->OnGaiaAccountsInCookieUpdated( 363 GetClient(0)->service()->OnGaiaAccountsInCookieUpdated(
237 accounts, signed_out_accounts, error); 364 accounts, signed_out_accounts, error);
238 } 365 }
239 366
240 { 367 {
241 HistogramTester histogram_tester; 368 HistogramTester histogram_tester;
242 369
243 // Trigger a sync and wait for it. 370 // Trigger a sync and wait for it.
244 GURL url = GURL("http://127.0.0.1/bubba2"); 371 GURL url = GURL(kURL2);
245 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, url, &old_windows)); 372 ASSERT_TRUE(NavigateTab(0, url));
246 TriggerSyncForModelTypes(0, syncer::ModelTypeSet(syncer::SESSIONS)); 373 WaitForURLOnServer(url);
247 ASSERT_TRUE(UpdatedProgressMarkerChecker(GetSyncService(0)).Wait());
248 374
249 // Verify the cookie jar mismatch bool is set to false. 375 // Verify the cookie jar mismatch bool is set to false.
250 ASSERT_TRUE(GetFakeServer()->GetLastCommitMessage(&message)); 376 ASSERT_TRUE(GetFakeServer()->GetLastCommitMessage(&message));
251 ASSERT_FALSE(message.commit().config_params().cookie_jar_mismatch()); 377 ASSERT_FALSE(message.commit().config_params().cookie_jar_mismatch());
252 378
253 // Verify the histograms were recorded properly. 379 // Verify the histograms were recorded properly.
254 ExpectUniqueSampleGE(histogram_tester, "Sync.CookieJarMatchOnNavigation", 380 ExpectUniqueSampleGE(histogram_tester, "Sync.CookieJarMatchOnNavigation",
255 true, 1); 381 true, 1);
256 histogram_tester.ExpectTotalCount("Sync.CookieJarEmptyOnMismatch", 0); 382 histogram_tester.ExpectTotalCount("Sync.CookieJarEmptyOnMismatch", 0);
257 } 383 }
258 } 384 }
OLDNEW
« no previous file with comments | « chrome/browser/sync/test/integration/sessions_helper.cc ('k') | chrome/browser/sync/test/integration/sync_test.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698