GPU workaround to simulate Out of Memory errors with large textures
[chromium-blink-merge.git] / content / test / data / indexeddb / blobs_use_quota.html
blob320d60bc5100c5dadac1d69fa5917bb6798a7bc6
1 <!DOCTYPE html>
2 <html>
3 <!--
4 Copyright 2014 The Chromium Authors. All rights reserved.
5 Use of this source code is governed by a BSD-style license that can be
6 found in the LICENSE file.
7 -->
8 <head>
9 <title>IDB Test that blobs use space when created and free up space when deleted</title>
10 <script src="common.js"></script>
11 <script>
13 // Constants.
14 var store_name = 'blobs_use_space';
15 var blob_key = 'blob_key';
16 var blob_size = 20 * 1024 * 1024;
18 // Shared variables.
19 var db;
20 var size_initial;
21 var size_after_write;
23 function test() {
24 indexedDBTest(prepareDatabase, getInitialSize);
27 function prepareDatabase() {
28 db = event.target.result;
29 db.createObjectStore(store_name);
32 function getInitialSize() {
33 getUsage(function(usage) {
34 size_initial = usage;
35 putBlob();
36 });
39 function putBlob() {
40 debug("Writing blob.");
42 var trans = db.transaction(store_name, 'readwrite');
43 trans.onabort = unexpectedAbortCallback;
44 trans.oncomplete = checkSizeIncreased;
46 var data = new Array(1 + blob_size).join("X");
47 var blob = new Blob([data]);
48 var request = trans.objectStore(store_name).put(blob, blob_key);
49 request.onerror = unexpectedErrorCallback;
52 function checkSizeIncreased() {
53 getUsage(function(usage) {
54 if (usage < size_initial + blob_size)
55 fail("Size increased by only " + (usage - size_initial) +
56 " after writing 20MB blob");
57 size_after_write = usage;
58 deleteBlob();
59 });
62 function deleteBlob() {
63 debug("Deleting blob.");
64 var trans = db.transaction(store_name, 'readwrite');
65 trans.onabort = unexpectedAbortCallback;
66 trans.oncomplete = checkSizeBackToInitial;
68 var request = trans.objectStore(store_name).delete(blob_key);
69 request.onerror = unexpectedErrorCallback;
72 function checkSizeBackToInitial() {
73 getUsage(function(usage) {
74 if (usage < size_after_write) {
75 done();
76 } else {
77 fail("Size after deleting blob is " + (usage - size_after_write) +
78 " higher than size after write");
80 });
83 function getUsage(cb) {
84 webkitStorageInfo.queryUsageAndQuota(
85 webkitStorageInfo.TEMPORARY,
86 function(usage, quota) {
87 debug("Current database size is " + usage + "B");
88 cb(usage);
90 unexpectedErrorCallback);
93 function displaySize(bytes) {
94 var k = bytes / 1024;
95 var m = k / 1024;
96 return bytes + " (" + k + "k) (" + m + "m)";
99 </script>
100 </head>
101 <body onLoad="test()">
102 <div id="status">Starting...<br></div>
103 </body>
104 </html>