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

branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
equal deleted inserted replaced
-1:000000000000 0:c8eaff65fc15
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
3
4 package org.mozilla.gecko.background.testhelpers;
5
6 import java.io.IOException;
7
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;
18
19 import android.content.Context;
20 import android.content.SharedPreferences;
21
22 /**
23 * GlobalSession touches the Android prefs system. Stub that out.
24 */
25 public class MockPrefsGlobalSession extends GlobalSession {
26
27 public MockSharedPreferences prefs;
28
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 }
36
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 }
46
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 {
53
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 }
59
60 @Override
61 public Context getContext() {
62 return null;
63 }
64 }

mercurial