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

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

Issue 10890002: Make V8ValueConverter.FromV8Value behave similarly to JSON.stringify (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: no more function Created 8 years, 3 months 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 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 var assertEq = chrome.test.assertEq;
6 var assertTrue = chrome.test.assertTrue;
7 var succeed = chrome.test.succeed;
8
5 function test(stage0) { 9 function test(stage0) {
6 var apis = [ 10 var apis = [
7 chrome.storage.sync, 11 chrome.storage.sync,
8 chrome.storage.local 12 chrome.storage.local
9 ]; 13 ];
10 apis.forEach(function(api) { 14 apis.forEach(function(api) {
11 api.succeed = chrome.test.callbackPass(api.clear.bind(api)); 15 api.succeed = chrome.test.callbackPass(api.clear.bind(api));
12 stage0.call(api); 16 stage0.call(api);
13 }); 17 });
14 } 18 }
15 19
16 chrome.test.runTests([ 20 chrome.test.runTests([
17 function getWhenEmpty() { 21 function getWhenEmpty() {
18 function stage0() { 22 function stage0() {
19 this.get('foo', stage1.bind(this)); 23 this.get('foo', stage1.bind(this));
20 } 24 }
21 function stage1(settings) { 25 function stage1(settings) {
22 chrome.test.assertEq({}, settings); 26 assertEq({}, settings);
23 this.get(['foo', 'bar'], stage2.bind(this)); 27 this.get(['foo', 'bar'], stage2.bind(this));
24 } 28 }
25 function stage2(settings) { 29 function stage2(settings) {
26 chrome.test.assertEq({}, settings); 30 assertEq({}, settings);
27 this.get(undefined, stage3.bind(this)); 31 this.get(undefined, stage3.bind(this));
28 } 32 }
29 function stage3(settings) { 33 function stage3(settings) {
30 chrome.test.assertEq({}, settings); 34 assertEq({}, settings);
31 this.succeed(); 35 this.succeed();
32 } 36 }
33 test(stage0); 37 test(stage0);
34 }, 38 },
35 39
36 function getWhenNonempty() { 40 function getWhenNonempty() {
37 function stage0() { 41 function stage0() {
38 this.set({ 42 this.set({
39 'foo' : 'bar', 43 'foo' : 'bar',
40 'baz' : 'qux', 44 'baz' : 'qux',
41 'hello': 'world' 45 'hello': 'world'
42 }, stage1.bind(this)); 46 }, stage1.bind(this));
43 } 47 }
44 function stage1() { 48 function stage1() {
45 this.get(['foo', 'baz'], stage2.bind(this)); 49 this.get(['foo', 'baz'], stage2.bind(this));
46 } 50 }
47 function stage2(settings) { 51 function stage2(settings) {
48 chrome.test.assertEq({ 52 assertEq({
49 'foo': 'bar', 53 'foo': 'bar',
50 'baz': 'qux' 54 'baz': 'qux'
51 }, settings); 55 }, settings);
52 this.get(['nothing', 'baz', 'hello', 'ignore'], stage3.bind(this)); 56 this.get(['nothing', 'baz', 'hello', 'ignore'], stage3.bind(this));
53 } 57 }
54 function stage3(settings) { 58 function stage3(settings) {
55 chrome.test.assertEq({ 59 assertEq({
56 'baz' : 'qux', 60 'baz' : 'qux',
57 'hello': 'world' 61 'hello': 'world'
58 }, settings); 62 }, settings);
59 this.get(null, stage4.bind(this)); 63 this.get(null, stage4.bind(this));
60 } 64 }
61 function stage4(settings) { 65 function stage4(settings) {
62 chrome.test.assertEq({ 66 assertEq({
63 'foo' : 'bar', 67 'foo' : 'bar',
64 'baz' : 'qux', 68 'baz' : 'qux',
65 'hello': 'world' 69 'hello': 'world'
66 }, settings); 70 }, settings);
67 this.succeed(); 71 this.succeed();
68 } 72 }
69 test(stage0); 73 test(stage0);
70 }, 74 },
71 75
72 function removeWhenEmpty() { 76 function removeWhenEmpty() {
(...skipping 14 matching lines...) Expand all
87 'hello': 'world' 91 'hello': 'world'
88 }, stage1.bind(this)); 92 }, stage1.bind(this));
89 } 93 }
90 function stage1() { 94 function stage1() {
91 this.remove('foo', stage2.bind(this)); 95 this.remove('foo', stage2.bind(this));
92 } 96 }
93 function stage2() { 97 function stage2() {
94 this.get(null, stage3.bind(this)); 98 this.get(null, stage3.bind(this));
95 } 99 }
96 function stage3(settings) { 100 function stage3(settings) {
97 chrome.test.assertEq({ 101 assertEq({
98 'baz' : 'qux', 102 'baz' : 'qux',
99 'hello': 'world' 103 'hello': 'world'
100 }, settings); 104 }, settings);
101 this.remove(['baz', 'nothing'], stage4.bind(this)); 105 this.remove(['baz', 'nothing'], stage4.bind(this));
102 } 106 }
103 function stage4() { 107 function stage4() {
104 this.get(null, stage5.bind(this)); 108 this.get(null, stage5.bind(this));
105 } 109 }
106 function stage5(settings) { 110 function stage5(settings) {
107 chrome.test.assertEq({ 111 assertEq({
108 'hello': 'world' 112 'hello': 'world'
109 }, settings); 113 }, settings);
110 this.remove('hello', stage6.bind(this)); 114 this.remove('hello', stage6.bind(this));
111 } 115 }
112 function stage6() { 116 function stage6() {
113 this.get(null, stage7.bind(this)); 117 this.get(null, stage7.bind(this));
114 } 118 }
115 function stage7(settings) { 119 function stage7(settings) {
116 chrome.test.assertEq({}, settings); 120 assertEq({}, settings);
117 this.succeed(); 121 this.succeed();
118 } 122 }
119 test(stage0); 123 test(stage0);
120 }, 124 },
121 125
122 function setWhenOverwriting() { 126 function setWhenOverwriting() {
123 function stage0() { 127 function stage0() {
124 this.set({ 128 this.set({
125 'foo' : 'bar', 129 'foo' : 'bar',
126 'baz' : 'qux', 130 'baz' : 'qux',
127 'hello': 'world' 131 'hello': 'world'
128 }, stage1.bind(this)); 132 }, stage1.bind(this));
129 } 133 }
130 function stage1() { 134 function stage1() {
131 this.set({ 135 this.set({
132 'foo' : 'otherBar', 136 'foo' : 'otherBar',
133 'baz' : 'otherQux' 137 'baz' : 'otherQux'
134 }, stage2.bind(this)); 138 }, stage2.bind(this));
135 } 139 }
136 function stage2() { 140 function stage2() {
137 this.get(null, stage3.bind(this)); 141 this.get(null, stage3.bind(this));
138 } 142 }
139 function stage3(settings) { 143 function stage3(settings) {
140 chrome.test.assertEq({ 144 assertEq({
141 'foo' : 'otherBar', 145 'foo' : 'otherBar',
142 'baz' : 'otherQux', 146 'baz' : 'otherQux',
143 'hello': 'world' 147 'hello': 'world'
144 }, settings); 148 }, settings);
145 this.set({ 149 this.set({
146 'baz' : 'anotherQux', 150 'baz' : 'anotherQux',
147 'hello': 'otherWorld', 151 'hello': 'otherWorld',
148 'some' : 'value' 152 'some' : 'value'
149 }, stage4.bind(this)); 153 }, stage4.bind(this));
150 } 154 }
151 function stage4() { 155 function stage4() {
152 this.get(null, stage5.bind(this)); 156 this.get(null, stage5.bind(this));
153 } 157 }
154 function stage5(settings) { 158 function stage5(settings) {
155 chrome.test.assertEq({ 159 assertEq({
156 'foo' : 'otherBar', 160 'foo' : 'otherBar',
157 'baz' : 'anotherQux', 161 'baz' : 'anotherQux',
158 'hello': 'otherWorld', 162 'hello': 'otherWorld',
159 'some' : 'value' 163 'some' : 'value'
160 }, settings); 164 }, settings);
161 this.succeed(); 165 this.succeed();
162 } 166 }
163 test(stage0); 167 test(stage0);
164 }, 168 },
165 169
166 function clearWhenEmpty() { 170 function clearWhenEmpty() {
167 function stage0() { 171 function stage0() {
168 this.clear(stage1.bind(this)); 172 this.clear(stage1.bind(this));
169 } 173 }
170 function stage1() { 174 function stage1() {
171 this.get(null, stage2.bind(this)); 175 this.get(null, stage2.bind(this));
172 } 176 }
173 function stage2(settings) { 177 function stage2(settings) {
174 chrome.test.assertEq({}, settings); 178 assertEq({}, settings);
175 this.succeed(); 179 this.succeed();
176 } 180 }
177 test(stage0); 181 test(stage0);
178 }, 182 },
179 183
180 function clearWhenNonempty() { 184 function clearWhenNonempty() {
181 function stage0() { 185 function stage0() {
182 this.set({ 186 this.set({
183 'foo' : 'bar', 187 'foo' : 'bar',
184 'baz' : 'qux', 188 'baz' : 'qux',
185 'hello': 'world' 189 'hello': 'world'
186 }, stage1.bind(this)); 190 }, stage1.bind(this));
187 } 191 }
188 function stage1() { 192 function stage1() {
189 this.clear(stage2.bind(this)); 193 this.clear(stage2.bind(this));
190 } 194 }
191 function stage2() { 195 function stage2() {
192 this.get(null, stage3.bind(this)); 196 this.get(null, stage3.bind(this));
193 } 197 }
194 function stage3(settings) { 198 function stage3(settings) {
195 chrome.test.assertEq({}, settings); 199 assertEq({}, settings);
196 this.succeed(); 200 this.succeed();
197 } 201 }
198 test(stage0); 202 test(stage0);
199 }, 203 },
200 204
201 function keysWithDots() { 205 function keysWithDots() {
202 function stage0() { 206 function stage0() {
203 this.set({ 207 this.set({
204 'foo.bar' : 'baz', 208 'foo.bar' : 'baz',
205 'one' : {'two': 'three'} 209 'one' : {'two': 'three'}
206 }, stage1.bind(this)); 210 }, stage1.bind(this));
207 } 211 }
208 function stage1() { 212 function stage1() {
209 this.get(['foo.bar', 'one'], stage2.bind(this)); 213 this.get(['foo.bar', 'one'], stage2.bind(this));
210 } 214 }
211 function stage2(settings) { 215 function stage2(settings) {
212 chrome.test.assertEq({ 216 assertEq({
213 'foo.bar' : 'baz', 217 'foo.bar' : 'baz',
214 'one' : {'two': 'three'} 218 'one' : {'two': 'three'}
215 }, settings); 219 }, settings);
216 this.get('one.two', stage3.bind(this)); 220 this.get('one.two', stage3.bind(this));
217 } 221 }
218 function stage3(settings) { 222 function stage3(settings) {
219 chrome.test.assertEq({}, settings); 223 assertEq({}, settings);
220 this.remove(['foo.bar', 'one.two'], stage4.bind(this)); 224 this.remove(['foo.bar', 'one.two'], stage4.bind(this));
221 } 225 }
222 function stage4() { 226 function stage4() {
223 this.get(null, stage5.bind(this)); 227 this.get(null, stage5.bind(this));
224 } 228 }
225 function stage5(settings) { 229 function stage5(settings) {
226 chrome.test.assertEq({ 230 assertEq({
227 'one' : {'two': 'three'} 231 'one' : {'two': 'three'}
228 }, settings); 232 }, settings);
229 this.succeed(); 233 this.succeed();
230 } 234 }
231 test(stage0); 235 test(stage0);
232 }, 236 },
233 237
234 function getWithDefaultValues() { 238 function getWithDefaultValues() {
235 function stage0() { 239 function stage0() {
236 this.get({ 240 this.get({
237 'foo': 'defaultBar', 241 'foo': 'defaultBar',
238 'baz': [1, 2, 3] 242 'baz': [1, 2, 3]
239 }, stage1.bind(this)); 243 }, stage1.bind(this));
240 } 244 }
241 function stage1(settings) { 245 function stage1(settings) {
242 chrome.test.assertEq({ 246 assertEq({
243 'foo': 'defaultBar', 247 'foo': 'defaultBar',
244 'baz': [1, 2, 3] 248 'baz': [1, 2, 3]
245 }, settings); 249 }, settings);
246 this.get(null, stage2.bind(this)); 250 this.get(null, stage2.bind(this));
247 } 251 }
248 function stage2(settings) { 252 function stage2(settings) {
249 chrome.test.assertEq({}, settings); 253 assertEq({}, settings);
250 this.set({'foo': 'bar'}, stage3.bind(this)); 254 this.set({'foo': 'bar'}, stage3.bind(this));
251 } 255 }
252 function stage3() { 256 function stage3() {
253 this.get({ 257 this.get({
254 'foo': 'defaultBar', 258 'foo': 'defaultBar',
255 'baz': [1, 2, 3] 259 'baz': [1, 2, 3]
256 }, stage4.bind(this)); 260 }, stage4.bind(this));
257 } 261 }
258 function stage4(settings) { 262 function stage4(settings) {
259 chrome.test.assertEq({ 263 assertEq({
260 'foo': 'bar', 264 'foo': 'bar',
261 'baz': [1, 2, 3] 265 'baz': [1, 2, 3]
262 }, settings); 266 }, settings);
263 this.set({'baz': {}}, stage5.bind(this)); 267 this.set({'baz': {}}, stage5.bind(this));
264 } 268 }
265 function stage5() { 269 function stage5() {
266 this.get({ 270 this.get({
267 'foo': 'defaultBar', 271 'foo': 'defaultBar',
268 'baz': [1, 2, 3] 272 'baz': [1, 2, 3]
269 }, stage6.bind(this)); 273 }, stage6.bind(this));
270 } 274 }
271 function stage6(settings) { 275 function stage6(settings) {
272 chrome.test.assertEq({ 276 assertEq({
273 'foo': 'bar', 277 'foo': 'bar',
274 'baz': {} 278 'baz': {}
275 }, settings); 279 }, settings);
276 this.remove('foo', stage7.bind(this)); 280 this.remove('foo', stage7.bind(this));
277 } 281 }
278 function stage7() { 282 function stage7() {
279 this.get({ 283 this.get({
280 'foo': 'defaultBar', 284 'foo': 'defaultBar',
281 'baz': [1, 2, 3] 285 'baz': [1, 2, 3]
282 }, stage8.bind(this)); 286 }, stage8.bind(this));
283 } 287 }
284 function stage8(settings) { 288 function stage8(settings) {
285 chrome.test.assertEq({ 289 assertEq({
286 'foo': 'defaultBar', 290 'foo': 'defaultBar',
287 'baz': {} 291 'baz': {}
288 }, settings); 292 }, settings);
289 this.succeed(); 293 this.succeed();
290 } 294 }
291 test(stage0); 295 test(stage0);
292 }, 296 },
293 297
294 298
295 function quota() { 299 function quota() {
296 // Just check that the constants are defined; no need to be forced to 300 // Just check that the constants are defined; no need to be forced to
297 // update them here as well if/when they change. 301 // update them here as well if/when they change.
298 chrome.test.assertTrue(chrome.storage.sync.QUOTA_BYTES > 0); 302 assertTrue(chrome.storage.sync.QUOTA_BYTES > 0);
299 chrome.test.assertTrue(chrome.storage.sync.QUOTA_BYTES_PER_ITEM > 0); 303 assertTrue(chrome.storage.sync.QUOTA_BYTES_PER_ITEM > 0);
300 chrome.test.assertTrue(chrome.storage.sync.MAX_ITEMS > 0); 304 assertTrue(chrome.storage.sync.MAX_ITEMS > 0);
301 305
302 chrome.test.assertTrue(chrome.storage.local.QUOTA_BYTES > 0); 306 assertTrue(chrome.storage.local.QUOTA_BYTES > 0);
303 chrome.test.assertEq('undefined', 307 assertEq('undefined', typeof chrome.storage.local.QUOTA_BYTES_PER_ITEM);
304 typeof chrome.storage.local.QUOTA_BYTES_PER_ITEM); 308 assertEq('undefined', typeof chrome.storage.local.MAX_ITEMS);
305 chrome.test.assertEq('undefined',
306 typeof chrome.storage.local.MAX_ITEMS);
307 309
308 var area = chrome.storage.sync; 310 var area = chrome.storage.sync;
309 function stage0() { 311 function stage0() {
310 area.getBytesInUse(null, stage1); 312 area.getBytesInUse(null, stage1);
311 } 313 }
312 function stage1(bytesInUse) { 314 function stage1(bytesInUse) {
313 chrome.test.assertEq(0, bytesInUse); 315 assertEq(0, bytesInUse);
314 area.set({ a: 42, b: 43, c: 44 }, stage2); 316 area.set({ a: 42, b: 43, c: 44 }, stage2);
315 } 317 }
316 function stage2() { 318 function stage2() {
317 area.getBytesInUse(null, stage3); 319 area.getBytesInUse(null, stage3);
318 } 320 }
319 function stage3(bytesInUse) { 321 function stage3(bytesInUse) {
320 chrome.test.assertEq(9, bytesInUse); 322 assertEq(9, bytesInUse);
321 area.getBytesInUse('a', stage4); 323 area.getBytesInUse('a', stage4);
322 } 324 }
323 function stage4(bytesInUse) { 325 function stage4(bytesInUse) {
324 chrome.test.assertEq(3, bytesInUse); 326 assertEq(3, bytesInUse);
325 area.getBytesInUse(['a', 'b'], stage5); 327 area.getBytesInUse(['a', 'b'], stage5);
326 } 328 }
327 function stage5(bytesInUse) { 329 function stage5(bytesInUse) {
328 chrome.test.assertEq(6, bytesInUse); 330 assertEq(6, bytesInUse);
329 chrome.test.succeed(); 331 succeed();
330 } 332 }
331 area.clear(stage0); 333 area.clear(stage0);
332 }, 334 },
335
336 function nullsInArgs() {
337 var area = chrome.storage.local;
338 function stage0() {
339 area.get({
340 foo: 'foo',
341 bar: null,
342 baz: undefined
343 }, stage1);
344 }
345 function stage1(values) {
346 assertEq({
347 foo: 'foo',
348 bar: null,
349 }, values);
350 area.set({
351 foo: 'foo',
352 bar: null,
353 baz: undefined
354 }, area.get.bind(area, stage2));
355 }
356 function stage2(values) {
357 assertEq({
358 foo: 'foo',
359 bar: null,
360 }, values);
361 succeed();
362 }
363 area.clear(stage0);
364 },
333 365
334 // NOTE: throttling test must come last, since each test runs with a single 366 // NOTE: throttling test must come last, since each test runs with a single
335 // quota. 367 // quota.
336 function throttling() { 368 function throttling() {
337 // Test script is as so: 369 // Test script is as so:
338 // 1 - storage.local shouldn't be exceeded. 370 // 1 - storage.local shouldn't be exceeded.
339 // 2 - storage.sync should be exceeded. 371 // 2 - storage.sync should be exceeded.
340 // 3 - storage.local still shouldn't be exceeded. 372 // 3 - storage.local still shouldn't be exceeded.
341 // 4 - storage.sync should still be exceeded. 373 // 4 - storage.sync should still be exceeded.
342 // 374 //
(...skipping 16 matching lines...) Expand all
359 var quotaError = 391 var quotaError =
360 "This request exceeds the MAX_WRITE_OPERATIONS_PER_HOUR quota."; 392 "This request exceeds the MAX_WRITE_OPERATIONS_PER_HOUR quota.";
361 393
362 clearNTimes(local, 1001, test.callbackPass(function() { 394 clearNTimes(local, 1001, test.callbackPass(function() {
363 clearNTimes(sync, 1001, test.callbackFail(quotaError, function() { 395 clearNTimes(sync, 1001, test.callbackFail(quotaError, function() {
364 clearNTimes(local, 1, test.callbackPass(function() { 396 clearNTimes(local, 1, test.callbackPass(function() {
365 clearNTimes(sync, 1, test.callbackFail(quotaError, test.succeed)); 397 clearNTimes(sync, 1, test.callbackFail(quotaError, test.succeed));
366 })); 398 }));
367 })); 399 }));
368 })); 400 }));
369 } 401 },
370 ]); 402 ]);
OLDNEW
« no previous file with comments | « chrome/renderer/resources/extensions/storage_custom_bindings.js ('k') | content/public/renderer/v8_value_converter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698