OLD | NEW |
---|---|
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 Loading... | |
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(errorIf) { | 86 function testEmptyList(errorIf) { |
81 var scanner = new MediaScanner([]); | 87 scanner.scan([]).then(function(files) { |
82 scanner.getFiles().then(function(files) { | |
83 errorIf(files.length !== 0); | 88 errorIf(files.length !== 0); |
hirono
2014/12/04 04:44:23
Please use assert and reportPromise.
Ben Kwa
2014/12/04 07:48:08
Okay, but can I make that change in a separate CL,
Ben Kwa
2014/12/04 19:53:01
Acknowledged. Will fix in a follow-up CL.
| |
84 }); | 89 }); |
85 } | 90 } |
86 | 91 |
87 /** | 92 /** |
88 * Verifies that scanning a simple single-level directory structure works. | 93 * Verifies that scanning a simple single-level directory structure works. |
89 */ | 94 */ |
90 function testSingleLevel(errorIf) { | 95 function testSingleLevel(errorIf) { |
91 var filenames = [ | 96 var filenames = [ |
92 'foo', | 97 'foo', |
93 'foo.jpg', | 98 'foo.jpg', |
94 'bar.gif', | 99 'bar.gif', |
95 'baz.avi', | 100 'baz.avi', |
96 'foo.mp3', | 101 'foo.mp3', |
97 'bar.txt' | 102 'bar.txt' |
98 ]; | 103 ]; |
99 var expectedFiles = [ | 104 var expectedFiles = [ |
100 '/testSingleLevel/foo.jpg', | 105 '/testSingleLevel/foo.jpg', |
101 '/testSingleLevel/bar.gif', | 106 '/testSingleLevel/bar.gif', |
102 '/testSingleLevel/baz.avi' | 107 '/testSingleLevel/baz.avi' |
103 ]; | 108 ]; |
104 makeTestFilesystemRoot('testSingleLevel') | 109 makeTestFilesystemRoot('testSingleLevel') |
105 .then(populateDir.bind(null, filenames)) | 110 .then(populateDir.bind(null, filenames)) |
106 .then( | 111 .then( |
107 /** | 112 /** |
108 * Scans the directory. | 113 * Scans the directory. |
109 * @param {!DirectoryEntry} root | 114 * @param {!DirectoryEntry} root |
110 */ | 115 */ |
111 function(root) { | 116 function(root) { |
112 var scanner = new MediaScanner([root]); | 117 return scanner.scan([root]); |
113 return scanner.getFiles(); | |
114 }) | 118 }) |
115 .then( | 119 .then( |
116 /** | 120 /** |
117 * Verifies the results of the media scan. | 121 * Verifies the results of the media scan. |
118 * @param {!Array.<!FileEntry>} scanResults | 122 * @param {!Array.<!FileEntry>} scanResults |
119 */ | 123 */ |
120 function(scanResults) { | 124 function(scanResults) { |
121 assertEquals(expectedFiles.length, scanResults.length); | 125 assertEquals(expectedFiles.length, scanResults.length); |
122 scanResults.forEach(function(result) { | 126 scanResults.forEach(function(result) { |
123 // Verify that the scanner only returns files. | 127 // Verify that the scanner only returns files. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
161 ]; | 165 ]; |
162 | 166 |
163 makeTestFilesystemRoot('testMultiLevel') | 167 makeTestFilesystemRoot('testMultiLevel') |
164 .then(populateDir.bind(null, filenames)) | 168 .then(populateDir.bind(null, filenames)) |
165 .then( | 169 .then( |
166 /** | 170 /** |
167 * Scans the directory. | 171 * Scans the directory. |
168 * @param {!DirectoryEntry} root | 172 * @param {!DirectoryEntry} root |
169 */ | 173 */ |
170 function(root) { | 174 function(root) { |
171 var scanner = new MediaScanner([root]); | 175 return scanner.scan([root]); |
172 return scanner.getFiles(); | |
173 }) | 176 }) |
174 .then( | 177 .then( |
175 /** | 178 /** |
176 * Verifies the results of the media scan. | 179 * Verifies the results of the media scan. |
177 * @param {!Array.<!FileEntry>} scanResults | 180 * @param {!Array.<!FileEntry>} scanResults |
178 */ | 181 */ |
179 function(scanResults) { | 182 function(scanResults) { |
180 assertEquals(expectedFiles.length, scanResults.length); | 183 assertEquals(expectedFiles.length, scanResults.length); |
181 scanResults.forEach(function(result) { | 184 scanResults.forEach(function(result) { |
182 // Verify that the scanner only returns files. | 185 // Verify that the scanner only returns files. |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
227 .then(populateDir.bind(null, filenames)) | 230 .then(populateDir.bind(null, filenames)) |
228 .then( | 231 .then( |
229 /** | 232 /** |
230 * Scans the directories. | 233 * Scans the directories. |
231 * @param {!DirectoryEntry} root | 234 * @param {!DirectoryEntry} root |
232 */ | 235 */ |
233 function(root) { | 236 function(root) { |
234 return Promise.all(['foo.0', 'foo.1'].map( | 237 return Promise.all(['foo.0', 'foo.1'].map( |
235 getDirectory.bind(null, root))).then( | 238 getDirectory.bind(null, root))).then( |
236 function(directories) { | 239 function(directories) { |
237 var scanner = new MediaScanner(directories); | 240 return scanner.scan(directories); |
238 return scanner.getFiles(); | |
239 }); | 241 }); |
240 }) | 242 }) |
241 .then( | 243 .then( |
242 /** | 244 /** |
243 * Verifies the results of the media scan. | 245 * Verifies the results of the media scan. |
244 * @param {!Array.<!FileEntry>} scanResults | 246 * @param {!Array.<!FileEntry>} scanResults |
245 */ | 247 */ |
246 function(scanResults) { | 248 function(scanResults) { |
247 assertEquals(expectedFiles.length, scanResults.length); | 249 assertEquals(expectedFiles.length, scanResults.length); |
248 scanResults.forEach(function(result) { | 250 scanResults.forEach(function(result) { |
249 // Verify that the scanner only returns files. | 251 // Verify that the scanner only returns files. |
250 assertTrue(result.isFile, result.fullPath + ' is not a file'); | 252 assertTrue(result.isFile, result.fullPath + ' is not a file'); |
251 assertTrue(expectedFiles.indexOf(result.fullPath) != -1, | 253 assertTrue(expectedFiles.indexOf(result.fullPath) != -1, |
252 result.fullPath + ' not found in control set'); | 254 result.fullPath + ' not found in control set'); |
253 }); | 255 }); |
254 // Signal test completion with no errors. | 256 // Signal test completion with no errors. |
255 errorIf(false); | 257 errorIf(false); |
hirono
2014/12/04 04:44:23
Please use assert and reportPromise.
Ben Kwa
2014/12/04 19:53:01
Acknowledged.
| |
256 }) | 258 }) |
257 .catch( | 259 .catch( |
258 function(e) { | 260 function(e) { |
259 // Catch failures and print them. | 261 // Catch failures and print them. |
260 console.error(e); | 262 console.error(e); |
261 errorIf(e); | 263 errorIf(e); |
262 }); | 264 }); |
263 } | 265 } |
OLD | NEW |