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

Unified Diff: chrome/test/data/file_manager/unit_tests/media_import_handler_unittest.js

Issue 762593006: Prototype implementation of MediaImportHandler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Sync to master. 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: chrome/test/data/file_manager/unit_tests/media_import_handler_unittest.js
diff --git a/chrome/test/data/file_manager/unit_tests/media_import_handler_unittest.js b/chrome/test/data/file_manager/unit_tests/media_import_handler_unittest.js
new file mode 100644
index 0000000000000000000000000000000000000000..0fab52fd88f14212f7b4509f5891f474bc2576d9
--- /dev/null
+++ b/chrome/test/data/file_manager/unit_tests/media_import_handler_unittest.js
@@ -0,0 +1,123 @@
+// 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.
+
+/**
+ * @type {!MockFileOperationManager}
+ */
+var fileOperationManager;
+
+/**
+ * @type {!MockMediaScanner}
+ */
+var mediaScanner;
+
+/**
+ * @type {!MediaImportHandler}
+ */
+var mediaImporter;
+
+/**
+ * @type {!VolumeInfo}
+ */
+var drive;
+
+function setUp() {
+ // Set up string assets.
+ loadTimeData.data = {
+ DRIVE_DIRECTORY_LABEL: 'My Drive',
+ DOWNLOADS_DIRECTORY_LABEL: 'Downloads'
+ };
+
+ fileOperationManager = new MockFileOperationManager();
+
+ mediaScanner = new MockMediaScanner();
+
+ var volumeManager = new MockVolumeManager();
+ drive = volumeManager.getCurrentProfileVolumeInfo(
+ VolumeManagerCommon.VolumeType.DRIVE);
+ // Create fake parented and non-parented roots.
+ drive.fileSystem.populate([
+ '/root/',
hirono 2014/12/04 04:44:22 nit: Indent should be 2 for array literals.
Ben Kwa 2014/12/04 19:53:01 Done.
+ '/other/'
+ ]);
+
+ MockVolumeManager.installMockSingleton(volumeManager);
+
+ mediaImporter = new MediaImportHandler(fileOperationManager, mediaScanner);
+}
+
+function tearDown() {
hirono 2014/12/04 04:44:22 You don't need to add tearDown if you don't use it
Ben Kwa 2014/12/04 19:53:00 Done.
+}
+
+function testGetImportDestination(callback) {
+ reportPromise(
+ MediaImportHandler.getImportDestination().then(
+ function(destination) {
+ // Verify that we get a directory back, and that it's rooted in
+ // Drive.
+ assertTrue(destination instanceof MockDirectoryEntry);
+ assertEquals(drive.fileSystem, destination.filesystem);
+ }),
+ callback);
+}
+
+function testImportFrom(callback) {
+ // Set up a filesystem with some files.
+ var fileSystem = MockFileSystem.create('fake-media-volume');
+ var filenames = [
+ '/DCIM/photos0/IMG00001.jpg',
hirono 2014/12/04 04:44:22 nit: Indent should be 2 for array literals.
Ben Kwa 2014/12/04 19:53:00 Done.
+ '/DCIM/photos0/IMG00002.jpg',
+ '/DCIM/photos0/IMG00003.jpg',
+ '/DCIM/photos1/IMG00001.jpg',
+ '/DCIM/photos1/IMG00002.jpg',
+ '/DCIM/photos1/IMG00003.jpg'
+ ];
+ fileSystem.populate(filenames);
+
+ // Set up some fake media scan results.
+ var media = filenames.map(function(filename) {
+ return fileSystem.entries[filename]; });
hirono 2014/12/04 04:44:23 nit: Just a style issue. Please put "});" at the n
Ben Kwa 2014/12/04 19:53:00 Done.
+ mediaScanner.setScanResults(media);
+
+ // Verify the results when the import operation is kicked off.
+ reportPromise(
+ fileOperationManager.whenPasteCalled().then(
+ function(args) {
+ // Verify that the task ID is correct.
+ assertEquals(importTask.taskId, args.opt_taskId);
+ // Verify that we're copying, not moving, files.
+ assertFalse(args.isMove);
+ // Verify that the sources are correct.
+ assertTrue(equalFileLists(media, args.sourceEntries));
+ // Verify that the destination is correct.
+ return MediaImportHandler.getImportDestination().then(
+ function(destination) {
+ assertEquals(destination.fullPath, args.targetEntry.fullPath);
+ });
+ }),
+ callback);
+ // Kick off an import
+ var importTask = mediaImporter.importFrom(fileSystem.root);
+}
+
+/**
+ * @return {boolean} True if the two lists contain the same set of FileEntries
+ * (two FileEntries are deemed to be "the same" if they have the same fullPath).
+ * False otherwise.
+ */
+function equalFileLists(list0, list1) {
hirono 2014/12/04 04:44:23 Maybe creating assertEntryListEquals is better for
Ben Kwa 2014/12/04 19:53:00 Done.
+ if (list0.length != list1.length) {
hirono 2014/12/04 04:44:22 nit: We prefer !== in our code.
hirono 2014/12/04 04:44:23 nit: We can drop {} if the condition and the body
Ben Kwa 2014/12/04 19:53:00 Done.
Ben Kwa 2014/12/04 19:53:00 Done.
+ return false;
+ }
+
+ /** @param {!FileEntry} entry */
+ var entryToPath = function(entry) { return entry.fullPath; };
+
+ var paths0 = list0.map(entryToPath);
+ var paths1 = list1.map(entryToPath);
+
+ return paths0.every(function(path) {
hirono 2014/12/04 04:44:22 Is it OK ['/A', '/A', '/B'] equals ['/A', '/B', '/
Ben Kwa 2014/12/04 19:53:00 Good catch, thanks! Fixed.
+ return paths1.indexOf(path) !== -1;
+ });
+}

Powered by Google App Engine
This is Rietveld 408576698