tizen beta release
[profile/ivi/webkit-efl.git] / LayoutTests / storage / indexeddb / mozilla / clear.html
1 <!DOCTYPE html>
2 <!--
3   original test: http://mxr.mozilla.org/mozilla2.0/source/dom/indexedDB/test/test_clear.html
4   license of original test:
5     " Any copyright is dedicated to the Public Domain.
6       http://creativecommons.org/publicdomain/zero/1.0/ "
7 -->
8 <html>
9 <head>
10 <script src="../../../fast/js/resources/js-test-pre.js"></script>
11 <script src="../resources/shared.js"></script>
12 </head>
13 <body>
14 <p id="description"></p>
15 <div id="console"></div>
16 <script>
17
18 description("Test IndexedDB's clearing an object store");
19 if (window.layoutTestController)
20     layoutTestController.waitUntilDone();
21
22 function test()
23 {
24     indexedDB = evalAndLog("indexedDB = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB;");
25     shouldBeFalse("indexedDB == null");
26     IDBDatabaseException = evalAndLog("IDBDatabaseException = window.IDBDatabaseException || window.webkitIDBDatabaseException;");
27     shouldBeFalse("IDBDatabaseException == null");
28     IDBTransaction = evalAndLog("IDBTransaction = window.IDBTransaction || window.webkitIDBTransaction;");
29     shouldBeFalse("IDBTransaction == null");
30
31     name = window.location.pathname;
32     description = "My Test Database";
33     request = evalAndLog("indexedDB.open(name, description)");
34     request.onsuccess = openSuccess;
35     request.onerror = unexpectedErrorCallback;
36 }
37
38 function openSuccess()
39 {
40     db = evalAndLog("db = event.target.result");
41
42     request = evalAndLog("request = db.setVersion('1')");
43     request.onsuccess = cleanDatabase;
44     request.onerror = unexpectedErrorCallback;
45 }
46
47 function cleanDatabase()
48 {
49     deleteAllObjectStores(db);
50
51     objectStore = evalAndLog("objectStore = db.createObjectStore('foo', { autoIncrement: true });");
52     request = evalAndLog("request = objectStore.add({});");
53     request.onsuccess = clear;
54     request.onerror = unexpectedErrorCallback;
55 }
56
57 function clear()
58 {
59     evalAndExpectException("db.transaction('foo').objectStore('foo').clear();", "IDBDatabaseException.READ_ONLY_ERR");
60     evalAndLog("db.transaction('foo', IDBTransaction.READ_WRITE).objectStore('foo').clear();");
61     request = evalAndLog("request = db.transaction('foo').objectStore('foo').openCursor();");
62     request.onsuccess = areWeClearYet;
63     request.onerror = unexpectedErrorCallback;
64 }
65
66 function areWeClearYet()
67 {
68     cursor = evalAndLog("cursor = request.result;");
69     shouldBe("cursor", "null");
70     done();
71 }
72
73
74 test();
75
76 </script>
77 </body>
78 </html>
79