Commit 45e673e6 authored by smckay's avatar smckay Committed by Commit bot

Show a little circly/arrowey badge for files that have been copied locally.

Update import history code to support tracking locally copied files (and their destinations). Tracking destination is necessary as we'll eventually need to do lookups against destinations in order to mark items as imported when they are fully synced to the cloud.

BUG=420680
TEST=browser_test: FileManagerJsTest.*

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

Cr-Commit-Position: refs/heads/master@{#310189}
parent 64c52354
......@@ -7,6 +7,7 @@
<html>
<body>
<script src="../../common/js/volume_manager_common.js"></script>
<script src="../../common/js/importer_common.js"></script>
<script src="../../common/js/mock_entry.js"></script>
<script src="../../common/js/unittest_util.js"></script>
......
......@@ -12,7 +12,10 @@ var FILE_SIZE = 1234;
var FILE_PATH = 'test/data';
/** @const {string} */
var GOOGLE_DRIVE = 'Google Drive';
var DEVICE = importer.Destination.DEVICE;
/** @const {string} */
var GOOGLE_DRIVE = importer.Destination.GOOGLE_DRIVE;
/**
* Space Cloud: Your source for interstellar cloud storage.
......@@ -32,6 +35,9 @@ var storage;
/** @type {!Promise.<!importer.PersistentImportHistory>|undefined} */
var historyProvider;
/** @type {Promise} */
var testPromise;
// Set up the test components.
function setUp() {
testFileEntry = new MockFileEntry(
......@@ -49,53 +55,95 @@ function setUp() {
historyProvider = history.refresh();
}
function testHistoryWasCopiedFalseForUnknownEntry(callback) {
// TestRecordWriter is pre-configured with a Space Cloud entry
// but not for this file.
testPromise = historyProvider.then(
function(history) {
history.wasCopied(testFileEntry, SPACE_CAMP).then(assertFalse);
});
reportPromise(testPromise, callback);
}
function testHistoryWasCopiedTrueForKnownEntryLoadedFromStorage(callback) {
// TestRecordWriter is pre-configured with this entry.
testPromise = historyProvider.then(
function(history) {
history.wasCopied(testFileEntry, GOOGLE_DRIVE).then(assertTrue);
});
reportPromise(testPromise, callback);
}
function testHistoryWasImportedTrueForKnownEntrySetAtRuntime(callback) {
testPromise = historyProvider.then(
function(history) {
history.markImported(testFileEntry, SPACE_CAMP).then(
function() {
history.wasImported(testFileEntry, SPACE_CAMP).then(assertTrue);
});
});
reportPromise(testPromise, callback);
}
function testCopyChangeFiresChangedEvent(callback) {
testPromise = historyProvider.then(
function(history) {
var recorder = new TestCallRecorder();
history.addObserver(recorder.callback);
history.markCopied(testFileEntry, SPACE_CAMP, 'url1').then(
function() {
Promise.resolve()
.then(
function() {
recorder.assertCallCount(1);
assertEquals(
importer.ImportHistory.State.COPIED,
recorder.getLastArguments()[0]['state']);
});
});
});
reportPromise(testPromise, callback);
}
function testHistoryWasImportedFalseForUnknownEntry(callback) {
// TestRecordWriter is pre-configured with a Space Cloud entry
// but not for this file.
historyProvider.then(
testPromise = historyProvider.then(
function(history) {
history.wasImported(testFileEntry, SPACE_CAMP).then(
function(result) {
callback(/* error */ result);
},
callback.bind(null, true));
},
callback.bind(null, true))
.catch(handleError.bind(null, callback));
history.wasImported(testFileEntry, SPACE_CAMP).then(assertFalse);
});
reportPromise(testPromise, callback);
}
function testHistoryWasImportedTrueForKnownEntryLoadedFromStorage(callback) {
// TestRecordWriter is pre-configured with this entry.
historyProvider.then(
testPromise = historyProvider.then(
function(history) {
history.wasImported(testFileEntry, GOOGLE_DRIVE).then(
function(result) {
callback(/* error */ !result);
},
callback.bind(null, true));
},
callback.bind(null, true))
.catch(handleError.bind(null, callback));
history.wasImported(testFileEntry, GOOGLE_DRIVE).then(assertTrue);
});
reportPromise(testPromise, callback);
}
function testHistoryWasImportedTrueForKnownEntrySetAtRuntime(callback) {
historyProvider.then(
testPromise = historyProvider.then(
function(history) {
history.markImported(testFileEntry, SPACE_CAMP).then(
function() {
history.wasImported(testFileEntry, SPACE_CAMP).then(
function(result) {
callback(/* error */ !result);
history.wasImported(testFileEntry, SPACE_CAMP).then(assertTrue);
});
},
callback.bind(null, true));
},
callback.bind(null, true))
.catch(handleError.bind(null, callback));
});
reportPromise(testPromise, callback);
}
function testHistoryChangeFiresChangedEvent(callback) {
historyProvider.then(
function testImportChangeFiresChangedEvent(callback) {
testPromise = historyProvider.then(
function(history) {
var recorder = new TestCallRecorder();
history.addObserver(recorder.callback);
......@@ -108,53 +156,50 @@ function testHistoryChangeFiresChangedEvent(callback) {
assertEquals(
importer.ImportHistory.State.IMPORTED,
recorder.getLastArguments()[0]['state']);
callback(false);
})
.catch(handleError.bind(null, callback));
},
callback.bind(null, true));
},
callback.bind(null, true))
.catch(handleError.bind(null, callback));
});
});
});
reportPromise(testPromise, callback);
}
function testHistoryObserverUnsubscribe(callback) {
historyProvider.then(
testPromise = historyProvider.then(
function(history) {
var recorder = new TestCallRecorder();
history.addObserver(recorder.callback);
history.removeObserver(recorder.callback);
history.markImported(testFileEntry, SPACE_CAMP).then(
var promises = [];
promises.push(history.markCopied(testFileEntry, SPACE_CAMP, 'url2'));
promises.push(history.markImported(testFileEntry, SPACE_CAMP));
Promise.all(promises).then(
function() {
Promise.resolve()
.then(
function() {
recorder.assertCallCount(0);
callback(false);
})
.catch(handleError.bind(null, callback));
},
callback.bind(null, true));
},
callback.bind(null, true))
.catch(handleError.bind(null, callback));
});
});
});
reportPromise(testPromise, callback);
}
function testRecordStorageRemembersPreviouslyWrittenRecords(callback) {
createRealStorage('recordStorageTest.data')
testPromise = createRealStorage('recordStorageTest.data')
.then(
function(storage) {
storage.write(['abc', '123']).then(
function() {
storage.readAll().then(
function(records) {
callback(/* error */ records.length != 1);
},
callback);
assertTrue(records.length != 1);
});
},
callback)
.catch(handleError.bind(null, callback));
});
});
reportPromise(testPromise, callback);
}
function testHistoryLoaderIntegration(callback) {
......@@ -171,7 +216,7 @@ function testHistoryLoaderIntegration(callback) {
/** @type {!TestSyncFileEntryProvider|undefined} */
var syncFileProvider;
createFileEntry('historyLoaderTest.data')
testPromise = createFileEntry('historyLoaderTest.data')
.then(
/**
* @param {!FileEntry} fileEntry
......@@ -208,6 +253,8 @@ function testHistoryLoaderIntegration(callback) {
function() {
syncFileProvider.fireSyncEvent();
})
// TODO(smckay): Add markCopied support once FileWriter issues
// are resolved.
.then(
/**
* @return {!Promise.<boolean>} Resolves with true if the
......@@ -218,9 +265,10 @@ function testHistoryLoaderIntegration(callback) {
})
.then(
function(wasImported) {
callback(/* error */ !wasImported);
})
.catch(handleError.bind(null, callback));
assertTrue(wasImported);
});
reportPromise(testPromise, callback);
}
/**
......@@ -285,8 +333,9 @@ var TestRecordStorage = function() {
// Pre-populate the store with some "previously written" data <wink>.
/** @private {!Array.<!Array.<string>>} */
this.records_ = [
[FILE_LAST_MODIFIED + '_' + FILE_SIZE, GOOGLE_DRIVE],
['99999_99999', SPACE_CAMP]
[1, FILE_LAST_MODIFIED + '_' + FILE_SIZE, GOOGLE_DRIVE],
[0, FILE_LAST_MODIFIED + '_' + FILE_SIZE, 'google-drive', 'url4'],
[1, '99999_99999', SPACE_CAMP]
];
/**
......
......@@ -204,10 +204,14 @@ importer.MediaImportHandler.ImportTask.prototype.onProgress_ =
/** @param {!FileEntry} entry */
importer.MediaImportHandler.ImportTask.prototype.markAsCopied_ =
function(entry) {
var destinationUrl = this.destination_.toURL() + '/' + entry.name;
this.historyLoader_.getHistory().then(
/** @param {!importer.ImportHistory} history */
function(history) {
history.markImported(entry, importer.Destination.GOOGLE_DRIVE);
history.markCopied(
entry,
importer.Destination.GOOGLE_DRIVE,
destinationUrl);
});
};
......
......@@ -163,7 +163,7 @@ function testUpdatesHistoryAfterImport(callback) {
importedMedia.forEach(
/** @param {!CopyCapture} */
function(capture) {
importHistory.assertImported(
importHistory.assertCopied(
capture.source, importer.Destination.GOOGLE_DRIVE);
});
}),
......
......@@ -15,8 +15,12 @@ var importer = importer || {};
* @implements {importer.ImportHistory}
*/
importer.TestImportHistory = function() {
/** @type {!Object.<string, !Object.<!importer.Destination, string>>} */
this.copiedPaths = {};
/** @type {!Object.<string, Array.<string>>} */
this.importedPaths = {};
};
/** @override */
......@@ -25,6 +29,47 @@ importer.TestImportHistory.prototype.getHistory =
return Promise.resolve(this);
};
/**
* @param {!FileEntry} entry
* @param {!importer.Destination} destination
*/
importer.TestImportHistory.prototype.assertCopied =
function(entry, destination) {
assertTrue(this.wasCopied_(entry, destination));
};
/**
* Fully synchronous version of wasCopied.
* @param {!FileEntry} entry
* @param {!importer.Destination} destination
* @return {boolean}
*/
importer.TestImportHistory.prototype.wasCopied_ =
function(entry, destination) {
var path = entry.fullPath;
return path in this.copiedPaths &&
this.copiedPaths[path].indexOf(destination) > -1;
};
/** @override */
importer.TestImportHistory.prototype.wasCopied =
function(entry, destination) {
var path = entry.fullPath;
return Promise.resolve(this.wasCopied_(entry, destination));
};
/** @override */
importer.TestImportHistory.prototype.markCopied =
function(entry, destination) {
var path = entry.fullPath;
if (path in this.copiedPaths) {
this.copiedPaths[path].push(destination);
} else {
this.copiedPaths[path] = [destination];
}
return Promise.resolve();
};
/**
* @param {!FileEntry} entry
* @param {!importer.Destination} destination
......
......@@ -29,6 +29,8 @@ importer.ELIGIBLE_VOLUME_TYPES_ = [
* @enum {string}
*/
importer.Destination = {
// locally copied, but not imported to cloud as of yet.
DEVICE: 'device',
GOOGLE_DRIVE: 'google-drive'
};
......
......@@ -750,6 +750,20 @@ body[type='full-page'] .detail-name .detail-icon {
height: 30px;
}
.badge {
height: 16px;
position: absolute;
right: 7px;
top: 7px;
width: 16px;
}
.copied .badge {
background-image: -webkit-image-set(
url(../images/files/ui/copied_badge.png) 1x,
url(../images/files/ui/2x/copied_badge.png) 2x);
}
.imported .badge {
background-image: -webkit-image-set(
url(../images/files/ui/drive_badge.png) 1x,
......@@ -761,7 +775,8 @@ body[type='full-page'] .detail-name .detail-icon {
width: 16px;
}
.imported .filename-label {
.imported .filename-label,
.copied .filename-label {
margin-right: 14px;
}
......
......@@ -294,11 +294,23 @@ FileGrid.applyHistoryBadges_ = function(entry, box, history) {
// a possibly-fragile sibling selector we just
// plop the imported class on the parent of both.
box.parentElement.classList.add('imported');
} else {
history.wasCopied(entry, importer.Destination.GOOGLE_DRIVE)
.then(
function(copied) {
if (copied) {
// TODO(smckay): update badges when history changes
// "box" is currently the sibling of the elemement
// we want to style. So rather than employing
// a possibly-fragile sibling selector we just
// plop the imported class on the parent of both.
box.parentElement.classList.add('copied');
}
});
}
});
};
/**
* Item for the Grid View.
* @constructor
......
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