michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: Cu.import("resource://services-sync/engines.js"); michael@0: Cu.import("resource://services-sync/service.js"); michael@0: Cu.import("resource://services-sync/util.js"); michael@0: michael@0: function run_test() { michael@0: run_next_test(); michael@0: } michael@0: michael@0: add_test(function test_tracker_basics() { michael@0: let tracker = new Tracker("Tracker", Service); michael@0: tracker.persistChangedIDs = false; michael@0: michael@0: let id = "the_id!"; michael@0: michael@0: _("Make sure nothing exists yet.."); michael@0: do_check_eq(tracker.changedIDs[id], null); michael@0: michael@0: _("Make sure adding of time 0 works"); michael@0: tracker.addChangedID(id, 0); michael@0: do_check_eq(tracker.changedIDs[id], 0); michael@0: michael@0: _("A newer time will replace the old 0"); michael@0: tracker.addChangedID(id, 10); michael@0: do_check_eq(tracker.changedIDs[id], 10); michael@0: michael@0: _("An older time will not replace the newer 10"); michael@0: tracker.addChangedID(id, 5); michael@0: do_check_eq(tracker.changedIDs[id], 10); michael@0: michael@0: _("Adding without time defaults to current time"); michael@0: tracker.addChangedID(id); michael@0: do_check_true(tracker.changedIDs[id] > 10); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: add_test(function test_tracker_persistence() { michael@0: let tracker = new Tracker("Tracker", Service); michael@0: let id = "abcdef"; michael@0: michael@0: tracker.persistChangedIDs = true; michael@0: tracker.onSavedChangedIDs = function () { michael@0: _("IDs saved."); michael@0: do_check_eq(5, tracker.changedIDs[id]); michael@0: michael@0: // Verify the write by reading the file back. michael@0: Utils.jsonLoad("changes/tracker", this, function (json) { michael@0: do_check_eq(5, json[id]); michael@0: tracker.persistChangedIDs = false; michael@0: delete tracker.onSavedChangedIDs; michael@0: run_next_test(); michael@0: }); michael@0: }; michael@0: michael@0: tracker.addChangedID(id, 5); michael@0: });