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