Commit 1d9b3e01 authored by Luciano Pacheco's avatar Luciano Pacheco Committed by Chromium LUCI CQ

Files app: Generate JS module for //u/f/f/b/j/media_scanner.js

JS modules for:
- //ui/file_manager/file_manager/background/js/
  - media_scanner.js
  - mock_media_scanner.js
  - media_scanner_unittest.m.js
- //u/file_manager/externs/background/media_scanner.js

Because Closure doesn't deal well importing the same namespace from
different files, I started splitting the "importer" namespace so each
file will have its own namespace.  Files in the "externs" directory will
have the suffix "Interface" on their namespace.  I'll use this logic for
all files related to "importer" namespace.

Bug: 1133186
Change-Id: I55b14aaa58a140e1e754ceaf15c51219df19578a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2596281Reviewed-by: default avatarJeremie Boulic <jboulic@chromium.org>
Commit-Queue: Jeremie Boulic <jboulic@chromium.org>
Auto-Submit: Luciano Pacheco <lucmult@chromium.org>
Cr-Commit-Position: refs/heads/master@{#837991}
parent 41ad7e1b
...@@ -185,7 +185,7 @@ IN_PROC_BROWSER_TEST_F(FileManagerJsTest, MediaImportHandlerTest) { ...@@ -185,7 +185,7 @@ IN_PROC_BROWSER_TEST_F(FileManagerJsTest, MediaImportHandlerTest) {
} }
IN_PROC_BROWSER_TEST_F(FileManagerJsTest, MediaScannerTest) { IN_PROC_BROWSER_TEST_F(FileManagerJsTest, MediaScannerTest) {
RunTestURL("background/js/media_scanner_unittest_gen.html"); RunTestURL("background/js/media_scanner_unittest.m_gen.html");
} }
IN_PROC_BROWSER_TEST_F(FileManagerJsTest, MetadataCacheItem) { IN_PROC_BROWSER_TEST_F(FileManagerJsTest, MetadataCacheItem) {
......
...@@ -68,6 +68,14 @@ js_library("import_history.m") { ...@@ -68,6 +68,14 @@ js_library("import_history.m") {
extra_deps = [ ":modulize" ] extra_deps = [ ":modulize" ]
} }
js_library("media_scanner.m") {
sources =
[ "$root_gen_dir/ui/file_manager/externs/background/media_scanner.m.js" ]
deps = [ "//ui/file_manager/file_manager/common/js:importer_common.m" ]
extra_deps = [ ":modulize" ]
}
js_library("progress_center.m") { js_library("progress_center.m") {
sources = [ sources = [
"$root_gen_dir/ui/file_manager/externs/background/progress_center.m.js", "$root_gen_dir/ui/file_manager/externs/background/progress_center.m.js",
...@@ -95,6 +103,7 @@ js_modulizer("modulize") { ...@@ -95,6 +103,7 @@ js_modulizer("modulize") {
"drive_sync_handler.js", "drive_sync_handler.js",
"file_operation_manager.js", "file_operation_manager.js",
"import_history.js", "import_history.js",
"media_scanner.js",
"progress_center.js", "progress_center.js",
"task_queue.js", "task_queue.js",
] ]
......
...@@ -34,7 +34,7 @@ class FileBrowserBackgroundFull extends BackgroundBase { ...@@ -34,7 +34,7 @@ class FileBrowserBackgroundFull extends BackgroundBase {
this.mediaImportHandler; this.mediaImportHandler;
/** /**
* @type {!importer.MediaScanner} * @type {!mediaScannerInterfaces.MediaScanner}
*/ */
this.mediaScanner; this.mediaScanner;
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
// Namespace // Namespace
// eslint-disable-next-line no-var
var importer = importer || {}; var importer = importer || {};
/** /**
...@@ -14,7 +15,7 @@ importer.ImportRunner = class { ...@@ -14,7 +15,7 @@ importer.ImportRunner = class {
/** /**
* Imports all media identified by a scanResult. * Imports all media identified by a scanResult.
* *
* @param {!importer.ScanResult} scanResult * @param {!mediaScannerInterfaces.ScanResult} scanResult
* @param {!importer.Destination} destination * @param {!importer.Destination} destination
* @param {!Promise<!DirectoryEntry>} directoryPromise * @param {!Promise<!DirectoryEntry>} directoryPromise
* *
......
...@@ -42,7 +42,7 @@ importer.MediaImportHandler.ImportTask = class { ...@@ -42,7 +42,7 @@ importer.MediaImportHandler.ImportTask = class {
/** /**
* @param {string} taskId * @param {string} taskId
* @param {!importerHistoryInterfaces.HistoryLoader} historyLoader * @param {!importerHistoryInterfaces.HistoryLoader} historyLoader
* @param {!importer.ScanResult} scanResult * @param {!mediaScannerInterfaces.ScanResult} scanResult
* @param {!Promise<!DirectoryEntry>} directoryPromise * @param {!Promise<!DirectoryEntry>} directoryPromise
* @param {!importer.Destination} destination The logical destination. * @param {!importer.Destination} destination The logical destination.
* @param {!importer.DispositionChecker.CheckerFunction} dispositionChecker * @param {!importer.DispositionChecker.CheckerFunction} dispositionChecker
......
...@@ -2,21 +2,22 @@ ...@@ -2,21 +2,22 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
var importer = importer || {}; // #import {importer} from '../../file_manager/common/js/importer_common.m.js';
/* #export */ const mediaScannerInterfaces = {};
/** /**
* Class representing the results of a scan operation. * Class representing the results of a scan operation.
* *
* @interface * @interface
*/ */
importer.MediaScanner = class { mediaScannerInterfaces.MediaScanner = class {
/** /**
* Initiates scanning. * Initiates scanning.
* *
* @param {!DirectoryEntry} directory * @param {!DirectoryEntry} directory
* @param {!importer.ScanMode} mode * @param {!importer.ScanMode} mode
* @return {!importer.ScanResult} ScanResult object representing the scan * @return {!mediaScannerInterfaces.ScanResult} ScanResult object representing
* job both while in-progress and when completed. * the scan job both while in-progress and when completed.
*/ */
scanDirectory(directory, mode) {} scanDirectory(directory, mode) {}
...@@ -27,37 +28,37 @@ importer.MediaScanner = class { ...@@ -27,37 +28,37 @@ importer.MediaScanner = class {
* must be of a supported media type. Individually supplied files * must be of a supported media type. Individually supplied files
* are not subject to deduplication. * are not subject to deduplication.
* @param {!importer.ScanMode} mode The method to detect new files. * @param {!importer.ScanMode} mode The method to detect new files.
* @return {!importer.ScanResult} ScanResult object representing the scan * @return {!mediaScannerInterfaces.ScanResult} ScanResult object representing
* job for the explicitly supplied entries. * the scan job for the explicitly supplied entries.
*/ */
scanFiles(entries, mode) {} scanFiles(entries, mode) {}
/** /**
* Adds an observer, which will be notified on scan events. * Adds an observer, which will be notified on scan events.
* *
* @param {!importer.ScanObserver} observer * @param {!mediaScannerInterfaces.ScanObserver} observer
*/ */
addObserver(observer) {} addObserver(observer) {}
/** /**
* Remove a previously registered observer. * Remove a previously registered observer.
* *
* @param {!importer.ScanObserver} observer * @param {!mediaScannerInterfaces.ScanObserver} observer
*/ */
removeObserver(observer) {} removeObserver(observer) {}
}; };
/** /**
* @typedef {function(!importer.ScanEvent, importer.ScanResult)} * @typedef {function(!importer.ScanEvent, mediaScannerInterfaces.ScanResult)}
*/ */
importer.ScanObserver; mediaScannerInterfaces.ScanObserver;
/** /**
* Class representing the results of a scan operation. * Class representing the results of a scan operation.
* *
* @interface * @interface
*/ */
importer.ScanResult = class { mediaScannerInterfaces.ScanResult = class {
/** /**
* @return {boolean} true if scanning is complete. * @return {boolean} true if scanning is complete.
*/ */
...@@ -116,12 +117,12 @@ importer.ScanResult = class { ...@@ -116,12 +117,12 @@ importer.ScanResult = class {
* Returns a promise that fires when scanning is finished * Returns a promise that fires when scanning is finished
* normally or has been canceled. * normally or has been canceled.
* *
* @return {!Promise<!importer.ScanResult>} * @return {!Promise<!mediaScannerInterfaces.ScanResult>}
*/ */
whenFinal() {} whenFinal() {}
/** /**
* @return {!importer.ScanResult.Statistics} * @return {!mediaScannerInterfaces.ScanResult.Statistics}
*/ */
getStatistics() {} getStatistics() {}
}; };
...@@ -139,4 +140,4 @@ importer.ScanResult = class { ...@@ -139,4 +140,4 @@ importer.ScanResult = class {
* progress: number * progress: number
* }} * }}
*/ */
importer.ScanResult.Statistics; mediaScannerInterfaces.ScanResult.Statistics;
...@@ -81,6 +81,7 @@ js_type_check("closure_compile_jsmodules") { ...@@ -81,6 +81,7 @@ js_type_check("closure_compile_jsmodules") {
":entry_location_impl.m", ":entry_location_impl.m",
":file_operation_util.m", ":file_operation_util.m",
":import_history.m", ":import_history.m",
":media_scanner.m",
":metadata_proxy.m", ":metadata_proxy.m",
":mock_drive_sync_handler.m", ":mock_drive_sync_handler.m",
":mock_file_operation_manager.m", ":mock_file_operation_manager.m",
...@@ -109,6 +110,7 @@ js_type_check("test_support_modules_type_check") { ...@@ -109,6 +110,7 @@ js_type_check("test_support_modules_type_check") {
uses_js_modules = true uses_js_modules = true
deps = [ deps = [
":mock_crostini.m", ":mock_crostini.m",
":mock_media_scanner.m",
":mock_volume_manager.m", ":mock_volume_manager.m",
":test_import_history.m", ":test_import_history.m",
] ]
...@@ -616,6 +618,18 @@ js_library("mock_media_scanner") { ...@@ -616,6 +618,18 @@ js_library("mock_media_scanner") {
visibility = [ "//ui/file_manager/file_manager/*" ] visibility = [ "//ui/file_manager/file_manager/*" ]
} }
js_library("mock_media_scanner.m") {
sources = [ "$root_gen_dir/ui/file_manager/file_manager/background/js/mock_media_scanner.m.js" ]
deps = [
":media_scanner.m",
"//chrome/test/data/webui:chai_assert",
"//ui/file_manager/externs/background:media_scanner.m",
"//ui/file_manager/file_manager/common/js:importer_common.m",
]
extra_deps = [ ":modulize" ]
}
js_library("media_scanner") { js_library("media_scanner") {
deps = [ deps = [
":file_operation_util", ":file_operation_util",
...@@ -624,11 +638,30 @@ js_library("media_scanner") { ...@@ -624,11 +638,30 @@ js_library("media_scanner") {
externs_list = [ "//ui/file_manager/externs/background/media_scanner.js" ] externs_list = [ "//ui/file_manager/externs/background/media_scanner.js" ]
} }
js_unittest("media_scanner_unittest") { js_library("media_scanner.m") {
sources = [ "$root_gen_dir/ui/file_manager/file_manager/background/js/media_scanner.m.js" ]
deps = [ deps = [
":media_scanner", ":file_operation_util.m",
":mock_media_scanner", ":metadata_proxy.m",
"//ui/file_manager/file_manager/common/js:test_importer_common", "//ui/file_manager/externs/background:media_scanner.m",
"//ui/file_manager/file_manager/common/js:importer_common.m",
"//ui/webui/resources/js:assert.m",
]
extra_deps = [ ":modulize" ]
}
js_unittest("media_scanner_unittest.m") {
deps = [
":file_operation_util.m",
":media_scanner.m",
":mock_media_scanner.m",
":test_import_history.m",
"//chrome/test/data/webui:chai_assert",
"//ui/file_manager/base/js:test_error_reporting.m",
"//ui/file_manager/externs/background:media_scanner.m",
"//ui/file_manager/file_manager/common/js:importer_common.m",
"//ui/file_manager/file_manager/common/js:unittest_util.m",
] ]
} }
...@@ -953,6 +986,7 @@ js_test_gen_html("js_test_gen_html_modules") { ...@@ -953,6 +986,7 @@ js_test_gen_html("js_test_gen_html_modules") {
":crostini_unittest.m", ":crostini_unittest.m",
":drive_sync_handler_unittest.m", ":drive_sync_handler_unittest.m",
":import_history_unittest.m", ":import_history_unittest.m",
":media_scanner_unittest.m",
":metadata_proxy_unittest.m", ":metadata_proxy_unittest.m",
":mount_metrics_unittest.m", ":mount_metrics_unittest.m",
":task_queue_unittest.m", ":task_queue_unittest.m",
...@@ -975,7 +1009,6 @@ js_test_gen_html("js_test_gen_html") { ...@@ -975,7 +1009,6 @@ js_test_gen_html("js_test_gen_html") {
":file_operation_handler_unittest", ":file_operation_handler_unittest",
":file_operation_manager_unittest", ":file_operation_manager_unittest",
":media_import_handler_unittest", ":media_import_handler_unittest",
":media_scanner_unittest",
":trash_unittest", ":trash_unittest",
":volume_manager_unittest", ":volume_manager_unittest",
] ]
...@@ -1006,6 +1039,8 @@ js_modulizer("modulize") { ...@@ -1006,6 +1039,8 @@ js_modulizer("modulize") {
"test_import_history.js", "test_import_history.js",
"import_history.js", "import_history.js",
"drive_sync_handler.js", "drive_sync_handler.js",
"media_scanner.js",
"mock_media_scanner.js",
] ]
namespace_rewrites = cr_namespace_rewrites namespace_rewrites = cr_namespace_rewrites
......
...@@ -63,11 +63,11 @@ class FileBrowserBackgroundImpl extends BackgroundBaseImpl { ...@@ -63,11 +63,11 @@ class FileBrowserBackgroundImpl extends BackgroundBaseImpl {
/** /**
* Provides support for scanning media devices as part of Cloud Import. * Provides support for scanning media devices as part of Cloud Import.
* @type {!importer.MediaScanner} * @type {!mediaScannerInterfaces.MediaScanner}
*/ */
this.mediaScanner = new importer.DefaultMediaScanner( this.mediaScanner = new mediaScanner.DefaultMediaScanner(
importerHistory.createMetadataHashcode, this.dispositionChecker_, importerHistory.createMetadataHashcode, this.dispositionChecker_,
importer.DefaultDirectoryWatcher.create); mediaScanner.DefaultDirectoryWatcher.create);
/** /**
* Handles importing of user media (e.g. photos, videos) from removable * Handles importing of user media (e.g. photos, videos) from removable
......
...@@ -205,7 +205,7 @@ importer.MediaImportHandler.ImportTaskImpl = ...@@ -205,7 +205,7 @@ importer.MediaImportHandler.ImportTaskImpl =
/** /**
* @param {string} taskId * @param {string} taskId
* @param {!importerHistoryInterfaces.HistoryLoader} historyLoader * @param {!importerHistoryInterfaces.HistoryLoader} historyLoader
* @param {!importer.ScanResult} scanResult * @param {!mediaScannerInterfaces.ScanResult} scanResult
* @param {!Promise<!DirectoryEntry>} directoryPromise * @param {!Promise<!DirectoryEntry>} directoryPromise
* @param {!importer.Destination} destination The logical destination. * @param {!importer.Destination} destination The logical destination.
* @param {!importer.DispositionChecker.CheckerFunction} dispositionChecker * @param {!importer.DispositionChecker.CheckerFunction} dispositionChecker
...@@ -224,7 +224,7 @@ importer.MediaImportHandler.ImportTaskImpl = ...@@ -224,7 +224,7 @@ importer.MediaImportHandler.ImportTaskImpl =
/** @private {!Promise<!DirectoryEntry>} */ /** @private {!Promise<!DirectoryEntry>} */
this.directoryPromise_ = directoryPromise; this.directoryPromise_ = directoryPromise;
/** @private {!importer.ScanResult} */ /** @private {!mediaScannerInterfaces.ScanResult} */
this.scanResult_ = scanResult; this.scanResult_ = scanResult;
/** @private {!importerHistoryInterfaces.HistoryLoader} */ /** @private {!importerHistoryInterfaces.HistoryLoader} */
......
...@@ -2,32 +2,43 @@ ...@@ -2,32 +2,43 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// clang-format off
// #import {assert} from 'chrome://resources/js/assert.m.js';
// #import {metadataProxy} from './metadata_proxy.m.js';
// #import {fileOperationUtil} from './file_operation_util.m.js';
// #import {importer} from '../../common/js/importer_common.m.js';
// #import {mediaScannerInterfaces} from '../../../externs/background/media_scanner.m.js';
// clang-format on
// Namespace
/* #export */ const mediaScanner = {};
/** /**
* Recursively scans through a list of given files and directories, and creates * Recursively scans through a list of given files and directories, and creates
* a list of media files. * a list of media files.
* *
* @implements {importer.MediaScanner} * @implements {mediaScannerInterfaces.MediaScanner}
*/ */
importer.DefaultMediaScanner = class { mediaScanner.DefaultMediaScanner = class {
/** /**
* @param {function(!FileEntry): !Promise<string>} hashGenerator * @param {function(!FileEntry): !Promise<string>} hashGenerator
* @param {function(!FileEntry, !importer.Destination, * @param {function(!FileEntry, !importer.Destination,
* !importer.ScanMode): * !importer.ScanMode):
* !Promise<!importer.Disposition>} dispositionChecker * !Promise<!importer.Disposition>} dispositionChecker
* @param {!importer.DirectoryWatcherFactory} watcherFactory * @param {!mediaScanner.DirectoryWatcherFactory} watcherFactory
*/ */
constructor(hashGenerator, dispositionChecker, watcherFactory) { constructor(hashGenerator, dispositionChecker, watcherFactory) {
/** /**
* A little factory for DefaultScanResults which allows us to forgo * A little factory for DefaultScanResults which allows us to forgo
* the saving it's dependencies in our fields. * the saving it's dependencies in our fields.
* @param {importer.ScanMode} mode Mode of the scan to find new files. * @param {importer.ScanMode} mode Mode of the scan to find new files.
* @return {!importer.DefaultScanResult} * @return {!mediaScanner.DefaultScanResult}
*/ */
this.createScanResult_ = mode => { this.createScanResult_ = mode => {
return new importer.DefaultScanResult(mode, hashGenerator); return new mediaScanner.DefaultScanResult(mode, hashGenerator);
}; };
/** @private {!Array<!importer.ScanObserver>} */ /** @private {!Array<!mediaScannerInterfaces.ScanObserver>} */
this.observers_ = []; this.observers_ = [];
/** /**
...@@ -39,7 +50,7 @@ importer.DefaultMediaScanner = class { ...@@ -39,7 +50,7 @@ importer.DefaultMediaScanner = class {
this.getDisposition_ = dispositionChecker; this.getDisposition_ = dispositionChecker;
/** /**
* @private {!importer.DirectoryWatcherFactory} * @private {!mediaScanner.DirectoryWatcherFactory}
* @const * @const
*/ */
this.watcherFactory_ = watcherFactory; this.watcherFactory_ = watcherFactory;
...@@ -67,7 +78,7 @@ importer.DefaultMediaScanner = class { ...@@ -67,7 +78,7 @@ importer.DefaultMediaScanner = class {
console.info(scan.name + ': Scanning directory ' + directory.fullPath); console.info(scan.name + ': Scanning directory ' + directory.fullPath);
const watcher = this.watcherFactory_( const watcher = this.watcherFactory_(
/** @this {importer.DefaultMediaScanner} */ /** @this {mediaScanner.DefaultMediaScanner} */
() => { () => {
scan.cancel(); scan.cancel();
this.notify_(importer.ScanEvent.INVALIDATED, scan); this.notify_(importer.ScanEvent.INVALIDATED, scan);
...@@ -119,7 +130,7 @@ importer.DefaultMediaScanner = class { ...@@ -119,7 +130,7 @@ importer.DefaultMediaScanner = class {
/** /**
* @param {!importer.DefaultScanResult} scan * @param {!mediaScanner.DefaultScanResult} scan
* @param {!Array<!FileEntry>} entries * @param {!Array<!FileEntry>} entries
* @return {!Promise} Resolves when scanning is finished normally * @return {!Promise} Resolves when scanning is finished normally
* or canceled. * or canceled.
...@@ -143,7 +154,7 @@ importer.DefaultMediaScanner = class { ...@@ -143,7 +154,7 @@ importer.DefaultMediaScanner = class {
} }
// the second arg to slice is an exclusive end index, so we +1 batch size. // the second arg to slice is an exclusive end index, so we +1 batch size.
const end = begin + importer.DefaultMediaScanner.SCAN_BATCH_SIZE; const end = begin + mediaScanner.DefaultMediaScanner.SCAN_BATCH_SIZE;
console.log(scan.name + ': Processing batch ' + begin + '-' + (end - 1)); console.log(scan.name + ': Processing batch ' + begin + '-' + (end - 1));
const batch = entries.slice(begin, end); const batch = entries.slice(begin, end);
...@@ -161,12 +172,12 @@ importer.DefaultMediaScanner = class { ...@@ -161,12 +172,12 @@ importer.DefaultMediaScanner = class {
* Notifies all listeners at some point in the near future. * Notifies all listeners at some point in the near future.
* *
* @param {!importer.ScanEvent} event * @param {!importer.ScanEvent} event
* @param {!importer.DefaultScanResult} result * @param {!mediaScanner.DefaultScanResult} result
* @private * @private
*/ */
notify_(event, result) { notify_(event, result) {
this.observers_.forEach( this.observers_.forEach(
/** @param {!importer.ScanObserver} observer */ /** @param {!mediaScannerInterfaces.ScanObserver} observer */
observer => { observer => {
observer(event, result); observer(event, result);
}); });
...@@ -177,7 +188,7 @@ importer.DefaultMediaScanner = class { ...@@ -177,7 +188,7 @@ importer.DefaultMediaScanner = class {
* watchers for each encountered directory. * watchers for each encountered directory.
* *
* @param {!DirectoryEntry} directory * @param {!DirectoryEntry} directory
* @param {!importer.DirectoryWatcher} watcher * @param {!mediaScanner.DirectoryWatcher} watcher
* @return {!Promise<!Array<!FileEntry>>} * @return {!Promise<!Array<!FileEntry>>}
* @private * @private
*/ */
...@@ -210,7 +221,7 @@ importer.DefaultMediaScanner = class { ...@@ -210,7 +221,7 @@ importer.DefaultMediaScanner = class {
/** /**
* Finds all files beneath directory. * Finds all files beneath directory.
* *
* @param {!importer.DefaultScanResult} scan * @param {!mediaScanner.DefaultScanResult} scan
* @param {!FileEntry} entry * @param {!FileEntry} entry
* @return {!Promise} * @return {!Promise}
* @private * @private
...@@ -234,7 +245,7 @@ importer.DefaultMediaScanner = class { ...@@ -234,7 +245,7 @@ importer.DefaultMediaScanner = class {
/** /**
* Adds a newly discovered file to the given scan result. * Adds a newly discovered file to the given scan result.
* *
* @param {!importer.DefaultScanResult} scan * @param {!mediaScanner.DefaultScanResult} scan
* @param {!FileEntry} entry * @param {!FileEntry} entry
* @return {!Promise} * @return {!Promise}
* @private * @private
...@@ -261,7 +272,7 @@ importer.DefaultMediaScanner = class { ...@@ -261,7 +272,7 @@ importer.DefaultMediaScanner = class {
* Adds a duplicate file to the given scan result. This is to track the * Adds a duplicate file to the given scan result. This is to track the
* number of duplicates that are being encountered. * number of duplicates that are being encountered.
* *
* @param {!importer.DefaultScanResult} scan * @param {!mediaScanner.DefaultScanResult} scan
* @param {!FileEntry} entry * @param {!FileEntry} entry
* @param {!importer.Disposition} disposition * @param {!importer.Disposition} disposition
* @return {!Promise} * @return {!Promise}
...@@ -276,7 +287,7 @@ importer.DefaultMediaScanner = class { ...@@ -276,7 +287,7 @@ importer.DefaultMediaScanner = class {
}; };
/** @const {number} */ /** @const {number} */
importer.DefaultMediaScanner.SCAN_BATCH_SIZE = 1; mediaScanner.DefaultMediaScanner.SCAN_BATCH_SIZE = 1;
/** /**
* Results of a scan operation. The object is "live" in that data can and * Results of a scan operation. The object is "live" in that data can and
...@@ -288,9 +299,9 @@ importer.DefaultMediaScanner.SCAN_BATCH_SIZE = 1; ...@@ -288,9 +299,9 @@ importer.DefaultMediaScanner.SCAN_BATCH_SIZE = 1;
* Note that classes implementing this should provide a read-only * Note that classes implementing this should provide a read-only
* {@code name} field. * {@code name} field.
* *
* @implements {importer.ScanResult} * @implements {mediaScannerInterfaces.ScanResult}
*/ */
importer.DefaultScanResult = class { mediaScanner.DefaultScanResult = class {
/** /**
* @param {importer.ScanMode} mode The scan mode applied for finding new * @param {importer.ScanMode} mode The scan mode applied for finding new
* files. * files.
...@@ -365,7 +376,7 @@ importer.DefaultScanResult = class { ...@@ -365,7 +376,7 @@ importer.DefaultScanResult = class {
*/ */
this.canceled_ = false; this.canceled_ = false;
/** @private {!importer.Resolver.<!importer.ScanResult>} */ /** @private {!importer.Resolver.<!mediaScannerInterfaces.ScanResult>} */
this.resolver_ = new importer.Resolver(); this.resolver_ = new importer.Resolver();
} }
...@@ -520,7 +531,7 @@ importer.DefaultScanResult = class { ...@@ -520,7 +531,7 @@ importer.DefaultScanResult = class {
* Watcher for directories. * Watcher for directories.
* @interface * @interface
*/ */
importer.DirectoryWatcher = class { mediaScanner.DirectoryWatcher = class {
constructor() { constructor() {
/** @type {boolean} */ /** @type {boolean} */
this.triggered = false; this.triggered = false;
...@@ -536,19 +547,19 @@ importer.DirectoryWatcher = class { ...@@ -536,19 +547,19 @@ importer.DirectoryWatcher = class {
/** /**
* @typedef {function()} * @typedef {function()}
*/ */
importer.DirectoryWatcherFactoryCallback; mediaScanner.DirectoryWatcherFactoryCallback;
/** /**
* @typedef {function(importer.DirectoryWatcherFactoryCallback): * @typedef {function(mediaScanner.DirectoryWatcherFactoryCallback):
* !importer.DirectoryWatcher} * !mediaScanner.DirectoryWatcher}
*/ */
importer.DirectoryWatcherFactory; mediaScanner.DirectoryWatcherFactory;
/** /**
* Watcher for directories. * Watcher for directories.
* @implements {importer.DirectoryWatcher} * @implements {mediaScanner.DirectoryWatcher}
*/ */
importer.DefaultDirectoryWatcher = class { mediaScanner.DefaultDirectoryWatcher = class {
/** /**
* @param {function()} callback Callback to be invoked when one of watched * @param {function()} callback Callback to be invoked when one of watched
* directories is changed. * directories is changed.
...@@ -564,10 +575,10 @@ importer.DefaultDirectoryWatcher = class { ...@@ -564,10 +575,10 @@ importer.DefaultDirectoryWatcher = class {
* Creates new directory watcher. * Creates new directory watcher.
* @param {function()} callback Callback to be invoked when one of watched * @param {function()} callback Callback to be invoked when one of watched
* directories is changed. * directories is changed.
* @return {!importer.DirectoryWatcher} * @return {!mediaScanner.DirectoryWatcher}
*/ */
static create(callback) { static create(callback) {
return new importer.DefaultDirectoryWatcher(callback); return new mediaScanner.DefaultDirectoryWatcher(callback);
} }
/** /**
......
...@@ -2,6 +2,18 @@ ...@@ -2,6 +2,18 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import {assertEquals, assertFalse, assertThrows} from 'chrome://test/chai_assert.js';
import {reportPromise} from '../../../base/js/test_error_reporting.m.js';
import {mediaScannerInterfaces} from '../../../externs/background/media_scanner.m.js';
import {importer} from '../../common/js/importer_common.m.js';
import {assertFileEntryPathsEqual} from '../../common/js/unittest_util.m.js';
import {fileOperationUtil} from './file_operation_util.m.js';
import {mediaScanner} from './media_scanner.m.js';
import {TestDirectoryWatcher} from './mock_media_scanner.m.js';
import {importerTestHistory} from './test_import_history.m.js';
/** /**
* Stub out the metrics package. * Stub out the metrics package.
* @type {!Object<!string, !Function>} * @type {!Object<!string, !Function>}
...@@ -11,7 +23,7 @@ const metrics = { ...@@ -11,7 +23,7 @@ const metrics = {
recordValue: function() {} recordValue: function() {}
}; };
/** @type {!importer.DefaultMediaScanner} */ /** @type {!mediaScanner.DefaultMediaScanner} */
let scanner; let scanner;
/** /**
...@@ -32,7 +44,7 @@ let watcher; ...@@ -32,7 +44,7 @@ let watcher;
let dispositionChecker; let dispositionChecker;
// Set up the test components. // Set up the test components.
function setUp() { export function setUp() {
importHistory = new importerTestHistory.TestImportHistory(); importHistory = new importerTestHistory.TestImportHistory();
// Setup a default disposition checker. Tests can replace it at runtime // Setup a default disposition checker. Tests can replace it at runtime
...@@ -41,7 +53,7 @@ function setUp() { ...@@ -41,7 +53,7 @@ function setUp() {
return Promise.resolve(importer.Disposition.ORIGINAL); return Promise.resolve(importer.Disposition.ORIGINAL);
}; };
scanner = new importer.DefaultMediaScanner( scanner = new mediaScanner.DefaultMediaScanner(
/** @param {!FileEntry} entry */ /** @param {!FileEntry} entry */
entry => { entry => {
return Promise.resolve(entry.name); return Promise.resolve(entry.name);
...@@ -58,13 +70,13 @@ function setUp() { ...@@ -58,13 +70,13 @@ function setUp() {
/** /**
* Verifies that scanning an empty filesystem produces an empty list. * Verifies that scanning an empty filesystem produces an empty list.
*/ */
function testEmptySourceList() { export function testEmptySourceList() {
assertThrows(() => { assertThrows(() => {
scanner.scanFiles([], scanMode); scanner.scanFiles([], scanMode);
}); });
} }
function testIsScanning(callback) { export function testIsScanning(callback) {
const filenames = [ const filenames = [
'happy', 'happy',
'thoughts', 'thoughts',
...@@ -84,7 +96,7 @@ function testIsScanning(callback) { ...@@ -84,7 +96,7 @@ function testIsScanning(callback) {
callback); callback);
} }
function testObserverNotifiedOnScanFinish(callback) { export function testObserverNotifiedOnScanFinish(callback) {
const filenames = [ const filenames = [
'happy', 'happy',
'thoughts', 'thoughts',
...@@ -116,7 +128,7 @@ function testObserverNotifiedOnScanFinish(callback) { ...@@ -116,7 +128,7 @@ function testObserverNotifiedOnScanFinish(callback) {
/** /**
* Verifies that scanFiles slurps up all specified files. * Verifies that scanFiles slurps up all specified files.
*/ */
function testScanFiles(callback) { export function testScanFiles(callback) {
const filenames = [ const filenames = [
'foo', 'foo',
'foo.jpg', 'foo.jpg',
...@@ -144,7 +156,7 @@ function testScanFiles(callback) { ...@@ -144,7 +156,7 @@ function testScanFiles(callback) {
/** /**
* Verifies that scanFiles skips duplicated files. * Verifies that scanFiles skips duplicated files.
*/ */
function testScanFilesIgnoresPreviousImports(callback) { export function testScanFilesIgnoresPreviousImports(callback) {
const filenames = [ const filenames = [
'oldimage1234.jpg', // a history duplicate 'oldimage1234.jpg', // a history duplicate
'driveimage1234.jpg', // a content duplicate 'driveimage1234.jpg', // a content duplicate
...@@ -186,7 +198,7 @@ function testScanFilesIgnoresPreviousImports(callback) { ...@@ -186,7 +198,7 @@ function testScanFilesIgnoresPreviousImports(callback) {
/** /**
* Verifies that scanning a simple single-level directory structure works. * Verifies that scanning a simple single-level directory structure works.
*/ */
function testEmptyScanResults(callback) { export function testEmptyScanResults(callback) {
const filenames = [ const filenames = [
'happy', 'happy',
'thoughts', 'thoughts',
...@@ -209,7 +221,7 @@ function testEmptyScanResults(callback) { ...@@ -209,7 +221,7 @@ function testEmptyScanResults(callback) {
/** /**
* Verifies that scanning a simple single-level directory structure works. * Verifies that scanning a simple single-level directory structure works.
*/ */
function testSingleLevel(callback) { export function testSingleLevel(callback) {
const filenames = [ const filenames = [
'foo', 'foo',
'foo.jpg', 'foo.jpg',
...@@ -242,7 +254,7 @@ function testSingleLevel(callback) { ...@@ -242,7 +254,7 @@ function testSingleLevel(callback) {
* Verifies that scanning a simple single-level directory produces 100% * Verifies that scanning a simple single-level directory produces 100%
* progress at completion. * progress at completion.
*/ */
function testProgress(callback) { export function testProgress(callback) {
const filenames = [ const filenames = [
'foo', 'foo',
'foo.jpg', 'foo.jpg',
...@@ -274,7 +286,7 @@ function testProgress(callback) { ...@@ -274,7 +286,7 @@ function testProgress(callback) {
/** /**
* Verifies that scanning ignores previously imported entries. * Verifies that scanning ignores previously imported entries.
*/ */
function testIgnoresPreviousImports(callback) { export function testIgnoresPreviousImports(callback) {
importHistory.importedPaths['/testIgnoresPreviousImports/oldimage1234.jpg'] = importHistory.importedPaths['/testIgnoresPreviousImports/oldimage1234.jpg'] =
[importer.Destination.GOOGLE_DRIVE]; [importer.Destination.GOOGLE_DRIVE];
const filenames = [ const filenames = [
...@@ -319,7 +331,7 @@ function testIgnoresPreviousImports(callback) { ...@@ -319,7 +331,7 @@ function testIgnoresPreviousImports(callback) {
reportPromise(promise, callback); reportPromise(promise, callback);
} }
function testTracksDuplicates(callback) { export function testTracksDuplicates(callback) {
importHistory.importedPaths['/testTracksDuplicates/oldimage1234.jpg'] = importHistory.importedPaths['/testTracksDuplicates/oldimage1234.jpg'] =
[importer.Destination.GOOGLE_DRIVE]; [importer.Destination.GOOGLE_DRIVE];
const filenames = [ const filenames = [
...@@ -366,7 +378,7 @@ function testTracksDuplicates(callback) { ...@@ -366,7 +378,7 @@ function testTracksDuplicates(callback) {
reportPromise(promise, callback); reportPromise(promise, callback);
} }
function testMultiLevel(callback) { export function testMultiLevel(callback) {
const filenames = [ const filenames = [
'foo.jpg', 'bar', 'foo.jpg', 'bar',
[ [
...@@ -404,7 +416,7 @@ function testMultiLevel(callback) { ...@@ -404,7 +416,7 @@ function testMultiLevel(callback) {
callback); callback);
} }
function testDedupesFilesInScanResult(callback) { export function testDedupesFilesInScanResult(callback) {
const filenames = [ const filenames = [
'foo.jpg', 'bar.jpg', 'foo.jpg', 'bar.jpg',
[ [
...@@ -446,11 +458,11 @@ function testDedupesFilesInScanResult(callback) { ...@@ -446,11 +458,11 @@ function testDedupesFilesInScanResult(callback) {
/** /**
* Verifies that scanning a simple single-level directory structure works. * Verifies that scanning a simple single-level directory structure works.
*/ */
function testDefaultScanResult() { export function testDefaultScanResult() {
const hashGenerator = file => { const hashGenerator = file => {
return file.toURL(); return file.toURL();
}; };
const scan = new importer.DefaultScanResult(scanMode, hashGenerator); const scan = new mediaScanner.DefaultScanResult(scanMode, hashGenerator);
// 0 before we set candidate count // 0 before we set candidate count
assertProgress(0, scan); assertProgress(0, scan);
...@@ -466,7 +478,7 @@ function testDefaultScanResult() { ...@@ -466,7 +478,7 @@ function testDefaultScanResult() {
assertProgress(100, scan); assertProgress(100, scan);
} }
function testInvalidation(callback) { export function testInvalidation(callback) {
const invalidatePromise = new Promise(fulfill => { const invalidatePromise = new Promise(fulfill => {
scanner.addObserver(fulfill); scanner.addObserver(fulfill);
}); });
...@@ -489,8 +501,8 @@ function testInvalidation(callback) { ...@@ -489,8 +501,8 @@ function testInvalidation(callback) {
/** /**
* Verifies the results of the media scan are as expected. * Verifies the results of the media scan are as expected.
* @param {number} expected, 0-100 * @param {number} expected, 0-100
* @param {!importer.ScanResult} scan * @param {!mediaScannerInterfaces.ScanResult} scan
* @return {!importer.ScanResult} * @return {!mediaScannerInterfaces.ScanResult}
*/ */
function assertProgress(expected, scan) { function assertProgress(expected, scan) {
assertEquals(expected, scan.getStatistics().progress); assertEquals(expected, scan.getStatistics().progress);
...@@ -500,8 +512,8 @@ function assertProgress(expected, scan) { ...@@ -500,8 +512,8 @@ function assertProgress(expected, scan) {
/** /**
* Verifies the results of the media scan are as expected. * Verifies the results of the media scan are as expected.
* @param {!Array<string>} expected * @param {!Array<string>} expected
* @param {!importer.ScanResult} scan * @param {!mediaScannerInterfaces.ScanResult} scan
* @return {!importer.ScanResult} * @return {!mediaScannerInterfaces.ScanResult}
*/ */
function assertFilesFound(expected, scan) { function assertFilesFound(expected, scan) {
assertFileEntryPathsEqual(expected, scan.getFileEntries()); assertFileEntryPathsEqual(expected, scan.getFileEntries());
...@@ -512,8 +524,8 @@ function assertFilesFound(expected, scan) { ...@@ -512,8 +524,8 @@ function assertFilesFound(expected, scan) {
/** /**
* Verifies the results of the media scan are as expected. * Verifies the results of the media scan are as expected.
* @param {!Array<string>} expected * @param {!Array<string>} expected
* @param {!importer.ScanResult} scan * @param {!mediaScannerInterfaces.ScanResult} scan
* @return {!importer.ScanResult} * @return {!mediaScannerInterfaces.ScanResult}
*/ */
function assertDuplicatesFound(expected, scan) { function assertDuplicatesFound(expected, scan) {
assertFileEntryPathsEqual(expected, scan.getDuplicateFileEntries()); assertFileEntryPathsEqual(expected, scan.getDuplicateFileEntries());
......
...@@ -2,14 +2,22 @@ ...@@ -2,14 +2,22 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// clang-format off
// #import {assertTrue, assertEquals} from 'chrome://test/chai_assert.js';
// #import {importer} from '../../common/js/importer_common.m.js';
// #import {mediaScannerInterfaces} from '../../../externs/background/media_scanner.m.js';
// #import {mediaScanner} from './media_scanner.m.js';
// clang-format on
/** /**
* importer.MediaScanner and importer.ScanResult test double. * mediaScannerInterfaces.MediaScanner and mediaScannerInterfaces.ScanResult
* test double.
* *
* @implements {importer.MediaScanner} * @implements {mediaScannerInterfaces.MediaScanner}
*/ */
class TestMediaScanner { /* #export */ class TestMediaScanner {
constructor() { constructor() {
/** @private {!Array<!importer.ScanResult>} */ /** @private {!Array<!mediaScannerInterfaces.ScanResult>} */
this.scans_ = []; this.scans_ = [];
/** /**
...@@ -26,7 +34,7 @@ class TestMediaScanner { ...@@ -26,7 +34,7 @@ class TestMediaScanner {
/** /**
* List of scan observers. * List of scan observers.
* @private {!Array<!importer.ScanObserver>} * @private {!Array<!mediaScannerInterfaces.ScanObserver>}
*/ */
this.observers = []; this.observers = [];
...@@ -90,7 +98,7 @@ class TestMediaScanner { ...@@ -90,7 +98,7 @@ class TestMediaScanner {
/** /**
* Notifies observers that a scan has finished. * Notifies observers that a scan has finished.
* @param {!importer.ScanResult} scan * @param {!mediaScannerInterfaces.ScanResult} scan
*/ */
finalize(scan) { finalize(scan) {
// Note the |scan| has {!TestScanResult} type in test, and needs a // Note the |scan| has {!TestScanResult} type in test, and needs a
...@@ -120,11 +128,12 @@ class TestMediaScanner { ...@@ -120,11 +128,12 @@ class TestMediaScanner {
} }
/** /**
* importer.MediaScanner and importer.ScanResult test double. * mediaScannerInterfaces.MediaScanner and mediaScannerInterfaces.ScanResult
* test double.
* *
* @implements {importer.ScanResult} * @implements {mediaScannerInterfaces.ScanResult}
*/ */
class TestScanResult { /* #export */ class TestScanResult {
/** /**
* @param {!Array<!FileEntry>} fileEntries * @param {!Array<!FileEntry>} fileEntries
*/ */
...@@ -162,7 +171,7 @@ class TestScanResult { ...@@ -162,7 +171,7 @@ class TestScanResult {
/** @private {boolean} */ /** @private {boolean} */
this.canceled_ = false; this.canceled_ = false;
/** @type {!Promise<!importer.ScanResult>} */ /** @type {!Promise<!mediaScannerInterfaces.ScanResult>} */
this.whenFinal_ = new Promise((resolve, reject) => { this.whenFinal_ = new Promise((resolve, reject) => {
this.resolveResult_ = result => { this.resolveResult_ = result => {
this.settled_ = true; this.settled_ = true;
...@@ -226,7 +235,7 @@ class TestScanResult { ...@@ -226,7 +235,7 @@ class TestScanResult {
duplicates[importer.Disposition.CONTENT_DUPLICATE] = 0; duplicates[importer.Disposition.CONTENT_DUPLICATE] = 0;
duplicates[importer.Disposition.HISTORY_DUPLICATE] = 0; duplicates[importer.Disposition.HISTORY_DUPLICATE] = 0;
duplicates[importer.Disposition.SCAN_DUPLICATE] = 0; duplicates[importer.Disposition.SCAN_DUPLICATE] = 0;
return /** @type {importer.ScanResult.Statistics} */ ({ return /** @type {mediaScannerInterfaces.ScanResult.Statistics} */ ({
scanDuration: this.scanDuration, scanDuration: this.scanDuration,
newFileCount: this.fileEntries.length, newFileCount: this.fileEntries.length,
duplicates: duplicates, duplicates: duplicates,
...@@ -243,9 +252,9 @@ class TestScanResult { ...@@ -243,9 +252,9 @@ class TestScanResult {
TestScanResult.lastId_ = 0; TestScanResult.lastId_ = 0;
/** /**
* @implements {importer.DirectoryWatcher} * @implements {mediaScanner.DirectoryWatcher}
*/ */
class TestDirectoryWatcher { /* #export */ class TestDirectoryWatcher {
constructor(callback) { constructor(callback) {
/** /**
* @public {function()} * @public {function()}
......
...@@ -50,7 +50,7 @@ class FileManager extends cr.EventTarget { ...@@ -50,7 +50,7 @@ class FileManager extends cr.EventTarget {
*/ */
this.onHistoryChangedBound_ = this.onHistoryChanged_.bind(this); this.onHistoryChangedBound_ = this.onHistoryChanged_.bind(this);
/** @private {?importer.MediaScanner} */ /** @private {?mediaScannerInterfaces.MediaScanner} */
this.mediaScanner_ = null; this.mediaScanner_ = null;
/** @private {?importer.ImportController} */ /** @private {?importer.ImportController} */
......
...@@ -26,7 +26,7 @@ importer.ImportController = class { ...@@ -26,7 +26,7 @@ importer.ImportController = class {
* @param {!importer.ControllerEnvironment} environment The class providing * @param {!importer.ControllerEnvironment} environment The class providing
* access to runtime environmental information, like the current * access to runtime environmental information, like the current
* directory, volume lookup and so-on. * directory, volume lookup and so-on.
* @param {!importer.MediaScanner} scanner * @param {!mediaScannerInterfaces.MediaScanner} scanner
* @param {!importer.ImportRunner} importRunner * @param {!importer.ImportRunner} importRunner
* @param {!importer.CommandWidget} commandWidget * @param {!importer.CommandWidget} commandWidget
*/ */
...@@ -40,7 +40,7 @@ importer.ImportController = class { ...@@ -40,7 +40,7 @@ importer.ImportController = class {
/** @private @const {!importer.ImportRunner} */ /** @private @const {!importer.ImportRunner} */
this.importRunner_ = importRunner; this.importRunner_ = importRunner;
/** @private @const {!importer.MediaScanner} */ /** @private @const {!mediaScannerInterfaces.MediaScanner} */
this.scanner_ = scanner; this.scanner_ = scanner;
/** @private @const {!importer.CommandWidget} */ /** @private @const {!importer.CommandWidget} */
...@@ -101,7 +101,7 @@ importer.ImportController = class { ...@@ -101,7 +101,7 @@ importer.ImportController = class {
/** /**
* @param {!importer.ScanEvent} event Command event. * @param {!importer.ScanEvent} event Command event.
* @param {importer.ScanResult} scan * @param {mediaScannerInterfaces.ScanResult} scan
* @private * @private
*/ */
onScanEvent_(event, scan) { onScanEvent_(event, scan) {
...@@ -305,7 +305,7 @@ importer.ImportController = class { ...@@ -305,7 +305,7 @@ importer.ImportController = class {
/** /**
* Checks the environment and updates UI as needed. * Checks the environment and updates UI as needed.
* @param {importer.ScanResult=} opt_scan If supplied, * @param {mediaScannerInterfaces.ScanResult=} opt_scan If supplied,
* @private * @private
*/ */
checkState_(opt_scan) { checkState_(opt_scan) {
...@@ -414,7 +414,7 @@ importer.ImportController = class { ...@@ -414,7 +414,7 @@ importer.ImportController = class {
/** /**
* @param {importer.ActivityState} activityState * @param {importer.ActivityState} activityState
* @param {importer.ScanResult=} opt_scan * @param {mediaScannerInterfaces.ScanResult=} opt_scan
* @param {number=} opt_destinationSizeBytes specifies the destination size in * @param {number=} opt_destinationSizeBytes specifies the destination size in
* bytes in case of space issues. * bytes in case of space issues.
* @private * @private
...@@ -439,7 +439,7 @@ importer.ImportController = class { ...@@ -439,7 +439,7 @@ importer.ImportController = class {
* Attempts to scan the current context. * Attempts to scan the current context.
* *
* @param {importer.ScanMode} mode How to detect new files. * @param {importer.ScanMode} mode How to detect new files.
* @return {importer.ScanResult} A scan object, * @return {mediaScannerInterfaces.ScanResult} A scan object,
* or null if scan is not possible in current context. * or null if scan is not possible in current context.
* @private * @private
*/ */
...@@ -462,7 +462,7 @@ importer.ImportController = class { ...@@ -462,7 +462,7 @@ importer.ImportController = class {
* Collection of import task related details. * Collection of import task related details.
* *
* @typedef {{ * @typedef {{
* scan: !importer.ScanResult, * scan: !mediaScannerInterfaces.ScanResult,
* task: !importer.MediaImportHandler.ImportTask, * task: !importer.MediaImportHandler.ImportTask,
* started: !Date * started: !Date
* }} * }}
...@@ -488,7 +488,7 @@ importer.CommandWidget = class { ...@@ -488,7 +488,7 @@ importer.CommandWidget = class {
/** /**
* @param {importer.ActivityState} activityState * @param {importer.ActivityState} activityState
* @param {importer.ScanResult=} opt_scan * @param {mediaScannerInterfaces.ScanResult=} opt_scan
* @param {number=} opt_destinationSizeBytes specifies the destination size in * @param {number=} opt_destinationSizeBytes specifies the destination size in
* bytes in case of space issues. * bytes in case of space issues.
*/ */
...@@ -919,24 +919,24 @@ importer.RuntimeCommandWidget = class { ...@@ -919,24 +919,24 @@ importer.RuntimeCommandWidget = class {
importer.ScanManager = class { importer.ScanManager = class {
/** /**
* @param {!importer.ControllerEnvironment} environment * @param {!importer.ControllerEnvironment} environment
* @param {!importer.MediaScanner} scanner * @param {!mediaScannerInterfaces.MediaScanner} scanner
*/ */
constructor(environment, scanner) { constructor(environment, scanner) {
/** @private {!importer.ControllerEnvironment} */ /** @private {!importer.ControllerEnvironment} */
this.environment_ = environment; this.environment_ = environment;
/** @private @const {!importer.MediaScanner} */ /** @private @const {!mediaScannerInterfaces.MediaScanner} */
this.scanner_ = scanner; this.scanner_ = scanner;
/** /**
* The active files scan, if any. * The active files scan, if any.
* @private {?importer.ScanResult} * @private {?mediaScannerInterfaces.ScanResult}
*/ */
this.selectionScan_ = null; this.selectionScan_ = null;
/** /**
* The active directory scan, if any. * The active directory scan, if any.
* @private {?importer.ScanResult} * @private {?mediaScannerInterfaces.ScanResult}
*/ */
this.directoryScan_ = null; this.directoryScan_ = null;
} }
...@@ -968,13 +968,16 @@ importer.ScanManager = class { ...@@ -968,13 +968,16 @@ importer.ScanManager = class {
this.directoryScan_ = null; this.directoryScan_ = null;
} }
/** @return {importer.ScanResult} Current active scan, or null if none. */ /**
* @return {mediaScannerInterfaces.ScanResult} Current active scan, or null
* if none.
*/
getActiveScan() { getActiveScan() {
return this.selectionScan_ || this.directoryScan_; return this.selectionScan_ || this.directoryScan_;
} }
/** /**
* @param {importer.ScanResult} scan * @param {mediaScannerInterfaces.ScanResult} scan
* @return {boolean} True if scan is the active scan...meaning the current * @return {boolean} True if scan is the active scan...meaning the current
* selection scan or the scan for the current directory. * selection scan or the scan for the current directory.
*/ */
...@@ -989,7 +992,7 @@ importer.ScanManager = class { ...@@ -989,7 +992,7 @@ importer.ScanManager = class {
* @param {!Array<!FileEntry>} entries * @param {!Array<!FileEntry>} entries
* @param {!importer.ScanMode} mode * @param {!importer.ScanMode} mode
* *
* @return {!importer.ScanResult} * @return {!mediaScannerInterfaces.ScanResult}
*/ */
getSelectionScan(entries, mode) { getSelectionScan(entries, mode) {
console.assert( console.assert(
...@@ -1003,7 +1006,7 @@ importer.ScanManager = class { ...@@ -1003,7 +1006,7 @@ importer.ScanManager = class {
* Returns a scan for the directory. * Returns a scan for the directory.
* *
* @param {!importer.ScanMode} mode * @param {!importer.ScanMode} mode
* @return {importer.ScanResult} * @return {mediaScannerInterfaces.ScanResult}
*/ */
getDirectoryScan(mode) { getDirectoryScan(mode) {
if (!this.directoryScan_) { if (!this.directoryScan_) {
......
...@@ -9,7 +9,7 @@ const EMPTY_EVENT = new Event('directory-changed'); ...@@ -9,7 +9,7 @@ const EMPTY_EVENT = new Event('directory-changed');
let volumeManager; let volumeManager;
/** @type {!TestMediaScanner} */ /** @type {!TestMediaScanner} */
let mediaScanner; let mediaScannerTest;
/** @type {!TestImportRunner} */ /** @type {!TestImportRunner} */
let mediaImporter; let mediaImporter;
...@@ -61,7 +61,7 @@ function setUp() { ...@@ -61,7 +61,7 @@ function setUp() {
assert(downloads); assert(downloads);
destinationVolume = downloads; destinationVolume = downloads;
mediaScanner = new TestMediaScanner(); mediaScannerTest = new TestMediaScanner();
mediaImporter = new TestImportRunner(); mediaImporter = new TestImportRunner();
} }
...@@ -116,7 +116,7 @@ function testVolumeUnmount_InvalidatesScans(callback) { ...@@ -116,7 +116,7 @@ function testVolumeUnmount_InvalidatesScans(callback) {
return widget.updateResolver.promise; return widget.updateResolver.promise;
}) })
.then(() => { .then(() => {
mediaScanner.assertScanCount(2); mediaScannerTest.assertScanCount(2);
}); });
reportPromise(promise, callback); reportPromise(promise, callback);
...@@ -160,8 +160,8 @@ function testDirectoryChange_CancelsScan(callback) { ...@@ -160,8 +160,8 @@ function testDirectoryChange_CancelsScan(callback) {
environment.directoryChangedListener(EMPTY_EVENT); environment.directoryChangedListener(EMPTY_EVENT);
}) })
.then(() => { .then(() => {
mediaScanner.assertScanCount(1); mediaScannerTest.assertScanCount(1);
mediaScanner.assertLastScanCanceled(); mediaScannerTest.assertLastScanCanceled();
}); });
reportPromise(promise, callback); reportPromise(promise, callback);
...@@ -190,8 +190,8 @@ function testWindowClose_CancelsScan(callback) { ...@@ -190,8 +190,8 @@ function testWindowClose_CancelsScan(callback) {
environment.windowCloseListener(); environment.windowCloseListener();
}) })
.then(() => { .then(() => {
mediaScanner.assertScanCount(1); mediaScannerTest.assertScanCount(1);
mediaScanner.assertLastScanCanceled(); mediaScannerTest.assertLastScanCanceled();
}); });
reportPromise(promise, callback); reportPromise(promise, callback);
...@@ -213,7 +213,7 @@ function testDirectoryChange_DetailsPanelVisibility_InitialChangeDir(callback) { ...@@ -213,7 +213,7 @@ function testDirectoryChange_DetailsPanelVisibility_InitialChangeDir(callback) {
// Ensure there is some content in the scan so the code that depends // Ensure there is some content in the scan so the code that depends
// on this state doesn't croak which it finds it missing. // on this state doesn't croak which it finds it missing.
mediaScanner.fileEntries.push(MockFileEntry.create( mediaScannerTest.fileEntries.push(MockFileEntry.create(
fileSystem, '/DCIM/photos0/IMG00001.jpg', getDefaultMetadata())); fileSystem, '/DCIM/photos0/IMG00001.jpg', getDefaultMetadata()));
// Make controller enter a scanning state. // Make controller enter a scanning state.
...@@ -225,7 +225,7 @@ function testDirectoryChange_DetailsPanelVisibility_InitialChangeDir(callback) { ...@@ -225,7 +225,7 @@ function testDirectoryChange_DetailsPanelVisibility_InitialChangeDir(callback) {
// "scanning..." // "scanning..."
assertFalse(widget.detailsVisible); assertFalse(widget.detailsVisible);
widget.resetPromises(); widget.resetPromises();
mediaScanner.finalizeScans(); mediaScannerTest.finalizeScans();
return widget.updateResolver.promise; return widget.updateResolver.promise;
}) })
.then(() => { .then(() => {
...@@ -276,7 +276,7 @@ function testSelectionChange_TriggersUpdate(callback) { ...@@ -276,7 +276,7 @@ function testSelectionChange_TriggersUpdate(callback) {
fileSystem, '/DCIM/photos0/IMG00001.jpg', getDefaultMetadata())); fileSystem, '/DCIM/photos0/IMG00001.jpg', getDefaultMetadata()));
environment.selectionChangedListener(); environment.selectionChangedListener();
mediaScanner.finalizeScans(); mediaScannerTest.finalizeScans();
reportPromise(widget.updateResolver.promise, callback); reportPromise(widget.updateResolver.promise, callback);
} }
...@@ -294,12 +294,12 @@ function testFinalizeScans_TriggersUpdate(callback) { ...@@ -294,12 +294,12 @@ function testFinalizeScans_TriggersUpdate(callback) {
// Ensure there is some content in the scan so the code that depends // Ensure there is some content in the scan so the code that depends
// on this state doesn't croak which it finds it missing. // on this state doesn't croak which it finds it missing.
mediaScanner.fileEntries.push(MockFileEntry.create( mediaScannerTest.fileEntries.push(MockFileEntry.create(
fileSystem, '/DCIM/photos0/IMG00001.jpg', getDefaultMetadata())); fileSystem, '/DCIM/photos0/IMG00001.jpg', getDefaultMetadata()));
environment.directoryChangedListener(EMPTY_EVENT); // initiates a scan. environment.directoryChangedListener(EMPTY_EVENT); // initiates a scan.
widget.resetPromises(); widget.resetPromises();
mediaScanner.finalizeScans(); mediaScannerTest.finalizeScans();
reportPromise(widget.updateResolver.promise, callback); reportPromise(widget.updateResolver.promise, callback);
} }
...@@ -345,7 +345,7 @@ function startImport(clickSource) { ...@@ -345,7 +345,7 @@ function startImport(clickSource) {
// Ensure there is some content in the scan so the code that depends // Ensure there is some content in the scan so the code that depends
// on this state doesn't croak which it finds it missing. // on this state doesn't croak which it finds it missing.
mediaScanner.fileEntries.push(MockFileEntry.create( mediaScannerTest.fileEntries.push(MockFileEntry.create(
fileSystem, '/DCIM/photos0/IMG00001.jpg', getDefaultMetadata())); fileSystem, '/DCIM/photos0/IMG00001.jpg', getDefaultMetadata()));
// First we need to force the controller into a scanning state. // First we need to force the controller into a scanning state.
...@@ -353,7 +353,7 @@ function startImport(clickSource) { ...@@ -353,7 +353,7 @@ function startImport(clickSource) {
return widget.updateResolver.promise.then(() => { return widget.updateResolver.promise.then(() => {
widget.resetPromises(); widget.resetPromises();
mediaScanner.finalizeScans(); mediaScannerTest.finalizeScans();
return widget.updateResolver.promise.then(() => { return widget.updateResolver.promise.then(() => {
widget.resetPromises(); widget.resetPromises();
widget.click(clickSource); widget.click(clickSource);
...@@ -368,12 +368,12 @@ function startImport(clickSource) { ...@@ -368,12 +368,12 @@ function startImport(clickSource) {
*/ */
class TestImportTask { class TestImportTask {
/** /**
* @param {!importer.ScanResult} scan * @param {!mediaScannerInterfaces.ScanResult} scan
* @param {!importer.Destination} destination * @param {!importer.Destination} destination
* @param {!Promise<!DirectoryEntry>} destinationDirectory * @param {!Promise<!DirectoryEntry>} destinationDirectory
*/ */
constructor(scan, destination, destinationDirectory) { constructor(scan, destination, destinationDirectory) {
/** @public {!importer.ScanResult} */ /** @public {!mediaScannerInterfaces.ScanResult} */
this.scan = scan; this.scan = scan;
/** @type {!importer.Destination} */ /** @type {!importer.Destination} */
...@@ -411,7 +411,7 @@ class TestImportTask { ...@@ -411,7 +411,7 @@ class TestImportTask {
*/ */
class TestImportRunner { class TestImportRunner {
constructor() { constructor() {
/** @public {!Array<!importer.ScanResult>} */ /** @public {!Array<!mediaScannerInterfaces.ScanResult>} */
this.imported = []; this.imported = [];
/** /**
...@@ -664,7 +664,7 @@ function createController(volumeType, volumeId, fileNames, currentDirectory) { ...@@ -664,7 +664,7 @@ function createController(volumeType, volumeId, fileNames, currentDirectory) {
sourceVolume.fileSystem.entries[currentDirectory]); sourceVolume.fileSystem.entries[currentDirectory]);
return new importer.ImportController( return new importer.ImportController(
environment, mediaScanner, mediaImporter, widget); environment, mediaScannerTest, mediaImporter, widget);
} }
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment