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
65
66
content / test / data / indexeddb / write_and_read_blob.html [blame]
<!DOCTYPE html>
<html>
<!--
Copyright 2020 The Chromium Authors
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<head>
<!-- Create a database. Write & read a blob. -->
<title>IDB test for blob key corruption</title>
<script type="text/javascript" src="common.js"></script>
<script>
function upgradeCallback(db) {
deleteAllObjectStores(db);
db.createObjectStore('storeName', { autoIncrement : true });
}
let db;
async function test() {
db = await promiseOpenDb('blob_corrupt_db', upgradeCallback);
const transaction = db.transaction('storeName', 'readwrite');
transaction.onabort = unexpectedAbortCallback;
transaction.onerror = unexpectedErrorCallback;
transaction.oncomplete = getBlob;
const objectStore = transaction.objectStore('storeName');
const request = objectStore.put({blob: new Blob(['abc'])}, 'key-0');
request.onerror = unexpectedErrorCallback;
}
let gcWhenDone = false;
function getBlob() {
const transaction = db.transaction('storeName', 'readwrite');
transaction.onabort = unexpectedAbortCallback;
transaction.onerror = unexpectedErrorCallback;
const objectStore = transaction.objectStore('storeName');
const request = objectStore.get('key-0');
request.onerror = unexpectedErrorCallback;
request.onsuccess = () => {
const reader = new FileReader();
reader.addEventListener("loadend", () => {
if (reader.result !== "abc") {
fail(`expected blob to contain 'abc', got '${reader.result}'`);
return;
}
if (gcWhenDone) gc();
done();
});
reader.readAsText(request.result.blob);
}
}
function testThenGc() {
document.location.hash = '';
gcWhenDone = true;
test();
}
</script>
</head>
<body onLoad="test()">
<div id="status">Starting...</div>
</body>
</html>