|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 package org.mozilla.gecko.background.fxa; |
|
5 |
|
6 import java.util.EnumSet; |
|
7 |
|
8 import junit.framework.Assert; |
|
9 |
|
10 import org.mozilla.gecko.background.helpers.AndroidSyncTestCase; |
|
11 import org.mozilla.gecko.fxa.FirefoxAccounts; |
|
12 import org.mozilla.gecko.fxa.sync.FxAccountSyncAdapter; |
|
13 import org.mozilla.gecko.sync.Utils; |
|
14 import org.mozilla.gecko.sync.setup.Constants; |
|
15 |
|
16 import android.content.ContentResolver; |
|
17 import android.os.Bundle; |
|
18 |
|
19 public class TestFirefoxAccounts extends AndroidSyncTestCase { |
|
20 private static class InnerFirefoxAccounts extends FirefoxAccounts { |
|
21 // For testing, since putHintsToSync is not public. |
|
22 public static Bundle makeTestBundle(EnumSet<SyncHint> syncHints, String[] stagesToSync, String[] stagesToSkip) { |
|
23 final Bundle bundle = new Bundle(); |
|
24 FirefoxAccounts.putHintsToSync(bundle, syncHints); |
|
25 Utils.putStageNamesToSync(bundle, stagesToSync, stagesToSkip); |
|
26 return bundle; |
|
27 } |
|
28 } |
|
29 |
|
30 protected void assertBundle(Bundle bundle, boolean manual, boolean respectLocal, boolean respectRemote, String stagesToSync, String stagesToSkip) { |
|
31 Assert.assertEquals(manual, bundle.getBoolean(ContentResolver.SYNC_EXTRAS_MANUAL)); |
|
32 Assert.assertEquals(respectLocal, bundle.getBoolean(FxAccountSyncAdapter.SYNC_EXTRAS_RESPECT_LOCAL_RATE_LIMIT)); |
|
33 Assert.assertEquals(respectRemote, bundle.getBoolean(FxAccountSyncAdapter.SYNC_EXTRAS_RESPECT_REMOTE_SERVER_BACKOFF)); |
|
34 Assert.assertEquals(stagesToSync, bundle.getString(Constants.EXTRAS_KEY_STAGES_TO_SYNC)); |
|
35 Assert.assertEquals(stagesToSkip, bundle.getString(Constants.EXTRAS_KEY_STAGES_TO_SKIP)); |
|
36 } |
|
37 |
|
38 public void testMakeTestBundle() { |
|
39 Bundle bundle; |
|
40 bundle = InnerFirefoxAccounts.makeTestBundle(FirefoxAccounts.FORCE, new String[] { "clients" }, null); |
|
41 assertBundle(bundle, true, false, false, "{\"clients\":0}", null); |
|
42 assertEquals(FirefoxAccounts.FORCE, FirefoxAccounts.getHintsToSyncFromBundle(bundle)); |
|
43 |
|
44 bundle = InnerFirefoxAccounts.makeTestBundle(FirefoxAccounts.NOW, null, new String[] { "bookmarks" }); |
|
45 assertBundle(bundle, true, true, true, null, "{\"bookmarks\":0}"); |
|
46 assertEquals(FirefoxAccounts.NOW, FirefoxAccounts.getHintsToSyncFromBundle(bundle)); |
|
47 |
|
48 bundle = InnerFirefoxAccounts.makeTestBundle(FirefoxAccounts.SOON, null, null); |
|
49 assertBundle(bundle, false, true, true, null, null); |
|
50 assertEquals(FirefoxAccounts.SOON, FirefoxAccounts.getHintsToSyncFromBundle(bundle)); |
|
51 } |
|
52 } |