Chromium Code Reviews| Index: chrome/test/data/extensions/api_test/sync_file_system/write_file_then_get_usage/test.js |
| diff --git a/chrome/test/data/extensions/api_test/sync_file_system/write_file_then_get_usage/test.js b/chrome/test/data/extensions/api_test/sync_file_system/write_file_then_get_usage/test.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..331ff06f4c5704a73bbc5c1c4ff1fefbe18e4562 |
| --- /dev/null |
| +++ b/chrome/test/data/extensions/api_test/sync_file_system/write_file_then_get_usage/test.js |
| @@ -0,0 +1,71 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +var fileEntry; |
| +var usageBeforeWrite; |
| +var testData = "12345"; |
| + |
| +var testStep = [ |
| + function () { |
| + chrome.syncFileSystem.requestFileSystem('drive', testStep.shift()); |
| + }, |
| + // Create empty file. |
| + function(fileSystem) { |
| + fileSystem.root.getFile('Test.txt', {create: true}, testStep.shift(), |
| + errorHandler); |
| + }, |
| + function(entry) { |
| + fileEntry = entry; |
| + testStep.shift()(); |
| + }, |
| + // Record usage before write. |
| + function() { |
| + chrome.syncFileSystem.getUsageAndQuota('drive', testStep.shift()); |
| + }, |
| + function(storageInfo) { |
| + usageBeforeWrite = storageInfo.usage_bytes; |
| + testStep.shift()(); |
| + }, |
| + // Write a known number of bytes. |
| + function() { |
| + fileEntry.createWriter(testStep.shift(), errorHandler); |
| + }, |
| + function (fileWriter) { |
| + fileWriter.onwriteend = function(e) { |
| + testStep.shift()(); |
| + }; |
| + fileWriter.onerror = function(e) { |
| + chrome.test.fail('Write failed: ' + e.toString()); |
| + }; |
| + fileWriter.seek(fileWriter.length); |
| + var blob = new Blob([testData], {type: "text/plain"}); |
| + fileWriter.write(blob); |
| + }, |
| + // Check the meta data for updated usage. |
| + function() { |
| + fileEntry.getMetadata(testStep.shift(), errorHandler); |
| + }, |
| + function (metadata) { |
| + chrome.test.assertEq(testData.length, metadata.size); |
| + testStep.shift()(); |
| + }, |
| + // Check global usage was updated. |
| + function() { |
| + chrome.syncFileSystem.getUsageAndQuota('drive', testStep.shift()); |
| + }, |
| + function(storageInfo) { |
| + var usageAfterWrite = storageInfo.usage_bytes; |
| + chrome.test.assertEq(testData.length, usageAfterWrite - usageBeforeWrite); |
| + chrome.test.succeed(); |
| + } |
| +]; |
| + |
| +function errorHandler() { |
| + chrome.test.fail(); |
| +} |
| + |
| +chrome.test.runTests([ |
| + chrome.test.callbackPass(testStep[0]) |
|
benwells
2012/11/10 10:22:56
Why are you using chrome.test.callbackPass here, t
calvinlo
2012/11/12 04:48:07
Sorry Ben. I'm kinda confused. When I was playing
|
| +]); |
| + |