IndexedDB: Support Array-type key paths
[WebKit-https.git] / LayoutTests / storage / indexeddb / mozilla / resources / create-objectstore-basics.js
1 // original test:
2 // http://mxr.mozilla.org/mozilla2.0/source/dom/indexedDB/test/test_create_objectStore.html
3 // license of original test:
4 // " Any copyright is dedicated to the Public Domain.
5 //   http://creativecommons.org/publicdomain/zero/1.0/ "
6
7 if (this.importScripts) {
8     importScripts('../../../../fast/js/resources/js-test-pre.js');
9     importScripts('../../resources/shared.js');
10 }
11
12 description("Test IndexedDB's creating object store and updating properties");
13
14 function test()
15 {
16     removeVendorPrefixes();
17
18     name = self.location.pathname;
19     description = "My Test Database";
20     request = evalAndLog("indexedDB.open(name, description)");
21     request.onsuccess = openSuccess;
22     request.onerror = unexpectedErrorCallback;
23 }
24
25 function openSuccess()
26 {
27     db = evalAndLog("db = event.target.result");
28
29     request = evalAndLog("request = db.setVersion('1')");
30     request.onsuccess = cleanDatabase;
31     request.onerror = unexpectedErrorCallback;
32 }
33
34 function cleanDatabase()
35 {
36     deleteAllObjectStores(db);
37
38     objectStoreInfo = [
39         { name: "1", options: { autoIncrement: true } },
40         { name: "2", options: { autoIncrement: false } },
41         { name: "3", options: { keyPath: "" } },
42         { name: "4", options: { keyPath: "", autoIncrement: true }, fail: true },
43         { name: "5", options: { keyPath: "", autoIncrement: false } },
44         { name: "6", options: { keyPath: "foo" } },
45         { name: "7", options: { keyPath: "foo", autoIncrement: false } },
46         { name: "8", options: { keyPath: "foo", autoIncrement: true } }
47     ];
48
49     for (var index in objectStoreInfo) {
50         index = parseInt(index);
51         info = objectStoreInfo[index];
52         if (!info.fail) {
53             objectStore = evalAndLog("objectStore = db.createObjectStore(info.name, info.options);");
54             shouldBe("objectStore.name", "info.name");
55             if (info.options && info.options.keyPath) {
56                 shouldBe("objectStore.keyPath", "info.options.keyPath");
57             }
58             shouldBe("objectStore.indexNames.length", "0");
59             shouldBe("event.target.transaction.db", "db");
60             shouldBeEqualToString("event.target.transaction.mode", "versionchange");
61         } else {
62             evalAndExpectException("objectStore = db.createObjectStore(info.name, info.options)", "DOMException.INVALID_ACCESS_ERR");
63         }
64     }
65
66     finishJSTest();
67 }
68
69 test();