1 if (this.importScripts) {
2 importScripts('../../../resources/js-test.js');
3 importScripts('shared.js');
6 description("Test the use of identical keypaths between objectstores and indexes");
8 indexedDBTest(prepareDatabase, storeCollidedStoreIndexData);
9 function prepareDatabase()
11 db = event.target.result;
12 event.target.transaction.onabort = unexpectedAbortCallback;
13 evalAndLog("store = db.createObjectStore('collideWithIndex', {keyPath: 'foo'})");
14 evalAndLog("index = store.createIndex('foo', 'foo')");
17 function resultShouldBe(v) {
18 return function(event) {
19 result = event.target.result;
20 shouldBeEqualToString("JSON.stringify(result)", v);
24 function storeCollidedStoreIndexData() {
25 var trans = db.transaction('collideWithIndex', 'readwrite');
27 objectStore = trans.objectStore('collideWithIndex');
28 index = objectStore.index('foo');
29 evalAndLog("objectStore.put({foo: 10})").onsuccess = function() {
30 evalAndLog("objectStore.get(10)").onsuccess = resultShouldBe('{"foo":10}');
31 evalAndLog("index.get(10)").onsuccess = resultShouldBe('{"foo":10}');
34 trans.oncomplete = testCollideAutoIncrementSetup;
35 trans.onabort = unexpectedAbortCallback;
38 function testCollideAutoIncrementSetup()
40 evalAndLog("db.close()");
41 evalAndLog("request = indexedDB.open(dbname, 2)");
42 request.onupgradeneeded = testCollideAutoIncrement;
43 request.onerror = unexpectedErrorCallback;
44 request.onblocked = unexpectedBlockedCallback;
45 request.onsuccess = storeCollidedAutoIncrementData;
48 function testCollideAutoIncrement()
50 db = event.target.result;
51 var trans = request.transaction;
52 deleteAllObjectStores(db);
53 evalAndLog("store = db.createObjectStore('collideWithAutoIncrement', {keyPath: 'foo', autoIncrement: true})");
54 evalAndLog("index = store.createIndex('foo', 'foo')");
56 trans.onerror = unexpectedErrorCallback;
57 trans.onabort = unexpectedAbortCallback;
60 function storeCollidedAutoIncrementData()
62 var trans = db.transaction('collideWithAutoIncrement', 'readwrite');
64 objectStore = trans.objectStore('collideWithAutoIncrement');
65 index = objectStore.index('foo');
66 // Insert some data to futz with the autoIncrement state.
67 for (var i = 5; i < 10; i++) {
68 evalAndLog("objectStore.put({foo:" + i + "})");
70 // Without a value, this requires the backend to generate a key, which must also be indexed.
71 evalAndLog("objectStore.put({'bar': 'baz'})").onsuccess = function(evt) {
73 shouldBe("event.target.result", "10");
74 evalAndLog("objectStore.get(10)").onsuccess = resultShouldBe('{"bar":"baz","foo":10}');
75 evalAndLog("index.get(10)").onsuccess = resultShouldBe('{"bar":"baz","foo":10}');
78 trans.oncomplete = testCollideIndexIndexSetup;
79 trans.onabort = unexpectedAbortCallback;
82 function testCollideIndexIndexSetup() {