Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(708)

Unified Diff: ui/file_manager/file_manager/background/js/mock_media_scanner.js

Issue 795833002: MediaScanner improvements (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: pull 'n merge. Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/file_manager/file_manager/background/js/mock_media_scanner.js
diff --git a/ui/file_manager/file_manager/background/js/mock_media_scanner.js b/ui/file_manager/file_manager/background/js/mock_media_scanner.js
index 72ce28863bcb72262114bcce8e0958c3ba5ff808..8f34a64dd13682c45094f91e4c147671b69e832c 100644
--- a/ui/file_manager/file_manager/background/js/mock_media_scanner.js
+++ b/ui/file_manager/file_manager/background/js/mock_media_scanner.js
@@ -3,27 +3,68 @@
// found in the LICENSE file.
/**
- * A fake media scanner for testing.
+ * importer.MediaScanner and importer.ScanResult test double.
+ *
* @constructor
* @struct
+ * @implements {importer.MediaScanner}
+ * @implements {importer.ScanResult}
*/
-function MockMediaScanner() {
- /** @private {!Array<!FileEntry>} */
- this.results_ = [];
+function TestMediaScanner() {
+ /**
+ * List of file entries found while scanning.
+ * @type {!Array.<!FileEntry>}
+ */
+ this.fileEntries = [];
+
+ /** @type {number} */
+ this.totalBytes = 100;
+
+ /** @type {number} */
+ this.scanDuration = 100;
+
+ /** @type {!Promise.<!importer.ScanResult>} */
+ this.whenFinished;
}
-/**
- * Returns scan "results".
- * @return {!Promise<!Array<!FileEntry>>}
- */
-MockMediaScanner.prototype.scan = function(entries) {
- return Promise.resolve(this.results_);
+/** @override */
+TestMediaScanner.prototype.scan = function(entries) {
+ var result = new TestScanResult(this);
+ this.whenFinished = Promise.resolve(result);
+ return result;
};
/**
- * Sets the entries that the scanner will return.
- * @param {!Array<!FileEntry>} entries
+ * importer.MediaScanner and importer.ScanResult test double.
+ *
+ * @constructor
+ * @struct
+ * @implements {importer.MediaScanner}
+ * @implements {importer.ScanResult}
+ *
+ * @param {!TestMediaScanner} scanner
*/
-MockMediaScanner.prototype.setScanResults = function(entries) {
- this.results_ = entries;
+function TestScanResult(scanner) {
+ /** @private {!TestMediaScanner} */
+ this.scanner_ = scanner;
+}
+
+/** @override */
+TestScanResult.prototype.getFileEntries = function() {
+ return this.scanner_.fileEntries;
+};
+
+/** @override */
+TestScanResult.prototype.getTotalBytes = function() {
+ return this.scanner_.totalBytes;
+};
+
+/** @override */
+TestScanResult.prototype.getScanDurationMs = function() {
+ return this.scanner_.scanDuration;
+};
+
+/** @override */
+TestScanResult.prototype.whenFinished = function() {
+ return this.scanner_.whenFinished;
};

Powered by Google App Engine
This is Rietveld 408576698