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

Side by Side Diff: chrome/test/data/file_manager/unit_tests/media_scanner_unittest.js

Issue 762593006: Prototype implementation of MediaImportHandler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Sync to master. Created 6 years 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
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 /** 5 /**
6 * Dummy private APIs. 6 * Dummy private APIs.
7 */ 7 */
8 var chrome; 8 var chrome;
9 9
10 /** 10 /**
11 * Callbacks registered by setTimeout. 11 * Callbacks registered by setTimeout.
12 * @type {Array.<function>} 12 * @type {Array.<function>}
13 */ 13 */
14 var timeoutCallbacks; 14 var timeoutCallbacks;
15 15
16 16
17 /**
18 * @type {!MediaScanner}
19 */
20 var scanner;
21
17 // Set up the test components. 22 // Set up the test components.
18 function setUp() { 23 function setUp() {
24 scanner = new MediaScanner();
19 } 25 }
20 26
21 /** 27 /**
22 * Creates a subdirectory within a temporary file system for testing. 28 * Creates a subdirectory within a temporary file system for testing.
23 * @param {string} directoryName Name of the test directory to create. Must be 29 * @param {string} directoryName Name of the test directory to create. Must be
24 * unique within this test suite. 30 * unique within this test suite.
25 */ 31 */
26 function makeTestFilesystemRoot(directoryName) { 32 function makeTestFilesystemRoot(directoryName) {
27 function makeTestFilesystem() { 33 function makeTestFilesystem() {
28 return new Promise(function(resolve, reject) { 34 return new Promise(function(resolve, reject) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 dir.getFile(filename, {create: true}, resolve, reject); 77 dir.getFile(filename, {create: true}, resolve, reject);
72 }); 78 });
73 } 79 }
74 })).then(function() { return dir; }); 80 })).then(function() { return dir; });
75 } 81 }
76 82
77 /** 83 /**
78 * Verifies that scanning an empty filesystem produces an empty list. 84 * Verifies that scanning an empty filesystem produces an empty list.
79 */ 85 */
80 function testEmptyList(callback) { 86 function testEmptyList(callback) {
81 var scanner = new MediaScanner([]);
82 reportPromise( 87 reportPromise(
83 scanner.getFiles().then(function(files) { 88 scanner.scan([]).then(function(files) {
84 assertEquals(0, files.length); 89 assertEquals(0, files.length);
85 }), 90 }),
86 callback); 91 callback);
87 } 92 }
88 93
89 /** 94 /**
90 * Verifies that scanning a simple single-level directory structure works. 95 * Verifies that scanning a simple single-level directory structure works.
91 */ 96 */
92 function testSingleLevel(callback) { 97 function testSingleLevel(callback) {
93 var filenames = [ 98 var filenames = [
(...skipping 11 matching lines...) Expand all
105 ]; 110 ];
106 reportPromise( 111 reportPromise(
107 makeTestFilesystemRoot('testSingleLevel') 112 makeTestFilesystemRoot('testSingleLevel')
108 .then(populateDir.bind(null, filenames)) 113 .then(populateDir.bind(null, filenames))
109 .then( 114 .then(
110 /** 115 /**
111 * Scans the directory. 116 * Scans the directory.
112 * @param {!DirectoryEntry} root 117 * @param {!DirectoryEntry} root
113 */ 118 */
114 function(root) { 119 function(root) {
115 var scanner = new MediaScanner([root]); 120 return scanner.scan([root]);
116 return scanner.getFiles();
117 }) 121 })
118 .then( 122 .then(
119 /** 123 /**
120 * Verifies the results of the media scan. 124 * Verifies the results of the media scan.
121 * @param {!Array.<!FileEntry>} scanResults 125 * @param {!Array.<!FileEntry>} scanResults
122 */ 126 */
123 function(scanResults) { 127 function(scanResults) {
124 assertEquals(expectedFiles.length, scanResults.length); 128 assertEquals(expectedFiles.length, scanResults.length);
125 scanResults.forEach(function(result) { 129 scanResults.forEach(function(result) {
126 // Verify that the scanner only returns files. 130 // Verify that the scanner only returns files.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 162
159 reportPromise( 163 reportPromise(
160 makeTestFilesystemRoot('testMultiLevel') 164 makeTestFilesystemRoot('testMultiLevel')
161 .then(populateDir.bind(null, filenames)) 165 .then(populateDir.bind(null, filenames))
162 .then( 166 .then(
163 /** 167 /**
164 * Scans the directory. 168 * Scans the directory.
165 * @param {!DirectoryEntry} root 169 * @param {!DirectoryEntry} root
166 */ 170 */
167 function(root) { 171 function(root) {
168 var scanner = new MediaScanner([root]); 172 return scanner.scan([root]);
169 return scanner.getFiles();
170 }) 173 })
171 .then( 174 .then(
172 /** 175 /**
173 * Verifies the results of the media scan. 176 * Verifies the results of the media scan.
174 * @param {!Array.<!FileEntry>} scanResults 177 * @param {!Array.<!FileEntry>} scanResults
175 */ 178 */
176 function(scanResults) { 179 function(scanResults) {
177 assertEquals(expectedFiles.length, scanResults.length); 180 assertEquals(expectedFiles.length, scanResults.length);
178 scanResults.forEach(function(result) { 181 scanResults.forEach(function(result) {
179 // Verify that the scanner only returns files. 182 // Verify that the scanner only returns files.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 .then(populateDir.bind(null, filenames)) 220 .then(populateDir.bind(null, filenames))
218 .then( 221 .then(
219 /** 222 /**
220 * Scans the directories. 223 * Scans the directories.
221 * @param {!DirectoryEntry} root 224 * @param {!DirectoryEntry} root
222 */ 225 */
223 function(root) { 226 function(root) {
224 return Promise.all(['foo.0', 'foo.1'].map( 227 return Promise.all(['foo.0', 'foo.1'].map(
225 getDirectory.bind(null, root))).then( 228 getDirectory.bind(null, root))).then(
226 function(directories) { 229 function(directories) {
227 var scanner = new MediaScanner(directories); 230 return scanner.scan(directories);
228 return scanner.getFiles();
229 }); 231 });
230 }) 232 })
231 .then( 233 .then(
232 /** 234 /**
233 * Verifies the results of the media scan. 235 * Verifies the results of the media scan.
234 * @param {!Array.<!FileEntry>} scanResults 236 * @param {!Array.<!FileEntry>} scanResults
235 */ 237 */
236 function(scanResults) { 238 function(scanResults) {
237 assertEquals(expectedFiles.length, scanResults.length); 239 assertEquals(expectedFiles.length, scanResults.length);
238 scanResults.forEach(function(result) { 240 scanResults.forEach(function(result) {
239 // Verify that the scanner only returns files. 241 // Verify that the scanner only returns files.
240 assertTrue(result.isFile, result.fullPath + ' is not a file'); 242 assertTrue(result.isFile, result.fullPath + ' is not a file');
241 assertTrue(expectedFiles.indexOf(result.fullPath) != -1, 243 assertTrue(expectedFiles.indexOf(result.fullPath) != -1,
242 result.fullPath + ' not found in control set'); 244 result.fullPath + ' not found in control set');
243 }); 245 });
244 }), 246 }),
245 callback); 247 callback);
246 } 248 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698