mobile/android/tests/background/junit3/src/fxa/TestFirefoxAccounts.java

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mobile/android/tests/background/junit3/src/fxa/TestFirefoxAccounts.java	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,52 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +package org.mozilla.gecko.background.fxa;
     1.8 +
     1.9 +import java.util.EnumSet;
    1.10 +
    1.11 +import junit.framework.Assert;
    1.12 +
    1.13 +import org.mozilla.gecko.background.helpers.AndroidSyncTestCase;
    1.14 +import org.mozilla.gecko.fxa.FirefoxAccounts;
    1.15 +import org.mozilla.gecko.fxa.sync.FxAccountSyncAdapter;
    1.16 +import org.mozilla.gecko.sync.Utils;
    1.17 +import org.mozilla.gecko.sync.setup.Constants;
    1.18 +
    1.19 +import android.content.ContentResolver;
    1.20 +import android.os.Bundle;
    1.21 +
    1.22 +public class TestFirefoxAccounts extends AndroidSyncTestCase {
    1.23 +  private static class InnerFirefoxAccounts extends FirefoxAccounts {
    1.24 +    // For testing, since putHintsToSync is not public.
    1.25 +    public static Bundle makeTestBundle(EnumSet<SyncHint> syncHints, String[] stagesToSync, String[] stagesToSkip) {
    1.26 +      final Bundle bundle = new Bundle();
    1.27 +      FirefoxAccounts.putHintsToSync(bundle, syncHints);
    1.28 +      Utils.putStageNamesToSync(bundle, stagesToSync, stagesToSkip);
    1.29 +      return bundle;
    1.30 +    }
    1.31 +  }
    1.32 +
    1.33 +  protected void assertBundle(Bundle bundle, boolean manual, boolean respectLocal, boolean respectRemote, String stagesToSync, String stagesToSkip) {
    1.34 +    Assert.assertEquals(manual, bundle.getBoolean(ContentResolver.SYNC_EXTRAS_MANUAL));
    1.35 +    Assert.assertEquals(respectLocal, bundle.getBoolean(FxAccountSyncAdapter.SYNC_EXTRAS_RESPECT_LOCAL_RATE_LIMIT));
    1.36 +    Assert.assertEquals(respectRemote, bundle.getBoolean(FxAccountSyncAdapter.SYNC_EXTRAS_RESPECT_REMOTE_SERVER_BACKOFF));
    1.37 +    Assert.assertEquals(stagesToSync, bundle.getString(Constants.EXTRAS_KEY_STAGES_TO_SYNC));
    1.38 +    Assert.assertEquals(stagesToSkip, bundle.getString(Constants.EXTRAS_KEY_STAGES_TO_SKIP));
    1.39 +  }
    1.40 +
    1.41 +  public void testMakeTestBundle() {
    1.42 +    Bundle bundle;
    1.43 +    bundle = InnerFirefoxAccounts.makeTestBundle(FirefoxAccounts.FORCE, new String[] { "clients" }, null);
    1.44 +    assertBundle(bundle, true, false, false, "{\"clients\":0}", null);
    1.45 +    assertEquals(FirefoxAccounts.FORCE, FirefoxAccounts.getHintsToSyncFromBundle(bundle));
    1.46 +
    1.47 +    bundle = InnerFirefoxAccounts.makeTestBundle(FirefoxAccounts.NOW, null, new String[] { "bookmarks" });
    1.48 +    assertBundle(bundle, true, true, true, null, "{\"bookmarks\":0}");
    1.49 +    assertEquals(FirefoxAccounts.NOW, FirefoxAccounts.getHintsToSyncFromBundle(bundle));
    1.50 +
    1.51 +    bundle = InnerFirefoxAccounts.makeTestBundle(FirefoxAccounts.SOON, null, null);
    1.52 +    assertBundle(bundle, false, true, true, null, null);
    1.53 +    assertEquals(FirefoxAccounts.SOON, FirefoxAccounts.getHintsToSyncFromBundle(bundle));
    1.54 +  }
    1.55 +}

mercurial