blob: 0ff74e68979ef5d1d5341b96834dee652bf3368a (
plain)
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
<!DOCTYPE html>
<html>
<body>
foobar!
</body>
<script>
var data = [
{ id: "0", name: "foo" },
];
var action = window.location.search.substring(1);
var finished = false;
var created = false; // We use that for 'read-no' action.
function finish(value) {
value ? alert('success') : alert('failure');
finished = true;
}
var request = window.indexedDB.open('AppIsolationTest');
request.onupgradeneeded = function(event) {
if (finished) {
finish(false);
return;
}
switch (action) {
case 'read-no':
created = true;
break;
case 'read-yes':
finish(false);
break;
case 'write':
created = true;
var db = event.target.result;
var objectStore = db.createObjectStore("test", { keyPath: "id" });
for (var i in data) {
objectStore.add(data[i]);
}
break;
}
}
request.onsuccess = function(event) {
if (finished) {
finish(false);
return;
}
var db = event.target.result;
// Think about close the db!
switch (action) {
case 'read-no':
db.close();
if (created) { // That means we have created it.
indexedDB.deleteDatabase('AppIsolationTest').onsuccess = function() {
finish(true);
};
} else {
finish(false);
}
break;
case 'read-yes':
db.transaction("test").objectStore("test").get("0").onsuccess = function(event) {
var name = event.target.result.name;
db.close();
indexedDB.deleteDatabase('AppIsolationTest').onsuccess = function() {
finish(name == 'foo');
};
};
break;
case 'write':
db.close();
// Success only if the db was actually created.
finish(created);
break;
}
};
</script>
</html>
|