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

Unified Diff: chrome/test/data/extensions/api_test/extfs/test.js

Issue 16439016: extfs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 6 months 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
« no previous file with comments | « chrome/test/data/extensions/api_test/extfs/manifest.json ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/data/extensions/api_test/extfs/test.js
diff --git a/chrome/test/data/extensions/api_test/extfs/test.js b/chrome/test/data/extensions/api_test/extfs/test.js
new file mode 100644
index 0000000000000000000000000000000000000000..7603bbe608beb25fe97950854e035ddd6e3f2431
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/extfs/test.js
@@ -0,0 +1,120 @@
+// Copyright 2013 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 globalFileSystem;
+var globalEntries = [];
+
+function errorCodeToString(code) {
+ var message = '';
+
+ switch (code) {
+ case FileError.QUOTA_EXCEEDED_ERR:
+ return 'QUOTA_EXCEEDED_ERR';
+ case FileError.NOT_FOUND_ERR:
+ return 'NOT_FOUND_ERR';
+ case FileError.SECURITY_ERR:
+ return 'SECURITY_ERR';
+ case FileError.INVALID_MODIFICATION_ERR:
+ return 'INVALID_MODIFICATION_ERR';
+ case FileError.INVALID_STATE_ERR:
+ return 'INVALID_STATE_ERR';
+ };
+
+ return 'Unknown Error';
+}
+
+var globalMountPointName = 'testfs';
+
+chrome.test.runTests([
+ // Request the access to the file system.
+ function requestFileSystem() {
+ chrome.fileBrowserPrivate.requestFileSystem(
+ function(fileSystem) {
+ chrome.test.assertTrue(!!fileSystem);
+ chrome.test.succeed();
+ globalFileSystem = fileSystem;
+ }
+ );
+ },
+
+ // TODO(satorux): It's not guaranteed that the 'testfs' mount point is
+ // already added. Should fix the race.
+
+ // Collect all entries in the file system recursively.
+ function collectEntries() {
+ var root = globalFileSystem.root;
+ // 'extfs' is mounted as 'extfs' in the root directory.
+ // Get an entry for it.
+ root.getDirectory(
+ globalMountPointName,
+ { create: false },
+ function(entry) {
+ var numInflight = 1;
+ // Try read the tree recursively.
+ function onEntries(entries) {
+ for (var i = 0; i < entries.length; i++) {
+ globalEntries.push(entries[i]);
+ if (entries[i].isDirectory) {
+ var reader = entries[i].createReader();
+ numInflight++;
+ reader.readEntries(onEntries);
+ }
+ }
+ numInflight--;
+ if (numInflight == 0)
+ chrome.test.succeed();
+ }
+ var reader = entry.createReader();
+ reader.readEntries(onEntries);
+ },
+ function(error) {
+ console.log('Failed to get directory entry: ' +
+ errorCodeToString(error.code));
+ chrome.test.fail();
+ });
+ },
+
+ // Prints all file names. This will print:
+ // Path: /extfs/file1
+ // Path: /extfs/dir1
+ // Path: /extfs/dir1/file2
+ // Path: /extfs/dir1/file3
+ // Path: /extfs/dir1/dir2
+ // Path: /extfs/dir1/dir2/file4
+ // Path: /extfs/dir1/dir2/dir3
+ function printFullPaths() {
+ for (var i = 0; i < globalEntries.length; i++) {
+ console.log('Path: ' + globalEntries[i].fullPath);
+ }
+ chrome.test.succeed();
+ },
+
+ // Print contents of all files.
+ function printFileContents() {
+ var numInflight = 0;
+ for (var i = 0; i < globalEntries.length; i++) {
+ var entry = globalEntries[i];
+ if (entry.isDirectory)
+ continue;
+
+ numInflight++;
+ entry.file(
+ function(file) {
+ var reader = new FileReader();
+ reader.onloadend = function(e) {
+ console.log(entry.fullPath + ': ' + this.result);
+ numInflight--;
+ if (numInflight == 0)
+ chrome.test.succeed();
+ }
+ reader.readAsText(file);
+ },
+ function(error) {
+ console.log('Failed to get the file object: ' +
+ errorCodeToString(error.code));
+ chrome.test.fail();
+ });
+ }
+ },
+]);
« no previous file with comments | « chrome/test/data/extensions/api_test/extfs/manifest.json ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698