storage-listings.html (4556B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 Storage inspector front end - tests 5 --> 6 <head> 7 <meta charset="utf-8"> 8 <title>Storage inspector test for listing hosts and storages</title> 9 </head> 10 <body> 11 <iframe src="http://sectest1.example.org/browser/devtools/client/storage/test/storage-unsecured-iframe.html"></iframe> 12 <iframe src="https://sectest1.example.org:443/browser/devtools/client/storage/test/storage-secured-iframe.html"></iframe> 13 <script type="application/javascript"> 14 "use strict"; 15 const partialHostname = location.hostname.match(/^[^.]+(\..*)$/)[1]; 16 const cookieExpiresTime1 = 2000000000000; 17 const cookieExpiresTime2 = 2000000001000; 18 // Setting up some cookies to eat. 19 document.cookie = "c1=foobar; expires=" + 20 new Date(cookieExpiresTime1).toGMTString() + "; path=/browser"; 21 document.cookie = "cs2=sessionCookie; path=/; domain=" + partialHostname; 22 document.cookie = "c3=foobar-2; expires=" + 23 new Date(cookieExpiresTime1).toGMTString() + "; path=/"; 24 document.cookie = "c4=foobar-3; expires=" + 25 new Date(cookieExpiresTime2).toGMTString() + "; path=/; domain=" + 26 partialHostname; 27 // ... and some local storage items .. 28 localStorage.setItem("ls1", "foobar"); 29 localStorage.setItem("ls2", "foobar-2"); 30 31 // Because localStorage contains key() on the prototype and it can't be iterated 32 // using object.keys() we check the the value "key" exists. 33 // See bug 1451991 for details. 34 localStorage.setItem("key", "value1"); 35 36 // ... and finally some session storage items too 37 sessionStorage.setItem("ss1", "foobar-3"); 38 39 // Because sessionStorage contains key() on the prototype and it can't be 40 // iterated using object.keys() we check the the value "key" exists. 41 // See bug 1451991 for details. 42 sessionStorage.setItem("key", "value2"); 43 44 dump("added cookies and storage from main page\n"); 45 46 const idbGenerator = async function () { 47 let request = indexedDB.open("idb1", 1); 48 request.onerror = function() { 49 throw new Error("error opening db connection"); 50 }; 51 const db = await new Promise(done => { 52 request.onupgradeneeded = event => { 53 const _db = event.target.result; 54 const store1 = _db.createObjectStore("obj1", { keyPath: "id" }); 55 store1.createIndex("name", "name", { unique: false }); 56 store1.createIndex("email", "email", { unique: true }); 57 _db.createObjectStore("obj2", { keyPath: "id2" }); // eslint-disable-line no-unused-vars 58 store1.transaction.oncomplete = () => { 59 done(_db); 60 }; 61 }; 62 }); 63 64 // Prevents AbortError 65 await new Promise(done => { 66 request.onsuccess = done; 67 }); 68 69 const transaction = db.transaction(["obj1", "obj2"], "readwrite"); 70 const store1 = transaction.objectStore("obj1"); 71 const store2 = transaction.objectStore("obj2"); 72 store1.add({id: 1, name: "foo", email: "foo@bar.com"}); 73 store1.add({id: 2, name: "foo2", email: "foo2@bar.com"}); 74 store1.add({id: 3, name: "foo2", email: "foo3@bar.com"}); 75 store2.add({ 76 id2: 1, 77 name: "foo", 78 email: "foo@bar.com", 79 extra: "baz" 80 }); 81 // Prevents AbortError during close() 82 await new Promise(success => { 83 transaction.oncomplete = success; 84 }); 85 86 db.close(); 87 88 request = indexedDB.open("idb2", 1); 89 const db2 = await new Promise(done => { 90 request.onupgradeneeded = event => { 91 const _db2 = event.target.result; 92 const store3 = _db2.createObjectStore("obj3", { keyPath: "id3" }); 93 store3.createIndex("name2", "name2", { unique: true }); 94 store3.transaction.oncomplete = () => { 95 done(_db2); 96 } 97 }; 98 }); 99 // Prevents AbortError during close() 100 await new Promise(done => { 101 request.onsuccess = done; 102 }); 103 db2.close(); 104 105 dump("added indexedDB from main page\n"); 106 }; 107 108 function deleteDB(dbName) { 109 return new Promise(resolve => { 110 dump("removing database " + dbName + " from " + document.location + "\n"); 111 indexedDB.deleteDatabase(dbName).onsuccess = resolve; 112 }); 113 } 114 115 async function fetchPut(cache, url) { 116 const response = await fetch(url); 117 await cache.put(url, response); 118 } 119 120 const cacheGenerator = async function () { 121 const cache = await caches.open("plop"); 122 await fetchPut(cache, "404_cached_file.js"); 123 await fetchPut(cache, "browser_storage_basic.js"); 124 }; 125 126 window.setup = async function () { 127 await idbGenerator(); 128 129 if (window.caches) { 130 await cacheGenerator(); 131 } 132 }; 133 134 window.clear = async function () { 135 await deleteDB("idb1"); 136 await deleteDB("idb2"); 137 138 if (window.caches) { 139 await caches.delete("plop"); 140 } 141 dump("removed indexedDB and cache data from " + document.location + "\n"); 142 }; 143 </script> 144 </body> 145 </html>