Cache API and IDB space usages should be initialized on first quota check
[WebKit-https.git] / LayoutTests / http / tests / IndexedDB / storage-limit.https.html
1 <html>
2 <head>
3 <script src="/js-test-resources/js-test.js"></script>
4 <script src="resources/shared.js"></script>
5 </head>
6 <body>
7 <script>
8 if (window.testRunner)
9     testRunner.setAllowStorageQuotaIncrease(false);
10
11 description("This test makes sure that storage of indexedDB does not grow unboundedly.");
12
13 window.caches.open("test").then(cache => {
14     return cache.put(new Request("/test"), new Response(new Uint8Array(204800)));
15 }).then(() => {
16     indexedDBTest(prepareDatabase, onOpenSuccess, {'suffix': '-1'});
17 }).catch(e => {
18     testFailed("Cache API store operation failed: " + e);
19     finishJSTest();
20 });
21
22 function prepareDatabase(event)
23 {
24     evalAndLog("db = event.target.result");
25     evalAndLog("store = db.createObjectStore('store')");
26 }
27
28 // Quota for test is 400ko, but IDB is eating some of it when initializing files.
29 // Let's make sure that 200ko is fine but 200ko after 200ko is not fine.
30 async function onOpenSuccess(event)
31 {
32     evalAndLog("db = event.target.result");
33     evalAndLog("store = db.transaction('store', 'readwrite').objectStore('store')");
34     evalAndLog("request = store.add(new Uint8Array(204800), 'key')");
35     request.onerror = function(event) {
36         shouldBeTrue("'error' in request");
37         shouldBe("request.error.code", "DOMException.QUOTA_EXCEEDED_ERR");
38         shouldBeEqualToString("request.error.name", "QuotaExceededError");
39         finishJSTest();
40     }
41
42     request.onsuccess = function(event) {
43         testFailed("Add operation should fail because storage limit is reached, but succeeded.");
44         finishJSTest();
45     }
46 }
47 </script>
48 </body>
49 </html>