michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: package org.mozilla.gecko.background.fxa; michael@0: michael@0: import java.util.EnumSet; michael@0: michael@0: import junit.framework.Assert; michael@0: michael@0: import org.mozilla.gecko.background.helpers.AndroidSyncTestCase; michael@0: import org.mozilla.gecko.fxa.FirefoxAccounts; michael@0: import org.mozilla.gecko.fxa.sync.FxAccountSyncAdapter; michael@0: import org.mozilla.gecko.sync.Utils; michael@0: import org.mozilla.gecko.sync.setup.Constants; michael@0: michael@0: import android.content.ContentResolver; michael@0: import android.os.Bundle; michael@0: michael@0: public class TestFirefoxAccounts extends AndroidSyncTestCase { michael@0: private static class InnerFirefoxAccounts extends FirefoxAccounts { michael@0: // For testing, since putHintsToSync is not public. michael@0: public static Bundle makeTestBundle(EnumSet syncHints, String[] stagesToSync, String[] stagesToSkip) { michael@0: final Bundle bundle = new Bundle(); michael@0: FirefoxAccounts.putHintsToSync(bundle, syncHints); michael@0: Utils.putStageNamesToSync(bundle, stagesToSync, stagesToSkip); michael@0: return bundle; michael@0: } michael@0: } michael@0: michael@0: protected void assertBundle(Bundle bundle, boolean manual, boolean respectLocal, boolean respectRemote, String stagesToSync, String stagesToSkip) { michael@0: Assert.assertEquals(manual, bundle.getBoolean(ContentResolver.SYNC_EXTRAS_MANUAL)); michael@0: Assert.assertEquals(respectLocal, bundle.getBoolean(FxAccountSyncAdapter.SYNC_EXTRAS_RESPECT_LOCAL_RATE_LIMIT)); michael@0: Assert.assertEquals(respectRemote, bundle.getBoolean(FxAccountSyncAdapter.SYNC_EXTRAS_RESPECT_REMOTE_SERVER_BACKOFF)); michael@0: Assert.assertEquals(stagesToSync, bundle.getString(Constants.EXTRAS_KEY_STAGES_TO_SYNC)); michael@0: Assert.assertEquals(stagesToSkip, bundle.getString(Constants.EXTRAS_KEY_STAGES_TO_SKIP)); michael@0: } michael@0: michael@0: public void testMakeTestBundle() { michael@0: Bundle bundle; michael@0: bundle = InnerFirefoxAccounts.makeTestBundle(FirefoxAccounts.FORCE, new String[] { "clients" }, null); michael@0: assertBundle(bundle, true, false, false, "{\"clients\":0}", null); michael@0: assertEquals(FirefoxAccounts.FORCE, FirefoxAccounts.getHintsToSyncFromBundle(bundle)); michael@0: michael@0: bundle = InnerFirefoxAccounts.makeTestBundle(FirefoxAccounts.NOW, null, new String[] { "bookmarks" }); michael@0: assertBundle(bundle, true, true, true, null, "{\"bookmarks\":0}"); michael@0: assertEquals(FirefoxAccounts.NOW, FirefoxAccounts.getHintsToSyncFromBundle(bundle)); michael@0: michael@0: bundle = InnerFirefoxAccounts.makeTestBundle(FirefoxAccounts.SOON, null, null); michael@0: assertBundle(bundle, false, true, true, null, null); michael@0: assertEquals(FirefoxAccounts.SOON, FirefoxAccounts.getHintsToSyncFromBundle(bundle)); michael@0: } michael@0: }