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

Side by Side 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, 5 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/test/data/extensions/api_test/extfs/manifest.json ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2013 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 globalFileSystem;
6 var globalEntries = [];
7
8 function errorCodeToString(code) {
9 var message = '';
10
11 switch (code) {
12 case FileError.QUOTA_EXCEEDED_ERR:
13 return 'QUOTA_EXCEEDED_ERR';
14 case FileError.NOT_FOUND_ERR:
15 return 'NOT_FOUND_ERR';
16 case FileError.SECURITY_ERR:
17 return 'SECURITY_ERR';
18 case FileError.INVALID_MODIFICATION_ERR:
19 return 'INVALID_MODIFICATION_ERR';
20 case FileError.INVALID_STATE_ERR:
21 return 'INVALID_STATE_ERR';
22 };
23
24 return 'Unknown Error';
25 }
26
27 var globalMountPointName = 'testfs';
28
29 chrome.test.runTests([
30 // Request the access to the file system.
31 function requestFileSystem() {
32 chrome.fileBrowserPrivate.requestFileSystem(
33 function(fileSystem) {
34 chrome.test.assertTrue(!!fileSystem);
35 chrome.test.succeed();
36 globalFileSystem = fileSystem;
37 }
38 );
39 },
40
41 // TODO(satorux): It's not guaranteed that the 'testfs' mount point is
42 // already added. Should fix the race.
43
44 // Collect all entries in the file system recursively.
45 function collectEntries() {
46 var root = globalFileSystem.root;
47 // 'extfs' is mounted as 'extfs' in the root directory.
48 // Get an entry for it.
49 root.getDirectory(
50 globalMountPointName,
51 { create: false },
52 function(entry) {
53 var numInflight = 1;
54 // Try read the tree recursively.
55 function onEntries(entries) {
56 for (var i = 0; i < entries.length; i++) {
57 globalEntries.push(entries[i]);
58 if (entries[i].isDirectory) {
59 var reader = entries[i].createReader();
60 numInflight++;
61 reader.readEntries(onEntries);
62 }
63 }
64 numInflight--;
65 if (numInflight == 0)
66 chrome.test.succeed();
67 }
68 var reader = entry.createReader();
69 reader.readEntries(onEntries);
70 },
71 function(error) {
72 console.log('Failed to get directory entry: ' +
73 errorCodeToString(error.code));
74 chrome.test.fail();
75 });
76 },
77
78 // Prints all file names. This will print:
79 // Path: /extfs/file1
80 // Path: /extfs/dir1
81 // Path: /extfs/dir1/file2
82 // Path: /extfs/dir1/file3
83 // Path: /extfs/dir1/dir2
84 // Path: /extfs/dir1/dir2/file4
85 // Path: /extfs/dir1/dir2/dir3
86 function printFullPaths() {
87 for (var i = 0; i < globalEntries.length; i++) {
88 console.log('Path: ' + globalEntries[i].fullPath);
89 }
90 chrome.test.succeed();
91 },
92
93 // Print contents of all files.
94 function printFileContents() {
95 var numInflight = 0;
96 for (var i = 0; i < globalEntries.length; i++) {
97 var entry = globalEntries[i];
98 if (entry.isDirectory)
99 continue;
100
101 numInflight++;
102 entry.file(
103 function(file) {
104 var reader = new FileReader();
105 reader.onloadend = function(e) {
106 console.log(entry.fullPath + ': ' + this.result);
107 numInflight--;
108 if (numInflight == 0)
109 chrome.test.succeed();
110 }
111 reader.readAsText(file);
112 },
113 function(error) {
114 console.log('Failed to get the file object: ' +
115 errorCodeToString(error.code));
116 chrome.test.fail();
117 });
118 }
119 },
120 ]);
OLDNEW
« 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