[Cocoa] Update Launch Services database in the WebContent process from the Network...
[WebKit-https.git] / LayoutTests / storage / indexeddb / resources / keypath-arrays.js
1 if (this.importScripts) {
2     importScripts('../../../resources/js-test.js');
3     importScripts('shared.js');
4 }
5
6 description("Test IndexedDB Array-type keyPaths");
7
8 indexedDBTest(prepareDatabase, testKeyPaths);
9 function prepareDatabase()
10 {
11     db = event.target.result;
12     event.target.transaction.onabort = unexpectedAbortCallback;
13     evalAndLog("store = db.createObjectStore('store', {keyPath: ['a', 'b']})");
14     evalAndLog("store.createIndex('index', ['c', 'd'])");
15
16     evalAndExpectException("db.createObjectStore('store-with-generator', {keyPath: ['a', 'b'], autoIncrement: true})", "DOMException.INVALID_ACCESS_ERR");
17     evalAndExpectException("store.createIndex('index-multientry', ['e', 'f'], {multiEntry: true})", "DOMException.INVALID_ACCESS_ERR");
18
19     debug("");
20     debug("Empty arrays are not valid key paths:");
21     evalAndExpectException("db.createObjectStore('store-keypath-empty-array', {keyPath: []})", "DOMException.SYNTAX_ERR");
22     evalAndExpectException("store.createIndex('index-keypath-empty-array', [])", "DOMException.SYNTAX_ERR");
23 }
24
25 function testKeyPaths()
26 {
27     debug("");
28     debug("testKeyPaths():");
29
30     transaction = evalAndLog("transaction = db.transaction(['store'], 'readwrite')");
31     transaction.onabort = unexpectedAbortCallback;
32     evalAndLog("store = transaction.objectStore('store')");
33     evalAndLog("index = store.index('index')");
34
35     debug("");
36     evalAndLog("request = store.put({a: 1, b: 2, c: 3, d: 4})");
37     request.onerror = unexpectedErrorCallback;
38     evalAndLog("request = store.put({a: 5, b: 6, c: 7, d: 8})");
39     request.onerror = unexpectedErrorCallback;
40     iteration = 0;
41     checkStore();
42
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]", "[5,6]"][iteration]);
50             if (0 === iteration) {
51               ++iteration;
52               cursor.continue();
53             }
54             else {
55               iteration = 0;
56               checkIndex();
57             }
58         };
59     };
60
61     function checkIndex() {
62         evalAndLog("request = index.openCursor()");
63         request.onerror = unexpectedErrorCallback;
64         request.onsuccess = function () {
65             evalAndLog("cursor = request.result");
66             shouldBeNonNull("cursor");
67             shouldBeEqualToString("JSON.stringify(cursor.primaryKey)", ["[1,2]", "[5,6]"][iteration]);
68             shouldBeEqualToString("JSON.stringify(cursor.key)", ["[3,4]", "[7,8]"][iteration]);
69             if (0 === iteration) {
70               ++iteration;
71               cursor.continue();
72             }
73         };
74     };
75
76     transaction.oncomplete = finishJSTest;
77 }