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.

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

mercurial