services/sync/tests/unit/test_forms_tracker.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

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://gre/modules/Log.jsm");
michael@0 5 Cu.import("resource://services-sync/engines/forms.js");
michael@0 6 Cu.import("resource://services-sync/service.js");
michael@0 7 Cu.import("resource://services-sync/util.js");
michael@0 8
michael@0 9 function run_test() {
michael@0 10 _("Verify we've got an empty tracker to work with.");
michael@0 11 let engine = new FormEngine(Service);
michael@0 12 let tracker = engine._tracker;
michael@0 13 // Don't do asynchronous writes.
michael@0 14 tracker.persistChangedIDs = false;
michael@0 15
michael@0 16 do_check_empty(tracker.changedIDs);
michael@0 17 Log.repository.rootLogger.addAppender(new Log.DumpAppender());
michael@0 18
michael@0 19 function addEntry(name, value) {
michael@0 20 engine._store.create({name: name, value: value});
michael@0 21 }
michael@0 22 function removeEntry(name, value) {
michael@0 23 guid = engine._findDupe({name: name, value: value});
michael@0 24 engine._store.remove({id: guid});
michael@0 25 }
michael@0 26
michael@0 27 try {
michael@0 28 _("Create an entry. Won't show because we haven't started tracking yet");
michael@0 29 addEntry("name", "John Doe");
michael@0 30 do_check_empty(tracker.changedIDs);
michael@0 31
michael@0 32 _("Tell the tracker to start tracking changes.");
michael@0 33 Svc.Obs.notify("weave:engine:start-tracking");
michael@0 34 removeEntry("name", "John Doe");
michael@0 35 addEntry("email", "john@doe.com");
michael@0 36 do_check_attribute_count(tracker.changedIDs, 2);
michael@0 37
michael@0 38 _("Notifying twice won't do any harm.");
michael@0 39 Svc.Obs.notify("weave:engine:start-tracking");
michael@0 40 addEntry("address", "Memory Lane");
michael@0 41 do_check_attribute_count(tracker.changedIDs, 3);
michael@0 42
michael@0 43 _("Let's stop tracking again.");
michael@0 44 tracker.clearChangedIDs();
michael@0 45 Svc.Obs.notify("weave:engine:stop-tracking");
michael@0 46 removeEntry("address", "Memory Lane");
michael@0 47 do_check_empty(tracker.changedIDs);
michael@0 48
michael@0 49 _("Notifying twice won't do any harm.");
michael@0 50 Svc.Obs.notify("weave:engine:stop-tracking");
michael@0 51 removeEntry("email", "john@doe.com");
michael@0 52 do_check_empty(tracker.changedIDs);
michael@0 53
michael@0 54 } finally {
michael@0 55 _("Clean up.");
michael@0 56 engine._store.wipe();
michael@0 57 }
michael@0 58 }

mercurial