OLD | NEW |
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_integration_test_util.h" | |
11 #include "chrome/browser/sync/test/integration/sync_test.h" | 10 #include "chrome/browser/sync/test/integration/sync_test.h" |
12 #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
" |
13 #include "chrome/common/url_constants.h" | 13 #include "chrome/common/url_constants.h" |
14 #include "components/browser_sync/profile_sync_service.h" | 14 #include "components/browser_sync/profile_sync_service.h" |
15 #include "components/history/core/browser/history_types.h" | 15 #include "components/history/core/browser/history_types.h" |
16 #include "components/sessions/core/session_types.h" | 16 #include "components/sessions/core/session_types.h" |
17 #include "components/sync/base/time.h" | 17 #include "components/sync/base/time.h" |
18 #include "components/sync/test/fake_server/fake_server_verifier.h" | 18 #include "components/sync/test/fake_server/fake_server_verifier.h" |
19 #include "components/sync/test/fake_server/sessions_hierarchy.h" | 19 #include "components/sync/test/fake_server/sessions_hierarchy.h" |
20 | 20 |
21 using fake_server::SessionsHierarchy; | 21 using fake_server::SessionsHierarchy; |
22 using sessions_helper::CheckInitialState; | 22 using sessions_helper::CheckInitialState; |
23 using sessions_helper::GetLocalWindows; | 23 using sessions_helper::GetLocalWindows; |
24 using sessions_helper::GetSessionData; | 24 using sessions_helper::GetSessionData; |
25 using sessions_helper::ModelAssociatorHasTabWithUrl; | 25 using sessions_helper::ModelAssociatorHasTabWithUrl; |
26 using sessions_helper::OpenTabAndGetLocalWindows; | 26 using sessions_helper::OpenTabAndGetLocalWindows; |
27 using sessions_helper::ScopedWindowMap; | 27 using sessions_helper::ScopedWindowMap; |
28 using sessions_helper::SessionWindowMap; | 28 using sessions_helper::SessionWindowMap; |
29 using sessions_helper::SyncedSessionVector; | 29 using sessions_helper::SyncedSessionVector; |
30 using sessions_helper::WaitForTabsToLoad; | 30 using sessions_helper::WaitForTabsToLoad; |
31 using sessions_helper::WindowsMatch; | 31 using sessions_helper::WindowsMatch; |
32 using sync_integration_test_util::AwaitCommitActivityCompletion; | |
33 using typed_urls_helper::GetUrlFromClient; | 32 using typed_urls_helper::GetUrlFromClient; |
34 | 33 |
35 class SingleClientSessionsSyncTest : public SyncTest { | 34 class SingleClientSessionsSyncTest : public SyncTest { |
36 public: | 35 public: |
37 SingleClientSessionsSyncTest() : SyncTest(SINGLE_CLIENT) {} | 36 SingleClientSessionsSyncTest() : SyncTest(SINGLE_CLIENT) {} |
38 ~SingleClientSessionsSyncTest() override {} | 37 ~SingleClientSessionsSyncTest() override {} |
39 | 38 |
40 private: | 39 private: |
41 DISALLOW_COPY_AND_ASSIGN(SingleClientSessionsSyncTest); | 40 DISALLOW_COPY_AND_ASSIGN(SingleClientSessionsSyncTest); |
42 }; | 41 }; |
43 | 42 |
44 IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, Sanity) { | 43 IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, Sanity) { |
45 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 44 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
46 | 45 |
47 ASSERT_TRUE(CheckInitialState(0)); | 46 ASSERT_TRUE(CheckInitialState(0)); |
48 | 47 |
49 // Add a new session to client 0 and wait for it to sync. | 48 // Add a new session to client 0 and wait for it to sync. |
50 ScopedWindowMap old_windows; | 49 ScopedWindowMap old_windows; |
51 GURL url = GURL("http://127.0.0.1/bubba"); | 50 GURL url = GURL("http://127.0.0.1/bubba"); |
52 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, url, &old_windows)); | 51 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, url, &old_windows)); |
53 ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService(0))); | 52 ASSERT_TRUE(UpdatedProgressMarkerChecker(GetSyncService(0)).Wait()); |
54 | 53 |
55 // Get foreign session data from client 0. | 54 // Get foreign session data from client 0. |
56 SyncedSessionVector sessions; | 55 SyncedSessionVector sessions; |
57 ASSERT_FALSE(GetSessionData(0, &sessions)); | 56 ASSERT_FALSE(GetSessionData(0, &sessions)); |
58 ASSERT_EQ(0U, sessions.size()); | 57 ASSERT_EQ(0U, sessions.size()); |
59 | 58 |
60 // Verify client didn't change. | 59 // Verify client didn't change. |
61 ScopedWindowMap new_windows; | 60 ScopedWindowMap new_windows; |
62 ASSERT_TRUE(GetLocalWindows(0, &new_windows)); | 61 ASSERT_TRUE(GetLocalWindows(0, &new_windows)); |
63 ASSERT_TRUE(WindowsMatch(old_windows, new_windows)); | 62 ASSERT_TRUE(WindowsMatch(old_windows, new_windows)); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 153 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
155 | 154 |
156 ASSERT_TRUE(CheckInitialState(0)); | 155 ASSERT_TRUE(CheckInitialState(0)); |
157 | 156 |
158 // Add a new session to client 0 and wait for it to sync. | 157 // Add a new session to client 0 and wait for it to sync. |
159 base::HistogramTester histogram_tester; | 158 base::HistogramTester histogram_tester; |
160 ScopedWindowMap old_windows; | 159 ScopedWindowMap old_windows; |
161 GURL url = GURL("http://127.0.0.1/bubba"); | 160 GURL url = GURL("http://127.0.0.1/bubba"); |
162 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, url, &old_windows)); | 161 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, url, &old_windows)); |
163 TriggerSyncForModelTypes(0, syncer::ModelTypeSet(syncer::SESSIONS)); | 162 TriggerSyncForModelTypes(0, syncer::ModelTypeSet(syncer::SESSIONS)); |
164 ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService(0))); | 163 ASSERT_TRUE(UpdatedProgressMarkerChecker(GetSyncService(0)).Wait()); |
165 | 164 |
166 // The cookie jar mismatch value will be true by default due to | 165 // The cookie jar mismatch value will be true by default due to |
167 // the way integration tests trigger signin (which does not involve a normal | 166 // the way integration tests trigger signin (which does not involve a normal |
168 // web content signin flow). | 167 // web content signin flow). |
169 sync_pb::ClientToServerMessage message; | 168 sync_pb::ClientToServerMessage message; |
170 ASSERT_TRUE(GetFakeServer()->GetLastCommitMessage(&message)); | 169 ASSERT_TRUE(GetFakeServer()->GetLastCommitMessage(&message)); |
171 ASSERT_TRUE(message.commit().config_params().cookie_jar_mismatch()); | 170 ASSERT_TRUE(message.commit().config_params().cookie_jar_mismatch()); |
172 histogram_tester.ExpectUniqueSample("Sync.CookieJarMatchOnNavigation", false, | 171 histogram_tester.ExpectUniqueSample("Sync.CookieJarMatchOnNavigation", false, |
173 1); | 172 1); |
174 histogram_tester.ExpectUniqueSample("Sync.CookieJarEmptyOnMismatch", true, 1); | 173 histogram_tester.ExpectUniqueSample("Sync.CookieJarEmptyOnMismatch", true, 1); |
175 | 174 |
176 // Trigger a cookie jar change (user signing in to content area). | 175 // Trigger a cookie jar change (user signing in to content area). |
177 gaia::ListedAccount signed_in_account; | 176 gaia::ListedAccount signed_in_account; |
178 signed_in_account.id = | 177 signed_in_account.id = |
179 GetClient(0)->service()->signin()->GetAuthenticatedAccountId(); | 178 GetClient(0)->service()->signin()->GetAuthenticatedAccountId(); |
180 std::vector<gaia::ListedAccount> accounts; | 179 std::vector<gaia::ListedAccount> accounts; |
181 std::vector<gaia::ListedAccount> signed_out_accounts; | 180 std::vector<gaia::ListedAccount> signed_out_accounts; |
182 accounts.push_back(signed_in_account); | 181 accounts.push_back(signed_in_account); |
183 GoogleServiceAuthError error(GoogleServiceAuthError::NONE); | 182 GoogleServiceAuthError error(GoogleServiceAuthError::NONE); |
184 GetClient(0)->service()->OnGaiaAccountsInCookieUpdated( | 183 GetClient(0)->service()->OnGaiaAccountsInCookieUpdated( |
185 accounts, signed_out_accounts, error); | 184 accounts, signed_out_accounts, error); |
186 | 185 |
187 // Trigger a sync and wait for it. | 186 // Trigger a sync and wait for it. |
188 url = GURL("http://127.0.0.1/bubba2"); | 187 url = GURL("http://127.0.0.1/bubba2"); |
189 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, url, &old_windows)); | 188 ASSERT_TRUE(OpenTabAndGetLocalWindows(0, url, &old_windows)); |
190 TriggerSyncForModelTypes(0, syncer::ModelTypeSet(syncer::SESSIONS)); | 189 TriggerSyncForModelTypes(0, syncer::ModelTypeSet(syncer::SESSIONS)); |
191 ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService(0))); | 190 ASSERT_TRUE(UpdatedProgressMarkerChecker(GetSyncService(0)).Wait()); |
192 | 191 |
193 // Verify the cookie jar mismatch bool is set to false. | 192 // Verify the cookie jar mismatch bool is set to false. |
194 ASSERT_TRUE(GetFakeServer()->GetLastCommitMessage(&message)); | 193 ASSERT_TRUE(GetFakeServer()->GetLastCommitMessage(&message)); |
195 ASSERT_FALSE(message.commit().config_params().cookie_jar_mismatch()); | 194 ASSERT_FALSE(message.commit().config_params().cookie_jar_mismatch()); |
196 | 195 |
197 // Verify the histograms were recorded properly. | 196 // Verify the histograms were recorded properly. |
198 histogram_tester.ExpectTotalCount("Sync.CookieJarMatchOnNavigation", 2); | 197 histogram_tester.ExpectTotalCount("Sync.CookieJarMatchOnNavigation", 2); |
199 histogram_tester.ExpectBucketCount("Sync.CookieJarMatchOnNavigation", true, | 198 histogram_tester.ExpectBucketCount("Sync.CookieJarMatchOnNavigation", true, |
200 1); | 199 1); |
201 histogram_tester.ExpectUniqueSample("Sync.CookieJarEmptyOnMismatch", true, 1); | 200 histogram_tester.ExpectUniqueSample("Sync.CookieJarEmptyOnMismatch", true, 1); |
202 } | 201 } |
OLD | NEW |