mobile/android/tests/background/junit3/src/testhelpers/MockPrefsGlobalSession.java

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial