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

Side by Side Diff: chrome/test/data/extensions/api_test/file_system_provider/read_directory/test.js

Issue 294073007: [fsp] Let extensions decide about the file system id. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased. Created 6 years, 7 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 'use strict'; 5 'use strict';
6 6
7 var fileSystemId; 7 /**
8 var fileSystem; 8 * @type {DOMFileSystem}
9 */
10 var fileSystem = null;
11
12 /**
13 * @type {string}
14 * @const
15 */
16 var FILE_SYSTEM_ID = 'vanilla';
9 17
10 /** 18 /**
11 * @type {Object} 19 * @type {Object}
12 * @const 20 * @const
13 */ 21 */
14 var TESTING_ROOT = Object.freeze({ 22 var TESTING_ROOT = Object.freeze({
15 isDirectory: true, 23 isDirectory: true,
16 name: '', 24 name: '',
17 size: 0, 25 size: 0,
18 modificationTime: new Date(2014, 4, 28, 10, 39, 15) 26 modificationTime: new Date(2014, 4, 28, 10, 39, 15)
(...skipping 26 matching lines...) Expand all
45 * @const 53 * @const
46 */ 54 */
47 var TESTING_TIRAMISU_FILE = Object.freeze({ 55 var TESTING_TIRAMISU_FILE = Object.freeze({
48 isDirectory: false, 56 isDirectory: false,
49 name: 'tiramisu.txt', 57 name: 'tiramisu.txt',
50 size: 1986, 58 size: 1986,
51 modificationTime: new Date(2014, 1, 25, 7, 36, 12) 59 modificationTime: new Date(2014, 1, 25, 7, 36, 12)
52 }); 60 });
53 61
54 /** 62 /**
63 * Gets volume information for the provided file system.
64 *
65 * @param {string} fileSystemId Id of the provided file system.
66 * @param {function(Object)} callback Callback to be called on result, with the
67 * volume information object in case of success, or null if not found.
68 */
69 function getVolumeInfo(fileSystemId, callback) {
70 chrome.fileBrowserPrivate.getVolumeMetadataList(function(volumeList) {
71 for (var i = 0; i < volumeList.length; i++) {
72 if (volumeList[i].extensionId == chrome.runtime.id &&
73 volumeList[i].fileSystemId == fileSystemId) {
74 callback(volumeList[i]);
75 return;
76 }
77 }
78 callback(null);
79 });
80 }
81
82 /**
55 * Returns entries in the requested directory. 83 * Returns entries in the requested directory.
56 * 84 *
57 * @param {number} inFileSystemId ID of the file system. 85 * @param {string} inFileSystemId ID of the file system.
58 * @param {string} directoryPath Path of the directory. 86 * @param {string} directoryPath Path of the directory.
59 * @param {function(Array.<Object>, boolean)} onSuccess Success callback with 87 * @param {function(Array.<Object>, boolean)} onSuccess Success callback with
60 * a list of entries. May be called multiple times. 88 * a list of entries. May be called multiple times.
61 * @param {function(string)} onError Error callback with an error code. 89 * @param {function(string)} onError Error callback with an error code.
62 */ 90 */
63 function onReadDirectoryRequested( 91 function onReadDirectoryRequested(
64 inFileSystemId, directoryPath, onSuccess, onError) { 92 inFileSystemId, directoryPath, onSuccess, onError) {
65 if (inFileSystemId != fileSystemId) { 93 if (inFileSystemId != FILE_SYSTEM_ID) {
66 onError('SECURITY_ERROR'); // enum ProviderError. 94 onError('SECURITY_ERROR'); // enum ProviderError.
67 return; 95 return;
68 } 96 }
69 97
70 if (directoryPath != '/' + TESTING_HELLO_DIR.name) { 98 if (directoryPath != '/' + TESTING_HELLO_DIR.name) {
71 onError('NOT_FOUND'); // enum ProviderError. 99 onError('NOT_FOUND'); // enum ProviderError.
72 return; 100 return;
73 } 101 }
74 102
75 onSuccess([TESTING_TIRAMISU_FILE], true /* has_next */); 103 onSuccess([TESTING_TIRAMISU_FILE], true /* has_next */);
76 onSuccess([TESTING_CANDIES_DIR], false /* has_next */); 104 onSuccess([TESTING_CANDIES_DIR], false /* has_next */);
77 } 105 }
78 106
79 /** 107 /**
80 * Returns metadata for the requested entry. 108 * Returns metadata for the requested entry.
81 * 109 *
82 * To successfully acquire a DirectoryEntry, or even a DOMFileSystem, this event 110 * To successfully acquire a DirectoryEntry, or even a DOMFileSystem, this event
83 * must be implemented and return correct values. 111 * must be implemented and return correct values.
84 * 112 *
85 * @param {number} inFileSystemId ID of the file system. 113 * @param {string} inFileSystemId ID of the file system.
86 * @param {string} entryPath Path of the requested entry. 114 * @param {string} entryPath Path of the requested entry.
87 * @param {function(Object)} onSuccess Success callback with metadata passed 115 * @param {function(Object)} onSuccess Success callback with metadata passed
88 * an argument. 116 * an argument.
89 * @param {function(string)} onError Error callback with an error code. 117 * @param {function(string)} onError Error callback with an error code.
90 */ 118 */
91 function onGetMetadataRequested( 119 function onGetMetadataRequested(
92 inFileSystemId, entryPath, onSuccess, onError) { 120 inFileSystemId, entryPath, onSuccess, onError) {
93 if (inFileSystemId != fileSystemId) { 121 if (inFileSystemId != FILE_SYSTEM_ID) {
94 onError('SECURITY_ERROR'); // enum ProviderError. 122 onError('SECURITY_ERROR'); // enum ProviderError.
95 return; 123 return;
96 } 124 }
97 125
98 if (entryPath == '/') { 126 if (entryPath == '/') {
99 onSuccess(TESTING_ROOT); 127 onSuccess(TESTING_ROOT);
100 return; 128 return;
101 } 129 }
102 130
103 if (entryPath == '/' + TESTING_HELLO_DIR.name) { 131 if (entryPath == '/' + TESTING_HELLO_DIR.name) {
104 onSuccess(TESTING_HELLO_DIR); 132 onSuccess(TESTING_HELLO_DIR);
105 return; 133 return;
106 } 134 }
107 135
108 onError('NOT_FOUND'); // enum ProviderError. 136 onError('NOT_FOUND'); // enum ProviderError.
109 } 137 }
110 138
111 /** 139 /**
112 * Sets up the tests. Called once per all test cases. In case of a failure, 140 * Sets up the tests. Called once per all test cases. In case of a failure,
113 * the callback is not called. 141 * the callback is not called.
114 * 142 *
115 * @param {function()} callback Success callback. 143 * @param {function()} callback Success callback.
116 */ 144 */
117 function setUp(callback) { 145 function setUp(callback) {
118 chrome.fileSystemProvider.mount('chocolate.zip', function(id) { 146 chrome.fileSystemProvider.mount(FILE_SYSTEM_ID, 'chocolate.zip', function() {
119 fileSystemId = id;
120 chrome.fileSystemProvider.onReadDirectoryRequested.addListener( 147 chrome.fileSystemProvider.onReadDirectoryRequested.addListener(
121 onReadDirectoryRequested); 148 onReadDirectoryRequested);
122 chrome.fileSystemProvider.onGetMetadataRequested.addListener( 149 chrome.fileSystemProvider.onGetMetadataRequested.addListener(
123 onGetMetadataRequested); 150 onGetMetadataRequested);
124 var volumeId =
125 'provided:' + chrome.runtime.id + '-' + fileSystemId + '-user';
126 151
127 chrome.fileBrowserPrivate.requestFileSystem( 152 getVolumeInfo(FILE_SYSTEM_ID, function(volumeInfo) {
128 volumeId, 153 chrome.test.assertTrue(!!volumeInfo);
129 function(inFileSystem) { 154 chrome.fileBrowserPrivate.requestFileSystem(
130 chrome.test.assertTrue(!!inFileSystem); 155 volumeInfo.volumeId,
156 function(inFileSystem) {
157 chrome.test.assertTrue(!!inFileSystem);
131 158
132 fileSystem = inFileSystem; 159 fileSystem = inFileSystem;
133 callback(); 160 callback();
134 }); 161 });
162 });
135 }, function() { 163 }, function() {
136 chrome.test.fail(); 164 chrome.test.fail();
137 }); 165 });
138 } 166 }
139 167
140 /** 168 /**
141 * Runs all of the test cases, one by one. 169 * Runs all of the test cases, one by one.
142 */ 170 */
143 function runTests() { 171 function runTests() {
144 chrome.test.runTests([ 172 chrome.test.runTests([
145 // Read contents of the /hello directory. This directory exists, so it 173 // Read contents of the /hello directory. This directory exists, so it
146 // should succeed. 174 // should succeed.
147 function readEntriesSuccess() { 175 function readEntriesSuccess() {
148 var onTestSuccess = chrome.test.callbackPass(function() {}); 176 var onTestSuccess = chrome.test.callbackPass();
149 fileSystem.root.getDirectory( 177 fileSystem.root.getDirectory(
150 'hello', 178 'hello',
151 {create: false}, 179 {create: false},
152 function(dirEntry) { 180 function(dirEntry) {
153 var dirReader = dirEntry.createReader(); 181 var dirReader = dirEntry.createReader();
154 var entries = []; 182 var entries = [];
155 var readEntriesNext = function() { 183 var readEntriesNext = function() {
156 dirReader.readEntries(function(inEntries) { 184 dirReader.readEntries(function(inEntries) {
157 Array.prototype.push.apply(entries, inEntries); 185 Array.prototype.push.apply(entries, inEntries);
158 if (!inEntries.length) { 186 if (!inEntries.length) {
(...skipping 16 matching lines...) Expand all
175 }; 203 };
176 readEntriesNext(); 204 readEntriesNext();
177 }, 205 },
178 function(error) { 206 function(error) {
179 chrome.test.fail(); 207 chrome.test.fail();
180 }); 208 });
181 }, 209 },
182 // Read contents of a directory which does not exist, what should return an 210 // Read contents of a directory which does not exist, what should return an
183 // error. 211 // error.
184 function readEntriesError() { 212 function readEntriesError() {
185 var onTestSuccess = chrome.test.callbackPass(function() {}); 213 var onTestSuccess = chrome.test.callbackPass();
186 fileSystem.root.getDirectory( 214 fileSystem.root.getDirectory(
187 'cranberries', 215 'cranberries',
188 {create: false}, 216 {create: false},
189 function(dirEntry) { 217 function(dirEntry) {
190 chrome.test.fail(); 218 chrome.test.fail();
191 }, 219 },
192 function(error) { 220 function(error) {
193 chrome.test.assertEq('NotFoundError', error.name); 221 chrome.test.assertEq('NotFoundError', error.name);
194 onTestSuccess(); 222 onTestSuccess();
195 }); 223 });
196 } 224 }
197 ]); 225 ]);
198 } 226 }
199 227
200 // Setup and run all of the test cases. 228 // Setup and run all of the test cases.
201 setUp(runTests); 229 setUp(runTests);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698