|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 _("Make sure the form store follows the Store api and correctly accesses the backend form storage"); |
|
5 Cu.import("resource://services-sync/engines/forms.js"); |
|
6 Cu.import("resource://services-sync/service.js"); |
|
7 Cu.import("resource://services-sync/util.js"); |
|
8 Cu.import("resource://gre/modules/Services.jsm"); |
|
9 |
|
10 function run_test() { |
|
11 let baseuri = "http://fake/uri/"; |
|
12 let engine = new FormEngine(Service); |
|
13 let store = engine._store; |
|
14 |
|
15 function applyEnsureNoFailures(records) { |
|
16 do_check_eq(store.applyIncomingBatch(records).length, 0); |
|
17 } |
|
18 |
|
19 _("Remove any existing entries"); |
|
20 store.wipe(); |
|
21 for (let id in store.getAllIDs()) { |
|
22 do_throw("Shouldn't get any ids!"); |
|
23 } |
|
24 |
|
25 _("Add a form entry"); |
|
26 applyEnsureNoFailures([{ |
|
27 id: Utils.makeGUID(), |
|
28 name: "name!!", |
|
29 value: "value??" |
|
30 }]); |
|
31 |
|
32 _("Should have 1 entry now"); |
|
33 let id = ""; |
|
34 for (let _id in store.getAllIDs()) { |
|
35 if (id == "") |
|
36 id = _id; |
|
37 else |
|
38 do_throw("Should have only gotten one!"); |
|
39 } |
|
40 do_check_true(store.itemExists(id)); |
|
41 |
|
42 _("Should be able to find this entry as a dupe"); |
|
43 do_check_eq(engine._findDupe({name: "name!!", value: "value??"}), id); |
|
44 |
|
45 let rec = store.createRecord(id); |
|
46 _("Got record for id", id, rec); |
|
47 do_check_eq(rec.name, "name!!"); |
|
48 do_check_eq(rec.value, "value??"); |
|
49 |
|
50 _("Create a non-existent id for delete"); |
|
51 do_check_true(store.createRecord("deleted!!").deleted); |
|
52 |
|
53 _("Try updating.. doesn't do anything yet"); |
|
54 store.update({}); |
|
55 |
|
56 _("Remove all entries"); |
|
57 store.wipe(); |
|
58 for (let id in store.getAllIDs()) { |
|
59 do_throw("Shouldn't get any ids!"); |
|
60 } |
|
61 |
|
62 _("Add another entry"); |
|
63 applyEnsureNoFailures([{ |
|
64 id: Utils.makeGUID(), |
|
65 name: "another", |
|
66 value: "entry" |
|
67 }]); |
|
68 id = ""; |
|
69 for (let _id in store.getAllIDs()) { |
|
70 if (id == "") |
|
71 id = _id; |
|
72 else |
|
73 do_throw("Should have only gotten one!"); |
|
74 } |
|
75 |
|
76 _("Change the id of the new entry to something else"); |
|
77 store.changeItemID(id, "newid"); |
|
78 |
|
79 _("Make sure it's there"); |
|
80 do_check_true(store.itemExists("newid")); |
|
81 |
|
82 _("Remove the entry"); |
|
83 store.remove({ |
|
84 id: "newid" |
|
85 }); |
|
86 for (let id in store.getAllIDs()) { |
|
87 do_throw("Shouldn't get any ids!"); |
|
88 } |
|
89 |
|
90 _("Removing the entry again shouldn't matter"); |
|
91 store.remove({ |
|
92 id: "newid" |
|
93 }); |
|
94 for (let id in store.getAllIDs()) { |
|
95 do_throw("Shouldn't get any ids!"); |
|
96 } |
|
97 |
|
98 _("Add another entry to delete using applyIncomingBatch"); |
|
99 let toDelete = { |
|
100 id: Utils.makeGUID(), |
|
101 name: "todelete", |
|
102 value: "entry" |
|
103 }; |
|
104 applyEnsureNoFailures([toDelete]); |
|
105 id = ""; |
|
106 for (let _id in store.getAllIDs()) { |
|
107 if (id == "") |
|
108 id = _id; |
|
109 else |
|
110 do_throw("Should have only gotten one!"); |
|
111 } |
|
112 do_check_true(store.itemExists(id)); |
|
113 // mark entry as deleted |
|
114 toDelete.id = id; |
|
115 toDelete.deleted = true; |
|
116 applyEnsureNoFailures([toDelete]); |
|
117 for (let id in store.getAllIDs()) { |
|
118 do_throw("Shouldn't get any ids!"); |
|
119 } |
|
120 |
|
121 _("Add an entry to wipe"); |
|
122 applyEnsureNoFailures([{ |
|
123 id: Utils.makeGUID(), |
|
124 name: "towipe", |
|
125 value: "entry" |
|
126 }]); |
|
127 |
|
128 store.wipe(); |
|
129 |
|
130 for (let id in store.getAllIDs()) { |
|
131 do_throw("Shouldn't get any ids!"); |
|
132 } |
|
133 |
|
134 _("Ensure we work if formfill is disabled."); |
|
135 Services.prefs.setBoolPref("browser.formfill.enable", false); |
|
136 try { |
|
137 // a search |
|
138 for (let id in store.getAllIDs()) { |
|
139 do_throw("Shouldn't get any ids!"); |
|
140 } |
|
141 // an update. |
|
142 applyEnsureNoFailures([{ |
|
143 id: Utils.makeGUID(), |
|
144 name: "some", |
|
145 value: "entry" |
|
146 }]); |
|
147 } finally { |
|
148 Services.prefs.clearUserPref("browser.formfill.enable"); |
|
149 store.wipe(); |
|
150 } |
|
151 } |