|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <!-- |
|
4 Bug 965872 - Storage inspector actor with cookies, local storage and session storage. |
|
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/toolkit/devtools/server/tests/browser/storage-unsecured-iframe.html"></iframe> |
|
12 <iframe src="https://sectest1.example.org:443/browser/toolkit/devtools/server/tests/browser/storage-secured-iframe.html"></iframe> |
|
13 <script type="application/javascript;version=1.7"> |
|
14 |
|
15 let partialHostname = location.hostname.match(/^[^.]+(\..*)$/)[1]; |
|
16 let cookieExpiresTime1 = 2000000000000; |
|
17 let 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; secure=true; expires=" + |
|
23 new Date(cookieExpiresTime2).toGMTString() + "; path=/"; |
|
24 // ... and some local storage items .. |
|
25 localStorage.setItem("ls1", "foobar"); |
|
26 localStorage.setItem("ls2", "foobar-2"); |
|
27 // ... and finally some session storage items too |
|
28 sessionStorage.setItem("ss1", "foobar-3"); |
|
29 console.log("added cookies and stuff from main page"); |
|
30 |
|
31 function success(event) { |
|
32 setupIDB.next(event); |
|
33 } |
|
34 |
|
35 window.idbGenerator = function*(callback) { |
|
36 let request = indexedDB.open("idb1", 1); |
|
37 request.onupgradeneeded = success; |
|
38 request.onerror = function(e) { |
|
39 throw new Error("error opening db connection"); |
|
40 }; |
|
41 let event = yield undefined; |
|
42 let db = event.target.result; |
|
43 let store1 = db.createObjectStore("obj1", { keyPath: "id" }); |
|
44 store1.createIndex("name", "name", { unique: false }); |
|
45 store1.createIndex("email", "email", { unique: true }); |
|
46 let store2 = db.createObjectStore("obj2", { keyPath: "id2" }); |
|
47 |
|
48 store1.add({id: 1, name: "foo", email: "foo@bar.com"}).onsuccess = success; |
|
49 yield undefined; |
|
50 store1.add({id: 2, name: "foo2", email: "foo2@bar.com"}).onsuccess = success; |
|
51 yield undefined; |
|
52 store1.add({id: 3, name: "foo2", email: "foo3@bar.com"}).onsuccess = success; |
|
53 yield undefined; |
|
54 store2.add({id2: 1, name: "foo", email: "foo@bar.com", extra: "baz"}).onsuccess = success; |
|
55 yield undefined; |
|
56 |
|
57 store1.transaction.oncomplete = success; |
|
58 yield undefined; |
|
59 db.close(); |
|
60 |
|
61 request = indexedDB.open("idb2", 1); |
|
62 request.onupgradeneeded = success; |
|
63 event = yield undefined; |
|
64 |
|
65 let db2 = event.target.result; |
|
66 let store3 = db2.createObjectStore("obj3", { keyPath: "id3" }); |
|
67 store3.createIndex("name2", "name2", { unique: true }); |
|
68 store3.transaction.oncomplete = success; |
|
69 yield undefined; |
|
70 db2.close(); |
|
71 console.log("added cookies and stuff from main page"); |
|
72 callback(); |
|
73 } |
|
74 |
|
75 function successClear(event) { |
|
76 clearIterator.next(event); |
|
77 } |
|
78 |
|
79 window.clear = function*(callback) { |
|
80 document.cookie = "c1=; expires=Thu, 01 Jan 1970 00:00:00 GMT"; |
|
81 document.cookie = "c3=; expires=Thu, 01 Jan 1970 00:00:00 GMT"; |
|
82 localStorage.clear(); |
|
83 indexedDB.deleteDatabase("idb1").onsuccess = successClear; |
|
84 yield undefined; |
|
85 indexedDB.deleteDatabase("idb2").onsuccess = successClear; |
|
86 yield undefined; |
|
87 console.log("removed cookies and stuff from main page"); |
|
88 callback(); |
|
89 } |
|
90 </script> |
|
91 </body> |
|
92 </html> |