Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(113)

Side by Side Diff: chrome/test/data/extensions/api_test/sync_file_system/write_file_then_get_usage/test.js

Issue 11368160: Added combined test for Syncable File System to write file and then get that usage gets updated. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: updated Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698