IDB: storage/indexeddb/mozilla/cursors.html fails
[WebKit-https.git] / LayoutTests / storage / indexeddb / mozilla / resources / clear.js
1 // original test:
2 // http://mxr.mozilla.org/mozilla2.0/source/dom/indexedDB/test/test_clear.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('../../../../resources/js-test-pre.js');
9     importScripts('../../resources/shared.js');
10 }
11
12 description("Test IndexedDB's clearing an object store");
13
14 indexedDBTest(prepareDatabase, clear);
15 function prepareDatabase()
16 {
17     db = event.target.result;
18     event.target.transaction.onabort = unexpectedAbortCallback;
19     objectStore = evalAndLog("objectStore = db.createObjectStore('foo', { autoIncrement: true });");
20     request = evalAndLog("request = objectStore.add({});");
21     request.onerror = unexpectedErrorCallback;
22 }
23
24 function clear()
25 {
26     evalAndExpectException("db.transaction('foo').objectStore('foo').clear();", "0", "'ReadOnlyError'");
27     transaction = evalAndLog("db.transaction('foo', 'readwrite')");
28     evalAndLog("transaction.objectStore('foo').clear();");
29     transaction.oncomplete = cleared;
30     transaction.onabort = unexpectedAbortCallback;
31 }
32
33 function cleared()
34 {
35     request = evalAndLog("request = db.transaction('foo').objectStore('foo').openCursor();");
36     request.onsuccess = areWeClearYet;
37     request.onerror = unexpectedErrorCallback;
38 }
39
40 function areWeClearYet()
41 {
42     cursor = evalAndLog("cursor = request.result;");
43     shouldBe("cursor", "null");
44     finishJSTest();
45 }