Commit 27c6768e authored by Joel Hockey's avatar Joel Hockey Committed by Commit Bot

FilesApp UI test rename file, add test.Event

Renamed chrome_file_manager.js to
chrome_file_manager_private_test_impl.js to make it clearer that the file
is for testing.

Added test.Event to be used for all fmp events.


Bug: 813477
Cq-Include-Trybots: master.tryserver.chromium.linux:closure_compilation
Change-Id: I7804480dd27f113005346a049242948c01666f08
Reviewed-on: https://chromium-review.googlesource.com/1100135Reviewed-by: default avatarAlexey Baskakov <loyso@chromium.org>
Commit-Queue: Joel Hockey <joelhockey@chromium.org>
Cr-Commit-Position: refs/heads/master@{#567123}
parent a44133cd
...@@ -6,15 +6,31 @@ ...@@ -6,15 +6,31 @@
// These APIs are provided natively to a chrome app, but since we are // These APIs are provided natively to a chrome app, but since we are
// running as a regular web page, we must provide test implementations. // running as a regular web page, we must provide test implementations.
// All testing functions in namespace 'test'.
var test = test || {};
/** @constructor */
test.Event = function() {
this.listeners_ = [];
};
/** @param {function} callback */
test.Event.prototype.addListener = function(callback) {
this.listeners_.push(callback);
};
/** @param {function} callback */
test.Event.prototype.removeListener = function(callback) {
this.listeners_ = this.listeners_.filter(l => l !== callback);
};
/** @param {...*} var_args */
test.Event.prototype.dispatchEvent = function(var_args) {
this.listeners_.forEach(l => l.apply(null, arguments));
};
chrome = { chrome = {
app: { app: {
runtime: { runtime: {
onLaunched: { onLaunched: new test.Event(),
addListener: () => {}, onRestarted: new test.Event(),
},
onRestarted: {
addListener: () => {},
},
}, },
window: { window: {
current: () => { current: () => {
...@@ -32,9 +48,7 @@ chrome = { ...@@ -32,9 +48,7 @@ chrome = {
contextMenus: { contextMenus: {
create: () => {}, create: () => {},
onClicked: { onClicked: new test.Event(),
addListener: () => {},
},
}, },
echoPrivate: { echoPrivate: {
...@@ -57,9 +71,7 @@ chrome = { ...@@ -57,9 +71,7 @@ chrome = {
}, },
fileBrowserHandler: { fileBrowserHandler: {
onExecute: { onExecute: new test.Event(),
addListener: () => {},
},
}, },
i18n: { i18n: {
...@@ -87,15 +99,9 @@ chrome = { ...@@ -87,15 +99,9 @@ chrome = {
}, },
notifications: { notifications: {
onButtonClicked: { onButtonClicked: new test.Event(),
addListener: () => {}, onClicked: new test.Event(),
}, onClosed: new test.Event(),
onClicked: {
addListener: () => {},
},
onClosed: {
addListener: () => {},
},
}, },
power: { power: {
...@@ -109,9 +115,7 @@ chrome = { ...@@ -109,9 +115,7 @@ chrome = {
}, },
// FileManager extension ID. // FileManager extension ID.
id: 'hhaomjibdihmijegdhdafkllkbggdgoj', id: 'hhaomjibdihmijegdhdafkllkbggdgoj',
onMessageExternal: { onMessageExternal: new test.Event(),
addListener: () => {},
},
sendMessage: (extensionId, message, options, opt_callback) => { sendMessage: (extensionId, message, options, opt_callback) => {
// Returns JSON. // Returns JSON.
if (opt_callback) if (opt_callback)
...@@ -139,9 +143,7 @@ chrome = { ...@@ -139,9 +143,7 @@ chrome = {
setTimeout(opt_callback, 0); setTimeout(opt_callback, 0);
}, },
}, },
onChanged: { onChanged: new test.Event(),
addListener: () => {},
},
sync: { sync: {
get: (keys, callback) => { get: (keys, callback) => {
setTimeout(callback, 0, {}); setTimeout(callback, 0, {});
...@@ -153,9 +155,7 @@ chrome = { ...@@ -153,9 +155,7 @@ chrome = {
// cws_widget_container.js loads the chrome web store widget as // cws_widget_container.js loads the chrome web store widget as
// a WebView. It calls WebView.request.onBeforeSendHeaders. // a WebView. It calls WebView.request.onBeforeSendHeaders.
HTMLElement.prototype.request = { HTMLElement.prototype.request = {
onBeforeSendHeaders: { onBeforeSendHeaders: new test.Event(),
addListener: () => {},
},
}; };
// cws_widget_container.js also calls WebView.stop. // cws_widget_container.js also calls WebView.stop.
......
...@@ -15,11 +15,6 @@ mockVolumeManager ...@@ -15,11 +15,6 @@ mockVolumeManager
chrome.fileManagerPrivate = { chrome.fileManagerPrivate = {
currentId_: 'test@example.com', currentId_: 'test@example.com',
dispatchEvent_: function(listenerType, event) {
setTimeout(() => {
this[listenerType].listeners_.forEach(l => l.call(null, event));
}, 0);
},
displayedId_: 'test@example.com', displayedId_: 'test@example.com',
preferences_: { preferences_: {
allowRedeemOffers: true, allowRedeemOffers: true,
...@@ -131,55 +126,22 @@ chrome.fileManagerPrivate = { ...@@ -131,55 +126,22 @@ chrome.fileManagerPrivate = {
callback(); callback();
}, this.mountCrostiniContainerDelay_); }, this.mountCrostiniContainerDelay_);
}, },
onAppsUpdated: { onAppsUpdated: new test.Event(),
addListener: () => {}, onCopyProgress: new test.Event(),
}, onDeviceChanged: new test.Event(),
onCopyProgress: { onDirectoryChanged: new test.Event(),
listeners_: [], onDriveConnectionStatusChanged: new test.Event(),
addListener: function(l) { onDriveSyncError: new test.Event(),
this.listeners_.push(l); onFileTransfersUpdated: new test.Event(),
}, onMountCompleted: new test.Event(),
removeListener: function(l) { onPreferencesChanged: new test.Event(),
this.listeners_ = this.listeners_.filter(e => e !== l);
},
},
onDeviceChanged: {
addListener: () => {},
},
onDirectoryChanged: {
listeners_: [],
addListener: function(l) {
this.listeners_.push(l);
},
removeListener: function(l) {
this.listeners_.splice(this.listeners_.indexOf(l), 1);
},
},
onDriveConnectionStatusChanged: {
addListener: () => {},
},
onDriveSyncError: {
addListener: () => {},
},
onFileTransfersUpdated: {
addListener: () => {},
},
onMountCompleted: {
listeners_: [],
addListener: function(l) {
this.listeners_.push(l);
},
},
onPreferencesChanged: {
addListener: () => {},
},
openInspector: (type) => {}, openInspector: (type) => {},
openSettingsSubpage: (sub_page) => {}, openSettingsSubpage: (sub_page) => {},
removeFileWatch: (entry, callback) => { removeFileWatch: (entry, callback) => {
setTimeout(callback, 0, true); setTimeout(callback, 0, true);
}, },
removeMount(volumeId) { removeMount(volumeId) {
chrome.fileManagerPrivate.dispatchEvent_('onMountCompleted', { chrome.fileManagerPrivate.onMountCompleted.dispatchEvent({
status: 'success', status: 'success',
eventType: 'unmount', eventType: 'unmount',
volumeMetadata: { volumeMetadata: {
......
...@@ -430,10 +430,9 @@ test.addEntries = function(downloads, drive, crostini) { ...@@ -430,10 +430,9 @@ test.addEntries = function(downloads, drive, crostini) {
test.TestEntryInfo.getMockFileSystemPopulateRows(crostini, '/'), true); test.TestEntryInfo.getMockFileSystemPopulateRows(crostini, '/'), true);
// Send onDirectoryChanged events. // Send onDirectoryChanged events.
chrome.fileManagerPrivate.dispatchEvent_( chrome.fileManagerPrivate.onDirectoryChanged.dispatchEvent(
'onDirectoryChanged', {eventType: 'changed', entry: fsDownloads.root}); {eventType: 'changed', entry: fsDownloads.root});
chrome.fileManagerPrivate.dispatchEvent_( chrome.fileManagerPrivate.onDirectoryChanged.dispatchEvent(
'onDirectoryChanged',
{eventType: 'changed', entry: fsDrive.entries['/root']}); {eventType: 'changed', entry: fsDrive.entries['/root']});
}; };
...@@ -441,7 +440,7 @@ test.addEntries = function(downloads, drive, crostini) { ...@@ -441,7 +440,7 @@ test.addEntries = function(downloads, drive, crostini) {
* Sends mount event for crostini volume. * Sends mount event for crostini volume.
*/ */
test.mountCrostini = function() { test.mountCrostini = function() {
chrome.fileManagerPrivate.dispatchEvent_('onMountCompleted', { chrome.fileManagerPrivate.onMountCompleted.dispatchEvent({
status: 'success', status: 'success',
eventType: 'mount', eventType: 'mount',
volumeMetadata: { volumeMetadata: {
......
...@@ -130,7 +130,7 @@ scripts += ['<script src="%s%s"></script>' % (ROOT, s) for s in [ ...@@ -130,7 +130,7 @@ scripts += ['<script src="%s%s"></script>' % (ROOT, s) for s in [
'background/js/volume_manager_impl.js', 'background/js/volume_manager_impl.js',
'background/js/mock_volume_manager.js', 'background/js/mock_volume_manager.js',
'foreground/js/constants.js', 'foreground/js/constants.js',
'test/js/chrome_file_manager.js', 'test/js/chrome_file_manager_private_test_impl.js',
'test/js/test_util.js', 'test/js/test_util.js',
] + ['test/' + s for s in os.listdir(os.path.join(ROOT_SRC, 'test')) ] + ['test/' + s for s in os.listdir(os.path.join(ROOT_SRC, 'test'))
if s.endswith('.js')]] if s.endswith('.js')]]
......
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