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

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

     1 /* Any copyright is dedicated to the Public Domain.
     2    http://creativecommons.org/publicdomain/zero/1.0/ */
     4 package org.mozilla.gecko.background.fxa;
     6 import java.util.EnumSet;
     8 import junit.framework.Assert;
    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;
    16 import android.content.ContentResolver;
    17 import android.os.Bundle;
    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   }
    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   }
    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));
    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));
    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 }

mercurial