mobile/android/tests/background/junit3/src/testhelpers/MockPrefsGlobalSession.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.testhelpers;
     6 import java.io.IOException;
     8 import org.json.simple.parser.ParseException;
     9 import org.mozilla.gecko.sync.GlobalSession;
    10 import org.mozilla.gecko.sync.NonObjectJSONException;
    11 import org.mozilla.gecko.sync.SyncConfiguration;
    12 import org.mozilla.gecko.sync.SyncConfigurationException;
    13 import org.mozilla.gecko.sync.crypto.KeyBundle;
    14 import org.mozilla.gecko.sync.delegates.ClientsDataDelegate;
    15 import org.mozilla.gecko.sync.delegates.GlobalSessionCallback;
    16 import org.mozilla.gecko.sync.net.AuthHeaderProvider;
    17 import org.mozilla.gecko.sync.net.BasicAuthHeaderProvider;
    19 import android.content.Context;
    20 import android.content.SharedPreferences;
    22 /**
    23  * GlobalSession touches the Android prefs system. Stub that out.
    24  */
    25 public class MockPrefsGlobalSession extends GlobalSession {
    27   public MockSharedPreferences prefs;
    29   public MockPrefsGlobalSession(
    30       SyncConfiguration config, GlobalSessionCallback callback, Context context,
    31       ClientsDataDelegate clientsDelegate)
    32       throws SyncConfigurationException, IllegalArgumentException, IOException,
    33       ParseException, NonObjectJSONException {
    34     super(config, callback, context, clientsDelegate, callback);
    35   }
    37   public static MockPrefsGlobalSession getSession(
    38       String username, String password,
    39       KeyBundle syncKeyBundle, GlobalSessionCallback callback, Context context,
    40       ClientsDataDelegate clientsDelegate)
    41       throws SyncConfigurationException, IllegalArgumentException, IOException,
    42       ParseException, NonObjectJSONException {
    43     return getSession(username, new BasicAuthHeaderProvider(username, password), null,
    44          syncKeyBundle, callback, context, clientsDelegate);
    45   }
    47   public static MockPrefsGlobalSession getSession(
    48       String username, AuthHeaderProvider authHeaderProvider, String prefsPath,
    49       KeyBundle syncKeyBundle, GlobalSessionCallback callback, Context context,
    50       ClientsDataDelegate clientsDelegate)
    51       throws SyncConfigurationException, IllegalArgumentException, IOException,
    52       ParseException, NonObjectJSONException {
    54     final SharedPreferences prefs = new MockSharedPreferences();
    55     final SyncConfiguration config = new SyncConfiguration(username, authHeaderProvider, prefs);
    56     config.syncKeyBundle = syncKeyBundle;
    57     return new MockPrefsGlobalSession(config, callback, context, clientsDelegate);
    58   }
    60   @Override
    61   public Context getContext() {
    62     return null;
    63   }
    64 }

mercurial