Bug 633681 - Add a Status.ready flag that indicates whether Sync has started up. r+a=mconnor

Also de-Sync.js-ify test_service_startup.js
This commit is contained in:
Philipp von Weitershausen 2011-02-17 13:41:13 -08:00
Родитель 2e22324475
Коммит 550ffdba88
3 изменённых файлов: 27 добавлений и 25 удалений

Просмотреть файл

@ -433,9 +433,12 @@ WeaveSvc.prototype = {
}
// Send an event now that Weave service is ready. We don't do this
// synchronously so that observers will definitely have access to the
// 'Weave' namespace.
Utils.delay(function() Svc.Obs.notify("weave:service:ready"), 0);
// synchronously so that observers can import this module before
// registering an observer.
Utils.delay(function() {
Status.ready = true;
Svc.Obs.notify("weave:service:ready");
}, 0);
},
_checkSetup: function WeaveSvc__checkSetup() {

Просмотреть файл

@ -42,6 +42,8 @@ const Cu = Components.utils;
Cu.import("resource://services-sync/constants.js");
let Status = {
ready: false,
get login() this._login,
set login(code) {
this._login = code;

Просмотреть файл

@ -1,5 +1,5 @@
Cu.import("resource://services-sync/ext/Observers.js");
Cu.import("resource://services-sync/ext/Sync.js");
Cu.import("resource://services-sync/status.js");
Cu.import("resource://services-sync/identity.js");
Cu.import("resource://services-sync/util.js");
Cu.import("resource://services-sync/engines.js");
@ -8,34 +8,31 @@ function run_test() {
_("When imported, Service.onStartup is called");
// Test fixtures
let observerCalled = false;
Observers.add("weave:service:ready", function (subject, data) {
observerCalled = true;
});
Svc.Prefs.set("registerEngines", "Tab,Bookmarks,Form,History");
Svc.Prefs.set("username", "johndoe");
try {
Cu.import("resource://services-sync/service.js");
Cu.import("resource://services-sync/service.js");
_("Service is enabled.");
do_check_eq(Service.enabled, true);
_("Service is enabled.");
do_check_eq(Service.enabled, true);
_("Engines are registered.");
let engines = Engines.getAll();
do_check_true(Utils.deepEquals([engine.name for each (engine in engines)],
['tabs', 'bookmarks', 'forms', 'history']));
_("Engines are registered.");
let engines = Engines.getAll();
do_check_true(Utils.deepEquals([engine.name for each (engine in engines)],
['tabs', 'bookmarks', 'forms', 'history']));
_("Identities are registered.");
do_check_eq(ID.get('WeaveID').username, "johndoe");
do_check_eq(ID.get('WeaveCryptoID').username, "johndoe");
_("Identities are registered.");
do_check_eq(ID.get('WeaveID').username, "johndoe");
do_check_eq(ID.get('WeaveCryptoID').username, "johndoe");
_("Observers are notified of startup");
// Synchronize with Service.onStartup's async notification
Sync.sleep(0);
do_check_true(observerCalled);
_("Observers are notified of startup");
do_test_pending();
do_check_false(Status.ready);
Observers.add("weave:service:ready", function (subject, data) {
do_check_true(Status.ready);
} finally {
// Clean up.
Svc.Prefs.resetBranch("");
}
do_test_finished();
});
}