зеркало из https://github.com/mozilla/pjs.git
Refactored client state-changing functions out of test_bookmark_syncing.js and into head.js, as part of the SyncTestingInfrastructure class, so that other test suites can use them.
This commit is contained in:
Родитель
7464b11b4c
Коммит
f041c5a9a5
|
@ -274,7 +274,7 @@ function FakeGUIDService() {
|
|||
};
|
||||
}
|
||||
|
||||
function SyncTestingInfrastructure() {
|
||||
function SyncTestingInfrastructure(engineCtor) {
|
||||
let __fakePasswords = {
|
||||
'Mozilla Services Password': {foo: "bar"},
|
||||
'Mozilla Services Encryption Passphrase': {foo: "passphrase"}
|
||||
|
@ -289,6 +289,7 @@ function SyncTestingInfrastructure() {
|
|||
};
|
||||
|
||||
Cu.import("resource://weave/identity.js");
|
||||
Cu.import("resource://weave/util.js");
|
||||
|
||||
ID.set('WeaveID',
|
||||
new Identity('Mozilla Services Encryption Passphrase', 'foo'));
|
||||
|
@ -301,6 +302,45 @@ function SyncTestingInfrastructure() {
|
|||
this.fakeFilesystem = new FakeFilesystemService({});
|
||||
this.fakeGUIDService = new FakeGUIDService();
|
||||
|
||||
this._logger = getTestLogger();
|
||||
this._Engine = engineCtor;
|
||||
this._clientStates = [];
|
||||
|
||||
this.saveClientState = function pushClientState(label) {
|
||||
let state = Utils.deepCopy(this.fakeFilesystem.fakeContents);
|
||||
this._clientStates[label] = state;
|
||||
};
|
||||
|
||||
this.restoreClientState = function restoreClientState(label) {
|
||||
let state = this._clientStates[label];
|
||||
|
||||
function _restoreState() {
|
||||
let self = yield;
|
||||
|
||||
this.fakeFilesystem.fakeContents = Utils.deepCopy(state);
|
||||
let engine = new this._Engine();
|
||||
engine._store.wipe();
|
||||
let originalSnapshot = Utils.deepCopy(engine._store.wrap());
|
||||
engine._snapshot.load();
|
||||
let snapshot = engine._snapshot.data;
|
||||
|
||||
engine._core.detectUpdates(self.cb, originalSnapshot, snapshot);
|
||||
let commands = yield;
|
||||
|
||||
engine._store.applyCommands.async(engine._store, self.cb, commands);
|
||||
yield;
|
||||
}
|
||||
|
||||
let self = this;
|
||||
|
||||
function restoreState(cb) {
|
||||
_restoreState.async(self, cb);
|
||||
}
|
||||
|
||||
this.runAsyncFunc("restore client state of " + label,
|
||||
restoreState);
|
||||
};
|
||||
|
||||
this.__makeCallback = function __makeCallback() {
|
||||
this.__callbackCalled = false;
|
||||
let self = this;
|
||||
|
@ -310,7 +350,7 @@ function SyncTestingInfrastructure() {
|
|||
};
|
||||
|
||||
this.runAsyncFunc = function runAsyncFunc(name, func) {
|
||||
let logger = getTestLogger();
|
||||
let logger = this._logger;
|
||||
|
||||
logger.info("-----------------------------------------");
|
||||
logger.info("Step '" + name + "' starting.");
|
||||
|
@ -324,4 +364,10 @@ function SyncTestingInfrastructure() {
|
|||
do_check_eq(Async.outstandingGenerators.length, 0);
|
||||
logger.info("Step '" + name + "' succeeded.");
|
||||
};
|
||||
|
||||
this.resetClientState = function resetClientState() {
|
||||
this.fakeFilesystem.fakeContents = {};
|
||||
let engine = new this._Engine();
|
||||
engine._store.wipe();
|
||||
};
|
||||
}
|
||||
|
|
|
@ -15,7 +15,11 @@ function FakeMicrosummaryService() {
|
|||
}
|
||||
|
||||
function run_test() {
|
||||
var syncTesting = new SyncTestingInfrastructure();
|
||||
// -----
|
||||
// Setup
|
||||
// -----
|
||||
|
||||
var syncTesting = new SyncTestingInfrastructure(BookmarksEngine);
|
||||
|
||||
function freshEngineSync(cb) {
|
||||
let engine = new BookmarksEngine();
|
||||
|
@ -23,47 +27,15 @@ function run_test() {
|
|||
engine.sync(cb);
|
||||
};
|
||||
|
||||
function resetProfile() {
|
||||
syncTesting.fakeFilesystem.fakeContents = {};
|
||||
let engine = new BookmarksEngine();
|
||||
engine._store.wipe();
|
||||
}
|
||||
|
||||
function saveClientState() {
|
||||
return Utils.deepCopy(syncTesting.fakeFilesystem.fakeContents);
|
||||
}
|
||||
|
||||
function restoreClientState(state, label) {
|
||||
function _restoreState() {
|
||||
let self = yield;
|
||||
|
||||
syncTesting.fakeFilesystem.fakeContents = Utils.deepCopy(state);
|
||||
let engine = new BookmarksEngine();
|
||||
engine._store.wipe();
|
||||
let originalSnapshot = Utils.deepCopy(engine._store.wrap());
|
||||
engine._snapshot.load();
|
||||
let snapshot = engine._snapshot.data;
|
||||
|
||||
engine._core.detectUpdates(self.cb, originalSnapshot, snapshot);
|
||||
let commands = yield;
|
||||
|
||||
engine._store.applyCommands.async(engine._store, self.cb, commands);
|
||||
yield;
|
||||
}
|
||||
|
||||
function restoreState(cb) {
|
||||
_restoreState.async(this, cb);
|
||||
}
|
||||
|
||||
syncTesting.runAsyncFunc("restore client state of " + label,
|
||||
restoreState);
|
||||
}
|
||||
|
||||
let bms = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
|
||||
getService(Ci.nsINavBookmarksService);
|
||||
|
||||
cleanUp();
|
||||
|
||||
// -----------
|
||||
// Test Proper
|
||||
// -----------
|
||||
|
||||
let boogleBm = bms.insertBookmark(bms.bookmarksMenuFolder,
|
||||
uri("http://www.boogle.com"),
|
||||
-1,
|
||||
|
@ -89,9 +61,9 @@ function run_test() {
|
|||
syncTesting.runAsyncFunc("swap bookmark order and re-sync",
|
||||
freshEngineSync);
|
||||
|
||||
var firstComputerState = saveClientState();
|
||||
syncTesting.saveClientState("first computer");
|
||||
|
||||
resetProfile();
|
||||
syncTesting.resetClientState();
|
||||
|
||||
syncTesting.runAsyncFunc("re-sync on second computer", freshEngineSync);
|
||||
|
||||
|
@ -104,8 +76,12 @@ function run_test() {
|
|||
syncTesting.runAsyncFunc("add bookmark on second computer and resync",
|
||||
freshEngineSync);
|
||||
|
||||
restoreClientState(firstComputerState, "first computer");
|
||||
syncTesting.restoreClientState("first computer");
|
||||
syncTesting.runAsyncFunc("re-sync on first computer", freshEngineSync);
|
||||
|
||||
// --------
|
||||
// Teardown
|
||||
// --------
|
||||
|
||||
cleanUp();
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче