2010-06-01 12:44:51 -07:00
|
|
|
_("Make sure the form store follows the Store api and correctly accesses the backend form storage");
|
2010-06-16 14:30:08 -07:00
|
|
|
Cu.import("resource://services-sync/engines/forms.js");
|
2011-02-03 10:23:38 -08:00
|
|
|
Cu.import("resource://services-sync/util.js");
|
2010-06-01 12:44:51 -07:00
|
|
|
|
|
|
|
function run_test() {
|
2010-08-12 13:19:41 -07:00
|
|
|
let baseuri = "http://fake/uri/";
|
2010-06-01 12:44:51 -07:00
|
|
|
let store = new FormEngine()._store;
|
|
|
|
|
2011-02-03 10:23:38 -08:00
|
|
|
function applyEnsureNoFailures(records) {
|
|
|
|
do_check_eq(store.applyIncomingBatch(records).length, 0);
|
|
|
|
}
|
|
|
|
|
2010-06-01 12:44:51 -07:00
|
|
|
_("Remove any existing entries");
|
|
|
|
store.wipe();
|
|
|
|
for (let id in store.getAllIDs()) {
|
|
|
|
do_throw("Shouldn't get any ids!");
|
|
|
|
}
|
|
|
|
|
|
|
|
_("Add a form entry");
|
2011-02-03 10:23:38 -08:00
|
|
|
applyEnsureNoFailures([{
|
|
|
|
id: Utils.makeGUID(),
|
2010-06-01 12:44:51 -07:00
|
|
|
name: "name!!",
|
|
|
|
value: "value??"
|
2011-02-03 10:23:38 -08:00
|
|
|
}]);
|
2010-06-01 12:44:51 -07:00
|
|
|
|
|
|
|
_("Should have 1 entry now");
|
|
|
|
let id = "";
|
|
|
|
for (let _id in store.getAllIDs()) {
|
|
|
|
if (id == "")
|
|
|
|
id = _id;
|
|
|
|
else
|
|
|
|
do_throw("Should have only gotten one!");
|
|
|
|
}
|
|
|
|
do_check_true(store.itemExists(id));
|
|
|
|
|
2010-11-29 16:41:17 -08:00
|
|
|
let rec = store.createRecord(id);
|
2010-06-01 12:44:51 -07:00
|
|
|
_("Got record for id", id, rec);
|
|
|
|
do_check_eq(rec.name, "name!!");
|
|
|
|
do_check_eq(rec.value, "value??");
|
|
|
|
|
2010-08-12 13:19:41 -07:00
|
|
|
_("Create a non-existent id for delete");
|
2010-11-29 16:41:17 -08:00
|
|
|
do_check_true(store.createRecord("deleted!!").deleted);
|
2010-06-01 12:44:51 -07:00
|
|
|
|
|
|
|
_("Try updating.. doesn't do anything yet");
|
|
|
|
store.update({});
|
|
|
|
|
|
|
|
_("Remove all entries");
|
|
|
|
store.wipe();
|
|
|
|
for (let id in store.getAllIDs()) {
|
|
|
|
do_throw("Shouldn't get any ids!");
|
|
|
|
}
|
|
|
|
|
|
|
|
_("Add another entry");
|
2011-02-03 10:23:38 -08:00
|
|
|
applyEnsureNoFailures([{
|
|
|
|
id: Utils.makeGUID(),
|
2010-06-01 12:44:51 -07:00
|
|
|
name: "another",
|
|
|
|
value: "entry"
|
2011-02-03 10:23:38 -08:00
|
|
|
}]);
|
2010-06-01 12:44:51 -07:00
|
|
|
id = "";
|
|
|
|
for (let _id in store.getAllIDs()) {
|
|
|
|
if (id == "")
|
|
|
|
id = _id;
|
|
|
|
else
|
|
|
|
do_throw("Should have only gotten one!");
|
|
|
|
}
|
|
|
|
|
|
|
|
_("Change the id of the new entry to something else");
|
|
|
|
store.changeItemID(id, "newid");
|
|
|
|
|
|
|
|
_("Make sure it's there");
|
|
|
|
do_check_true(store.itemExists("newid"));
|
|
|
|
|
|
|
|
_("Remove the entry");
|
|
|
|
store.remove({
|
|
|
|
id: "newid"
|
|
|
|
});
|
|
|
|
for (let id in store.getAllIDs()) {
|
|
|
|
do_throw("Shouldn't get any ids!");
|
|
|
|
}
|
|
|
|
|
|
|
|
_("Removing the entry again shouldn't matter");
|
|
|
|
store.remove({
|
|
|
|
id: "newid"
|
|
|
|
});
|
|
|
|
for (let id in store.getAllIDs()) {
|
|
|
|
do_throw("Shouldn't get any ids!");
|
|
|
|
}
|
2012-04-06 12:26:00 -07:00
|
|
|
|
|
|
|
_("Add another entry to delete using applyIncomingBatch");
|
|
|
|
let toDelete = {
|
|
|
|
id: Utils.makeGUID(),
|
|
|
|
name: "todelete",
|
|
|
|
value: "entry"
|
|
|
|
};
|
|
|
|
applyEnsureNoFailures([toDelete]);
|
|
|
|
id = "";
|
|
|
|
for (let _id in store.getAllIDs()) {
|
|
|
|
if (id == "")
|
|
|
|
id = _id;
|
|
|
|
else
|
|
|
|
do_throw("Should have only gotten one!");
|
|
|
|
}
|
|
|
|
do_check_true(store.itemExists(id));
|
|
|
|
// mark entry as deleted
|
|
|
|
toDelete.id = id;
|
|
|
|
toDelete.deleted = true;
|
|
|
|
applyEnsureNoFailures([toDelete]);
|
|
|
|
for (let id in store.getAllIDs()) {
|
|
|
|
do_throw("Shouldn't get any ids!");
|
|
|
|
}
|
|
|
|
|
|
|
|
_("Add an entry to wipe");
|
|
|
|
applyEnsureNoFailures([{
|
|
|
|
id: Utils.makeGUID(),
|
|
|
|
name: "towipe",
|
|
|
|
value: "entry"
|
|
|
|
}]);
|
|
|
|
|
|
|
|
Utils.runInTransaction(Svc.Form.DBConnection, function() {
|
|
|
|
store.wipe();
|
|
|
|
});
|
|
|
|
|
|
|
|
for (let id in store.getAllIDs()) {
|
|
|
|
do_throw("Shouldn't get any ids!");
|
|
|
|
}
|
2010-06-01 12:44:51 -07:00
|
|
|
}
|