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

Unified 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 side-by-side diff with in-line comments
Download patch
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])
+]);
+

Powered by Google App Engine
This is Rietveld 408576698