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..dbc440b90b875876d2e45274c1f881007a34843c |
| --- /dev/null |
| +++ b/chrome/test/data/extensions/api_test/sync_file_system/write_file_then_get_usage/test.js |
| @@ -0,0 +1,74 @@ |
| +// 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 usageAfterWrite; |
| +var testData = "12345"; |
| + |
| +var testStep = [ |
| + function () { |
| + chrome.syncFileSystem.requestFileSystem('drive', testStep.shift()); |
| + }, |
| + // Create empty file |
|
kinuko
2012/11/09 07:24:49
nit: please end comments with '.' (here and below)
calvinlo
2012/11/09 08:06:14
Done.
|
| + function(fileSystem) { |
| + fileSystem.root.getFile('Test.txt', {create: true}, testStep.shift(), |
| + errorHandler); |
| + }, |
| + function(fe) { |
| + fileEntry = fe; |
| + 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); |
|
kinuko
2012/11/09 07:24:49
nit: it might be intentional (if so it's ok) but w
calvinlo
2012/11/09 08:06:14
This was intentional so that the comment // Write
|
| + }, |
| + 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.assertTrue(metadata.size > 0); |
|
kinuko
2012/11/09 07:24:49
...or assertEq with testData.length?
(metadata.siz
calvinlo
2012/11/09 08:06:14
Done.
|
| + testStep.shift()(); |
| + }, |
| + // Check global usage was updated |
| + function() { |
| + chrome.syncFileSystem.getUsageAndQuota('drive', testStep.shift()); |
| + }, |
| + function(storageInfo) { |
| + 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]) |
| +]); |
| + |