1 var testGenerator = testSteps();
3 function* testSteps() {
4 const name = this.window
5 ? window.location.pathname
6 : "test_storage_manager_estimate.js";
7 const objectStoreName = "storagesManager";
10 ok("estimate" in navigator.storage, "Has estimate function");
11 is(typeof navigator.storage.estimate, "function", "estimate is function");
13 navigator.storage.estimate() instanceof Promise,
14 "estimate() method exists and returns a Promise"
17 navigator.storage.estimate().then(estimation => {
18 testGenerator.next(estimation.usage);
21 let before = yield undefined;
23 let request = indexedDB.open(name, 1);
24 request.onerror = errorHandler;
25 request.onupgradeneeded = grabEventAndContinueHandler;
26 request.onsuccess = continueToNextStep;
27 let event = yield undefined;
29 let db = event.target.result;
30 db.onerror = errorHandler;
32 let objectStore = db.createObjectStore(objectStoreName, {});
35 navigator.storage.estimate().then(estimation => {
36 testGenerator.next(estimation.usage);
38 let usageAfterCreate = yield undefined;
40 usageAfterCreate > before,
41 "estimated usage must increase after createObjectStore"
44 let txn = db.transaction(objectStoreName, "readwrite");
45 objectStore = txn.objectStore(objectStoreName);
46 objectStore.put(new Uint8Array(arraySize), "k");
47 txn.oncomplete = continueToNextStep;
48 txn.onabort = errorHandler;
49 txn.onerror = errorHandler;
50 event = yield undefined;
52 navigator.storage.estimate().then(estimation => {
53 testGenerator.next(estimation.usage);
55 let usageAfterPut = yield undefined;
57 usageAfterPut > usageAfterCreate,
58 "estimated usage must increase after putting large object"
66 async function setup(isXOrigin) {
67 // Bug 1746646: Make mochitests work with TCP enabled (cookieBehavior = 5)
68 // Acquire storage access permission here so that the iframe has
69 // first-party access to the storage estimate. Without this, it is
70 // isolated and this test will always fail
72 await SpecialPowers.pushPrefEnv({
75 "privacy.partition.always_partition_third_party_non_cookie_storage",
80 SpecialPowers.wrap(document).notifyUserGestureActivation();
81 await SpecialPowers.addPermission(
86 await SpecialPowers.wrap(document).requestStorageAccess();