| 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 * Stub out the metrics package. |
| 7 * @type {!Object} |
| 7 */ | 8 */ |
| 8 var chrome; | 9 var metrics = { |
| 10 recordTime: function() {}, |
| 11 recordValue: function() {} |
| 12 }; |
| 9 | 13 |
| 10 /** | 14 /** @type {!importer.DefaultMediaScanner} */ |
| 11 * Callbacks registered by setTimeout. | 15 var scanner; |
| 12 * @type {Array.<function>} | |
| 13 */ | |
| 14 var timeoutCallbacks; | |
| 15 | 16 |
| 16 | 17 /** @type {!importer.TestImportHistory} */ |
| 17 /** | 18 var importHistory; |
| 18 * @type {!importer.DefaultMediaScanner} | |
| 19 */ | |
| 20 var scanner; | |
| 21 | 19 |
| 22 // Set up the test components. | 20 // Set up the test components. |
| 23 function setUp() { | 21 function setUp() { |
| 24 scanner = new importer.DefaultMediaScanner(); | 22 |
| 23 importHistory = new importer.TestImportHistory(); |
| 24 scanner = new importer.DefaultMediaScanner( |
| 25 Promise.resolve(importHistory)); |
| 25 } | 26 } |
| 26 | 27 |
| 27 /** | 28 /** |
| 28 * Creates a subdirectory within a temporary file system for testing. | 29 * Creates a subdirectory within a temporary file system for testing. |
| 30 * |
| 29 * @param {string} directoryName Name of the test directory to create. Must be | 31 * @param {string} directoryName Name of the test directory to create. Must be |
| 30 * unique within this test suite. | 32 * unique within this test suite. |
| 31 */ | 33 */ |
| 32 function makeTestFileSystemRoot(directoryName) { | 34 function makeTestFileSystemRoot(directoryName) { |
| 33 function makeTestFilesystem() { | 35 function makeTestFilesystem() { |
| 34 return new Promise(function(resolve, reject) { | 36 return new Promise(function(resolve, reject) { |
| 35 window.webkitRequestFileSystem( | 37 window.webkitRequestFileSystem( |
| 36 window.TEMPORARY, | 38 window.TEMPORARY, |
| 37 1024*1024, | 39 1024 * 1024, |
| 38 resolve, | 40 resolve, |
| 39 reject); | 41 reject); |
| 40 }); | 42 }); |
| 41 } | 43 } |
| 42 | 44 |
| 43 return makeTestFilesystem() | 45 return makeTestFilesystem() |
| 44 .then( | 46 .then( |
| 45 // Create a directory, pretend that's the root. | 47 // Create a directory, pretend that's the root. |
| 46 function(fs) { | 48 function(fs) { |
| 47 return new Promise(function(resolve, reject) { | 49 return new Promise(function(resolve, reject) { |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 * Scans the directory. | 140 * Scans the directory. |
| 139 * @param {!DirectoryEntry} root | 141 * @param {!DirectoryEntry} root |
| 140 */ | 142 */ |
| 141 function(root) { | 143 function(root) { |
| 142 return scanner.scan([root]).whenFinished(); | 144 return scanner.scan([root]).whenFinished(); |
| 143 }) | 145 }) |
| 144 .then(assertResults.bind(null, expectedFiles)), | 146 .then(assertResults.bind(null, expectedFiles)), |
| 145 callback); | 147 callback); |
| 146 } | 148 } |
| 147 | 149 |
| 150 /** |
| 151 * Verifies that scanning a simple single-level directory structure works. |
| 152 */ |
| 153 function testIgnoresPreviouslyImports(callback) { |
| 154 importHistory.importedPaths[ |
| 155 '/testIgnoresPreviouslyImports/oldimage1234.jpg'] = |
| 156 [importer.Destination.GOOGLE_DRIVE]; |
| 157 var filenames = [ |
| 158 'oldimage1234.jpg', |
| 159 'foo.jpg', |
| 160 'bar.gif', |
| 161 'baz.avi' |
| 162 ]; |
| 163 var expectedFiles = [ |
| 164 '/testIgnoresPreviouslyImports/foo.jpg', |
| 165 '/testIgnoresPreviouslyImports/bar.gif', |
| 166 '/testIgnoresPreviouslyImports/baz.avi' |
| 167 ]; |
| 168 reportPromise( |
| 169 makeTestFileSystemRoot('testIgnoresPreviouslyImports') |
| 170 .then(populateDir.bind(null, filenames)) |
| 171 .then( |
| 172 /** |
| 173 * Scans the directory. |
| 174 * @param {!DirectoryEntry} root |
| 175 */ |
| 176 function(root) { |
| 177 return scanner.scan([root]).whenFinished(); |
| 178 }) |
| 179 .then(assertResults.bind(null, expectedFiles)), |
| 180 callback); |
| 181 } |
| 182 |
| 148 function testMultiLevel(callback) { | 183 function testMultiLevel(callback) { |
| 149 var filenames = [ | 184 var filenames = [ |
| 150 'foo.jpg', | 185 'foo.jpg', |
| 151 'bar', | 186 'bar', |
| 152 [ | 187 [ |
| 153 'foo.0', | 188 'foo.0', |
| 154 'bar.0.jpg' | 189 'bar.0.jpg' |
| 155 ], | 190 ], |
| 156 [ | 191 [ |
| 157 'foo.1', | 192 'foo.1', |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 | 267 |
| 233 /** | 268 /** |
| 234 * Verifies the results of the media scan are as expected. | 269 * Verifies the results of the media scan are as expected. |
| 235 * @param {!impoter.ScanResults} results | 270 * @param {!impoter.ScanResults} results |
| 236 */ | 271 */ |
| 237 function assertResults(expected, results) { | 272 function assertResults(expected, results) { |
| 238 assertFileEntryPathsEqual(expected, results.getFileEntries()); | 273 assertFileEntryPathsEqual(expected, results.getFileEntries()); |
| 239 assertTrue(results.getScanDurationMs() > 0); | 274 assertTrue(results.getScanDurationMs() > 0); |
| 240 // TODO(smckay): Add coverage for getTotalBytes. | 275 // TODO(smckay): Add coverage for getTotalBytes. |
| 241 } | 276 } |
| OLD | NEW |