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.
9 <title>IDB Test that blobs use space when created and free up space when deleted
</title>
10 <script src=
"common.js"></script>
14 var store_name
= 'blobs_use_space';
15 var blob_key
= 'blob_key';
16 var blob_size
= 20 * 1024 * 1024;
24 indexedDBTest(prepareDatabase
, getInitialSize
);
27 function prepareDatabase() {
28 db
= event
.target
.result
;
29 db
.createObjectStore(store_name
);
32 function getInitialSize() {
33 getUsage(function(usage
) {
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
;
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
) {
77 fail("Size after deleting blob is " + (usage
- size_after_write
) +
78 " higher than size after write");
83 function getUsage(cb
) {
84 webkitStorageInfo
.queryUsageAndQuota(
85 webkitStorageInfo
.TEMPORARY
,
86 function(usage
, quota
) {
87 debug("Current database size is " + usage
+ "B");
90 unexpectedErrorCallback
);
93 function displaySize(bytes
) {
96 return bytes
+ " (" + k
+ "k) (" + m
+ "m)";
101 <body onLoad=
"test()">
102 <div id=
"status">Starting...
<br></div>