1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
content / test / data / indexeddb / delete_compact.html [blame]
<!DOCTYPE html>
<html>
<head>
<!--
Copyright 2013 The Chromium Authors
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<title>IDB test that database deletion triggers a compaction</title>
<script type="text/javascript" src="common.js"></script>
<script>
var dbname = 'delete_compact';
// Follow navigation requests from the browser test.
window.onhashchange = test;
function test()
{
if (location.hash === '#fill')
fill();
else if (location.hash === '#purge')
purge();
else if (location.hash !== '#pass' && location.hash !== '#fail')
fail('unexpected hash');
}
function fill()
{
var bytes = 0;
var request = indexedDB.open(dbname);
request.onerror = unexpectedErrorCallback;
request.onupgradeneeded = function() {
var db = request.result;
var store = db.createObjectStore('store');
var kilobyte = Array(512+1).join('\u0100'); // 2 bytes in UTF-8 or UTF-16.
var megabyte = Array(1024+1).join(kilobyte);
for (var i = 0; i < 5; ++i) {
store.put(megabyte, i);
bytes += 1024 * 1024;
}
};
request.onsuccess = function() {
var db = request.result;
db.close();
done('filled with ' + bytes + ' bytes');
};
}
function purge()
{
var request = indexedDB.deleteDatabase(dbname);
request.onerror = unexpectedErrorCallback;
request.onsuccess = function() {
done('purged');
};
}
</script>
</head>
<body onload="test()">
<div id="status">Starting...</div>
</body>
</html>