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: import java.util.HashMap; michael@0: michael@0: import org.json.simple.parser.ParseException; michael@0: import org.mozilla.gecko.sync.EngineSettings; 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.GlobalSessionCallback; michael@0: import org.mozilla.gecko.sync.net.BasicAuthHeaderProvider; michael@0: import org.mozilla.gecko.sync.stage.CompletedStage; michael@0: import org.mozilla.gecko.sync.stage.GlobalSyncStage; michael@0: import org.mozilla.gecko.sync.stage.GlobalSyncStage.Stage; michael@0: michael@0: michael@0: public class MockGlobalSession extends MockPrefsGlobalSession { michael@0: michael@0: public MockGlobalSession(String username, String password, KeyBundle keyBundle, GlobalSessionCallback callback) throws SyncConfigurationException, IllegalArgumentException, NonObjectJSONException, IOException, ParseException { michael@0: this(new SyncConfiguration(username, new BasicAuthHeaderProvider(username, password), new MockSharedPreferences(), keyBundle), callback); michael@0: } michael@0: michael@0: public MockGlobalSession(SyncConfiguration config, GlobalSessionCallback callback) michael@0: throws SyncConfigurationException, IllegalArgumentException, IOException, ParseException, NonObjectJSONException { michael@0: super(config, callback, null, null); michael@0: } michael@0: michael@0: @Override michael@0: public boolean isEngineRemotelyEnabled(String engine, EngineSettings engineSettings) { michael@0: return false; michael@0: } michael@0: michael@0: @Override michael@0: protected void prepareStages() { michael@0: super.prepareStages(); michael@0: HashMap newStages = new HashMap(this.stages); michael@0: michael@0: for (Stage stage : this.stages.keySet()) { michael@0: newStages.put(stage, new MockServerSyncStage()); michael@0: } michael@0: michael@0: // This signals that the global session is complete. michael@0: newStages.put(Stage.completed, new CompletedStage()); michael@0: michael@0: this.stages = newStages; michael@0: } michael@0: michael@0: public MockGlobalSession withStage(Stage stage, GlobalSyncStage syncStage) { michael@0: stages.put(stage, syncStage); michael@0: michael@0: return this; michael@0: } michael@0: }