1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/services/sync/tests/unit/test_forms_tracker.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,58 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +Cu.import("resource://gre/modules/Log.jsm"); 1.8 +Cu.import("resource://services-sync/engines/forms.js"); 1.9 +Cu.import("resource://services-sync/service.js"); 1.10 +Cu.import("resource://services-sync/util.js"); 1.11 + 1.12 +function run_test() { 1.13 + _("Verify we've got an empty tracker to work with."); 1.14 + let engine = new FormEngine(Service); 1.15 + let tracker = engine._tracker; 1.16 + // Don't do asynchronous writes. 1.17 + tracker.persistChangedIDs = false; 1.18 + 1.19 + do_check_empty(tracker.changedIDs); 1.20 + Log.repository.rootLogger.addAppender(new Log.DumpAppender()); 1.21 + 1.22 + function addEntry(name, value) { 1.23 + engine._store.create({name: name, value: value}); 1.24 + } 1.25 + function removeEntry(name, value) { 1.26 + guid = engine._findDupe({name: name, value: value}); 1.27 + engine._store.remove({id: guid}); 1.28 + } 1.29 + 1.30 + try { 1.31 + _("Create an entry. Won't show because we haven't started tracking yet"); 1.32 + addEntry("name", "John Doe"); 1.33 + do_check_empty(tracker.changedIDs); 1.34 + 1.35 + _("Tell the tracker to start tracking changes."); 1.36 + Svc.Obs.notify("weave:engine:start-tracking"); 1.37 + removeEntry("name", "John Doe"); 1.38 + addEntry("email", "john@doe.com"); 1.39 + do_check_attribute_count(tracker.changedIDs, 2); 1.40 + 1.41 + _("Notifying twice won't do any harm."); 1.42 + Svc.Obs.notify("weave:engine:start-tracking"); 1.43 + addEntry("address", "Memory Lane"); 1.44 + do_check_attribute_count(tracker.changedIDs, 3); 1.45 + 1.46 + _("Let's stop tracking again."); 1.47 + tracker.clearChangedIDs(); 1.48 + Svc.Obs.notify("weave:engine:stop-tracking"); 1.49 + removeEntry("address", "Memory Lane"); 1.50 + do_check_empty(tracker.changedIDs); 1.51 + 1.52 + _("Notifying twice won't do any harm."); 1.53 + Svc.Obs.notify("weave:engine:stop-tracking"); 1.54 + removeEntry("email", "john@doe.com"); 1.55 + do_check_empty(tracker.changedIDs); 1.56 + 1.57 + } finally { 1.58 + _("Clean up."); 1.59 + engine._store.wipe(); 1.60 + } 1.61 +}