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

Side by Side Diff: chrome/test/data/extensions/api_test/file_system_provider/get_metadata/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(2013, 3, 27, 9, 38, 14) 26 modificationTime: new Date(2013, 3, 27, 9, 38, 14)
(...skipping 15 matching lines...) Expand all
34 * @const 42 * @const
35 */ 43 */
36 var TESTING_WRONG_TIME_FILE = Object.freeze({ 44 var TESTING_WRONG_TIME_FILE = Object.freeze({
37 isDirectory: false, 45 isDirectory: false,
38 name: 'invalid-time.txt', 46 name: 'invalid-time.txt',
39 size: 4096, 47 size: 4096,
40 modificationTime: new Date('Invalid date.') 48 modificationTime: new Date('Invalid date.')
41 }); 49 });
42 50
43 /** 51 /**
52 * Gets volume information for the provided file system.
53 *
54 * @param {string} fileSystemId Id of the provided file system.
55 * @param {function(Object)} callback Callback to be called on result, with the
56 * volume information object in case of success, or null if not found.
57 */
58 function getVolumeInfo(fileSystemId, callback) {
59 chrome.fileBrowserPrivate.getVolumeMetadataList(function(volumeList) {
60 for (var i = 0; i < volumeList.length; i++) {
61 if (volumeList[i].extensionId == chrome.runtime.id &&
62 volumeList[i].fileSystemId == fileSystemId) {
63 callback(volumeList[i]);
64 return;
65 }
66 }
67 callback(null);
68 });
69 }
70
71 /**
44 * Returns metadata for a requested entry. 72 * Returns metadata for a requested entry.
45 * 73 *
46 * @param {number} inFileSystemId ID of the file system. 74 * @param {string} inFileSystemId ID of the file system.
47 * @param {string} entryPath Path of the requested entry. 75 * @param {string} entryPath Path of the requested entry.
48 * @param {function(Object)} onSuccess Success callback with metadata passed 76 * @param {function(Object)} onSuccess Success callback with metadata passed
49 * an argument. 77 * an argument.
50 * @param {function(string)} onError Error callback with an error code. 78 * @param {function(string)} onError Error callback with an error code.
51 */ 79 */
52 function onGetMetadataRequested( 80 function onGetMetadataRequested(inFileSystemId, entryPath, onSuccess, onError) {
53 inFileSystemId, entryPath, onSuccess, onError) { 81 if (inFileSystemId != FILE_SYSTEM_ID) {
54 if (inFileSystemId != fileSystemId) {
55 onError('SECURITY_ERROR'); // enum ProviderError. 82 onError('SECURITY_ERROR'); // enum ProviderError.
56 return; 83 return;
57 } 84 }
58 85
59 if (entryPath == '/') { 86 if (entryPath == '/') {
60 onSuccess(TESTING_ROOT); 87 onSuccess(TESTING_ROOT);
61 return; 88 return;
62 } 89 }
63 90
64 if (entryPath == '/' + TESTING_FILE.name) { 91 if (entryPath == '/' + TESTING_FILE.name) {
65 onSuccess(TESTING_FILE); 92 onSuccess(TESTING_FILE);
66 return; 93 return;
67 } 94 }
68 95
69 if (entryPath == '/' + TESTING_WRONG_TIME_FILE.name) { 96 if (entryPath == '/' + TESTING_WRONG_TIME_FILE.name) {
70 onSuccess(TESTING_WRONG_TIME_FILE); 97 onSuccess(TESTING_WRONG_TIME_FILE);
71 return; 98 return;
72 } 99 }
73 100
74 onError('NOT_FOUND'); // enum ProviderError. 101 onError('NOT_FOUND'); // enum ProviderError.
75 } 102 }
76 103
77 /** 104 /**
78 * Sets up the tests. Called once per all test cases. In case of a failure, 105 * Sets up the tests. Called once per all test cases. In case of a failure,
79 * the callback is not called. 106 * the callback is not called.
80 * 107 *
81 * @param {function()} callback Success callback. 108 * @param {function()} callback Success callback.
82 */ 109 */
83 function setUp(callback) { 110 function setUp(callback) {
84 chrome.fileSystemProvider.mount('chocolate.zip', function(id) { 111 chrome.fileSystemProvider.mount(FILE_SYSTEM_ID, 'chocolate.zip', function() {
85 fileSystemId = id;
86 chrome.fileSystemProvider.onGetMetadataRequested.addListener( 112 chrome.fileSystemProvider.onGetMetadataRequested.addListener(
87 onGetMetadataRequested); 113 onGetMetadataRequested);
88 var volumeId =
89 'provided:' + chrome.runtime.id + '-' + fileSystemId + '-user';
90 114
91 chrome.fileBrowserPrivate.requestFileSystem( 115 getVolumeInfo(FILE_SYSTEM_ID, function(volumeInfo) {
92 volumeId, 116 chrome.test.assertTrue(!!volumeInfo);
93 function(inFileSystem) { 117 chrome.fileBrowserPrivate.requestFileSystem(
94 chrome.test.assertTrue(!!inFileSystem); 118 volumeInfo.volumeId,
119 function(inFileSystem) {
120 chrome.test.assertTrue(!!inFileSystem);
95 121
96 fileSystem = inFileSystem; 122 fileSystem = inFileSystem;
97 callback(); 123 callback();
98 }); 124 });
125 });
99 }, function() { 126 }, function() {
100 chrome.test.fail(); 127 chrome.test.fail();
101 }); 128 });
102 } 129 }
103 130
104 /** 131 /**
105 * Runs all of the test cases, one by one. 132 * Runs all of the test cases, one by one.
106 */ 133 */
107 function runTests() { 134 function runTests() {
108 chrome.test.runTests([ 135 chrome.test.runTests([
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 function(error) { 222 function(error) {
196 chrome.test.assertEq('TypeMismatchError', error.name); 223 chrome.test.assertEq('TypeMismatchError', error.name);
197 onSuccess(); 224 onSuccess();
198 }); 225 });
199 } 226 }
200 ]); 227 ]);
201 } 228 }
202 229
203 // Setup and run all of the test cases. 230 // Setup and run all of the test cases.
204 setUp(runTests); 231 setUp(runTests);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698