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