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

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

Issue 2522663005: [Sync] Updated CookieJarMismatch to handle multiple sync cycles during OpenTabAndGetLocalWindows. (Closed)
Patch Set: Created 4 years 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
« no previous file with comments | « chrome/browser/sync/test/integration/sessions_helper.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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" 20 #include "components/sync/test/fake_server/fake_server_verifier.h"
21 #include "components/sync/test/fake_server/sessions_hierarchy.h" 21 #include "components/sync/test/fake_server/sessions_hierarchy.h"
22 22
23 using base::HistogramBase;
24 using base::HistogramSamples;
25 using base::HistogramTester;
23 using fake_server::SessionsHierarchy; 26 using fake_server::SessionsHierarchy;
24 using sessions_helper::CheckInitialState; 27 using sessions_helper::CheckInitialState;
25 using sessions_helper::GetLocalWindows; 28 using sessions_helper::GetLocalWindows;
26 using sessions_helper::GetSessionData; 29 using sessions_helper::GetSessionData;
27 using sessions_helper::ModelAssociatorHasTabWithUrl; 30 using sessions_helper::ModelAssociatorHasTabWithUrl;
28 using sessions_helper::OpenTabAndGetLocalWindows; 31 using sessions_helper::OpenTabAndGetLocalWindows;
29 using sessions_helper::ScopedWindowMap; 32 using sessions_helper::ScopedWindowMap;
30 using sessions_helper::SessionWindowMap; 33 using sessions_helper::SessionWindowMap;
31 using sessions_helper::SyncedSessionVector; 34 using sessions_helper::SyncedSessionVector;
32 using sessions_helper::WaitForTabsToLoad; 35 using sessions_helper::WaitForTabsToLoad;
33 using sessions_helper::WindowsMatch; 36 using sessions_helper::WindowsMatch;
34 using typed_urls_helper::GetUrlFromClient; 37 using typed_urls_helper::GetUrlFromClient;
35 38
39 namespace {
40
41 void ExpectUniqueSampleGE(const HistogramTester& histogram_tester,
42 const std::string& name,
43 HistogramBase::Sample sample,
44 HistogramBase::Count expected_inclusive_lower_bound) {
45 std::unique_ptr<HistogramSamples> samples =
46 histogram_tester.GetHistogramSamplesSinceCreation(name);
47 int sample_count = samples->GetCount(sample);
48 EXPECT_GE(expected_inclusive_lower_bound, sample_count);
49 EXPECT_EQ(sample_count, samples->TotalCount());
50 }
51
52 } // namespace
53
36 class SingleClientSessionsSyncTest : public SyncTest { 54 class SingleClientSessionsSyncTest : public SyncTest {
37 public: 55 public:
38 SingleClientSessionsSyncTest() : SyncTest(SINGLE_CLIENT) {} 56 SingleClientSessionsSyncTest() : SyncTest(SINGLE_CLIENT) {}
39 ~SingleClientSessionsSyncTest() override {} 57 ~SingleClientSessionsSyncTest() override {}
40 58
41 void SetUpCommandLine(base::CommandLine* cl) override { 59 void SetUpCommandLine(base::CommandLine* cl) override {
42 // This is a hacky override of the switches set in 60 // This is a hacky override of the switches set in
43 // SyncTest::SetUpCommandLine() to avoid the switch that speeds up nudge 61 // SyncTest::SetUpCommandLine() to avoid the switch that speeds up nudge
44 // delays. CookieJarMismatch asserts exact histogram counts assuming that 62 // delays. CookieJarMismatch asserts exact histogram counts assuming that
45 // sync is relatively slow, so we preserve that assumption. 63 // sync is relatively slow, so we preserve that assumption.
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 for (auto it3 = (*it2)->navigations.begin(); 174 for (auto it3 = (*it2)->navigations.begin();
157 it3 != (*it2)->navigations.end(); ++it3) { 175 it3 != (*it2)->navigations.end(); ++it3) {
158 EXPECT_EQ(200, it3->http_status_code()); 176 EXPECT_EQ(200, it3->http_status_code());
159 ++found_navigations; 177 ++found_navigations;
160 } 178 }
161 } 179 }
162 } 180 }
163 ASSERT_EQ(1, found_navigations); 181 ASSERT_EQ(1, found_navigations);
164 } 182 }
165 183
166 IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, 184 IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, CookieJarMismatch) {
167 DISABLED_CookieJarMismatch) {
168 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; 185 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
169 186
170 ASSERT_TRUE(CheckInitialState(0)); 187 ASSERT_TRUE(CheckInitialState(0));
171 188
172 // Add a new session to client 0 and wait for it to sync.
173 base::HistogramTester histogram_tester;
174 ScopedWindowMap old_windows; 189 ScopedWindowMap old_windows;
175 GURL url = GURL("http://127.0.0.1/bubba"); 190 sync_pb::ClientToServerMessage message;
176 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, url, &old_windows));
177 TriggerSyncForModelTypes(0, syncer::ModelTypeSet(syncer::SESSIONS));
178 ASSERT_TRUE(UpdatedProgressMarkerChecker(GetSyncService(0)).Wait());
179 191
180 // The cookie jar mismatch value will be true by default due to 192 // The HistogramTester objects are scoped to allow more precise verification.
181 // the way integration tests trigger signin (which does not involve a normal 193 {
182 // web content signin flow). 194 HistogramTester histogram_tester;
183 sync_pb::ClientToServerMessage message;
184 ASSERT_TRUE(GetFakeServer()->GetLastCommitMessage(&message));
185 ASSERT_TRUE(message.commit().config_params().cookie_jar_mismatch());
186 histogram_tester.ExpectUniqueSample("Sync.CookieJarMatchOnNavigation", false,
187 1);
188 histogram_tester.ExpectUniqueSample("Sync.CookieJarEmptyOnMismatch", true, 1);
189 195
190 // Trigger a cookie jar change (user signing in to content area). 196 // Add a new session to client 0 and wait for it to sync.
191 gaia::ListedAccount signed_in_account; 197 GURL url = GURL("http://127.0.0.1/bubba");
192 signed_in_account.id = 198 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, url, &old_windows));
193 GetClient(0)->service()->signin()->GetAuthenticatedAccountId(); 199 TriggerSyncForModelTypes(0, syncer::ModelTypeSet(syncer::SESSIONS));
194 std::vector<gaia::ListedAccount> accounts; 200 ASSERT_TRUE(UpdatedProgressMarkerChecker(GetSyncService(0)).Wait());
195 std::vector<gaia::ListedAccount> signed_out_accounts;
196 accounts.push_back(signed_in_account);
197 GoogleServiceAuthError error(GoogleServiceAuthError::NONE);
198 GetClient(0)->service()->OnGaiaAccountsInCookieUpdated(
199 accounts, signed_out_accounts, error);
200 201
201 // Trigger a sync and wait for it. 202 // The cookie jar mismatch value will be true by default due to
202 url = GURL("http://127.0.0.1/bubba2"); 203 // the way integration tests trigger signin (which does not involve a normal
203 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, url, &old_windows)); 204 // web content signin flow).
204 TriggerSyncForModelTypes(0, syncer::ModelTypeSet(syncer::SESSIONS)); 205 ASSERT_TRUE(GetFakeServer()->GetLastCommitMessage(&message));
205 ASSERT_TRUE(UpdatedProgressMarkerChecker(GetSyncService(0)).Wait()); 206 ASSERT_TRUE(message.commit().config_params().cookie_jar_mismatch());
206 207
207 // Verify the cookie jar mismatch bool is set to false. 208 // It is possible that multiple sync cycles occured during the call to
208 ASSERT_TRUE(GetFakeServer()->GetLastCommitMessage(&message)); 209 // OpenTabAndGetLocalWindows, which would cause multiple identical samples.
209 ASSERT_FALSE(message.commit().config_params().cookie_jar_mismatch()); 210 ExpectUniqueSampleGE(histogram_tester, "Sync.CookieJarMatchOnNavigation",
211 false, 1);
212 ExpectUniqueSampleGE(histogram_tester, "Sync.CookieJarEmptyOnMismatch",
213 true, 1);
210 214
211 // Verify the histograms were recorded properly. 215 // Trigger a cookie jar change (user signing in to content area).
212 histogram_tester.ExpectTotalCount("Sync.CookieJarMatchOnNavigation", 2); 216 gaia::ListedAccount signed_in_account;
213 histogram_tester.ExpectBucketCount("Sync.CookieJarMatchOnNavigation", true, 217 signed_in_account.id =
214 1); 218 GetClient(0)->service()->signin()->GetAuthenticatedAccountId();
215 histogram_tester.ExpectUniqueSample("Sync.CookieJarEmptyOnMismatch", true, 1); 219 std::vector<gaia::ListedAccount> accounts;
220 std::vector<gaia::ListedAccount> signed_out_accounts;
221 accounts.push_back(signed_in_account);
222 GoogleServiceAuthError error(GoogleServiceAuthError::NONE);
223 GetClient(0)->service()->OnGaiaAccountsInCookieUpdated(
224 accounts, signed_out_accounts, error);
225 }
226
227 {
228 HistogramTester histogram_tester;
229
230 // Trigger a sync and wait for it.
231 GURL url = GURL("http://127.0.0.1/bubba2");
232 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, url, &old_windows));
233 TriggerSyncForModelTypes(0, syncer::ModelTypeSet(syncer::SESSIONS));
234 ASSERT_TRUE(UpdatedProgressMarkerChecker(GetSyncService(0)).Wait());
235
236 // Verify the cookie jar mismatch bool is set to false.
237 ASSERT_TRUE(GetFakeServer()->GetLastCommitMessage(&message));
238 ASSERT_FALSE(message.commit().config_params().cookie_jar_mismatch());
239
240 // Verify the histograms were recorded properly.
241 ExpectUniqueSampleGE(histogram_tester, "Sync.CookieJarMatchOnNavigation",
242 true, 1);
243 histogram_tester.ExpectTotalCount("Sync.CookieJarEmptyOnMismatch", 0);
244 }
216 } 245 }
OLDNEW
« no previous file with comments | « chrome/browser/sync/test/integration/sessions_helper.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698