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.testhelpers; michael@0: michael@0: import java.io.IOException; michael@0: michael@0: import org.json.simple.parser.ParseException; michael@0: import org.mozilla.gecko.sync.GlobalSession; michael@0: import org.mozilla.gecko.sync.NonObjectJSONException; michael@0: import org.mozilla.gecko.sync.SyncConfiguration; michael@0: import org.mozilla.gecko.sync.SyncConfigurationException; michael@0: import org.mozilla.gecko.sync.crypto.KeyBundle; michael@0: import org.mozilla.gecko.sync.delegates.ClientsDataDelegate; michael@0: import org.mozilla.gecko.sync.delegates.GlobalSessionCallback; michael@0: import org.mozilla.gecko.sync.net.AuthHeaderProvider; michael@0: import org.mozilla.gecko.sync.net.BasicAuthHeaderProvider; michael@0: michael@0: import android.content.Context; michael@0: import android.content.SharedPreferences; michael@0: michael@0: /** michael@0: * GlobalSession touches the Android prefs system. Stub that out. michael@0: */ michael@0: public class MockPrefsGlobalSession extends GlobalSession { michael@0: michael@0: public MockSharedPreferences prefs; michael@0: michael@0: public MockPrefsGlobalSession( michael@0: SyncConfiguration config, GlobalSessionCallback callback, Context context, michael@0: ClientsDataDelegate clientsDelegate) michael@0: throws SyncConfigurationException, IllegalArgumentException, IOException, michael@0: ParseException, NonObjectJSONException { michael@0: super(config, callback, context, clientsDelegate, callback); michael@0: } michael@0: michael@0: public static MockPrefsGlobalSession getSession( michael@0: String username, String password, michael@0: KeyBundle syncKeyBundle, GlobalSessionCallback callback, Context context, michael@0: ClientsDataDelegate clientsDelegate) michael@0: throws SyncConfigurationException, IllegalArgumentException, IOException, michael@0: ParseException, NonObjectJSONException { michael@0: return getSession(username, new BasicAuthHeaderProvider(username, password), null, michael@0: syncKeyBundle, callback, context, clientsDelegate); michael@0: } michael@0: michael@0: public static MockPrefsGlobalSession getSession( michael@0: String username, AuthHeaderProvider authHeaderProvider, String prefsPath, michael@0: KeyBundle syncKeyBundle, GlobalSessionCallback callback, Context context, michael@0: ClientsDataDelegate clientsDelegate) michael@0: throws SyncConfigurationException, IllegalArgumentException, IOException, michael@0: ParseException, NonObjectJSONException { michael@0: michael@0: final SharedPreferences prefs = new MockSharedPreferences(); michael@0: final SyncConfiguration config = new SyncConfiguration(username, authHeaderProvider, prefs); michael@0: config.syncKeyBundle = syncKeyBundle; michael@0: return new MockPrefsGlobalSession(config, callback, context, clientsDelegate); michael@0: } michael@0: michael@0: @Override michael@0: public Context getContext() { michael@0: return null; michael@0: } michael@0: }