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 * Stub out the metrics package. | 6 * Stub out the metrics package. |
7 * @type {!Object.<!string, !Function>} | 7 * @type {!Object.<!string, !Function>} |
8 */ | 8 */ |
9 var metrics = { | 9 var metrics = { |
10 recordTime: function() {}, | 10 recordTime: function() {}, |
11 recordValue: function() {} | 11 recordValue: function() {} |
12 }; | 12 }; |
13 | 13 |
14 /** @type {!importer.DefaultMediaScanner} */ | 14 /** @type {!importer.DefaultMediaScanner} */ |
15 var scanner; | 15 var scanner; |
16 | 16 |
17 /** @type {!importer.TestImportHistory} */ | 17 /** @type {!importer.TestImportHistory} */ |
18 var importHistory; | 18 var importHistory; |
19 | 19 |
20 /** @type {!importer.TestDirectoryWatcher} */ | 20 /** @type {!importer.TestDirectoryWatcher} */ |
21 var watcher; | 21 var watcher; |
22 | 22 |
| 23 /** |
| 24 * @type {function(!FileEntry, !importer.Destination): |
| 25 * !Promise<!importer.Disposition>} |
| 26 */ |
| 27 var dispositionChecker; |
| 28 |
23 // Set up the test components. | 29 // Set up the test components. |
24 function setUp() { | 30 function setUp() { |
25 | 31 |
| 32 |
26 importHistory = new importer.TestImportHistory(); | 33 importHistory = new importer.TestImportHistory(); |
| 34 // This is the default disposition checker. |
| 35 // Tests can replace this at runtime if they |
| 36 // want specialized behaviors. |
| 37 dispositionChecker = function() { |
| 38 return Promise.resolve(importer.Disposition.ORIGINAL); |
| 39 }; |
| 40 |
27 scanner = new importer.DefaultMediaScanner( | 41 scanner = new importer.DefaultMediaScanner( |
28 /** @param {!FileEntry} entry */ | 42 /** @param {!FileEntry} entry */ |
29 function(entry) { | 43 function(entry) { |
30 return Promise.resolve(entry.name); | 44 return Promise.resolve(entry.name); |
31 }, | 45 }, |
32 importHistory, | 46 function(entry, destination) { |
| 47 return dispositionChecker(entry, destination); |
| 48 }, |
33 function(callback) { | 49 function(callback) { |
34 watcher = new TestDirectoryWatcher(callback); | 50 watcher = new TestDirectoryWatcher(callback); |
35 return watcher; | 51 return watcher; |
36 }); | 52 }); |
37 } | 53 } |
38 | 54 |
39 /** | 55 /** |
40 * Verifies that scanning an empty filesystem produces an empty list. | 56 * Verifies that scanning an empty filesystem produces an empty list. |
41 */ | 57 */ |
42 function testEmptySourceList() { | 58 function testEmptySourceList() { |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 } | 169 } |
154 | 170 |
155 /** | 171 /** |
156 * Verifies that scanning ignores previously imported entries. | 172 * Verifies that scanning ignores previously imported entries. |
157 */ | 173 */ |
158 function testIgnoresPreviousImports(callback) { | 174 function testIgnoresPreviousImports(callback) { |
159 importHistory.importedPaths[ | 175 importHistory.importedPaths[ |
160 '/testIgnoresPreviousImports/oldimage1234.jpg'] = | 176 '/testIgnoresPreviousImports/oldimage1234.jpg'] = |
161 [importer.Destination.GOOGLE_DRIVE]; | 177 [importer.Destination.GOOGLE_DRIVE]; |
162 var filenames = [ | 178 var filenames = [ |
163 'oldimage1234.jpg', | 179 'oldimage1234.jpg', // a history duplicate |
| 180 'driveimage1234.jpg', // a content duplicate |
164 'foo.jpg', | 181 'foo.jpg', |
165 'bar.gif', | 182 'bar.gif', |
166 'baz.avi' | 183 'baz.avi' |
167 ]; | 184 ]; |
| 185 |
| 186 // Replace the default dispositionChecker with a function |
| 187 // that treats our dupes accordingly. |
| 188 dispositionChecker = function(entry, destination) { |
| 189 if (entry.name === filenames[0]) { |
| 190 return Promise.resolve(importer.Disposition.HISTORY_DUPLICATE); |
| 191 } |
| 192 if (entry.name === filenames[1]) { |
| 193 return Promise.resolve(importer.Disposition.CONTENT_DUPLICATE); |
| 194 } |
| 195 return Promise.resolve(importer.Disposition.ORIGINAL); |
| 196 }; |
| 197 |
168 var expectedFiles = [ | 198 var expectedFiles = [ |
169 '/testIgnoresPreviousImports/foo.jpg', | 199 '/testIgnoresPreviousImports/foo.jpg', |
170 '/testIgnoresPreviousImports/bar.gif', | 200 '/testIgnoresPreviousImports/bar.gif', |
171 '/testIgnoresPreviousImports/baz.avi' | 201 '/testIgnoresPreviousImports/baz.avi' |
172 ]; | 202 ]; |
173 reportPromise( | 203 reportPromise( |
174 makeTestFileSystemRoot('testIgnoresPreviousImports') | 204 makeTestFileSystemRoot('testIgnoresPreviousImports') |
175 .then(populateDir.bind(null, filenames)) | 205 .then(populateDir.bind(null, filenames)) |
176 .then( | 206 .then( |
177 /** | 207 /** |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 return Promise.all(['foo.0', 'foo.1'].map( | 293 return Promise.all(['foo.0', 'foo.1'].map( |
264 getDirectory.bind(null, root))).then( | 294 getDirectory.bind(null, root))).then( |
265 function(directories) { | 295 function(directories) { |
266 return scanner.scan(directories).whenFinal(); | 296 return scanner.scan(directories).whenFinal(); |
267 }); | 297 }); |
268 }) | 298 }) |
269 .then(assertResults.bind(null, expectedFiles)), | 299 .then(assertResults.bind(null, expectedFiles)), |
270 callback); | 300 callback); |
271 } | 301 } |
272 | 302 |
273 function testDedupesFiles(callback) { | 303 function testDedupesFilesInScanResult(callback) { |
274 var filenames = [ | 304 var filenames = [ |
275 [ | 305 [ |
276 'a', | 306 'a', |
277 'foo.jpg', | 307 'foo.jpg', |
278 'bar.jpg' | 308 'bar.jpg' |
279 ], | 309 ], |
280 [ | 310 [ |
281 'b', | 311 'b', |
282 'foo.jpg', | 312 'foo.jpg', |
283 'bar.jpg', | 313 'bar.jpg', |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 return new Promise( | 438 return new Promise( |
409 function(resolve, reject) { | 439 function(resolve, reject) { |
410 dir.getFile(filename, {create: true}, resolve, reject); | 440 dir.getFile(filename, {create: true}, resolve, reject); |
411 }); | 441 }); |
412 } | 442 } |
413 })).then( | 443 })).then( |
414 function() { | 444 function() { |
415 return dir; | 445 return dir; |
416 }); | 446 }); |
417 } | 447 } |
OLD | NEW |