Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / storage / indexeddb / resources / cursor-properties.js
blobe4e7b7b4084997f6ca264a4094aae44c19a0a382
1 if (this.importScripts) {
2     importScripts('../../../resources/js-test.js');
3     importScripts('shared.js');
6 description("Test that IndexedDB's cursor key/primaryKey/value properties preserve mutations.");
8 function test()
10     setDBNameFromPath();
12     request = evalAndLog("indexedDB.deleteDatabase(dbname)");
13     request.onblocked = unexpectedBlockedCallback;
14     request.onerror = unexpectedErrorCallback;
15     request.onsuccess = function() {
16         request = evalAndLog("indexedDB.open(dbname, 1)");
17         request.onblocked = unexpectedBlockedCallback;
18         request.onerror = unexpectedErrorCallback;
19         request.onupgradeneeded = onUpgradeNeeded;
20         request.onsuccess = onOpenSuccess;
21     };
24 function onUpgradeNeeded(evt)
26     preamble(evt);
27     evalAndLog("db = event.target.result");
28     evalAndLog("store = db.createObjectStore('store')");
29     evalAndLog("index = store.createIndex('index', 'id')");
30     evalAndLog("store.put({id: ['indexKey']}, ['primaryKey'])");
33 function onOpenSuccess(evt)
35     preamble(evt);
36     evalAndLog("db = event.target.result");
37     evalAndLog("trans = db.transaction('store')");
38     trans.onabort = unexpectedAbortCallback;
39     evalAndLog("store = trans.objectStore('store')");
40     evalAndLog("index = store.index('index')");
42     debug("");
43     evalAndLog("request = index.openCursor()");
44     request.onerror = unexpectedErrorCallback;
45     request.onsuccess = function onCursorSuccess(evt) {
46         preamble(evt);
47         evalAndLog("cursor = event.target.result");
48         shouldBeNonNull("cursor");
49         shouldBeTrue("areArraysEqual(cursor.key, ['indexKey'])");
50         shouldBeTrue("areArraysEqual(cursor.primaryKey, ['primaryKey'])");
51         checkProperty("cursor.key");
52         checkProperty("cursor.primaryKey");
53         checkProperty("cursor.value");
54     };
56     trans.oncomplete = finishJSTest;
59 function checkProperty(property)
61     debug("");
63     debug("Check identity:");
64     evalAndLog("v = " + property);
65     shouldBeTrue("v === " + property);
67     debug("Check read-only:");
68     evalAndLog(property + " = null");
69     shouldBeTrue("v === " + property);
71     debug("Check mutability:");
72     evalAndLog(property + ".expando = 123");
73     shouldBe(property + ".expando", "123");
76 test();