Commit 604f2464 authored by Noel Gordon's avatar Noel Gordon Committed by Commit Bot

Closure compile media_scanner_unittest

 - remove media_scanner_unittest.html, update build rules to closure
   compile this unittest, auto-generate this unittest file.
 - fix closure type errors (the test mocks and unittest code diverged
   from the real world over time, sadly), fix or add commentary.
 - import*ScanResults => import*ScanResult, the former is undefined.
 - scanDirectory|File require a |mode| argument per the externs, so
   add it everywhere.
 - re-order the test media scan and scan result class definitions to
   follow the definition order of their extern file.
 - run the js formatter over the code.

Bug: 905931
Change-Id: I27239333e2ab2d8bc1c50c6bcade75cc2d6b6701
Reviewed-on: https://chromium-review.googlesource.com/c/1348874Reviewed-by: default avatarStuart Langley <slangley@chromium.org>
Commit-Queue: Noel Gordon <noel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#610506}
parent 7dd3be88
...@@ -71,8 +71,7 @@ IN_PROC_BROWSER_TEST_F(FileManagerJsTest, FileTableTest) { ...@@ -71,8 +71,7 @@ IN_PROC_BROWSER_TEST_F(FileManagerJsTest, FileTableTest) {
} }
IN_PROC_BROWSER_TEST_F(FileManagerJsTest, MediaScannerTest) { IN_PROC_BROWSER_TEST_F(FileManagerJsTest, MediaScannerTest) {
RunTest(base::FilePath( RunGeneratedTest("/background/js/media_scanner_unittest.html");
FILE_PATH_LITERAL("background/js/media_scanner_unittest.html")));
} }
IN_PROC_BROWSER_TEST_F(FileManagerJsTest, LRUCacheTest) { IN_PROC_BROWSER_TEST_F(FileManagerJsTest, LRUCacheTest) {
......
...@@ -197,6 +197,8 @@ js_library("file_operation_util") { ...@@ -197,6 +197,8 @@ js_library("file_operation_util") {
"../../common/js:async_util", "../../common/js:async_util",
"../../common/js:util", "../../common/js:util",
] ]
externs_list =
[ "//ui/file_manager/externs/file_operation_progress_event.js" ]
} }
js_library("metadata_proxy") { js_library("metadata_proxy") {
...@@ -250,11 +252,28 @@ js_library("media_import_handler") { ...@@ -250,11 +252,28 @@ js_library("media_import_handler") {
] ]
} }
js_library("mock_media_scanner") {
testonly = true
deps = [
":test_import_history",
]
externs_list = [ "../../../externs/background/media_scanner.js" ]
}
js_library("media_scanner") { js_library("media_scanner") {
deps = [ deps = [
":file_operation_util", ":file_operation_util",
"../../common/js:importer_common", "../../common/js:importer_common",
] ]
externs_list = [ "../../../externs/background/media_scanner.js" ]
}
js_unittest("media_scanner_unittest") {
deps = [
":media_scanner",
":mock_media_scanner",
"//ui/file_manager/file_manager/common/js:test_importer_common",
]
} }
js_library("mock_volume_manager") { js_library("mock_volume_manager") {
...@@ -287,6 +306,13 @@ js_library("task_queue") { ...@@ -287,6 +306,13 @@ js_library("task_queue") {
js_library("test_util_base") { js_library("test_util_base") {
} }
js_library("test_import_history") {
testonly = true
deps = [
":import_history",
]
}
js_library("runtime_loaded_test_util") { js_library("runtime_loaded_test_util") {
# TODO(tapted): Move this target to //ui/file_manager/base. It is used in the # TODO(tapted): Move this target to //ui/file_manager/base. It is used in the
# background page of all |related_apps|, but loaded at runtime by # background page of all |related_apps|, but loaded at runtime by
...@@ -359,6 +385,7 @@ js_unit_tests("unit_tests") { ...@@ -359,6 +385,7 @@ js_unit_tests("unit_tests") {
deps = [ deps = [
":crostini_unittest", ":crostini_unittest",
":import_history_unittest", ":import_history_unittest",
":media_scanner_unittest",
":volume_manager_unittest", ":volume_manager_unittest",
] ]
} }
<!DOCTYPE html>
<!-- Copyright 2014 The Chromium Authors. All rights reserved.
-- Use of this source code is governed by a BSD-style license that can be
-- found in the LICENSE file.
-->
<html>
<body>
<script src="../../../../../ui/webui/resources/js/cr.js"></script>
<script src="../../../../../ui/webui/resources/js/cr/event_target.js"></script>
<script src="../../../../../ui/webui/resources/js/load_time_data.js"></script>
<script src="../../../base/js/volume_manager_types.js"></script>
<script src="../../common/js/file_type.js"></script>
<script src="../../common/js/importer_common.js"></script>
<script src="../../common/js/lru_cache.js"></script>
<script src="../../common/js/mock_entry.js"></script>
<script src="../../common/js/mock_file_system.js"></script>
<script src="../../../base/js/test_error_reporting.js"></script>
<script src="../../common/js/unittest_util.js"></script>
<script src="../../common/js/util.js"></script>
<script src="metadata_proxy.js"></script>
<script src="file_operation_util.js"></script>
<script src="import_history.js"></script>
<script src="media_scanner.js"></script>
<script src="mock_media_scanner.js"></script>
<script src="test_import_history.js"></script>
<script src="media_scanner_unittest.js"></script>
</body>
</html>
...@@ -14,10 +14,15 @@ var metrics = { ...@@ -14,10 +14,15 @@ var metrics = {
/** @type {!importer.DefaultMediaScanner} */ /** @type {!importer.DefaultMediaScanner} */
var scanner; var scanner;
/**
* @const {importer.ScanMode}
*/
var scanMode = importer.ScanMode.HISTORY;
/** @type {!importer.TestImportHistory} */ /** @type {!importer.TestImportHistory} */
var importHistory; var importHistory;
/** @type {!importer.TestDirectoryWatcher} */ /** @type {!TestDirectoryWatcher} */
var watcher; var watcher;
/** /**
...@@ -28,12 +33,10 @@ var dispositionChecker; ...@@ -28,12 +33,10 @@ var dispositionChecker;
// Set up the test components. // Set up the test components.
function setUp() { function setUp() {
importHistory = new importer.TestImportHistory(); importHistory = new importer.TestImportHistory();
// This is the default disposition checker.
// Tests can replace this at runtime if they // Setup a default disposition checker. Tests can replace it at runtime
// want specialized behaviors. // if they need specialized disposition check behavior.
dispositionChecker = function() { dispositionChecker = function() {
return Promise.resolve(importer.Disposition.ORIGINAL); return Promise.resolve(importer.Disposition.ORIGINAL);
}; };
...@@ -56,10 +59,9 @@ function setUp() { ...@@ -56,10 +59,9 @@ function setUp() {
* Verifies that scanning an empty filesystem produces an empty list. * Verifies that scanning an empty filesystem produces an empty list.
*/ */
function testEmptySourceList() { function testEmptySourceList() {
assertThrows( assertThrows(function() {
function() { scanner.scanFiles([], scanMode);
scanner.scanFiles([]); });
});
} }
function testIsScanning(callback) { function testIsScanning(callback) {
...@@ -76,7 +78,7 @@ function testIsScanning(callback) { ...@@ -76,7 +78,7 @@ function testIsScanning(callback) {
* @param {!DirectoryEntry} root * @param {!DirectoryEntry} root
*/ */
function(root) { function(root) {
var results = scanner.scanDirectory(root); var results = scanner.scanDirectory(root, scanMode);
assertFalse(results.isFinal()); assertFalse(results.isFinal());
}), }),
callback); callback);
...@@ -98,8 +100,8 @@ function testObserverNotifiedOnScanFinish(callback) { ...@@ -98,8 +100,8 @@ function testObserverNotifiedOnScanFinish(callback) {
// Kick off a scan so we can get notified of a scan being finished. // Kick off a scan so we can get notified of a scan being finished.
// We kick this off first so we can capture the result for // We kick this off first so we can capture the result for
// use in an assert. Promises ensure the scan won't finish // use in an assert. Promises ensure the scan won't finish
// until after our funciton is fully processed. // until after our function is fully processed.
var result = scanner.scanDirectory(root); var result = scanner.scanDirectory(root, scanMode);
scanner.addObserver( scanner.addObserver(
function(eventType, scanResult) { function(eventType, scanResult) {
assertEquals(importer.ScanEvent.FINALIZED, eventType); assertEquals(importer.ScanEvent.FINALIZED, eventType);
...@@ -107,10 +109,9 @@ function testObserverNotifiedOnScanFinish(callback) { ...@@ -107,10 +109,9 @@ function testObserverNotifiedOnScanFinish(callback) {
callback(false); callback(false);
}); });
}) })
.catch( .catch(function() {
function() { callback(true);
callback(true); });
});
} }
/** /**
...@@ -135,7 +136,7 @@ function testScanFiles(callback) { ...@@ -135,7 +136,7 @@ function testScanFiles(callback) {
.then( .then(
/** @param {!Array<!FileEntry>} files */ /** @param {!Array<!FileEntry>} files */
function(files) { function(files) {
return scanner.scanFiles(files).whenFinal(); return scanner.scanFiles(files, scanMode).whenFinal();
}) })
.then(assertFilesFound.bind(null, expectedFiles)), .then(assertFilesFound.bind(null, expectedFiles)),
callback); callback);
...@@ -177,7 +178,7 @@ function testScanFilesIgnoresPreviousImports(callback) { ...@@ -177,7 +178,7 @@ function testScanFilesIgnoresPreviousImports(callback) {
.then( .then(
/** @param {!Array<!FileEntry>} files */ /** @param {!Array<!FileEntry>} files */
function(files) { function(files) {
return scanner.scanFiles(files).whenFinal(); return scanner.scanFiles(files, scanMode).whenFinal();
}) })
.then(assertFilesFound.bind(null, expectedFiles)), .then(assertFilesFound.bind(null, expectedFiles)),
callback); callback);
...@@ -200,7 +201,7 @@ function testEmptyScanResults(callback) { ...@@ -200,7 +201,7 @@ function testEmptyScanResults(callback) {
* @param {!DirectoryEntry} root * @param {!DirectoryEntry} root
*/ */
function(root) { function(root) {
return scanner.scanDirectory(root).whenFinal(); return scanner.scanDirectory(root, scanMode).whenFinal();
}) })
.then(assertFilesFound.bind(null, [])), .then(assertFilesFound.bind(null, [])),
callback); callback);
...@@ -232,7 +233,7 @@ function testSingleLevel(callback) { ...@@ -232,7 +233,7 @@ function testSingleLevel(callback) {
* @param {!DirectoryEntry} root * @param {!DirectoryEntry} root
*/ */
function(root) { function(root) {
return scanner.scanDirectory(root).whenFinal(); return scanner.scanDirectory(root, scanMode).whenFinal();
}) })
.then(assertFilesFound.bind(null, expectedFiles)), .then(assertFilesFound.bind(null, expectedFiles)),
callback); callback);
...@@ -265,7 +266,7 @@ function testProgress(callback) { ...@@ -265,7 +266,7 @@ function testProgress(callback) {
* @param {!DirectoryEntry} root * @param {!DirectoryEntry} root
*/ */
function(root) { function(root) {
return scanner.scanDirectory(root).whenFinal(); return scanner.scanDirectory(root, scanMode).whenFinal();
}) })
.then(assertProgress.bind(null, 100)), .then(assertProgress.bind(null, 100)),
callback); callback);
...@@ -304,17 +305,18 @@ function testIgnoresPreviousImports(callback) { ...@@ -304,17 +305,18 @@ function testIgnoresPreviousImports(callback) {
'/testIgnoresPreviousImports/baz.avi' '/testIgnoresPreviousImports/baz.avi'
]; ];
var promise = makeTestFileSystemRoot('testIgnoresPreviousImports') var promise =
.then(populateDir.bind(null, filenames)) makeTestFileSystemRoot('testIgnoresPreviousImports')
.then( .then(populateDir.bind(null, filenames))
/** .then(
* Scans the directory. /**
* @param {!DirectoryEntry} root * Scans the directory.
*/ * @param {!DirectoryEntry} root
function(root) { */
return scanner.scanDirectory(root).whenFinal(); function(root) {
}) return scanner.scanDirectory(root, scanMode).whenFinal();
.then(assertFilesFound.bind(null, expectedFiles)); })
.then(assertFilesFound.bind(null, expectedFiles));
reportPromise(promise, callback); reportPromise(promise, callback);
} }
...@@ -351,18 +353,18 @@ function testTracksDuplicates(callback) { ...@@ -351,18 +353,18 @@ function testTracksDuplicates(callback) {
'/testTracksDuplicates/driveimage9999.jpg' '/testTracksDuplicates/driveimage9999.jpg'
]; ];
var promise =
var promise = makeTestFileSystemRoot('testTracksDuplicates') makeTestFileSystemRoot('testTracksDuplicates')
.then(populateDir.bind(null, filenames)) .then(populateDir.bind(null, filenames))
.then( .then(
/** /**
* Scans the directory. * Scans the directory.
* @param {!DirectoryEntry} root * @param {!DirectoryEntry} root
*/ */
function(root) { function(root) {
return scanner.scanDirectory(root).whenFinal(); return scanner.scanDirectory(root, scanMode).whenFinal();
}) })
.then(assertDuplicatesFound.bind(null, expectedDuplicates)); .then(assertDuplicatesFound.bind(null, expectedDuplicates));
reportPromise(promise, callback); reportPromise(promise, callback);
} }
...@@ -400,7 +402,7 @@ function testMultiLevel(callback) { ...@@ -400,7 +402,7 @@ function testMultiLevel(callback) {
* @param {!DirectoryEntry} root * @param {!DirectoryEntry} root
*/ */
function(root) { function(root) {
return scanner.scanDirectory(root).whenFinal(); return scanner.scanDirectory(root, scanMode).whenFinal();
}) })
.then(assertFilesFound.bind(null, expectedFiles)), .then(assertFilesFound.bind(null, expectedFiles)),
callback); callback);
...@@ -440,7 +442,7 @@ function testDedupesFilesInScanResult(callback) { ...@@ -440,7 +442,7 @@ function testDedupesFilesInScanResult(callback) {
* @param {!DirectoryEntry} root * @param {!DirectoryEntry} root
*/ */
function(root) { function(root) {
return scanner.scanDirectory(root).whenFinal(); return scanner.scanDirectory(root, scanMode).whenFinal();
}) })
.then(assertFilesFound.bind(null, expectedFiles)), .then(assertFilesFound.bind(null, expectedFiles)),
callback); callback);
...@@ -453,7 +455,7 @@ function testDefaultScanResult() { ...@@ -453,7 +455,7 @@ function testDefaultScanResult() {
var hashGenerator = function(file) { var hashGenerator = function(file) {
return file.toURL(); return file.toURL();
}; };
var scan = new importer.DefaultScanResult(hashGenerator); var scan = new importer.DefaultScanResult(scanMode, hashGenerator);
// 0 before we set candidate count // 0 before we set candidate count
assertProgress(0, scan); assertProgress(0, scan);
...@@ -482,18 +484,18 @@ function testInvalidation(callback) { ...@@ -482,18 +484,18 @@ function testInvalidation(callback) {
* @param {!DirectoryEntry} root * @param {!DirectoryEntry} root
*/ */
function(root) { function(root) {
scan = scanner.scanDirectory(root); scanner.scanDirectory(root, scanMode);
watcher.callback(); watcher.callback();
return invalidatePromise; return invalidatePromise;
}), }),
callback); 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.ScanResults} scan * @param {!importer.ScanResult} scan
* @return {!importer.ScanResults} * @return {!importer.ScanResult}
*/ */
function assertProgress(expected, scan) { function assertProgress(expected, scan) {
assertEquals(expected, scan.getStatistics().progress); assertEquals(expected, scan.getStatistics().progress);
...@@ -503,8 +505,8 @@ function assertProgress(expected, scan) { ...@@ -503,8 +505,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.ScanResults} scan * @param {!importer.ScanResult} scan
* @return {!importer.ScanResults} * @return {!importer.ScanResult}
*/ */
function assertFilesFound(expected, scan) { function assertFilesFound(expected, scan) {
assertFileEntryPathsEqual(expected, scan.getFileEntries()); assertFileEntryPathsEqual(expected, scan.getFileEntries());
...@@ -515,8 +517,8 @@ function assertFilesFound(expected, scan) { ...@@ -515,8 +517,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.ScanResults} scan * @param {!importer.ScanResult} scan
* @return {!importer.ScanResults} * @return {!importer.ScanResult}
*/ */
function assertDuplicatesFound(expected, scan) { function assertDuplicatesFound(expected, scan) {
assertFileEntryPathsEqual(expected, scan.getDuplicateFileEntries()); assertFileEntryPathsEqual(expected, scan.getDuplicateFileEntries());
...@@ -580,10 +582,10 @@ function populateDir(filenames, dir) { ...@@ -580,10 +582,10 @@ function populateDir(filenames, dir) {
}) })
.then(populateDir.bind(null, filename)); .then(populateDir.bind(null, filename));
} else { } else {
return new Promise( var name = /** @type {string} */ (filename);
function(resolve, reject) { return new Promise(function(resolve, reject) {
dir.getFile(filename, {create: true}, resolve, reject); dir.getFile(name, {create: true}, resolve, reject);
}); });
} }
})).then( })).then(
function() { function() {
......
...@@ -10,8 +10,7 @@ ...@@ -10,8 +10,7 @@
* @implements {importer.MediaScanner} * @implements {importer.MediaScanner}
*/ */
function TestMediaScanner() { function TestMediaScanner() {
/** @private {!Array<!importer.ScanResult>} */
/** @private {!importer.ScanResult} */
this.scans_ = []; this.scans_ = [];
/** /**
...@@ -21,38 +20,26 @@ function TestMediaScanner() { ...@@ -21,38 +20,26 @@ function TestMediaScanner() {
this.fileEntries = []; this.fileEntries = [];
/** /**
* List of file entries found while scanning. * List of duplicate file entries found while scanning.
* @type {!Array<!FileEntry>} * @type {!Array<!FileEntry>}
*/ */
this.duplicateFileEntries = []; this.duplicateFileEntries = [];
/** @type {number} */ /**
* List of scan observers.
* @private {!Array<!importer.ScanObserver>}
*/
this.observers = [];
/** @private {number} */
this.totalBytes = 100; this.totalBytes = 100;
/** @type {number} */ /** @private {number} */
this.scanDuration = 100; this.scanDuration = 100;
/** @private {!Array<!importer.ScanObserver>} */
this.observers = [];
} }
/** @override */ /** @override */
TestMediaScanner.prototype.addObserver = function(observer) { TestMediaScanner.prototype.scanDirectory = function(directory, mode) {
this.observers.push(observer);
};
/** @override */
TestMediaScanner.prototype.removeObserver = function(observer) {
var index = this.observers.indexOf(observer);
if (index > -1) {
this.observers.splice(index, 1);
} else {
console.warn('Ignoring request to remove observer that is not registered.');
}
};
/** @override */
TestMediaScanner.prototype.scanDirectory = function(directory) {
var scan = new TestScanResult(this.fileEntries); var scan = new TestScanResult(this.fileEntries);
scan.totalBytes = this.totalBytes; scan.totalBytes = this.totalBytes;
scan.scanDuration = this.scanDuration; scan.scanDuration = this.scanDuration;
...@@ -61,7 +48,7 @@ TestMediaScanner.prototype.scanDirectory = function(directory) { ...@@ -61,7 +48,7 @@ TestMediaScanner.prototype.scanDirectory = function(directory) {
}; };
/** @override */ /** @override */
TestMediaScanner.prototype.scanFiles = function(entries) { TestMediaScanner.prototype.scanFiles = function(entries, mode) {
var scan = new TestScanResult(this.fileEntries); var scan = new TestScanResult(this.fileEntries);
scan.totalBytes = this.totalBytes; scan.totalBytes = this.totalBytes;
scan.scanDuration = this.scanDuration; scan.scanDuration = this.scanDuration;
...@@ -69,6 +56,21 @@ TestMediaScanner.prototype.scanFiles = function(entries) { ...@@ -69,6 +56,21 @@ TestMediaScanner.prototype.scanFiles = function(entries) {
return scan; return scan;
}; };
/** @override */
TestMediaScanner.prototype.addObserver = function(observer) {
this.observers.push(observer);
};
/** @override */
TestMediaScanner.prototype.removeObserver = function(observer) {
var index = this.observers.indexOf(observer);
if (index !== -1) {
this.observers.splice(index, 1);
} else {
console.warn('Ignoring request to remove unregistered observer');
}
};
/** /**
* Finalizes all previously started scans. * Finalizes all previously started scans.
*/ */
...@@ -78,7 +80,6 @@ TestMediaScanner.prototype.finalizeScans = function() { ...@@ -78,7 +80,6 @@ TestMediaScanner.prototype.finalizeScans = function() {
/** /**
* Notifies observers that the most recently started scan has been updated. * Notifies observers that the most recently started scan has been updated.
* @param {!importer.ScanResult} result
*/ */
TestMediaScanner.prototype.update = function() { TestMediaScanner.prototype.update = function() {
assertTrue(this.scans_.length > 0); assertTrue(this.scans_.length > 0);
...@@ -91,14 +92,16 @@ TestMediaScanner.prototype.update = function() { ...@@ -91,14 +92,16 @@ TestMediaScanner.prototype.update = function() {
/** /**
* Notifies observers that a scan has finished. * Notifies observers that a scan has finished.
* @param {!importer.ScanResult} result * @param {!importer.ScanResult} scan
*/ */
TestMediaScanner.prototype.finalize = function(result) { TestMediaScanner.prototype.finalize = function(scan) {
result.finalize(); // Note the |scan| has {!TestScanResult} type in test, and needs a
this.observers.forEach( // finalize() call before being notified to scan observers.
function(observer) { /** @type {!TestScanResult} */ (scan).finalize();
observer(importer.ScanEvent.FINALIZED, result);
}); this.observers.forEach(function(observer) {
observer(importer.ScanEvent.FINALIZED, scan);
});
}; };
/** /**
...@@ -137,7 +140,7 @@ function TestScanResult(fileEntries) { ...@@ -137,7 +140,7 @@ function TestScanResult(fileEntries) {
this.fileEntries = fileEntries.slice(); this.fileEntries = fileEntries.slice();
/** /**
* List of file entries found while scanning. * List of duplicate file entries found while scanning.
* @type {!Array<!FileEntry>} * @type {!Array<!FileEntry>}
*/ */
this.duplicateFileEntries = []; this.duplicateFileEntries = [];
...@@ -148,10 +151,10 @@ function TestScanResult(fileEntries) { ...@@ -148,10 +151,10 @@ function TestScanResult(fileEntries) {
/** @type {number} */ /** @type {number} */
this.scanDuration = 100; this.scanDuration = 100;
/** @type {function} */ /** @type {function(*)} */
this.resolveResult_; this.resolveResult_;
/** @type {function} */ /** @type {function()} */
this.rejectResult_; this.rejectResult_;
/** @type {boolean} */ /** @type {boolean} */
...@@ -186,52 +189,61 @@ TestScanResult.prototype = { ...@@ -186,52 +189,61 @@ TestScanResult.prototype = {
}; };
/** @override */ /** @override */
TestScanResult.prototype.getFileEntries = function() { TestScanResult.prototype.isFinal = function() {
return this.fileEntries; return this.settled_;
}; };
/** @override */ /** @override */
TestScanResult.prototype.getDuplicateFileEntries = function() { TestScanResult.prototype.cancel = function() {
return this.duplicateFileEntries; this.canceled_ = true;
}; };
/** @override */ /** @override */
TestScanResult.prototype.finalize = function() { TestScanResult.prototype.canceled = function() {
return this.resolveResult_(this); return this.canceled_;
}; };
/** @override */ /** @override */
TestScanResult.prototype.whenFinal = function() { TestScanResult.prototype.setCandidateCount = function() {
return this.whenFinal_; console.warn('setCandidateCount: not implemented');
}; };
/** @override */ /** @override */
TestScanResult.prototype.isFinal = function() { TestScanResult.prototype.onCandidatesProcessed = function() {
return this.settled_; console.warn('onCandidatesProcessed: not implemented');
}; };
/** @override */ /** @override */
TestScanResult.prototype.cancel = function() { TestScanResult.prototype.getFileEntries = function() {
this.canceled_ = true; return this.fileEntries;
}; };
/** @override */ /** @override */
TestScanResult.prototype.canceled = function() { TestScanResult.prototype.getDuplicateFileEntries = function() {
return this.canceled_; return this.duplicateFileEntries;
};
/** @override */
TestScanResult.prototype.whenFinal = function() {
return this.whenFinal_;
}; };
/** @override */ /** @override */
TestScanResult.prototype.getStatistics = function() { TestScanResult.prototype.getStatistics = function() {
duplicates = {}; var duplicates = {};
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 { return /** @type {importer.ScanResult.Statistics} */ ({
scanDuration: this.scanDuration, scanDuration: this.scanDuration,
newFileCount: this.fileEntries.length, newFileCount: this.fileEntries.length,
duplicates: duplicates, duplicates: duplicates,
sizeBytes: this.totalBytes sizeBytes: this.totalBytes
}; });
};
TestScanResult.prototype.finalize = function() {
return this.resolveResult_(this);
}; };
/** /**
......
...@@ -24,45 +24,35 @@ importer.TestImportHistory = function() { ...@@ -24,45 +24,35 @@ importer.TestImportHistory = function() {
/** /**
* If null, history has been loaded and listeners notified. * If null, history has been loaded and listeners notified.
* *
* @private {Array<!importer.ImportHistory>} * @private {Array<!function(!importer.ImportHistory)>}
*/ */
this.loadListeners_ = []; this.loadListeners_ = [];
}; };
/** @override */ /** @override */
importer.TestImportHistory.prototype.getHistory = importer.TestImportHistory.prototype.getHistory = function() {
function() { Promise.resolve().then(() => {
Promise.resolve().then( if (this.loadListeners_) {
/** @this {importer.TestImportHistory} */ this.loadListeners_.forEach((listener) => listener(this));
function() { // Null out listeners...this is our signal that history has
if (this.loadListeners_) { // been loaded ... resulting in all future listener added
this.loadListeners_.forEach( // being notified immediately
/** @param {!Array<!importer.ImportHistory>} listener */ this.loadListeners_ = null;
function(listener) { }
listener(this); });
}.bind(this));
// Null out listeners...this is our signal that history has
// been loaded ... resulting in all future listener added
// being notified immediately
this.loadListeners_ = null;
}
}.bind(this));
return Promise.resolve(this); return Promise.resolve(this);
}; };
/** @override */ /** @override */
importer.TestImportHistory.prototype.addHistoryLoadedListener = importer.TestImportHistory.prototype.addHistoryLoadedListener = function(
function(listener) { listener) {
// Notify immediately if history is already loaded. assertTrue(typeof listener === 'function');
// Notify listener immediately if history is already loaded.
if (this.loadListeners_ === null) { if (this.loadListeners_ === null) {
Promise.resolve(this.history_).then( setTimeout(listener, 0, this);
/** @param {!importer.ImportHistory} history */
function(history) {
listener(history);
});
} else { } else {
this.loadListeners_.push(listeners); this.loadListeners_.push(listener);
} }
}; };
...@@ -154,6 +144,12 @@ importer.TestImportHistory.prototype.markImported = ...@@ -154,6 +144,12 @@ importer.TestImportHistory.prototype.markImported =
return Promise.resolve(); return Promise.resolve();
}; };
/** @override */
importer.TestImportHistory.prototype.whenReady = function() {};
/** @override */
importer.TestImportHistory.prototype.markImportedByUrl = function() {};
/** @override */ /** @override */
importer.TestImportHistory.prototype.addObserver = function() {}; importer.TestImportHistory.prototype.addObserver = function() {};
......
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