Add a storage limit for IndexedDB
[WebKit-https.git] / LayoutTests / storage / indexeddb / resources / storage-limit.js
1 if (this.importScripts) {
2     importScripts('../../../resources/js-test.js');
3     importScripts('shared.js');
4 }
5
6 var quota = 1024 * 1024; // 1 MB
7 description("This test makes sure that storage of indexedDB does not grow unboundedly.");
8
9 if (window.testRunner)
10     testRunner.setIDBPerOriginQuota(quota);
11
12 indexedDBTest(prepareDatabase, onOpenSuccess);
13
14 function prepareDatabase(event)
15 {
16     preamble(event);
17     evalAndLog("db = event.target.result");
18     evalAndLog("store = db.createObjectStore('store')");
19 }
20
21 function onOpenSuccess(event)
22 {
23     preamble(event);
24     evalAndLog("db = event.target.result");
25     evalAndLog("store = db.transaction('store', 'readwrite').objectStore('store')");
26     evalAndLog("request = store.add(new Uint8Array(" + (quota + 1) + "), 0)");
27     request.onerror = function(event) {
28         shouldBeTrue("'error' in request");
29         shouldBe("request.error.code", "DOMException.QUOTA_EXCEEDED_ERR");
30         shouldBeEqualToString("request.error.name", "QuotaExceededError");
31         finishJSTest();
32     }
33
34     request.onsuccess = function(event) {
35         testFailed("Add operation should fail because storage limit is reached, but succeeded.");
36         finishJSTest();
37     }
38 }