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

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

Powered by Google App Engine
This is Rietveld 408576698