1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mobile/android/tests/background/junit3/src/testhelpers/MockPrefsGlobalSession.java Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,64 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +package org.mozilla.gecko.background.testhelpers; 1.8 + 1.9 +import java.io.IOException; 1.10 + 1.11 +import org.json.simple.parser.ParseException; 1.12 +import org.mozilla.gecko.sync.GlobalSession; 1.13 +import org.mozilla.gecko.sync.NonObjectJSONException; 1.14 +import org.mozilla.gecko.sync.SyncConfiguration; 1.15 +import org.mozilla.gecko.sync.SyncConfigurationException; 1.16 +import org.mozilla.gecko.sync.crypto.KeyBundle; 1.17 +import org.mozilla.gecko.sync.delegates.ClientsDataDelegate; 1.18 +import org.mozilla.gecko.sync.delegates.GlobalSessionCallback; 1.19 +import org.mozilla.gecko.sync.net.AuthHeaderProvider; 1.20 +import org.mozilla.gecko.sync.net.BasicAuthHeaderProvider; 1.21 + 1.22 +import android.content.Context; 1.23 +import android.content.SharedPreferences; 1.24 + 1.25 +/** 1.26 + * GlobalSession touches the Android prefs system. Stub that out. 1.27 + */ 1.28 +public class MockPrefsGlobalSession extends GlobalSession { 1.29 + 1.30 + public MockSharedPreferences prefs; 1.31 + 1.32 + public MockPrefsGlobalSession( 1.33 + SyncConfiguration config, GlobalSessionCallback callback, Context context, 1.34 + ClientsDataDelegate clientsDelegate) 1.35 + throws SyncConfigurationException, IllegalArgumentException, IOException, 1.36 + ParseException, NonObjectJSONException { 1.37 + super(config, callback, context, clientsDelegate, callback); 1.38 + } 1.39 + 1.40 + public static MockPrefsGlobalSession getSession( 1.41 + String username, String password, 1.42 + KeyBundle syncKeyBundle, GlobalSessionCallback callback, Context context, 1.43 + ClientsDataDelegate clientsDelegate) 1.44 + throws SyncConfigurationException, IllegalArgumentException, IOException, 1.45 + ParseException, NonObjectJSONException { 1.46 + return getSession(username, new BasicAuthHeaderProvider(username, password), null, 1.47 + syncKeyBundle, callback, context, clientsDelegate); 1.48 + } 1.49 + 1.50 + public static MockPrefsGlobalSession getSession( 1.51 + String username, AuthHeaderProvider authHeaderProvider, String prefsPath, 1.52 + KeyBundle syncKeyBundle, GlobalSessionCallback callback, Context context, 1.53 + ClientsDataDelegate clientsDelegate) 1.54 + throws SyncConfigurationException, IllegalArgumentException, IOException, 1.55 + ParseException, NonObjectJSONException { 1.56 + 1.57 + final SharedPreferences prefs = new MockSharedPreferences(); 1.58 + final SyncConfiguration config = new SyncConfiguration(username, authHeaderProvider, prefs); 1.59 + config.syncKeyBundle = syncKeyBundle; 1.60 + return new MockPrefsGlobalSession(config, callback, context, clientsDelegate); 1.61 + } 1.62 + 1.63 + @Override 1.64 + public Context getContext() { 1.65 + return null; 1.66 + } 1.67 +}