OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 package org.chromium.sync; | 5 package org.chromium.components.sync; |
6 | 6 |
7 import android.accounts.Account; | 7 import android.accounts.Account; |
8 import android.content.Context; | 8 import android.content.Context; |
9 import android.os.Bundle; | 9 import android.os.Bundle; |
10 import android.test.InstrumentationTestCase; | 10 import android.test.InstrumentationTestCase; |
11 import android.test.suitebuilder.annotation.SmallTest; | 11 import android.test.suitebuilder.annotation.SmallTest; |
12 | 12 |
13 import org.chromium.base.ThreadUtils; | 13 import org.chromium.base.ThreadUtils; |
14 import org.chromium.base.test.util.DisabledTest; | 14 import org.chromium.base.test.util.DisabledTest; |
15 import org.chromium.base.test.util.Feature; | 15 import org.chromium.base.test.util.Feature; |
16 import org.chromium.sync.AndroidSyncSettings.AndroidSyncSettingsObserver; | 16 import org.chromium.components.sync.AndroidSyncSettings.AndroidSyncSettingsObser
ver; |
17 import org.chromium.sync.signin.AccountManagerHelper; | 17 import org.chromium.components.sync.signin.AccountManagerHelper; |
18 import org.chromium.sync.test.util.AccountHolder; | 18 import org.chromium.components.sync.test.util.AccountHolder; |
19 import org.chromium.sync.test.util.MockAccountManager; | 19 import org.chromium.components.sync.test.util.MockAccountManager; |
20 import org.chromium.sync.test.util.MockSyncContentResolverDelegate; | 20 import org.chromium.components.sync.test.util.MockSyncContentResolverDelegate; |
21 | 21 |
22 /** | 22 /** |
23 * Tests for AndroidSyncSettings. | 23 * Tests for AndroidSyncSettings. |
24 */ | 24 */ |
25 @DisabledTest(message = "https://crbug.com/605567") | 25 @DisabledTest(message = "https://crbug.com/605567") |
26 public class AndroidSyncSettingsTest extends InstrumentationTestCase { | 26 public class AndroidSyncSettingsTest extends InstrumentationTestCase { |
27 | |
28 private static class CountingMockSyncContentResolverDelegate | 27 private static class CountingMockSyncContentResolverDelegate |
29 extends MockSyncContentResolverDelegate { | 28 extends MockSyncContentResolverDelegate { |
30 private int mGetMasterSyncAutomaticallyCalls; | 29 private int mGetMasterSyncAutomaticallyCalls; |
31 private int mGetSyncAutomaticallyCalls; | 30 private int mGetSyncAutomaticallyCalls; |
32 private int mGetIsSyncableCalls; | 31 private int mGetIsSyncableCalls; |
33 private int mSetIsSyncableCalls; | 32 private int mSetIsSyncableCalls; |
34 private int mSetSyncAutomaticallyCalls; | 33 private int mSetSyncAutomaticallyCalls; |
35 private int mRemovePeriodicSyncCalls; | 34 private int mRemovePeriodicSyncCalls; |
36 | 35 |
37 @Override | 36 @Override |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 // mAlternateAccount was set to be syncable and not have periodic syncs. | 159 // mAlternateAccount was set to be syncable and not have periodic syncs. |
161 assertEquals(3, mSyncContentResolverDelegate.mSetIsSyncableCalls); | 160 assertEquals(3, mSyncContentResolverDelegate.mSetIsSyncableCalls); |
162 assertEquals(2, mSyncContentResolverDelegate.mRemovePeriodicSyncCalls); | 161 assertEquals(2, mSyncContentResolverDelegate.mRemovePeriodicSyncCalls); |
163 } | 162 } |
164 | 163 |
165 @SmallTest | 164 @SmallTest |
166 @Feature({"Sync"}) | 165 @Feature({"Sync"}) |
167 public void testToggleMasterSyncFromSettings() throws InterruptedException { | 166 public void testToggleMasterSyncFromSettings() throws InterruptedException { |
168 mSyncContentResolverDelegate.setMasterSyncAutomatically(true); | 167 mSyncContentResolverDelegate.setMasterSyncAutomatically(true); |
169 mSyncContentResolverDelegate.waitForLastNotificationCompleted(); | 168 mSyncContentResolverDelegate.waitForLastNotificationCompleted(); |
170 assertTrue("master sync should be set", | 169 assertTrue("master sync should be set", AndroidSyncSettings.isMasterSync
Enabled(mContext)); |
171 AndroidSyncSettings.isMasterSyncEnabled(mContext)); | |
172 | 170 |
173 mSyncContentResolverDelegate.setMasterSyncAutomatically(false); | 171 mSyncContentResolverDelegate.setMasterSyncAutomatically(false); |
174 mSyncContentResolverDelegate.waitForLastNotificationCompleted(); | 172 mSyncContentResolverDelegate.waitForLastNotificationCompleted(); |
175 assertFalse("master sync should be unset", | 173 assertFalse( |
176 AndroidSyncSettings.isMasterSyncEnabled(mContext)); | 174 "master sync should be unset", AndroidSyncSettings.isMasterSyncE
nabled(mContext)); |
177 } | 175 } |
178 | 176 |
179 @SmallTest | 177 @SmallTest |
180 @Feature({"Sync"}) | 178 @Feature({"Sync"}) |
181 public void testToggleChromeSyncFromSettings() throws InterruptedException { | 179 public void testToggleChromeSyncFromSettings() throws InterruptedException { |
182 // Turn on syncability. | 180 // Turn on syncability. |
183 mSyncContentResolverDelegate.setMasterSyncAutomatically(true); | 181 mSyncContentResolverDelegate.setMasterSyncAutomatically(true); |
184 mSyncContentResolverDelegate.waitForLastNotificationCompleted(); | 182 mSyncContentResolverDelegate.waitForLastNotificationCompleted(); |
185 | 183 |
186 // First sync | 184 // First sync |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 mSyncContentResolverDelegate.setMasterSyncAutomatically(true); | 238 mSyncContentResolverDelegate.setMasterSyncAutomatically(true); |
241 mSyncContentResolverDelegate.waitForLastNotificationCompleted(); | 239 mSyncContentResolverDelegate.waitForLastNotificationCompleted(); |
242 | 240 |
243 enableChromeSyncOnUiThread(); | 241 enableChromeSyncOnUiThread(); |
244 mSyncContentResolverDelegate.waitForLastNotificationCompleted(); | 242 mSyncContentResolverDelegate.waitForLastNotificationCompleted(); |
245 assertTrue("account should be synced", AndroidSyncSettings.isSyncEnabled
(mContext)); | 243 assertTrue("account should be synced", AndroidSyncSettings.isSyncEnabled
(mContext)); |
246 | 244 |
247 AndroidSyncSettings.updateAccount(mContext, mAlternateAccount); | 245 AndroidSyncSettings.updateAccount(mContext, mAlternateAccount); |
248 enableChromeSyncOnUiThread(); | 246 enableChromeSyncOnUiThread(); |
249 mSyncContentResolverDelegate.waitForLastNotificationCompleted(); | 247 mSyncContentResolverDelegate.waitForLastNotificationCompleted(); |
250 assertTrue("alternate account should be synced", | 248 assertTrue( |
251 AndroidSyncSettings.isSyncEnabled(mContext)); | 249 "alternate account should be synced", AndroidSyncSettings.isSync
Enabled(mContext)); |
252 | 250 |
253 disableChromeSyncOnUiThread(); | 251 disableChromeSyncOnUiThread(); |
254 mSyncContentResolverDelegate.waitForLastNotificationCompleted(); | 252 mSyncContentResolverDelegate.waitForLastNotificationCompleted(); |
255 assertFalse("alternate account should not be synced", | 253 assertFalse("alternate account should not be synced", |
256 AndroidSyncSettings.isSyncEnabled(mContext)); | 254 AndroidSyncSettings.isSyncEnabled(mContext)); |
257 AndroidSyncSettings.updateAccount(mContext, mAccount); | 255 AndroidSyncSettings.updateAccount(mContext, mAccount); |
258 assertTrue("account should still be synced", AndroidSyncSettings.isSyncE
nabled(mContext)); | 256 assertTrue("account should still be synced", AndroidSyncSettings.isSyncE
nabled(mContext)); |
259 | 257 |
260 // Ensure we don't erroneously re-use cached data. | 258 // Ensure we don't erroneously re-use cached data. |
261 AndroidSyncSettings.updateAccount(mContext, null); | 259 AndroidSyncSettings.updateAccount(mContext, null); |
262 assertFalse("null account should not be synced", | 260 assertFalse( |
263 AndroidSyncSettings.isSyncEnabled(mContext)); | 261 "null account should not be synced", AndroidSyncSettings.isSyncE
nabled(mContext)); |
264 } | 262 } |
265 | 263 |
266 @SmallTest | 264 @SmallTest |
267 @Feature({"Sync"}) | 265 @Feature({"Sync"}) |
268 public void testSyncSettingsCaching() throws InterruptedException { | 266 public void testSyncSettingsCaching() throws InterruptedException { |
269 // Turn on syncability. | 267 // Turn on syncability. |
270 mSyncContentResolverDelegate.setMasterSyncAutomatically(true); | 268 mSyncContentResolverDelegate.setMasterSyncAutomatically(true); |
271 mSyncContentResolverDelegate.waitForLastNotificationCompleted(); | 269 mSyncContentResolverDelegate.waitForLastNotificationCompleted(); |
272 | 270 |
273 enableChromeSyncOnUiThread(); | 271 enableChromeSyncOnUiThread(); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 assertTrue(mSyncContentResolverDelegate.getIsSyncable(mAccount, mAuthori
ty) == 0); | 378 assertTrue(mSyncContentResolverDelegate.getIsSyncable(mAccount, mAuthori
ty) == 0); |
381 assertTrue(mSyncContentResolverDelegate.getSyncAutomatically(mAccount, m
Authority)); | 379 assertTrue(mSyncContentResolverDelegate.getSyncAutomatically(mAccount, m
Authority)); |
382 | 380 |
383 // Ensure bug is fixed. | 381 // Ensure bug is fixed. |
384 AndroidSyncSettings.enableChromeSync(mContext); | 382 AndroidSyncSettings.enableChromeSync(mContext); |
385 assertTrue(mSyncContentResolverDelegate.getIsSyncable(mAccount, mAuthori
ty) == 1); | 383 assertTrue(mSyncContentResolverDelegate.getIsSyncable(mAccount, mAuthori
ty) == 1); |
386 // Should still be enabled. | 384 // Should still be enabled. |
387 assertTrue(mSyncContentResolverDelegate.getSyncAutomatically(mAccount, m
Authority)); | 385 assertTrue(mSyncContentResolverDelegate.getSyncAutomatically(mAccount, m
Authority)); |
388 } | 386 } |
389 } | 387 } |
OLD | NEW |