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
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | Cu.import("resource://services-sync/engines.js"); |
michael@0 | 5 | Cu.import("resource://services-sync/service.js"); |
michael@0 | 6 | Cu.import("resource://services-sync/util.js"); |
michael@0 | 7 | |
michael@0 | 8 | function run_test() { |
michael@0 | 9 | run_next_test(); |
michael@0 | 10 | } |
michael@0 | 11 | |
michael@0 | 12 | add_test(function test_tracker_basics() { |
michael@0 | 13 | let tracker = new Tracker("Tracker", Service); |
michael@0 | 14 | tracker.persistChangedIDs = false; |
michael@0 | 15 | |
michael@0 | 16 | let id = "the_id!"; |
michael@0 | 17 | |
michael@0 | 18 | _("Make sure nothing exists yet.."); |
michael@0 | 19 | do_check_eq(tracker.changedIDs[id], null); |
michael@0 | 20 | |
michael@0 | 21 | _("Make sure adding of time 0 works"); |
michael@0 | 22 | tracker.addChangedID(id, 0); |
michael@0 | 23 | do_check_eq(tracker.changedIDs[id], 0); |
michael@0 | 24 | |
michael@0 | 25 | _("A newer time will replace the old 0"); |
michael@0 | 26 | tracker.addChangedID(id, 10); |
michael@0 | 27 | do_check_eq(tracker.changedIDs[id], 10); |
michael@0 | 28 | |
michael@0 | 29 | _("An older time will not replace the newer 10"); |
michael@0 | 30 | tracker.addChangedID(id, 5); |
michael@0 | 31 | do_check_eq(tracker.changedIDs[id], 10); |
michael@0 | 32 | |
michael@0 | 33 | _("Adding without time defaults to current time"); |
michael@0 | 34 | tracker.addChangedID(id); |
michael@0 | 35 | do_check_true(tracker.changedIDs[id] > 10); |
michael@0 | 36 | |
michael@0 | 37 | run_next_test(); |
michael@0 | 38 | }); |
michael@0 | 39 | |
michael@0 | 40 | add_test(function test_tracker_persistence() { |
michael@0 | 41 | let tracker = new Tracker("Tracker", Service); |
michael@0 | 42 | let id = "abcdef"; |
michael@0 | 43 | |
michael@0 | 44 | tracker.persistChangedIDs = true; |
michael@0 | 45 | tracker.onSavedChangedIDs = function () { |
michael@0 | 46 | _("IDs saved."); |
michael@0 | 47 | do_check_eq(5, tracker.changedIDs[id]); |
michael@0 | 48 | |
michael@0 | 49 | // Verify the write by reading the file back. |
michael@0 | 50 | Utils.jsonLoad("changes/tracker", this, function (json) { |
michael@0 | 51 | do_check_eq(5, json[id]); |
michael@0 | 52 | tracker.persistChangedIDs = false; |
michael@0 | 53 | delete tracker.onSavedChangedIDs; |
michael@0 | 54 | run_next_test(); |
michael@0 | 55 | }); |
michael@0 | 56 | }; |
michael@0 | 57 | |
michael@0 | 58 | tracker.addChangedID(id, 5); |
michael@0 | 59 | }); |