OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 var fileEntry; |
| 6 var fileSystem; |
| 7 var usageBeforeWrite; |
| 8 var testData = "12345"; |
| 9 |
| 10 var testStep = [ |
| 11 function () { |
| 12 chrome.syncFileSystem.requestFileSystem('drive', testStep.shift()); |
| 13 }, |
| 14 // Create empty file. |
| 15 function(fs) { |
| 16 fileSystem = fs; |
| 17 fileSystem.root.getFile('Test.txt', {create: true}, testStep.shift(), |
| 18 errorHandler); |
| 19 }, |
| 20 function(entry) { |
| 21 fileEntry = entry; |
| 22 testStep.shift()(); |
| 23 }, |
| 24 // Record usage before write. |
| 25 function() { |
| 26 chrome.syncFileSystem.getUsageAndQuota(fileSystem, testStep.shift()); |
| 27 }, |
| 28 function(storageInfo) { |
| 29 usageBeforeWrite = storageInfo.usage_bytes; |
| 30 testStep.shift()(); |
| 31 }, |
| 32 // Write a known number of bytes. |
| 33 function() { |
| 34 fileEntry.createWriter(testStep.shift(), errorHandler); |
| 35 }, |
| 36 function (fileWriter) { |
| 37 fileWriter.onwriteend = function(e) { |
| 38 testStep.shift()(); |
| 39 }; |
| 40 fileWriter.onerror = function(e) { |
| 41 chrome.test.fail('Write failed: ' + e.toString()); |
| 42 }; |
| 43 fileWriter.seek(fileWriter.length); |
| 44 var blob = new Blob([testData], {type: "text/plain"}); |
| 45 fileWriter.write(blob); |
| 46 }, |
| 47 // Check the meta data for updated usage. |
| 48 function() { |
| 49 fileEntry.getMetadata(testStep.shift(), errorHandler); |
| 50 }, |
| 51 function (metadata) { |
| 52 chrome.test.assertEq(testData.length, metadata.size); |
| 53 testStep.shift()(); |
| 54 }, |
| 55 // Check global usage was updated. |
| 56 function() { |
| 57 chrome.syncFileSystem.getUsageAndQuota(fileSystem, testStep.shift()); |
| 58 }, |
| 59 function(storageInfo) { |
| 60 var usageAfterWrite = storageInfo.usage_bytes; |
| 61 chrome.test.assertEq(testData.length, usageAfterWrite - usageBeforeWrite); |
| 62 chrome.test.succeed(); |
| 63 } |
| 64 ]; |
| 65 |
| 66 function errorHandler() { |
| 67 chrome.test.fail(); |
| 68 } |
| 69 |
| 70 chrome.test.runTests([ |
| 71 testStep[0] |
| 72 ]); |
| 73 |
OLD | NEW |