Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / storage / indexeddb / resources / keypath-fetch-key.js
blobac5b05deb8521dc9af175cc1979c48814376d01b
1 if (this.importScripts) {
2     importScripts('../../../resources/js-test.js');
3     importScripts('shared.js');
6 description("Test IndexedDB keyPaths");
8 testData = [{ name: "simple identifier",
9               value: {id:10},
10               keyPath: "id",
11               key: 10 },
12             { name: "simple identifiers",
13               value: {id1:10, id2:20},
14               keyPath: "id1",
15               key: 10 },
16             { name: "nested identifiers",
17               value: {outer:{inner:10}},
18               keyPath: "outer.inner",
19               key: 10 },
20             { name: "nested identifiers with distractions",
21               value: {outer:{inner:10}, inner:{outer:20}},
22               keyPath: "outer.inner",
23               key: 10 },
25 nextToOpen = 0;
27 indexedDBTest(prepareDatabase);
28 var db = null;
29 var trans = null;
30 function prepareDatabase()
32     db = db || event.target.result;
33     if (!trans) {
34         trans = event.target.transaction;
35         trans.onabort = unexpectedAbortCallback;
36     }
37     debug("");
38     debug("testing " + testData[nextToOpen].name);
39     deleteAllObjectStores(db);
40     objectStore = evalAndLog("objectStore = db.createObjectStore(testData[nextToOpen].name, {keyPath: testData[nextToOpen].keyPath});");
41     result = evalAndLog("result = objectStore.add(testData[nextToOpen].value);");
42     result.onerror = unexpectedErrorCallback;
43     result.onsuccess = openCursor;
46 function openCursor()
48     result = evalAndLog("result = objectStore.openCursor();");
49     result.onerror = unexpectedErrorCallback;
50     result.onsuccess = checkCursor;
53 function checkCursor()
55     cursor = evalAndLog("cursor = event.target.result;");
56     if (cursor) {
57         shouldBe("cursor.key", "testData[nextToOpen].key");
58     } else {
59         testFailed("cursor is null");
60     }
61     if (++nextToOpen < testData.length) {
62         prepareDatabase();
63     } else {
64         finishJSTest();
65     }