| 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 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 function stage5(bytesInUse) { | 327 function stage5(bytesInUse) { |
| 328 chrome.test.assertEq(6, bytesInUse); | 328 chrome.test.assertEq(6, bytesInUse); |
| 329 chrome.test.succeed(); | 329 chrome.test.succeed(); |
| 330 } | 330 } |
| 331 area.clear(stage0); | 331 area.clear(stage0); |
| 332 }, | 332 }, |
| 333 | 333 |
| 334 // NOTE: throttling test must come last, since each test runs with a single | 334 // NOTE: throttling test must come last, since each test runs with a single |
| 335 // quota. | 335 // quota. |
| 336 function throttling() { | 336 function throttling() { |
| 337 // We can only really test one of the namespaces since they will all get | 337 // Test script is as so: |
| 338 // throttled together. | 338 // 1 - storage.local shouldn't be exceeded. |
| 339 var api = chrome.storage.sync; | 339 // 2 - storage.sync should be exceeded. |
| 340 // 3 - storage.local still shouldn't be exceeded. |
| 341 // 4 - storage.sync should still be exceeded. |
| 342 // |
| 343 // In general, things should get throttled after 1000 calls (though in |
| 344 // reality will be fewer due to previous tests). |
| 340 | 345 |
| 341 // Should get throttled after 1000 calls (though in reality will be fewer | 346 function clearNTimes(area, n, whenDone) { |
| 342 // due to previous tests). | 347 if (n <= 0) { |
| 343 var maxRequests = 1001; | 348 whenDone(); |
| 349 } else { |
| 350 area.clear(function() { |
| 351 clearNTimes(area, n - 1, whenDone); |
| 352 }); |
| 353 } |
| 354 } |
| 344 | 355 |
| 345 function next() { | 356 var local = chrome.storage.local; |
| 346 api.clear((--maxRequests > 0) ? next : done); | 357 var sync = chrome.storage.sync; |
| 347 } | 358 var test = chrome.test; |
| 348 function done() { | 359 var quotaError = "This request exceeds available quota."; |
| 349 chrome.test.assertEq( | 360 |
| 350 "This request exceeds available quota.", | 361 clearNTimes(local, 1001, test.callbackPass(function() { |
| 351 chrome.extension.lastError.message); | 362 clearNTimes(sync, 1001, test.callbackFail(quotaError, function() { |
| 352 chrome.test.succeed(); | 363 clearNTimes(local, 1, test.callbackPass(function() { |
| 353 } | 364 clearNTimes(sync, 1, test.callbackFail(quotaError, test.succeed)); |
| 354 api.clear(next); | 365 })); |
| 366 })); |
| 367 })); |
| 355 } | 368 } |
| 356 | |
| 357 ]); | 369 ]); |
| OLD | NEW |