mobile/android/tests/background/junit3/src/testhelpers/MockGlobalSession.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.

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 import java.util.HashMap;
michael@0 8
michael@0 9 import org.json.simple.parser.ParseException;
michael@0 10 import org.mozilla.gecko.sync.EngineSettings;
michael@0 11 import org.mozilla.gecko.sync.NonObjectJSONException;
michael@0 12 import org.mozilla.gecko.sync.SyncConfiguration;
michael@0 13 import org.mozilla.gecko.sync.SyncConfigurationException;
michael@0 14 import org.mozilla.gecko.sync.crypto.KeyBundle;
michael@0 15 import org.mozilla.gecko.sync.delegates.GlobalSessionCallback;
michael@0 16 import org.mozilla.gecko.sync.net.BasicAuthHeaderProvider;
michael@0 17 import org.mozilla.gecko.sync.stage.CompletedStage;
michael@0 18 import org.mozilla.gecko.sync.stage.GlobalSyncStage;
michael@0 19 import org.mozilla.gecko.sync.stage.GlobalSyncStage.Stage;
michael@0 20
michael@0 21
michael@0 22 public class MockGlobalSession extends MockPrefsGlobalSession {
michael@0 23
michael@0 24 public MockGlobalSession(String username, String password, KeyBundle keyBundle, GlobalSessionCallback callback) throws SyncConfigurationException, IllegalArgumentException, NonObjectJSONException, IOException, ParseException {
michael@0 25 this(new SyncConfiguration(username, new BasicAuthHeaderProvider(username, password), new MockSharedPreferences(), keyBundle), callback);
michael@0 26 }
michael@0 27
michael@0 28 public MockGlobalSession(SyncConfiguration config, GlobalSessionCallback callback)
michael@0 29 throws SyncConfigurationException, IllegalArgumentException, IOException, ParseException, NonObjectJSONException {
michael@0 30 super(config, callback, null, null);
michael@0 31 }
michael@0 32
michael@0 33 @Override
michael@0 34 public boolean isEngineRemotelyEnabled(String engine, EngineSettings engineSettings) {
michael@0 35 return false;
michael@0 36 }
michael@0 37
michael@0 38 @Override
michael@0 39 protected void prepareStages() {
michael@0 40 super.prepareStages();
michael@0 41 HashMap<Stage, GlobalSyncStage> newStages = new HashMap<Stage, GlobalSyncStage>(this.stages);
michael@0 42
michael@0 43 for (Stage stage : this.stages.keySet()) {
michael@0 44 newStages.put(stage, new MockServerSyncStage());
michael@0 45 }
michael@0 46
michael@0 47 // This signals that the global session is complete.
michael@0 48 newStages.put(Stage.completed, new CompletedStage());
michael@0 49
michael@0 50 this.stages = newStages;
michael@0 51 }
michael@0 52
michael@0 53 public MockGlobalSession withStage(Stage stage, GlobalSyncStage syncStage) {
michael@0 54 stages.put(stage, syncStage);
michael@0 55
michael@0 56 return this;
michael@0 57 }
michael@0 58 }

mercurial