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

Unified Diff: ui/file_manager/file_manager/foreground/js/import_controller_unittest.js

Issue 886093003: Add support for size checking selection based scans. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update DefaultScanResult to use importerResolver instead of hand rolled support...was investigating… Created 5 years, 11 months 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/foreground/js/import_controller_unittest.js
diff --git a/ui/file_manager/file_manager/foreground/js/import_controller_unittest.js b/ui/file_manager/file_manager/foreground/js/import_controller_unittest.js
index 89d72efb9e04711818a1af3de59ddb84f5b80af8..d2c47fcba50c86bfff4ce138b6e8ec7c9154a78f 100644
--- a/ui/file_manager/file_manager/foreground/js/import_controller_unittest.js
+++ b/ui/file_manager/file_manager/foreground/js/import_controller_unittest.js
@@ -23,8 +23,10 @@ var destinationVolume;
/** @type {!importer.TestCommandWidget} */
var widget;
-// Set up string assets.
-loadTimeData.data = {
+/**
+ * @enum {string}
+ */
+var MESSAGES = {
CLOUD_IMPORT_BUTTON_LABEL: 'Import it!',
CLOUD_IMPORT_ACTIVE_IMPORT_BUTTON_LABEL: 'Already importing!',
CLOUD_IMPORT_EMPTY_SCAN_BUTTON_LABEL: 'No new media',
@@ -34,6 +36,9 @@ loadTimeData.data = {
DOWNLOADS_DIRECTORY_LABEL: 'Downloads'
};
+// Set up string assets.
+loadTimeData.data = MESSAGES;
+
function setUp() {
// Stub out metrics support.
metrics = {
@@ -118,9 +123,12 @@ function testGetCommandUpdate_InitiatesScan(callback) {
function(response) {
assertTrue(response.visible);
assertFalse(response.executable);
-
+ assertEquals(
+ response.label,
+ MESSAGES.CLOUD_IMPORT_SCANNING_BUTTON_LABEL);
mediaScanner.assertScanCount(1);
});
+
reportPromise(promise, callback);
}
@@ -153,6 +161,50 @@ function testGetCommandUpdate_CanExecuteAfterScanIsFinalized(callback) {
function(response) {
assertTrue(response.visible);
assertTrue(response.executable);
+ assertEquals(
+ response.label,
+ MESSAGES.CLOUD_IMPORT_BUTTON_LABEL);
+ });
+
+ reportPromise(promise, callback);
+}
+
+function testGetCommandUpdate_DisabledForInsufficientLocalStorage(callback) {
+ var controller = createController(
+ VolumeManagerCommon.VolumeType.MTP,
+ 'mtp-volume',
+ [
+ '/DCIM/',
+ '/DCIM/photos0/',
+ '/DCIM/photos0/IMG00001.jpg',
+ '/DCIM/photos0/IMG00002.jpg',
+ '/DCIM/photos1/',
+ '/DCIM/photos1/IMG00001.jpg',
+ '/DCIM/photos1/IMG00003.jpg'
+ ],
+ '/DCIM');
+
+ var fileSystem = new MockFileSystem('testFs');
+ mediaScanner.fileEntries.push(
+ new MockFileEntry(
+ fileSystem,
+ '/DCIM/photos0/IMG00001.jpg',
+ {size: 1000000}));
+
+ environment.freeStorageSpace = 100;
+ environment.directoryChangedListener_(); // initiates a scan.
+ var promise = widget.updatePromise.then(
+ function() {
+ widget.resetPromise();
+ mediaScanner.finalizeScans();
+ return widget.updatePromise;
+ }).then(
+ function(response) {
+ assertTrue(response.visible);
+ assertFalse(response.executable);
+ assertEquals(
+ response.label,
+ MESSAGES.CLOUD_IMPORT_INSUFFICIENT_SPACE_BUTTON_LABEL);
});
reportPromise(promise, callback);
@@ -173,18 +225,59 @@ function testGetCommandUpdate_CannotExecuteEmptyScanResult(callback) {
],
'/DCIM');
- controller.getCommandUpdate();
- mediaScanner.finalizeScans();
-
var promise = controller.getCommandUpdate().then(
- function(response) {
- assertTrue(response.visible);
- assertFalse(response.executable);
+ function() {
+ mediaScanner.finalizeScans();
+
+ return controller.getCommandUpdate().then(
+ function(response) {
+ assertTrue(response.visible);
+ assertFalse(response.executable);
+ assertEquals(
+ response.label,
+ MESSAGES.CLOUD_IMPORT_EMPTY_SCAN_BUTTON_LABEL);
+ });
});
reportPromise(promise, callback);
}
+function testGetCommandUpdate_DisabledWhileImporting(callback) {
+ var controller = createController(
+ VolumeManagerCommon.VolumeType.MTP,
+ 'mtp-volume',
+ [
+ '/DCIM/',
+ '/DCIM/photos0/',
+ '/DCIM/photos0/IMG00001.jpg',
+ '/DCIM/photos0/IMG00002.jpg',
+ ],
+ '/DCIM');
+
+// First we need to force the controller into a scanning state.
+environment.directoryChangedListener_();
+
+var promise = widget.updatePromise.then(
+ function() {
+ widget.resetPromise();
+ widget.executeListener();
+ mediaImporter.assertImportsStarted(1);
+ // return the reset promise so as to allow execution
+ // to complete before the test is finished...even though
+ // we're not waiting on anything in particular.
+ return controller.getCommandUpdate();
+ }).then(
+ function(response) {
+ assertTrue(response.visible);
+ assertFalse(response.executable);
+ assertEquals(
+ response.label,
+ MESSAGES.CLOUD_IMPORT_ACTIVE_IMPORT_BUTTON_LABEL);
+ });
+
+ reportPromise(promise, callback);
+}
+
function testClick_StartsImport(callback) {
var controller = createController(
VolumeManagerCommon.VolumeType.MTP,
@@ -265,6 +358,21 @@ function testDirectoryChange_TriggersUpdate(callback) {
reportPromise(widget.updatePromise, callback);
}
+function testSelectionChange_TriggersUpdate(callback) {
+ var controller = createController(
+ VolumeManagerCommon.VolumeType.MTP,
+ 'mtp-volume',
+ [
+ '/DCIM/',
+ '/DCIM/photos0/',
+ '/DCIM/photos0/IMG00001.jpg',
+ ],
+ '/DCIM');
+
+ environment.selectionChangedListener_();
+ reportPromise(widget.updatePromise, callback);
+}
+
function testVolumeUnmount_TriggersUpdate(callback) {
var controller = createController(
VolumeManagerCommon.VolumeType.MTP,
@@ -506,7 +614,10 @@ TestControllerEnvironment = function(volumeInfo, directory) {
/** @private {function()} */
this.directoryChangedListener_;
- /** @public {!DirectoryEntry} */
+ /** @private {function()} */
+ this.selectionChangedListener_;
+
+ /** @public {!Entry} */
this.selection = [];
/** @public {boolean} */
@@ -572,6 +683,12 @@ TestControllerEnvironment.prototype.addDirectoryChangedListener =
this.directoryChangedListener_ = listener;
};
+/** @override */
+TestControllerEnvironment.prototype.addSelectionChangedListener =
+ function(listener) {
+ this.selectionChangedListener_ = listener;
+};
+
/**
* Simulates an unmount event.
*/

Powered by Google App Engine
This is Rietveld 408576698