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