|
1 <html xmlns="http://www.w3.org/1999/xhtml"> |
|
2 <head> |
|
3 <title>sessionStorage basic test</title> |
|
4 |
|
5 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
6 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
|
7 |
|
8 <script type="application/javascript;version=1.7"> |
|
9 |
|
10 var expectedTypes = [ |
|
11 "localStorage", |
|
12 "localStorage", |
|
13 "sessionStorage", |
|
14 "localStorage", |
|
15 "sessionStorage", |
|
16 "sessionStorage", |
|
17 "localStorage", |
|
18 "sessionStorage", |
|
19 "localStorage", |
|
20 "sessionStorage", |
|
21 "localStorage", |
|
22 "sessionStorage", |
|
23 "sessionStorage", |
|
24 "localStorage", |
|
25 "sessionStorage", |
|
26 "localStorage", |
|
27 ]; |
|
28 |
|
29 var tests = Tests(); |
|
30 function setup() { |
|
31 sessionStorage.clear(); |
|
32 SimpleTest.executeSoon(function() { |
|
33 tests.next(); |
|
34 }); |
|
35 } |
|
36 |
|
37 function Tests() |
|
38 { |
|
39 // Initially check the both storages are empty |
|
40 is(sessionStorage.length, 0, "Session storage is empty [1]"); |
|
41 is(localStorage.length, 0, "Local storage is empty [1]"); |
|
42 |
|
43 var onStorageChanged = { |
|
44 observe: function(subject, topic, type) { |
|
45 if (topic == "dom-storage2-changed") { |
|
46 ok(expectedTypes.length > 0, "Not more then expected events encountered"); |
|
47 is(type, expectedTypes.shift(), "Expected type of the storage notificaiton"); |
|
48 tests.next(); |
|
49 } |
|
50 } |
|
51 } |
|
52 |
|
53 // Listen for dom-storage2-changed notification |
|
54 SpecialPowers.Services.obs.addObserver(onStorageChanged, |
|
55 "dom-storage2-changed", false); |
|
56 |
|
57 // add an empty-value key |
|
58 localStorage.setItem("empty", ""); |
|
59 yield undefined; |
|
60 |
|
61 localStorage.setItem("empty", "value-1"); |
|
62 yield undefined; |
|
63 |
|
64 sessionStorage.setItem("empty", ""); |
|
65 yield undefined; |
|
66 |
|
67 localStorage.removeItem("empty"); |
|
68 yield undefined; |
|
69 |
|
70 sessionStorage.setItem("empty", "value-1"); |
|
71 yield undefined; |
|
72 |
|
73 sessionStorage.removeItem("empty"); |
|
74 yield undefined; |
|
75 |
|
76 localStorage.setItem("key1", "value-1"); |
|
77 yield undefined; |
|
78 |
|
79 sessionStorage.setItem("key2", "value-2"); |
|
80 yield undefined; |
|
81 |
|
82 localStorage.setItem("key1", "value-1-2"); |
|
83 yield undefined; |
|
84 |
|
85 sessionStorage.setItem("key2", "value-2-2"); |
|
86 yield undefined; |
|
87 |
|
88 localStorage.setItem("key3", "value-3"); |
|
89 yield undefined; |
|
90 |
|
91 sessionStorage.setItem("key4", "value-4"); |
|
92 yield undefined; |
|
93 |
|
94 sessionStorage.removeItem("key4"); |
|
95 yield undefined; |
|
96 |
|
97 localStorage.setItem("key4", "value-4"); |
|
98 yield undefined; |
|
99 |
|
100 sessionStorage.clear(); |
|
101 yield undefined; |
|
102 |
|
103 localStorage.clear(); |
|
104 yield undefined; |
|
105 |
|
106 SimpleTest.executeSoon(function () { |
|
107 SpecialPowers.Services.obs.removeObserver(onStorageChanged, |
|
108 "dom-storage2-changed", false); |
|
109 is(expectedTypes.length, 0, "received the correct number of events"); |
|
110 |
|
111 sessionStorage.clear(); |
|
112 localStorage.clear(); |
|
113 tests = null; |
|
114 SimpleTest.finish(); |
|
115 }); |
|
116 } |
|
117 |
|
118 SimpleTest.waitForExplicitFinish(); |
|
119 |
|
120 </script> |
|
121 |
|
122 </head> |
|
123 |
|
124 <body onload="setup();"> |
|
125 |
|
126 </body> |
|
127 </html> |