OLD | NEW |
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 function test(stage0) { | 5 function test(stage0) { |
6 var apis = [ | 6 var apis = [ |
7 chrome.storage.sync, | 7 chrome.storage.sync, |
8 chrome.storage.local | 8 chrome.storage.local |
9 ]; | 9 ]; |
10 apis.forEach(function(api) { | 10 apis.forEach(function(api) { |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 function stage8(settings) { | 284 function stage8(settings) { |
285 chrome.test.assertEq({ | 285 chrome.test.assertEq({ |
286 'foo': 'defaultBar', | 286 'foo': 'defaultBar', |
287 'baz': {} | 287 'baz': {} |
288 }, settings); | 288 }, settings); |
289 this.succeed(); | 289 this.succeed(); |
290 } | 290 } |
291 test(stage0); | 291 test(stage0); |
292 }, | 292 }, |
293 | 293 |
| 294 |
| 295 function quota() { |
| 296 // Just check that the constants are defined; no need to be forced to |
| 297 // update them here as well if/when they change. |
| 298 chrome.test.assertTrue(chrome.storage.sync.QUOTA_BYTES > 0); |
| 299 chrome.test.assertTrue(chrome.storage.sync.QUOTA_BYTES_PER_ITEM > 0); |
| 300 chrome.test.assertTrue(chrome.storage.sync.MAX_ITEMS > 0); |
| 301 |
| 302 chrome.test.assertTrue(chrome.storage.local.QUOTA_BYTES > 0); |
| 303 chrome.test.assertEq('undefined', |
| 304 typeof chrome.storage.local.QUOTA_BYTES_PER_ITEM); |
| 305 chrome.test.assertEq('undefined', |
| 306 typeof chrome.storage.local.MAX_ITEMS); |
| 307 |
| 308 var area = chrome.storage.sync; |
| 309 function stage0() { |
| 310 area.getBytesInUse(null, stage1); |
| 311 } |
| 312 function stage1(bytesInUse) { |
| 313 chrome.test.assertEq(0, bytesInUse); |
| 314 area.set({ a: 42, b: 43, c: 44 }, stage2); |
| 315 } |
| 316 function stage2() { |
| 317 area.getBytesInUse(null, stage3); |
| 318 } |
| 319 function stage3(bytesInUse) { |
| 320 chrome.test.assertEq(9, bytesInUse); |
| 321 area.getBytesInUse('a', stage4); |
| 322 } |
| 323 function stage4(bytesInUse) { |
| 324 chrome.test.assertEq(3, bytesInUse); |
| 325 area.getBytesInUse(['a', 'b'], stage5); |
| 326 } |
| 327 function stage5(bytesInUse) { |
| 328 chrome.test.assertEq(6, bytesInUse); |
| 329 chrome.test.succeed(); |
| 330 } |
| 331 area.clear(stage0); |
| 332 }, |
| 333 |
| 334 // NOTE: throttling test must come last, since each test runs with a single |
| 335 // quota. |
294 function throttling() { | 336 function throttling() { |
295 // We can only really test one of the namespaces since they will all get | 337 // We can only really test one of the namespaces since they will all get |
296 // throttled together. | 338 // throttled together. |
297 var api = chrome.storage.sync; | 339 var api = chrome.storage.sync; |
298 | 340 |
299 // Should get throttled after 1000 calls. | 341 // Should get throttled after 1000 calls (though in reality will be fewer |
| 342 // due to previous tests). |
300 var maxRequests = 1001; | 343 var maxRequests = 1001; |
301 | 344 |
302 function next() { | 345 function next() { |
303 api.clear((--maxRequests > 0) ? next : done); | 346 api.clear((--maxRequests > 0) ? next : done); |
304 } | 347 } |
305 function done() { | 348 function done() { |
306 chrome.test.assertEq( | 349 chrome.test.assertEq( |
307 "This request exceeds available quota.", | 350 "This request exceeds available quota.", |
308 chrome.extension.lastError.message); | 351 chrome.extension.lastError.message); |
309 chrome.test.succeed(); | 352 chrome.test.succeed(); |
310 } | 353 } |
311 api.clear(next); | 354 api.clear(next); |
312 } | 355 } |
| 356 |
313 ]); | 357 ]); |
OLD | NEW |