Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
4 Cu.import("resource://services-sync/engines.js");
5 Cu.import("resource://services-sync/service.js");
6 Cu.import("resource://services-sync/util.js");
8 function run_test() {
9 run_next_test();
10 }
12 add_test(function test_tracker_basics() {
13 let tracker = new Tracker("Tracker", Service);
14 tracker.persistChangedIDs = false;
16 let id = "the_id!";
18 _("Make sure nothing exists yet..");
19 do_check_eq(tracker.changedIDs[id], null);
21 _("Make sure adding of time 0 works");
22 tracker.addChangedID(id, 0);
23 do_check_eq(tracker.changedIDs[id], 0);
25 _("A newer time will replace the old 0");
26 tracker.addChangedID(id, 10);
27 do_check_eq(tracker.changedIDs[id], 10);
29 _("An older time will not replace the newer 10");
30 tracker.addChangedID(id, 5);
31 do_check_eq(tracker.changedIDs[id], 10);
33 _("Adding without time defaults to current time");
34 tracker.addChangedID(id);
35 do_check_true(tracker.changedIDs[id] > 10);
37 run_next_test();
38 });
40 add_test(function test_tracker_persistence() {
41 let tracker = new Tracker("Tracker", Service);
42 let id = "abcdef";
44 tracker.persistChangedIDs = true;
45 tracker.onSavedChangedIDs = function () {
46 _("IDs saved.");
47 do_check_eq(5, tracker.changedIDs[id]);
49 // Verify the write by reading the file back.
50 Utils.jsonLoad("changes/tracker", this, function (json) {
51 do_check_eq(5, json[id]);
52 tracker.persistChangedIDs = false;
53 delete tracker.onSavedChangedIDs;
54 run_next_test();
55 });
56 };
58 tracker.addChangedID(id, 5);
59 });