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(stage1); |
| 311 } |
| 312 function stage1(bytesInUse) { |
| 313 chrome.test.assertEq(0, bytesInUse); |
| 314 area.set({ a: 42 }, stage2); |
| 315 } |
| 316 function stage2() { |
| 317 area.getBytesInUse(stage3); |
| 318 } |
| 319 function stage3(bytesInUse) { |
| 320 chrome.test.assertEq(3, bytesInUse); |
| 321 chrome.test.succeed(); |
| 322 } |
| 323 area.clear(stage0); |
| 324 }, |
| 325 |
| 326 // NOTE: throttling test must come last, since each test runs with a single |
| 327 // quota. |
294 function throttling() { | 328 function throttling() { |
295 // We can only really test one of the namespaces since they will all get | 329 // We can only really test one of the namespaces since they will all get |
296 // throttled together. | 330 // throttled together. |
297 var api = chrome.storage.sync; | 331 var api = chrome.storage.sync; |
298 | 332 |
299 // Should get throttled after 1000 calls. | 333 // Should get throttled after 1000 calls (though in reality will be fewer |
| 334 // due to previous tests). |
300 var maxRequests = 1001; | 335 var maxRequests = 1001; |
301 | 336 |
302 function next() { | 337 function next() { |
303 api.clear((--maxRequests > 0) ? next : done); | 338 api.clear((--maxRequests > 0) ? next : done); |
304 } | 339 } |
305 function done() { | 340 function done() { |
306 chrome.test.assertEq( | 341 chrome.test.assertEq( |
307 "This request exceeds available quota.", | 342 "This request exceeds available quota.", |
308 chrome.extension.lastError.message); | 343 chrome.extension.lastError.message); |
309 chrome.test.succeed(); | 344 chrome.test.succeed(); |
310 } | 345 } |
311 api.clear(next); | 346 api.clear(next); |
312 } | 347 } |
| 348 |
313 ]); | 349 ]); |
OLD | NEW |