2 * Any copyright is dedicated to the Public Domain.
3 * http://creativecommons.org/publicdomain/zero/1.0/
6 /* exported testGenerator, disableWorkerTest */
7 var disableWorkerTest = "Need a way to set temporary prefs from a worker";
9 var testGenerator = testSteps();
11 function* testSteps() {
12 const spec = "http://foo.com";
13 const name = this.window
14 ? window.location.pathname
15 : "test_quotaExceeded_recovery";
16 const objectStoreName = "foo";
18 const android = mozinfo.os == "android";
20 // We want 512 KB database on Android and 4 MB database on other platforms.
21 const groupLimitKB = android ? 512 : 4096;
23 // The group limit is calculated as 20% of the global temporary storage limit.
24 const tempStorageLimitKB = groupLimitKB * 5;
26 // We want 64 KB chunks on Android and 512 KB chunks on other platforms.
27 const dataSizeKB = android ? 64 : 512;
28 const dataSize = dataSizeKB * 1024;
32 for (let blobs of [false, true]) {
33 setTemporaryStorageLimit(tempStorageLimitKB);
35 clearAllDatabases(continueToNextStepSync);
38 info("Opening database");
40 let request = indexedDB.openForPrincipal(getPrincipal(spec), name);
41 request.onerror = errorHandler;
42 request.onupgradeneeded = grabEventAndContinueHandler;
43 request.onsuccess = unexpectedSuccessHandler;
48 request.onupgradeneeded = unexpectedSuccessHandler;
49 request.onsuccess = grabEventAndContinueHandler;
51 info("Creating objectStore");
53 request.result.createObjectStore(objectStoreName, { autoIncrement: true });
58 let db = request.result;
59 db.onerror = errorHandler;
61 ok(true, "Filling database");
68 obj.data = getRandomView(dataSize);
76 obj.data = getBlob(getView(dataSize));
79 let trans = db.transaction(objectStoreName, "readwrite");
80 request = trans.objectStore(objectStoreName).add(obj);
81 request.onerror = function(event) {
82 event.stopPropagation();
85 trans.oncomplete = function(event) {
90 testGenerator.next(true);
92 trans.onabort = function(event) {
93 is(trans.error.name, "QuotaExceededError", "Reached quota limit");
94 testGenerator.next(false);
97 let completeFired = yield undefined;
99 ok(true, "Got complete event");
103 ok(true, "Got abort event");
105 if (iter++ == maxIter) {
110 ok(i == j, "Recycled entire database");
114 trans = db.transaction(objectStoreName, "readwrite");
116 // Don't use a cursor for deleting stored blobs (Cursors prolong live
117 // of stored files since each record must be fetched from the database
118 // first which creates a memory reference to the stored blob.)
120 request = trans.objectStore(objectStoreName).clear();
122 request = trans.objectStore(objectStoreName).openCursor();
123 request.onsuccess = function(event) {
124 let cursor = event.target.result;
132 trans.onabort = unexpectedSuccessHandler;
133 trans.oncomplete = grabEventAndContinueHandler;