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 @@
// These APIs are provided natively to a chrome app, but since we are
// 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 = {
app: {
runtime: {
onLaunched: {
addListener: () => {},
},
onRestarted: {
addListener: () => {},
},
onLaunched: new test.Event(),
onRestarted: new test.Event(),
},
window: {
current: () => {
......@@ -32,9 +48,7 @@ chrome = {
contextMenus: {
create: () => {},
onClicked: {
addListener: () => {},
},
onClicked: new test.Event(),
},
echoPrivate: {
......@@ -57,9 +71,7 @@ chrome = {
},
fileBrowserHandler: {
onExecute: {
addListener: () => {},
},
onExecute: new test.Event(),
},
i18n: {
......@@ -87,15 +99,9 @@ chrome = {
},
notifications: {
onButtonClicked: {
addListener: () => {},
},
onClicked: {
addListener: () => {},
},
onClosed: {
addListener: () => {},
},
onButtonClicked: new test.Event(),
onClicked: new test.Event(),
onClosed: new test.Event(),
},
power: {
......@@ -109,9 +115,7 @@ chrome = {
},
// FileManager extension ID.
id: 'hhaomjibdihmijegdhdafkllkbggdgoj',
onMessageExternal: {
addListener: () => {},
},
onMessageExternal: new test.Event(),
sendMessage: (extensionId, message, options, opt_callback) => {
// Returns JSON.
if (opt_callback)
......@@ -139,9 +143,7 @@ chrome = {
setTimeout(opt_callback, 0);
},
},
onChanged: {
addListener: () => {},
},
onChanged: new test.Event(),
sync: {
get: (keys, callback) => {
setTimeout(callback, 0, {});
......@@ -153,9 +155,7 @@ chrome = {
// cws_widget_container.js loads the chrome web store widget as
// a WebView. It calls WebView.request.onBeforeSendHeaders.
HTMLElement.prototype.request = {
onBeforeSendHeaders: {
addListener: () => {},
},
onBeforeSendHeaders: new test.Event(),
};
// cws_widget_container.js also calls WebView.stop.
......
......@@ -15,11 +15,6 @@ mockVolumeManager
chrome.fileManagerPrivate = {
currentId_: 'test@example.com',
dispatchEvent_: function(listenerType, event) {
setTimeout(() => {
this[listenerType].listeners_.forEach(l => l.call(null, event));
}, 0);
},
displayedId_: 'test@example.com',
preferences_: {
allowRedeemOffers: true,
......@@ -131,55 +126,22 @@ chrome.fileManagerPrivate = {
callback();
}, this.mountCrostiniContainerDelay_);
},
onAppsUpdated: {
addListener: () => {},
},
onCopyProgress: {
listeners_: [],
addListener: function(l) {
this.listeners_.push(l);
},
removeListener: function(l) {
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: () => {},
},
onAppsUpdated: new test.Event(),
onCopyProgress: new test.Event(),
onDeviceChanged: new test.Event(),
onDirectoryChanged: new test.Event(),
onDriveConnectionStatusChanged: new test.Event(),
onDriveSyncError: new test.Event(),
onFileTransfersUpdated: new test.Event(),
onMountCompleted: new test.Event(),
onPreferencesChanged: new test.Event(),
openInspector: (type) => {},
openSettingsSubpage: (sub_page) => {},
removeFileWatch: (entry, callback) => {
setTimeout(callback, 0, true);
},
removeMount(volumeId) {
chrome.fileManagerPrivate.dispatchEvent_('onMountCompleted', {
chrome.fileManagerPrivate.onMountCompleted.dispatchEvent({
status: 'success',
eventType: 'unmount',
volumeMetadata: {
......
......@@ -430,10 +430,9 @@ test.addEntries = function(downloads, drive, crostini) {
test.TestEntryInfo.getMockFileSystemPopulateRows(crostini, '/'), true);
// Send onDirectoryChanged events.
chrome.fileManagerPrivate.dispatchEvent_(
'onDirectoryChanged', {eventType: 'changed', entry: fsDownloads.root});
chrome.fileManagerPrivate.dispatchEvent_(
'onDirectoryChanged',
chrome.fileManagerPrivate.onDirectoryChanged.dispatchEvent(
{eventType: 'changed', entry: fsDownloads.root});
chrome.fileManagerPrivate.onDirectoryChanged.dispatchEvent(
{eventType: 'changed', entry: fsDrive.entries['/root']});
};
......@@ -441,7 +440,7 @@ test.addEntries = function(downloads, drive, crostini) {
* Sends mount event for crostini volume.
*/
test.mountCrostini = function() {
chrome.fileManagerPrivate.dispatchEvent_('onMountCompleted', {
chrome.fileManagerPrivate.onMountCompleted.dispatchEvent({
status: 'success',
eventType: 'mount',
volumeMetadata: {
......
......@@ -130,7 +130,7 @@ scripts += ['<script src="%s%s"></script>' % (ROOT, s) for s in [
'background/js/volume_manager_impl.js',
'background/js/mock_volume_manager.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/' + s for s in os.listdir(os.path.join(ROOT_SRC, 'test'))
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