michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: _("Make sure the form store follows the Store api and correctly accesses the backend form storage"); michael@0: Cu.import("resource://services-sync/engines/forms.js"); michael@0: Cu.import("resource://services-sync/service.js"); michael@0: Cu.import("resource://services-sync/util.js"); michael@0: Cu.import("resource://gre/modules/Services.jsm"); michael@0: michael@0: function run_test() { michael@0: let baseuri = "http://fake/uri/"; michael@0: let engine = new FormEngine(Service); michael@0: let store = engine._store; michael@0: michael@0: function applyEnsureNoFailures(records) { michael@0: do_check_eq(store.applyIncomingBatch(records).length, 0); michael@0: } michael@0: michael@0: _("Remove any existing entries"); michael@0: store.wipe(); michael@0: for (let id in store.getAllIDs()) { michael@0: do_throw("Shouldn't get any ids!"); michael@0: } michael@0: michael@0: _("Add a form entry"); michael@0: applyEnsureNoFailures([{ michael@0: id: Utils.makeGUID(), michael@0: name: "name!!", michael@0: value: "value??" michael@0: }]); michael@0: michael@0: _("Should have 1 entry now"); michael@0: let id = ""; michael@0: for (let _id in store.getAllIDs()) { michael@0: if (id == "") michael@0: id = _id; michael@0: else michael@0: do_throw("Should have only gotten one!"); michael@0: } michael@0: do_check_true(store.itemExists(id)); michael@0: michael@0: _("Should be able to find this entry as a dupe"); michael@0: do_check_eq(engine._findDupe({name: "name!!", value: "value??"}), id); michael@0: michael@0: let rec = store.createRecord(id); michael@0: _("Got record for id", id, rec); michael@0: do_check_eq(rec.name, "name!!"); michael@0: do_check_eq(rec.value, "value??"); michael@0: michael@0: _("Create a non-existent id for delete"); michael@0: do_check_true(store.createRecord("deleted!!").deleted); michael@0: michael@0: _("Try updating.. doesn't do anything yet"); michael@0: store.update({}); michael@0: michael@0: _("Remove all entries"); michael@0: store.wipe(); michael@0: for (let id in store.getAllIDs()) { michael@0: do_throw("Shouldn't get any ids!"); michael@0: } michael@0: michael@0: _("Add another entry"); michael@0: applyEnsureNoFailures([{ michael@0: id: Utils.makeGUID(), michael@0: name: "another", michael@0: value: "entry" michael@0: }]); michael@0: id = ""; michael@0: for (let _id in store.getAllIDs()) { michael@0: if (id == "") michael@0: id = _id; michael@0: else michael@0: do_throw("Should have only gotten one!"); michael@0: } michael@0: michael@0: _("Change the id of the new entry to something else"); michael@0: store.changeItemID(id, "newid"); michael@0: michael@0: _("Make sure it's there"); michael@0: do_check_true(store.itemExists("newid")); michael@0: michael@0: _("Remove the entry"); michael@0: store.remove({ michael@0: id: "newid" michael@0: }); michael@0: for (let id in store.getAllIDs()) { michael@0: do_throw("Shouldn't get any ids!"); michael@0: } michael@0: michael@0: _("Removing the entry again shouldn't matter"); michael@0: store.remove({ michael@0: id: "newid" michael@0: }); michael@0: for (let id in store.getAllIDs()) { michael@0: do_throw("Shouldn't get any ids!"); michael@0: } michael@0: michael@0: _("Add another entry to delete using applyIncomingBatch"); michael@0: let toDelete = { michael@0: id: Utils.makeGUID(), michael@0: name: "todelete", michael@0: value: "entry" michael@0: }; michael@0: applyEnsureNoFailures([toDelete]); michael@0: id = ""; michael@0: for (let _id in store.getAllIDs()) { michael@0: if (id == "") michael@0: id = _id; michael@0: else michael@0: do_throw("Should have only gotten one!"); michael@0: } michael@0: do_check_true(store.itemExists(id)); michael@0: // mark entry as deleted michael@0: toDelete.id = id; michael@0: toDelete.deleted = true; michael@0: applyEnsureNoFailures([toDelete]); michael@0: for (let id in store.getAllIDs()) { michael@0: do_throw("Shouldn't get any ids!"); michael@0: } michael@0: michael@0: _("Add an entry to wipe"); michael@0: applyEnsureNoFailures([{ michael@0: id: Utils.makeGUID(), michael@0: name: "towipe", michael@0: value: "entry" michael@0: }]); michael@0: michael@0: store.wipe(); michael@0: michael@0: for (let id in store.getAllIDs()) { michael@0: do_throw("Shouldn't get any ids!"); michael@0: } michael@0: michael@0: _("Ensure we work if formfill is disabled."); michael@0: Services.prefs.setBoolPref("browser.formfill.enable", false); michael@0: try { michael@0: // a search michael@0: for (let id in store.getAllIDs()) { michael@0: do_throw("Shouldn't get any ids!"); michael@0: } michael@0: // an update. michael@0: applyEnsureNoFailures([{ michael@0: id: Utils.makeGUID(), michael@0: name: "some", michael@0: value: "entry" michael@0: }]); michael@0: } finally { michael@0: Services.prefs.clearUserPref("browser.formfill.enable"); michael@0: store.wipe(); michael@0: } michael@0: }