Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / storage / indexeddb / resources / keypath-arrays.js
blobfb623b9f218ee0c0cbe526900900eec0c538099c
1 if (this.importScripts) {
2     importScripts('../../../resources/js-test.js');
3     importScripts('shared.js');
6 description("Test IndexedDB Array-type keyPaths");
8 indexedDBTest(prepareDatabase, testKeyPaths);
9 function prepareDatabase()
11     db = event.target.result;
12     event.target.transaction.onabort = unexpectedAbortCallback;
13     evalAndLog("store = db.createObjectStore('store', {keyPath: ['a', 'b']})");
14     evalAndLog("index = store.createIndex('index', ['c', 'd'])");
16     shouldBeTrue("areArraysEqual(index.keyPath, ['c', 'd'])");
17     shouldBeFalse("index.keyPath instanceof DOMStringList");
19     evalAndExpectException("db.createObjectStore('store-with-generator', {keyPath: ['a', 'b'], autoIncrement: true})", "DOMException.INVALID_ACCESS_ERR");
20     evalAndExpectException("store.createIndex('index-multientry', ['e', 'f'], {multiEntry: true})", "DOMException.INVALID_ACCESS_ERR");
22     debug("");
23     debug("Empty arrays are not valid key paths:");
24     evalAndExpectException("db.createObjectStore('store-keypath-empty-array', {keyPath: []})", "DOMException.SYNTAX_ERR");
25     evalAndExpectException("store.createIndex('index-keypath-empty-array', [])", "DOMException.SYNTAX_ERR");
28 function testKeyPaths()
30     debug("");
31     debug("testKeyPaths():");
33     transaction = evalAndLog("transaction = db.transaction(['store'], 'readwrite')");
34     transaction.onabort = unexpectedAbortCallback;
35     evalAndLog("store = transaction.objectStore('store')");
36     evalAndLog("index = store.index('index')");
38     debug("");
39     evalAndLog("request = store.put({a: 1, b: 2, c: 3, d: 4})");
40     request.onerror = unexpectedErrorCallback;
41     checkStore();
43     function checkStore() {
44         evalAndLog("request = store.openCursor()");
45         request.onerror = unexpectedErrorCallback;
46         request.onsuccess = function () {
47             evalAndLog("cursor = request.result");
48             shouldBeNonNull("cursor");
49             shouldBeEqualToString("JSON.stringify(cursor.key)", "[1,2]");
50             checkIndex();
51         };
52     };
54     function checkIndex() {
55         evalAndLog("request = index.openCursor()");
56         request.onerror = unexpectedErrorCallback;
57         request.onsuccess = function () {
58             evalAndLog("cursor = request.result");
59             shouldBeNonNull("cursor");
60             shouldBeEqualToString("JSON.stringify(cursor.primaryKey)", "[1,2]");
61             shouldBeEqualToString("JSON.stringify(cursor.key)", "[3,4]");
62         };
63     };
65     transaction.oncomplete = finishJSTest;