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