Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Commit

Permalink
Ensure the destination url reported to ImportHistory is correctly enc…
Browse files Browse the repository at this point in the history
…oded. Eliminates a bug where files will spaces in name were not being marked as synced.

Also:
1) Remove an unused method (with a TODO body) in ImportTask.

BUG=461174
TEST=browser_test: FileManagerJsTest.*

Review URL: https://codereview.chromium.org/954943006

Cr-Commit-Position: refs/heads/master@{#318197}
(cherry picked from commit 4cf03c7)

Files.app: Fix js exceptions in table rendering.

The status column isn't always visible.  Account for that when attempting to update table elements.

BUG=461723

Review URL: https://codereview.chromium.org/952893008

Cr-Commit-Position: refs/heads/master@{#318060}
(cherry picked from commit 4e9ddaa)

TBR=mtomasz

Review URL: https://codereview.chromium.org/961403002

Cr-Commit-Position: refs/branch-heads/2311@{#53}
Cr-Branched-From: 09b7de5-refs/heads/master@{#317474}
  • Loading branch information
DaddingtonPalace committed Feb 27, 2015
1 parent d36c2a2 commit 22cd68a
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 31 deletions.
19 changes: 4 additions & 15 deletions ui/file_manager/file_manager/background/js/media_import_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ importer.MediaImportHandler.ImportTask.prototype.copy_ =
*/
var onComplete = function(destinationEntry) {
this.cancelCallback_ = null;
this.markAsCopied_(entry, destinationDirectory);
this.markAsCopied_(entry, destinationEntry);
this.notify(importer.TaskQueue.UpdateType.PROGRESS);
resolver.resolve(destinationEntry);
};
Expand Down Expand Up @@ -440,24 +440,13 @@ importer.MediaImportHandler.ImportTask.prototype.copy_ =
return resolver.promise;
};

/**
* A callback to notify listeners when a file has been copied.
* @param {string} sourceUrl
* @param {Entry} destination
*/
importer.MediaImportHandler.ImportTask.prototype.onEntryChanged_ =
function(sourceUrl, destination) {
// TODO(kenobi): Add code to notify observers when entries are created.
};

/**
* @param {!FileEntry} entry
* @param {!DirectoryEntry} destinationDirectory
* @param {!FileEntry} destinationEntry
*/
importer.MediaImportHandler.ImportTask.prototype.markAsCopied_ =
function(entry, destinationDirectory) {
function(entry, destinationEntry) {
this.remainingFilesCount_--;
var destinationUrl = destinationDirectory.toURL() + '/' + entry.name;
this.historyLoader_.getHistory().then(
/**
* @param {!importer.ImportHistory} history
Expand All @@ -467,7 +456,7 @@ importer.MediaImportHandler.ImportTask.prototype.markAsCopied_ =
history.markCopied(
entry,
this.destination_,
destinationUrl);
destinationEntry.toURL());
}.bind(this))
.catch(importer.getLogger().catcher('import-task-mark-as-copied'));
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,8 @@ function setUp() {

importHistory = new importer.TestImportHistory();
mediaScanner = new TestMediaScanner();
destinationFileSystem = new MockFileSystem(destinationFactory);
destinationFactory = new Promise(
function(resolve, reject) {
resolve(destinationFileSystem.root);
}).then(
function(directory) {
return directory;
});
destinationFileSystem = new MockFileSystem('googleDriveFilesystem');
destinationFactory = Promise.resolve(destinationFileSystem.root);
duplicateFinderFactory = new importer.TestDuplicateFinder.Factory();

mediaImporter = new importer.MediaImportHandler(
Expand Down Expand Up @@ -136,6 +130,49 @@ function testImportMedia(callback) {
scanResult.finalize();
}

function testImportMedia_EmploysEncodedUrls(callback) {
var media = setupFileSystem([
'/DCIM/photos0/Mom and Dad.jpg',
]);

var scanResult = new TestScanResult(media);
var importTask = mediaImporter.importFromScanResult(
scanResult,
importer.Destination.GOOGLE_DRIVE,
destinationFactory);

var promise = new Promise(
function(resolve, reject) {
importTask.addObserver(
/**
* @param {!importer.TaskQueue.UpdateType} updateType
* @param {!importer.TaskQueue.Task} task
*/
function(updateType, task) {
switch (updateType) {
case importer.TaskQueue.UpdateType.COMPLETE:
resolve(destinationFileSystem.root.getAllChildren());
break;
case importer.TaskQueue.UpdateType.ERROR:
reject('Task failed :(');
break;
}
});
})
.then(
function(copiedEntries) {
var expected = 'Mom%20and%20Dad.jpg';
var url = copiedEntries[0].toURL();
assertTrue(url.length > expected.length);
var actual = url.substring(url.length - expected.length);
assertEquals(expected, actual);
});

reportPromise(promise, callback);

scanResult.finalize();
}

// Verifies that when files with duplicate names are imported, that they don't
// overwrite one another.
function testImportMediaWithDuplicateFilenames(callback) {
Expand Down Expand Up @@ -396,6 +433,11 @@ function testImportWithDuplicates(callback) {
}

function testImportWithErrors(callback) {

// Quiet the logger just in this test where we expect errors.
// Elsewhere, it's better for errors to be seen by test authors.
importer.setupTestLogger().quiet();

var media = setupFileSystem([
'/DCIM/photos0/IMG00001.jpg',
'/DCIM/photos0/IMG00002.jpg',
Expand Down
7 changes: 6 additions & 1 deletion ui/file_manager/file_manager/common/js/mock_entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,12 @@ MockEntry.prototype = {
* @return {string} Fake URL.
*/
MockEntry.prototype.toURL = function() {
return this.filesystem.rootURL + this.fullPath;
var segments = this.fullPath.split('/');
for (var i = 0; i < segments.length; i++) {
segments[i] = encodeURIComponent(segments[i]);
}

return this.filesystem.rootURL + segments.join('/');
};

/**
Expand Down
30 changes: 25 additions & 5 deletions ui/file_manager/file_manager/common/js/test_importer_common.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ var importer = importer || {};
/**
* Sets up a logger for use in unit tests. The test logger doesn't attempt to
* access chrome's sync file system. Call this during setUp.
* @return {!importer.TestLogger}
*/
importer.setupTestLogger = function() {
importer.logger_ = new importer.TestLogger();
var logger = new importer.TestLogger();
importer.logger_ = logger;
return logger;
};

/**
Expand All @@ -24,25 +27,42 @@ importer.setupTestLogger = function() {
importer.TestLogger = function() {
/** @public {!TestCallRecorder} */
this.errorRecorder = new TestCallRecorder();

/** @type {boolean} Should we print stuff to console */
this.quiet_ = false;
};

/**
* Causes logger to stop printing anything to console.
* This can be useful when errors are expected in tests.
*/
importer.TestLogger.prototype.quiet = function() {
this.quiet_ = true;
};

/** @override */
importer.TestLogger.prototype.info = function(content) {
console.log(content);
if (!this.quiet_) {
console.log(content);
}
};

/** @override */
importer.TestLogger.prototype.error = function(content) {
this.errorRecorder.callback(content);
console.error(content);
console.error(new Error('Error stack').stack);
if (!this.quiet_) {
console.error(content);
console.error(new Error('Error stack').stack);
}
};

/** @override */
importer.TestLogger.prototype.catcher = function(context) {
return function(error) {
this.error('Caught promise error. Context: ' + context +
' Error: ' + error.message);
console.error(error.stack);
if (!this.quiet_) {
console.error(error.stack);
}
}.bind(this);
};
9 changes: 7 additions & 2 deletions ui/file_manager/file_manager/foreground/js/ui/file_table.js
Original file line number Diff line number Diff line change
Expand Up @@ -742,8 +742,13 @@ FileTable.prototype.updateFileMetadata = function(item, entry) {
/** @type {!HTMLDivElement} */ (item.querySelector('.date')), entry);
this.updateSize_(
/** @type {!HTMLDivElement} */ (item.querySelector('.size')), entry);
this.updateStatus_(
/** @type {!HTMLDivElement} */ (item.querySelector('.status')), entry);

// The status column isn't always visible.
// TODO(kenobi): Clean up once the status column's fate is determined.
var statusEl = item.querySelector('.status');
if (statusEl) {
this.updateStatus_(/** @type {!HTMLDivElement} */ (statusEl), entry);
}
};

/**
Expand Down

0 comments on commit 22cd68a

Please sign in to comment.