Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(170)

Side by Side Diff: chrome/test/data/extensions/api_test/settings/simple_test/background.html

Issue 8670012: Extension Settings API: move the API functions into an object SettingsNamepace, (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 <script> 1 <script>
2 // Calls chrome.test.succeed after the settings have been cleared for the next 2 // Calls chrome.test.succeed after the settings have been cleared for the next
3 // test. 3 // test.
4 function succeed() { 4 function succeed() {
5 chrome.experimental.settings.clear(chrome.test.succeed); 5 this.clear(this.countDown);
6 }
7
8 function test(stage0) {
9 // Make sure chrome.test.succeed() is only called once (see succeed()).
Matt Perry 2011/11/23 03:35:05 chrome.test.callbackPass might be better suited fo
not at google - send to devlin 2011/11/23 11:04:52 Nice.
10 var countDown = function() {
11 if (--this.count === 0) {
12 chrome.test.succeed();
13 }
14 }.bind({ count: 2 });
15
16 var apis = [
17 chrome.experimental.settings.sync,
18 chrome.experimental.settings.local
19 ];
20 apis.forEach(function(api) { api.countDown = countDown; });
21 apis.forEach(function(api) { stage0.call(api); });
6 } 22 }
7 23
8 chrome.test.runTests([ 24 chrome.test.runTests([
9 function getWhenEmpty() { 25 function getWhenEmpty() {
10 function stage0() { 26 function stage0() {
11 chrome.experimental.settings.get('foo', stage1); 27 this.get('foo', stage1.bind(this));
12 } 28 }
13 function stage1(settings) { 29 function stage1(settings) {
14 chrome.test.assertEq({}, settings); 30 chrome.test.assertEq({}, settings);
15 chrome.experimental.settings.get(['foo', 'bar'], stage2); 31 this.get(['foo', 'bar'], stage2.bind(this));
16 } 32 }
17 function stage2(settings) { 33 function stage2(settings) {
18 chrome.test.assertEq({}, settings); 34 chrome.test.assertEq({}, settings);
19 chrome.experimental.settings.get(undefined, stage3); 35 this.get(undefined, stage3.bind(this));
20 } 36 }
21 function stage3(settings) { 37 function stage3(settings) {
22 chrome.test.assertEq({}, settings); 38 chrome.test.assertEq({}, settings);
23 succeed(); 39 succeed.call(this);
24 } 40 }
25 stage0(); 41 test(stage0);
26 }, 42 },
27 43
28 function getWhenNonempty() { 44 function getWhenNonempty() {
29 function stage0() { 45 function stage0() {
30 chrome.experimental.settings.set({ 46 this.set({
31 'foo' : 'bar', 47 'foo' : 'bar',
32 'baz' : 'qux', 48 'baz' : 'qux',
33 'hello': 'world' 49 'hello': 'world'
34 }, stage1); 50 }, stage1.bind(this));
35 } 51 }
36 function stage1() { 52 function stage1() {
37 chrome.experimental.settings.get(['foo', 'baz'], stage2); 53 this.get(['foo', 'baz'], stage2.bind(this));
38 } 54 }
39 function stage2(settings) { 55 function stage2(settings) {
40 chrome.test.assertEq({ 56 chrome.test.assertEq({
41 'foo': 'bar', 57 'foo': 'bar',
42 'baz': 'qux' 58 'baz': 'qux'
43 }, settings); 59 }, settings);
44 chrome.experimental.settings.get( 60 this.get(['nothing', 'baz', 'hello', 'ignore'], stage3.bind(this));
45 ['nothing', 'baz', 'hello', 'ignore'], stage3);
46 } 61 }
47 function stage3(settings) { 62 function stage3(settings) {
48 chrome.test.assertEq({ 63 chrome.test.assertEq({
49 'baz' : 'qux', 64 'baz' : 'qux',
50 'hello': 'world' 65 'hello': 'world'
51 }, settings); 66 }, settings);
52 chrome.experimental.settings.get(null, stage4); 67 this.get(null, stage4.bind(this));
53 } 68 }
54 function stage4(settings) { 69 function stage4(settings) {
55 chrome.test.assertEq({ 70 chrome.test.assertEq({
56 'foo' : 'bar', 71 'foo' : 'bar',
57 'baz' : 'qux', 72 'baz' : 'qux',
58 'hello': 'world' 73 'hello': 'world'
59 }, settings); 74 }, settings);
60 succeed(); 75 succeed.call(this);
61 } 76 }
62 stage0(); 77 test(stage0);
63 }, 78 },
64 79
65 function removeWhenEmpty() { 80 function removeWhenEmpty() {
66 function stage0() { 81 function stage0() {
67 chrome.experimental.settings.remove('foo', stage1); 82 this.remove('foo', stage1.bind(this));
68 } 83 }
69 function stage1() { 84 function stage1() {
70 chrome.experimental.settings.remove(['foo', 'bar'], stage2); 85 this.remove(['foo', 'bar'], succeed.bind(this));
71 } 86 }
72 function stage2() { 87 test(stage0);
73 succeed();
74 }
75 stage0();
76 }, 88 },
77 89
78 function removeWhenNonempty() { 90 function removeWhenNonempty() {
79 function stage0() { 91 function stage0() {
80 chrome.experimental.settings.set({ 92 this.set({
81 'foo' : 'bar', 93 'foo' : 'bar',
82 'baz' : 'qux', 94 'baz' : 'qux',
83 'hello': 'world' 95 'hello': 'world'
84 }, stage1); 96 }, stage1.bind(this));
85 } 97 }
86 function stage1() { 98 function stage1() {
87 chrome.experimental.settings.remove('foo', stage2); 99 this.remove('foo', stage2.bind(this));
88 } 100 }
89 function stage2() { 101 function stage2() {
90 chrome.experimental.settings.get(null, stage3); 102 this.get(null, stage3.bind(this));
91 } 103 }
92 function stage3(settings) { 104 function stage3(settings) {
93 chrome.test.assertEq({ 105 chrome.test.assertEq({
94 'baz' : 'qux', 106 'baz' : 'qux',
95 'hello': 'world' 107 'hello': 'world'
96 }, settings); 108 }, settings);
97 chrome.experimental.settings.remove(['baz', 'nothing'], stage4); 109 this.remove(['baz', 'nothing'], stage4.bind(this));
98 } 110 }
99 function stage4() { 111 function stage4() {
100 chrome.experimental.settings.get(null, stage5); 112 this.get(null, stage5.bind(this));
101 } 113 }
102 function stage5(settings) { 114 function stage5(settings) {
103 chrome.test.assertEq({ 115 chrome.test.assertEq({
104 'hello': 'world' 116 'hello': 'world'
105 }, settings); 117 }, settings);
106 chrome.experimental.settings.remove('hello', stage6); 118 this.remove('hello', stage6.bind(this));
107 } 119 }
108 function stage6() { 120 function stage6() {
109 chrome.experimental.settings.get(null, stage7); 121 this.get(null, stage7.bind(this));
110 } 122 }
111 function stage7(settings) { 123 function stage7(settings) {
112 chrome.test.assertEq({}, settings); 124 chrome.test.assertEq({}, settings);
113 succeed(); 125 succeed.call(this);
114 } 126 }
115 stage0(); 127 test(stage0);
116 }, 128 },
117 129
118 function setWhenOverwriting() { 130 function setWhenOverwriting() {
119 function stage0() { 131 function stage0() {
120 chrome.experimental.settings.set({ 132 this.set({
121 'foo' : 'bar', 133 'foo' : 'bar',
122 'baz' : 'qux', 134 'baz' : 'qux',
123 'hello': 'world' 135 'hello': 'world'
124 }, stage1); 136 }, stage1.bind(this));
125 } 137 }
126 function stage1() { 138 function stage1() {
127 chrome.experimental.settings.set({ 139 this.set({
128 'foo' : 'otherBar', 140 'foo' : 'otherBar',
129 'baz' : 'otherQux' 141 'baz' : 'otherQux'
130 }, stage2); 142 }, stage2.bind(this));
131 } 143 }
132 function stage2() { 144 function stage2() {
133 chrome.experimental.settings.get(null, stage3); 145 this.get(null, stage3.bind(this));
134 } 146 }
135 function stage3(settings) { 147 function stage3(settings) {
136 chrome.test.assertEq({ 148 chrome.test.assertEq({
137 'foo' : 'otherBar', 149 'foo' : 'otherBar',
138 'baz' : 'otherQux', 150 'baz' : 'otherQux',
139 'hello': 'world' 151 'hello': 'world'
140 }, settings); 152 }, settings);
141 chrome.experimental.settings.set({ 153 this.set({
142 'baz' : 'anotherQux', 154 'baz' : 'anotherQux',
143 'hello': 'otherWorld', 155 'hello': 'otherWorld',
144 'some' : 'value' 156 'some' : 'value'
145 }, stage4); 157 }, stage4.bind(this));
146 } 158 }
147 function stage4() { 159 function stage4() {
148 chrome.experimental.settings.get(null, stage5); 160 this.get(null, stage5.bind(this));
149 } 161 }
150 function stage5(settings) { 162 function stage5(settings) {
151 chrome.test.assertEq({ 163 chrome.test.assertEq({
152 'foo' : 'otherBar', 164 'foo' : 'otherBar',
153 'baz' : 'anotherQux', 165 'baz' : 'anotherQux',
154 'hello': 'otherWorld', 166 'hello': 'otherWorld',
155 'some' : 'value' 167 'some' : 'value'
156 }, settings); 168 }, settings);
157 succeed(); 169 succeed.call(this);
158 } 170 }
159 stage0(); 171 test(stage0);
160 }, 172 },
161 173
162 function clearWhenEmpty() { 174 function clearWhenEmpty() {
163 function stage0() { 175 function stage0() {
164 chrome.experimental.settings.clear(stage1); 176 this.clear(stage1.bind(this));
165 } 177 }
166 function stage1() { 178 function stage1() {
167 chrome.experimental.settings.get(null, stage2); 179 this.get(null, stage2.bind(this));
168 } 180 }
169 function stage2(settings) { 181 function stage2(settings) {
170 chrome.test.assertEq({}, settings); 182 chrome.test.assertEq({}, settings);
171 succeed(); 183 succeed.call(this);
172 } 184 }
173 stage0(); 185 test(stage0);
174 }, 186 },
175 187
176 function clearWhenNonempty() { 188 function clearWhenNonempty() {
177 function stage0() { 189 function stage0() {
178 chrome.experimental.settings.set({ 190 this.set({
179 'foo' : 'bar', 191 'foo' : 'bar',
180 'baz' : 'qux', 192 'baz' : 'qux',
181 'hello': 'world' 193 'hello': 'world'
182 }, stage1); 194 }, stage1.bind(this));
183 } 195 }
184 function stage1() { 196 function stage1() {
185 chrome.experimental.settings.clear(stage2); 197 this.clear(stage2.bind(this));
186 } 198 }
187 function stage2() { 199 function stage2() {
188 chrome.experimental.settings.get(null, stage3); 200 this.get(null, stage3.bind(this));
189 } 201 }
190 function stage3(settings) { 202 function stage3(settings) {
191 chrome.test.assertEq({}, settings); 203 chrome.test.assertEq({}, settings);
192 succeed(); 204 succeed.call(this);
193 } 205 }
194 stage0(); 206 test(stage0);
195 }, 207 },
196 208
197 function keysWithDots() { 209 function keysWithDots() {
198 function stage0() { 210 function stage0() {
199 chrome.experimental.settings.set({ 211 this.set({
200 'foo.bar' : 'baz', 212 'foo.bar' : 'baz',
201 'one' : {'two': 'three'} 213 'one' : {'two': 'three'}
202 }, stage1); 214 }, stage1.bind(this));
203 } 215 }
204 function stage1() { 216 function stage1() {
205 chrome.experimental.settings.get(['foo.bar', 'one'], stage2); 217 this.get(['foo.bar', 'one'], stage2.bind(this));
206 } 218 }
207 function stage2(settings) { 219 function stage2(settings) {
208 chrome.test.assertEq({ 220 chrome.test.assertEq({
209 'foo.bar' : 'baz', 221 'foo.bar' : 'baz',
210 'one' : {'two': 'three'} 222 'one' : {'two': 'three'}
211 }, settings); 223 }, settings);
212 chrome.experimental.settings.get('one.two', stage3); 224 this.get('one.two', stage3.bind(this));
213 } 225 }
214 function stage3(settings) { 226 function stage3(settings) {
215 chrome.test.assertEq({}, settings); 227 chrome.test.assertEq({}, settings);
216 chrome.experimental.settings.remove(['foo.bar', 'one.two'], stage4); 228 this.remove(['foo.bar', 'one.two'], stage4.bind(this));
217 } 229 }
218 function stage4() { 230 function stage4() {
219 chrome.experimental.settings.get(null, stage5); 231 this.get(null, stage5.bind(this));
220 } 232 }
221 function stage5(settings) { 233 function stage5(settings) {
222 chrome.test.assertEq({ 234 chrome.test.assertEq({
223 'one' : {'two': 'three'} 235 'one' : {'two': 'three'}
224 }, settings); 236 }, settings);
225 succeed(); 237 succeed.call(this);
226 } 238 }
227 stage0(); 239 test(stage0);
228 }, 240 },
229 241
230 function getWithDefaultValues() { 242 function getWithDefaultValues() {
231 function stage0() { 243 function stage0() {
232 chrome.experimental.settings.get({ 244 this.get({
233 'foo': 'defaultBar', 245 'foo': 'defaultBar',
234 'baz': [1, 2, 3] 246 'baz': [1, 2, 3]
235 }, stage1); 247 }, stage1.bind(this));
236 } 248 }
237 function stage1(settings) { 249 function stage1(settings) {
238 chrome.test.assertEq({ 250 chrome.test.assertEq({
239 'foo': 'defaultBar', 251 'foo': 'defaultBar',
240 'baz': [1, 2, 3] 252 'baz': [1, 2, 3]
241 }, settings); 253 }, settings);
242 chrome.experimental.settings.get(null, stage2); 254 this.get(null, stage2.bind(this));
243 } 255 }
244 function stage2(settings) { 256 function stage2(settings) {
245 chrome.test.assertEq({}, settings); 257 chrome.test.assertEq({}, settings);
246 chrome.experimental.settings.set({'foo': 'bar'}, stage3); 258 this.set({'foo': 'bar'}, stage3.bind(this));
247 } 259 }
248 function stage3() { 260 function stage3() {
249 chrome.experimental.settings.get({ 261 this.get({
250 'foo': 'defaultBar', 262 'foo': 'defaultBar',
251 'baz': [1, 2, 3] 263 'baz': [1, 2, 3]
252 }, stage4); 264 }, stage4.bind(this));
253 } 265 }
254 function stage4(settings) { 266 function stage4(settings) {
255 chrome.test.assertEq({ 267 chrome.test.assertEq({
256 'foo': 'bar', 268 'foo': 'bar',
257 'baz': [1, 2, 3] 269 'baz': [1, 2, 3]
258 }, settings); 270 }, settings);
259 chrome.experimental.settings.set({'baz': {}}, stage5); 271 this.set({'baz': {}}, stage5.bind(this));
260 } 272 }
261 function stage5() { 273 function stage5() {
262 chrome.experimental.settings.get({ 274 this.get({
263 'foo': 'defaultBar', 275 'foo': 'defaultBar',
264 'baz': [1, 2, 3] 276 'baz': [1, 2, 3]
265 }, stage6); 277 }, stage6.bind(this));
266 } 278 }
267 function stage6(settings) { 279 function stage6(settings) {
268 chrome.test.assertEq({ 280 chrome.test.assertEq({
269 'foo': 'bar', 281 'foo': 'bar',
270 'baz': {} 282 'baz': {}
271 }, settings); 283 }, settings);
272 chrome.experimental.settings.remove('foo', stage7); 284 this.remove('foo', stage7.bind(this));
273 } 285 }
274 function stage7() { 286 function stage7() {
275 chrome.experimental.settings.get({ 287 this.get({
276 'foo': 'defaultBar', 288 'foo': 'defaultBar',
277 'baz': [1, 2, 3] 289 'baz': [1, 2, 3]
278 }, stage8); 290 }, stage8.bind(this));
279 } 291 }
280 function stage8(settings) { 292 function stage8(settings) {
281 chrome.test.assertEq({ 293 chrome.test.assertEq({
282 'foo': 'defaultBar', 294 'foo': 'defaultBar',
283 'baz': {} 295 'baz': {}
284 }, settings); 296 }, settings);
285 succeed(); 297 succeed.call(this);
286 } 298 }
287 stage0(); 299 test(stage0);
288 }, 300 },
289 301
290 function throttling() { 302 function throttling() {
303 // We can only really test one of the namespaces since they will all get
304 // throttled together.
305 var api = chrome.experimental.settings.sync;
306
291 // Should get throttled after 1000 calls. 307 // Should get throttled after 1000 calls.
292 var maxRequests = 1001; 308 var maxRequests = 1001;
309
293 function next() { 310 function next() {
294 chrome.experimental.settings.clear((--maxRequests > 0) ? next : done); 311 api.clear((--maxRequests > 0) ? next : done);
295 } 312 }
296 function done() { 313 function done() {
297 chrome.test.assertEq( 314 chrome.test.assertEq(
298 "This request exceeds available quota.", 315 "This request exceeds available quota.",
299 chrome.extension.lastError.message); 316 chrome.extension.lastError.message);
300 succeed(); 317 chrome.test.succeed();
301 } 318 }
302 chrome.experimental.settings.clear(next); 319 api.clear(next);
303 } 320 }
304 ]); 321 ]);
305 </script> 322 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698