forked from pouchdb/pouchdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
websql_storage_limit.html
83 lines (73 loc) · 2.59 KB
/
websql_storage_limit.html
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
<!doctype html>
<html>
<body>
<h1>WebSQL storage limit stress test</h1>
<form action='#' id="myform" onsubmit="runTest();return false;">
<h3>Choose size in MB:</h3>
<input type="radio" id="5" name="size" value="5"/>
<label for="5">5</label>
<input type="radio" id="10" name="size" value="10" checked="checked"/>
<label for="5">10</label>
<input type="radio" id="50" name="size" value="50"/>
<label for="5">50</label>
<input type="radio" id="100" name="size" value="100"/>
<label for="5">100</label>
<input type="radio" id="500" name="size" value="500"/>
<label for="5">500</label>
<input type="radio" id="1000" name="size" value="1000"/>
<label for="5">1000</label>
<p/>
<button>Run test</button>
</form>
<p/>
<pre id="log"> </pre>
<script src="../../dist/pouchdb.js"></script>
<script>
function getRadioValue() {
var inputs = document.getElementsByName("size");
for (var i = 0; i < inputs.length; i++) {
if (inputs[i].checked) {
return inputs[i].value;
}
}
}
function log(text) {
document.getElementById('log').appendChild(document.createTextNode(text + '\n'));
}
log('this is a load test designed to reproduce the 10MB size limit bug on Safari/iOS 7');
log("if all's well, you should see a success message, else an error");
log("you can use Safari's 'reset Safari' option to try again\n");
function runTest() {
log('starting...');
var BATCH_SIZE = 1000;
var ITERATIONS = 1000;
var pouch = new PouchDB('websql_stress', {adapter: 'websql', size: getRadioValue()});
var promise = PouchDB.utils.Promise.resolve();
function addDocs(i) {
promise = promise.then(function () {
var docs = [];
for (var j = 0; j < BATCH_SIZE; j++) {
docs.push({});
}
return pouch.bulkDocs({docs: docs}).then(function () {
var numDone = (i + 1) * BATCH_SIZE;
var total = BATCH_SIZE * ITERATIONS;
var percent = (Math.round((numDone / total) * 10000) / 100).toFixed(2);
log('Added ' + numDone + '/' + total + ' (' + percent + '%) docs so far...');
});
});
}
for (var i = 0; i < ITERATIONS; i++) {
addDocs(i);
}
promise.then(function () {
log('Success!');
}, function (err) {
log('Failure!');
log(err);
});
return false;
}
</script>
</body>
</html>