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