2010-08-06 14:25:59 -07:00
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
2010-08-06 14:40:06 -07:00
|
|
|
Cu.import("resource://services-sync/engines.js");
|
2010-08-06 08:31:21 -07:00
|
|
|
Cu.import("resource://services-sync/engines/history.js");
|
|
|
|
Cu.import("resource://services-sync/util.js");
|
|
|
|
|
2011-02-10 09:06:55 -08:00
|
|
|
function onScoreUpdated(callback) {
|
|
|
|
Svc.Obs.add("weave:engine:score:updated", function observer() {
|
|
|
|
Svc.Obs.remove("weave:engine:score:updated", observer);
|
|
|
|
try {
|
|
|
|
callback();
|
|
|
|
} catch (ex) {
|
|
|
|
do_throw(ex);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2010-08-06 08:31:21 -07:00
|
|
|
function run_test() {
|
2010-08-06 14:40:06 -07:00
|
|
|
Engines.register(HistoryEngine);
|
2011-02-10 14:12:25 -08:00
|
|
|
let engine = Engines.get("history");
|
|
|
|
let tracker = engine._tracker;
|
2010-08-06 14:40:06 -07:00
|
|
|
|
2010-08-06 08:31:21 -07:00
|
|
|
_("Verify we've got an empty tracker to work with.");
|
|
|
|
do_check_eq([id for (id in tracker.changedIDs)].length, 0);
|
|
|
|
|
|
|
|
let _counter = 0;
|
|
|
|
function addVisit() {
|
|
|
|
Svc.History.addVisit(Utils.makeURI("http://getfirefox.com/" + _counter),
|
|
|
|
Date.now() * 1000, null, 1, false, 0);
|
|
|
|
_counter += 1;
|
|
|
|
}
|
|
|
|
|
2011-02-10 09:06:55 -08:00
|
|
|
do_test_pending();
|
|
|
|
asyncChainTests(function (next) {
|
|
|
|
|
2010-12-06 17:25:35 -08:00
|
|
|
_("Create history item. Won't show because we haven't started tracking yet");
|
2010-08-06 08:31:21 -07:00
|
|
|
addVisit();
|
2011-02-10 09:06:55 -08:00
|
|
|
Utils.delay(function() {
|
|
|
|
do_check_eq([id for (id in tracker.changedIDs)].length, 0);
|
|
|
|
next();
|
|
|
|
}, 0);
|
|
|
|
|
|
|
|
}, function (next) {
|
2010-08-06 08:31:21 -07:00
|
|
|
|
|
|
|
_("Tell the tracker to start tracking changes.");
|
2011-02-10 09:06:55 -08:00
|
|
|
onScoreUpdated(function() {
|
|
|
|
do_check_eq([id for (id in tracker.changedIDs)].length, 1);
|
|
|
|
next();
|
|
|
|
});
|
2010-08-06 08:31:21 -07:00
|
|
|
Svc.Obs.notify("weave:engine:start-tracking");
|
|
|
|
addVisit();
|
2011-02-10 09:06:55 -08:00
|
|
|
|
|
|
|
}, function (next) {
|
2010-08-06 08:31:21 -07:00
|
|
|
|
|
|
|
_("Notifying twice won't do any harm.");
|
2011-02-10 09:06:55 -08:00
|
|
|
onScoreUpdated(function() {
|
|
|
|
do_check_eq([id for (id in tracker.changedIDs)].length, 2);
|
|
|
|
next();
|
|
|
|
});
|
2010-08-06 08:31:21 -07:00
|
|
|
Svc.Obs.notify("weave:engine:start-tracking");
|
|
|
|
addVisit();
|
2011-02-10 09:06:55 -08:00
|
|
|
|
2011-02-10 14:12:25 -08:00
|
|
|
}, function (next) {
|
|
|
|
|
|
|
|
_("Deletions are tracked.");
|
|
|
|
let uri = Utils.makeURI("http://getfirefox.com/0");
|
|
|
|
let guid = engine._store.GUIDForUri(uri);
|
|
|
|
do_check_false(guid in tracker.changedIDs);
|
|
|
|
|
|
|
|
onScoreUpdated(function() {
|
|
|
|
do_check_true(guid in tracker.changedIDs);
|
|
|
|
do_check_eq([id for (id in tracker.changedIDs)].length, 3);
|
|
|
|
next();
|
|
|
|
});
|
|
|
|
Svc.History.removePage(uri);
|
|
|
|
|
2011-02-10 09:06:55 -08:00
|
|
|
}, function (next) {
|
2010-08-06 08:31:21 -07:00
|
|
|
|
|
|
|
_("Let's stop tracking again.");
|
|
|
|
tracker.clearChangedIDs();
|
|
|
|
Svc.Obs.notify("weave:engine:stop-tracking");
|
|
|
|
addVisit();
|
2011-02-10 09:06:55 -08:00
|
|
|
Utils.delay(function() {
|
|
|
|
do_check_eq([id for (id in tracker.changedIDs)].length, 0);
|
|
|
|
next();
|
|
|
|
}, 0);
|
|
|
|
|
|
|
|
}, function (next) {
|
2010-08-06 08:31:21 -07:00
|
|
|
|
|
|
|
_("Notifying twice won't do any harm.");
|
|
|
|
Svc.Obs.notify("weave:engine:stop-tracking");
|
|
|
|
addVisit();
|
2011-02-10 09:06:55 -08:00
|
|
|
Utils.delay(function() {
|
|
|
|
do_check_eq([id for (id in tracker.changedIDs)].length, 0);
|
|
|
|
next();
|
|
|
|
}, 0);
|
|
|
|
|
|
|
|
}, function (next) {
|
|
|
|
|
2010-08-06 08:31:21 -07:00
|
|
|
_("Clean up.");
|
|
|
|
Svc.History.removeAllPages();
|
2011-02-10 09:06:55 -08:00
|
|
|
do_test_finished();
|
|
|
|
|
|
|
|
})();
|
2010-08-06 08:31:21 -07:00
|
|
|
}
|