1 if (this.importScripts) {
2 importScripts('../../../resources/js-test.js');
3 importScripts('shared.js');
6 description("Verify that you can put the same data in 2 different databases without uniqueness constraints firing.");
13 indexedDBTest(prepareDatabase, test, {'suffix': '-1'});
15 indexedDBTest(prepareDatabase, finishJSTest, {'suffix': '-2'});
17 function prepareDatabase()
19 db = event.target.result;
21 self.store = evalAndLog("db.createObjectStore('storeName', null)");
22 self.indexObject = evalAndLog("store.createIndex('indexName', 'x')");
28 request = evalAndLog("store.add({x: 'value', y: 'zzz'}, 'key')");
29 request.onsuccess = addMore;
30 request.onerror = unexpectedErrorCallback;
35 request = evalAndLog("event.target.source.add({x: 'value2', y: 'zzz2'}, 'key2')");
36 request.onsuccess = getData;
37 request.onerror = unexpectedErrorCallback;
42 request = evalAndLog("indexObject.getKey('value')");
43 request.onsuccess = getObjectData;
44 request.onerror = unexpectedErrorCallback;
47 function getObjectData()
49 shouldBeEqualToString("event.target.result", "key");
51 request = evalAndLog("indexObject.get('value')");
52 request.onsuccess = getDataFail;
53 request.onerror = unexpectedErrorCallback;
56 function getDataFail()
58 shouldBeEqualToString("event.target.result.x", "value");
59 shouldBeEqualToString("event.target.result.y", "zzz");
61 request = evalAndLog("indexObject.getKey('does not exist')");
62 request.onsuccess = getObjectDataFail;
63 request.onerror = unexpectedErrorCallback;
66 function getObjectDataFail()
68 shouldBe("event.target.result", "undefined");
70 request = evalAndLog("indexObject.get('does not exist')");
71 request.onsuccess = openKeyCursor;
72 request.onerror = unexpectedErrorCallback;
75 function openKeyCursor()
77 shouldBe("event.target.result", "undefined");
79 self.request = evalAndLog("indexObject.openKeyCursor()");
80 request.onsuccess = cursor1Continue;
81 request.onerror = unexpectedErrorCallback;
84 function cursor1Continue()
86 shouldBeNonNull("event.target.result");
87 shouldBeEqualToString("event.target.result.key", "value");
88 shouldBeEqualToString("event.target.result.primaryKey", "key");
90 // We re-use the last request object.
91 evalAndLog("event.target.result.continue()");
92 self.request.onsuccess = cursor1Continue2;
95 function cursor1Continue2()
97 shouldBeNonNull("event.target.result");
98 shouldBeEqualToString("event.target.result.key", "value2");
99 shouldBeEqualToString("event.target.result.primaryKey", "key2");
101 // We re-use the last request object.
102 evalAndLog("event.target.result.continue()");
103 self.request.onsuccess = openObjectCursor;
106 function openObjectCursor()
108 shouldBeNull("event.target.result");
110 self.request = evalAndLog("indexObject.openCursor()");
111 request.onsuccess = cursor2Continue;
112 request.onerror = unexpectedErrorCallback;
115 function cursor2Continue()
117 shouldBeNonNull("event.target.result");
118 shouldBeEqualToString("event.target.result.key", "value");
119 shouldBeEqualToString("event.target.result.value.x", "value");
120 shouldBeEqualToString("event.target.result.value.y", "zzz");
122 // We re-use the last request object.
123 evalAndLog("event.target.result.continue()");
124 self.request.onsuccess = cursor2Continue2;
127 function cursor2Continue2()
129 shouldBeNonNull("event.target.result");
130 shouldBeEqualToString("event.target.result.key", "value2");
131 shouldBeEqualToString("event.target.result.value.x", "value2");
132 shouldBeEqualToString("event.target.result.value.y", "zzz2");
134 // We re-use the last request object.
135 evalAndLog("event.target.result.continue()");
136 self.request.onsuccess = last;
141 shouldBeNull("event.target.result");