1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>bug 600307</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="localStorageCommon.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
<script type="text/javascript">
/*
This is strictly implementation specific test for dom storage code from bug 600307.
It exercises code for asynchronous data flushing with regard to cache life time and its preload.
"flush + reload" means to tell the database to store all pending data then wipe the cached content and reload it from the db
"reload" only means to simulate situation when there is a pending flush for an origin but a new cache is about to preload
which is a corner case happening rarely ; this helps check the next preload operation will load correct data from the database anyway
Case 1: set | flush + reload | remove | set | remove | flush + reload | get ?= null
checks coalescing optimization for single key changes does work correctly for repeated removals of a key
Case 2: set | set | clear | flush + reload | count ?= 0
checks whether clear operation superseeds setting keys, the database must be empty for the origin
Case 3: set | set | clear | reload | count ?= 0
check the corner case when a data clear flush is pending but a new cache is about to preload
*/
function startTest()
{
// Have an untouched land
localStorage.clear();
// Initial flush
localStorageFlush(function() {
is(localStorage.length, 0, "localStorage empty at the test start");
// Basic test 1 (set a key, check presence after reload):
localStorage.setItem("item", "value");
localStorageFlushAndReload(function() {
is(localStorage.getItem("item"), "value", "Basic persistance works");
is(localStorage.length, 1, "1 item in localStorage");
// Basic test 2 (set a key twice, check presence of the last value):
localStorage.setItem("item", "value2");
localStorage.setItem("item", "value3");
localStorageFlushAndReload(function() {
is(localStorage.getItem("item"), "value3", "Basic persistance 2 works");
// Basic test 3 (remove a key, check it has been deleted):
localStorage.removeItem("item");
localStorageFlushAndReload(function() {
is(localStorage.getItem("item"), null, "Basic delete works");
// Basic test 4 (set and remove a key, check it is not present):
localStorage.setItem("item", "value4");
localStorage.removeItem("item");
localStorageFlushAndReload(function() {
is(localStorage.getItem("item"), null, "Basic delete 2 works");
// Case 1:
localStorage.setItem("item", "value");
localStorageFlushAndReload(function() {
localStorage.removeItem("item");
localStorage.setItem("item", "value2");
localStorage.removeItem("item");
localStorageFlushAndReload(function() {
is(localStorage.getItem("item"), null, "Item deleted in case 1");
// Case 2:
localStorage.setItem("item", "value");
localStorage.setItem("item2", "value2");
localStorage.clear();
localStorageFlushAndReload(function() {
is(localStorage.length, 0, "localStorage clean in case 2");
// Case 3:
localStorageFlush(function() {
localStorage.setItem("item", "value");
localStorage.setItem("item2", "value2");
localStorage.clear();
localStorageReload();
is(localStorage.length, 0, "localStorage clean in case 4");
if (SpecialPowers.Cc["@mozilla.org/xre/app-info;1"].getService(
SpecialPowers.Ci.nsIXULRuntime).processType != SpecialPowers.Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT) {
// Following tests cannot be run in a child/plugin process type
SimpleTest.finish();
return;
}
// Cookies clean 1
localStorageFlush(function() {
localStorage.setItem("item", "value");
localStorageClearAll();
is(localStorage.length, 0, "localStorage clean after cookies deletion");
localStorage.setItem("item2", "value2");
is(localStorage.getItem("item"), null, "Unexpected key 1, cookies delete");
is(localStorage.getItem("item2"), "value2", "Expected key 2, cookies delete");
localStorageFlushAndReload(function() {
is(localStorage.getItem("item"), null, "Unexpected key 1, cookies delete");
is(localStorage.getItem("item2"), "value2", "Expected key 2, cookies delete");
// Cookies clean 2
localStorage.clear();
localStorageFlush(function() {
localStorage.setItem("item", "value");
localStorageClearAll();
is(localStorage.length, 0, "localStorage clean after cookies deletion 2");
localStorageFlushAndReload(function() {
is(localStorage.length, 0, "localStorage clean after cookies deletion 2");
// Domain clean 1
localStorageFlush(function() {
localStorage.setItem("item", "value");
localStorageClearDomain("test");
is(localStorage.length, 0, "localStorage clean after domain deletion");
localStorage.setItem("item2", "value2");
is(localStorage.getItem("item"), null, "Unexpected key 1, domain delete");
is(localStorage.getItem("item2"), "value2", "Expected key 2, domain delete");
localStorageFlushAndReload(function() {
is(localStorage.getItem("item"), null, "Unexpected key 1, domain delete");
is(localStorage.getItem("item2"), "value2", "Expected key 2, domain delete");
// Domain clean 2
localStorage.clear();
localStorageFlush(function() {
localStorage.setItem("item", "value");
localStorageClearDomain("test");
is(localStorage.length, 0, "localStorage clean after domain deletion 2");
localStorageFlushAndReload(function() {
is(localStorage.length, 0, "localStorage clean after domain deletion 2");
SimpleTest.finish();
});
});
});
});
});
});
});
});
});
});
});
});
});
});
});
});
});
}
SimpleTest.waitForExplicitFinish();
</script>
</head>
<body onload="startTest();">
</body>
</html>
|