Commit 52a31949 authored by Joel Hockey's avatar Joel Hockey Committed by Commit Bot

Run integration tests using test/main.html

Converted integration_tests/delete.js to test/js/delete.js

Copied the parts of integration_tests/test_util.js required
for delete.js to test/js/test_util.js and got TestEntryInfo
integrated with MockVolumeManager.

Added extra API implementations required:
- chrome.i18n
- chrome.mediaGalleries
- window.domAutomationController

Added webui_resource_test.js and test_util.js to create script.

Bug: 813477
Cq-Include-Trybots: master.tryserver.chromium.linux:closure_compilation
Change-Id: Ie6704f98f8d8c2116c72c2d7a2c22cda246eb0a0
Reviewed-on: https://chromium-review.googlesource.com/961986
Commit-Queue: Joel Hockey <joelhockey@chromium.org>
Reviewed-by: default avatarSasha Morrissey <sashab@chromium.org>
Cr-Commit-Position: refs/heads/master@{#543564}
parent 823c476a
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
action("create_test_main") {
script = "//ui/file_manager/file_manager/test/scripts/create_test_main.py"
output = "$target_gen_dir/main.html"
args = [ "--output=" + rebase_path(output, root_build_dir) ]
outputs = [
output,
]
}
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
function testDeleteMenuItemIsDisabledWhenNoItemIsSelected(done) {
setupAndWaitUntilReady()
.then(detailTable => {
return waitForElement('list.list');
})
.then(emptySpace => {
assertTrue(test.util.sync.fakeMouseRightClick(window, 'list.list'));
return waitForElement('#file-context-menu:not([hidden])');
})
.then(result => {
return waitForElement(
'cr-menu-item[command="#delete"][disabled="disabled"]');
})
.then(result => {
done();
})
.catch(err => {
console.error(err);
done(true);
});
}
function testDeleteOneItemFromToolbar(done) {
var beforeDeletion = TestEntryInfo.getExpectedRows([
ENTRIES.photos,
ENTRIES.hello,
ENTRIES.world,
ENTRIES.desktop,
ENTRIES.beautiful
]);
var afterDeletion = TestEntryInfo.getExpectedRows([
ENTRIES.photos,
ENTRIES.hello,
ENTRIES.world,
ENTRIES.beautiful
]);
setupAndWaitUntilReady()
.then(detailTable => {
return waitForFiles(beforeDeletion);
})
.then(result => {
return test.util.sync.selectFile(window, 'My Desktop Background.png');
})
.then(result => {
assertTrue(result);
return test.util.sync.fakeMouseClick(window, 'button#delete-button');
})
.then(result => {
assertTrue(result);
return waitForElement('.cr-dialog-container.shown');
})
.then(result => {
return test.util.sync.fakeMouseClick(window, 'button.cr-dialog-ok');
})
.then(result => {
assertTrue(result);
return waitForFiles(afterDeletion);
})
.then(result => {
done();
})
.catch(err => {
console.error(err);
done(err);
});
}
......@@ -26,7 +26,6 @@ chrome = {
commandLinePrivate: {
switches_: {},
hasSwitch: (name, callback) => {
console.debug('chrome.commandLinePrivate.hasSwitch called', name);
setTimeout(callback, 0, chrome.commandLinePrivate.switches_[name]);
},
},
......@@ -40,7 +39,6 @@ chrome = {
echoPrivate: {
getOfferInfo: (id, callback) => {
console.debug('chrome.echoPrivate.getOfferInfo called', id);
setTimeout(() => {
// checkSpaceAndMaybeShowWelcomeBanner_ relies on lastError being set.
chrome.runtime.lastError = {message: 'Not found'};
......@@ -52,7 +50,6 @@ chrome = {
extension: {
getViews: (fetchProperties) => {
console.debug('chrome.extension.getViews called', fetchProperties);
// Returns Window[].
return [window];
},
......@@ -65,11 +62,18 @@ chrome = {
},
},
i18n: {
getMessage: (messageName, opt_substitutions) => {
return messageName;
},
},
metricsPrivate: {
MetricTypeType: {
HISTOGRAM_LINEAR: 'histogram-linear',
},
recordMediumCount: () => {},
recordPercentage: () => {},
recordSmallCount: () => {},
recordTime: () => {},
recordUserAction: () => {},
......@@ -97,19 +101,31 @@ chrome = {
onMessageExternal: {
addListener: () => {},
},
sendMessage: (extensionId, message, options, opt_callback) => {
// Returns JSON.
if (opt_callback)
setTimeout(opt_callback(''), 0);
},
},
storage: {
state: {},
local: {
get: (keys, callback) => {
console.debug('chrome.storage.local.get', keys);
setTimeout(callback, 0, {});
var keys = keys instanceof Array ? keys : [keys];
var result = {};
keys.forEach(function(key) {
if (key in chrome.storage.state)
result[key] = chrome.storage.state[key];
});
setTimeout(callback, 0, result);
},
set: (items, callback) => {
console.debug('chrome.storage.local.set', items);
if (callback) {
setTimeout(callback, 0);
set: (items, opt_callback) => {
for (var key in items) {
chrome.storage.state[key] = items[key];
}
if (opt_callback)
setTimeout(opt_callback, 0);
},
},
onChanged: {
......@@ -117,7 +133,6 @@ chrome = {
},
sync: {
get: (keys, callback) => {
console.debug('chrome.storage.sync.get', keys);
setTimeout(callback, 0, {});
}
},
......@@ -128,14 +143,17 @@ chrome = {
// a WebView. It calls WebView.request.onBeforeSendHeaders.
HTMLElement.prototype.request = {
onBeforeSendHeaders: {
addListener: () => {
console.debug(
'HTMLElement.request.onBeforeSendHeaders.addListener called');
},
addListener: () => {},
},
};
// cws_widget_container.js also calls WebView.stop.
HTMLElement.prototype.stop = () => {
console.debug('HTMLElement.stop called');
HTMLElement.prototype.stop = () => {};
// domAutomationController is provided in tests, but is
// useful for debugging tests in browser.
window.domAutomationController = window.domAutomationController || {
send: msg => {
console.debug('domAutomationController.send', msg);
},
};
......@@ -7,17 +7,19 @@
// running as a regular web page, we must provide test implementations.
mockVolumeManager = new MockVolumeManager();
mockVolumeManager
.getCurrentProfileVolumeInfo(VolumeManagerCommon.VolumeType.DOWNLOADS)
.fileSystem.populate(
['/New Folder/', '/a.txt', '/kittens.jpg', '/unknown.ext']);
// Create drive /root/ immediately.
mockVolumeManager
.getCurrentProfileVolumeInfo(VolumeManagerCommon.VolumeType.DRIVE)
.fileSystem.populate(
['/root/New Folder/', '/root/a.txt', '/root/kittens.jpg']);
.fileSystem.populate(['/root/']);
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,
......@@ -28,6 +30,9 @@ chrome.fileManagerPrivate = {
timezone: 'Australia/Sydney',
use24hourClock: false,
},
listeners_: {
'onDirectoryChanged': [],
},
profiles_: [{
displayName: 'Test User',
isCurrentProfile: true,
......@@ -40,67 +45,60 @@ chrome.fileManagerPrivate = {
NATIVE_SOURCE: 'native_source',
},
addFileWatch: (entry, callback) => {
console.debug('c.fmp.addFileWatch called', entry);
// Returns success.
setTimeout(callback, 0, true);
},
enableExternalFileScheme: () => {
console.debug('c.fmp.enableExternalFileScheme called');
},
enableExternalFileScheme: () => {},
executeTask: (taskId, entries, callback) => {
console.debug('c.fmp.executeTask called', taskId, entries);
// Returns opened|message_sent|failed|empty.
setTimeout(callback, 0, 'failed');
},
getDriveConnectionState: (callback) => {
console.debug('c.fmp.getDriveConnectionState called');
setTimeout(callback, 0, mockVolumeManager.getDriveConnectionState());
},
getEntryProperties: (entries, names, callback) => {
console.debug('c.fmp.getEntryProperties called', entries, names);
// Returns EntryProperties[].
var results = [];
for (var i = 0; i < entries.length; i++) {
results.push({});
}
entries.forEach(entry => {
var props = {};
names.forEach(name => {
props[name] = entry.metadata[name];
});
results.push(props);
});
setTimeout(callback, 0, results);
},
getFileTasks: (entries, callback) => {
console.debug('c.fmp.getFileTasks called', entries);
// Returns FileTask[].
setTimeout(callback, 0, []);
},
getPreferences: (callback) => {
console.debug('c.fmp.getPreferences called');
setTimeout(callback, 0, chrome.fileManagerPrivate.preferences_);
},
getProfiles: (callback) => {
console.debug('c.fmp.getProfiles called');
// Returns profiles, currentId, displayedId
setTimeout(
callback, 0, chrome.fileManagerPrivate.profiles_,
chrome.fileManagerPrivate.currentId_,
chrome.fileManagerPrivate.displayedId_);
},
getProviders: (callback) => {
console.debug('c.fmp.getProviders called');
// Returns Provider[].
setTimeout(callback, 0, []);
},
getRecentFiles: (restriction, callback) => {
console.debug('c.fmp.getRecentFiles called', restriction);
// Returns Entry[].
setTimeout(callback, 0, []);
},
getSizeStats: (volumeId, callback) => {
console.debug('c.fmp.getSizeStats called', volumeId);
// MountPointSizeStats { totalSize: double, remainingSize: double }
setTimeout(callback, 0, {totalSize: 16e9, remainingSize: 8e9});
},
getStrings: (callback) => {
console.debug('c.fmp.getStrings called');
// Returns map of strings.
setTimeout(callback, 0, loadTimeData.data_);
},
getVolumeMetadataList: (callback) => {
console.debug('c.fmp.getVolumeMetadatalist called');
var list = [];
for (var i = 0; i < mockVolumeManager.volumeInfoList.length; i++) {
list.push(mockVolumeManager.volumeInfoList.item(i));
......@@ -108,80 +106,70 @@ chrome.fileManagerPrivate = {
setTimeout(callback, 0, list);
},
grantAccess: (entryUrls, callback) => {
console.debug('c.fmp.grantAccess called', entryUrls);
setTimeout(callback, 0);
},
isUMAEnabled: (callback) => {
console.debug('c.fmp.isUMAEnabled called');
setTimeout(callback, 0, false);
},
onAppsUpdated: {
addListener: () => {
console.debug('c.fmp.onAppsUpdated.addListener called');
},
addListener: () => {},
},
onDeviceChanged: {
addListener: () => {
console.debug('c.fmp.onDeviceChanged.addListener called');
},
addListener: () => {},
},
onDirectoryChanged: {
addListener: () => {
console.debug('c.fmp.onDirectoryChanged.addListener called');
listeners_: [],
addListener: function(l) {
this.listeners_.push(l);
},
},
onDriveConnectionStatusChanged: {
addListener: () => {
console.debug('c.fmp.onDriveConnectionStatusChanged.addListener called');
},
addListener: () => {},
},
onDriveSyncError: {
addListener: () => {
console.debug('c.fmp.onDriveSyncError.addListener called');
},
addListener: () => {},
},
onFileTransfersUpdated: {
addListener: () => {
console.debug('c.fmp.onFileTransfersUpdated.addListener called');
},
addListener: () => {},
},
onMountCompleted: {
addListener: () => {
console.debug('c.fmp.onMountCompleted.addListener called');
},
addListener: () => {},
},
onPreferencesChanged: {
addListener: () => {
console.debug('c.fmp.onPreferencesChanged.addListener called');
},
addListener: () => {},
},
removeFileWatch: (entry, callback) => {
console.debug('c.fmp.removeFileWatch called', entry);
setTimeout(callback, 0, true);
},
requestWebStoreAccessToken: (callback) => {
console.debug('c.fmp.requestWebStoreAccessToken called');
setTimeout(callback, 0, chrome.fileManagerPrivate.token_);
},
resolveIsolatedEntries: (entries, callback) => {
console.debug('c.fmp.resolveIsolatedEntries called', entries);
setTimeout(callback, 0, entries);
},
searchDriveMetadata: (searchParams, callback) => {
console.debug('c.fmp.searchDriveMetadata called', searchParams);
// Returns SearchResult[].
// SearchResult { entry: Entry, highlightedBaseName: string }
setTimeout(callback, 0, []);
},
validatePathNameLength: (parentEntry, name, callback) => {
console.debug('c.fmp.validatePathNameLength called', parentEntry, name);
setTimeout(callback, 0, true);
},
};
chrome.mediaGalleries = {
getMetadata: (mediaFile, options, callback) => {
// Returns metdata {mimeType: ..., ...}.
setTimeout(() => {
webkitResolveLocalFileSystemURL(mediaFile.name, entry => {
callback({mimeType: entry.metadata.contentMimeType});
}, 0);
});
},
};
chrome.fileSystem = {
requestFileSystem: (options, callback) => {
console.debug('chrome.fileSystem.requestFileSystem called', options);
var volume =
mockVolumeManager.volumeInfoList.findByVolumeId(options.volumeId);
setTimeout(callback, 0, volume ? volume.fileSystem : null);
......@@ -195,13 +183,14 @@ chrome.fileSystem = {
* @param {function(!DOMException)} errorCallback Error callback.
*/
webkitResolveLocalFileSystemURL = (url, successCallback, errorCallback) => {
console.debug('webkitResolveLocalFileSystemURL', url);
var match = url.match(/^filesystem:(\w+)(\/.*)/);
if (match) {
var volumeType = match[1];
var path = match[2];
var volume = mockVolumeManager.getCurrentProfileVolumeInfo(volumeType);
if (volume) {
// Decode URI in file paths.
path = path.split('/').map(decodeURIComponent).join('/');
var entry = volume.fileSystem.entries[path];
if (entry) {
setTimeout(successCallback, 0, entry);
......
......@@ -9,12 +9,14 @@
loadTimeData.data = new Proxy(
{
AUDIO_FILE_TYPE: '$1 audio',
CANCEL_LABEL: 'Cancel',
CHROMEOS_RELEASE_BOARD: 'unknown',
COPY_ITEMS_REMAINING: 'Copying $1 items...',
DEFAULT_NEW_FOLDER_NAME: 'New Folder',
DELETE_FILE_NAME: 'Deleting "$1"...',
DOWNLOADS_DIRECTORY_LABEL: 'Downloads',
DATE_COLUMN_LABEL: 'Date modified',
DRIVE_BUY_MORE_SPACE: 'Buy more storage...',
DRIVE_DIRECTORY_LABEL: 'Google Drive',
DRIVE_MENU_HELP: 'Help',
......@@ -40,22 +42,34 @@ loadTimeData.data = new Proxy(
EMPTY_FOLDER: 'Nothing to see here...',
FILENAME_LABEL: 'File name',
GALLERY_CONFIRM_DELETE_ONE: 'Are you sure you want to delete "$1"?',
GDOC_DOCUMENT_FILE_TYPE: 'Google document',
GENERIC_FILE_TYPE: '$1 file',
GOOGLE_DRIVE_REDEEM_URL: 'http://www.google.com/intl/en/chrome/' +
'devices/goodies.html?utm_source=filesapp&utm_medium=banner&' +
'utm_campaign=gsg',
IMAGE_FILE_TYPE: '$1 image',
INSTALL_NEW_EXTENSION_LABEL: 'Install new from the webstore',
MANY_ENTRIES_SELECTED: '$1 items selected',
MANY_FILES_SELECTED: '$1 files selected',
NAME_COLUMN_LABEL: 'Name',
OFFLINE_COLUMN_LABEL: 'Available offline',
OK_LABEL: 'OK',
ONE_DIRECTORY_SELECTED: '1 folder selected',
ONE_FILE_SELECTED: '1 file selected',
OPEN_LABEL: 'Open',
PLAIN_TEXT_FILE_TYPE: 'Plain text',
PREPARING_LABEL: 'Preparing',
SIZE_COLUMN_LABEL: 'Size',
SPACE_AVAILABLE: '$1 available',
STATUS_COLUMN_LABEL: 'Status',
TYPE_COLUMN_LABEL: 'Type',
UI_LOCALE: 'en_US',
RECENT_ROOT_LABEL: 'Recent',
SEARCH_TEXT_LABEL: 'Search',
SIZE_BYTES: '$1 bytes',
SIZE_GB: '$1 GB',
SIZE_KB: '$1 KB',
SIZE_PB: '$1 PB',
SUGGEST_DIALOG_INSTALLATION_FAILED: 'Installation failed.',
SUGGEST_DIALOG_INSTALLING_SPINNER_ALT: 'Installing',
SUGGEST_DIALOG_LINK_TO_WEBSTORE: 'See more...',
......@@ -63,6 +77,7 @@ loadTimeData.data = new Proxy(
SUGGEST_DIALOG_TITLE: 'Select an app to open this file',
TASK_OPEN: 'Open',
TOGGLE_HIDDEN_FILES_COMMAND_LABEL: 'Show hidden files',
VIDEO_FILE_TYPE: '$1 video',
WAITING_FOR_SPACE_INFO: 'Waiting for space info...',
language: 'en',
textdirection: 'ltr',
......@@ -84,8 +99,6 @@ loadTimeData.data = new Proxy(
/^SHORTCUT_/,
/_BUTTON_LABEL$/,
/_BUTTON_TOOLTIP$/,
/_COLUMN_LABEL$/,
/_FILE_TYPE$/,
];
for (var i = 0; i < autoConvert.length; i++) {
if (prop.match(autoConvert[i])) {
......
This diff is collapsed.
......@@ -11,11 +11,22 @@ as a regular webapp.
"""
import argparse
import os
import sys
assert __name__ == '__main__'
# If --output is provided, create specified empty file.
parser = argparse.ArgumentParser()
parser.add_argument('--output')
args = parser.parse_args()
if args.output:
with open(args.output, 'w') as output:
output.write('')
root = os.path.abspath(os.path.join(sys.path[0], '../..'))
scripts = []
GENERATED_HTML = ('<!-- Generated by:\n -- ui/file_manager/file_manager/'
......@@ -25,14 +36,16 @@ GENERATED_JS = ('// Generated by:\n// ui/file_manager/file_manager/'
def read(path):
return open(os.path.join(root, path)).read()
with open(os.path.join(root, path)) as f:
return f.read()
def write(path, content):
fullpath = os.path.join(root, path)
if not os.path.exists(os.path.dirname(fullpath)):
os.makedirs(os.path.dirname(fullpath))
open(fullpath, 'w').write(content)
with open(fullpath, 'w') as f:
f.write(content)
def insertbeforeline(f, match, lines):
......@@ -118,24 +131,26 @@ main_html = replaceline(
])
# Add scripts for testing.
scripts += [
'<script src="js/chrome_api_test_impl.js"></script>',
'<script src="../../../webui/resources/js/assert.js"></script>',
'<script src="../../../webui/resources/js/cr.js"></script>',
'<script src="../../../webui/resources/js/cr/event_target.js"></script>',
('<script src="../../../webui/resources/js/cr/ui/array_data_model.js">'
'</script>'),
'<script src="../../../webui/resources/js/load_time_data.js"></script>',
'<script src="js/strings.js"></script>',
'<script src="../common/js/util.js"></script>',
'<script src="../common/js/mock_entry.js"></script>',
'<script src="../common/js/volume_manager_common.js"></script>',
'<script src="../background/js/volume_info_impl.js"></script>',
'<script src="../background/js/volume_info_list_impl.js"></script>',
'<script src="../background/js/volume_manager_impl.js"></script>',
'<script src="../background/js/mock_volume_manager.js"></script>',
'<script src="js/chrome_file_manager.js"></script>',
]
scripts += ['<script src="%s"></script>' % s for s in (
'js/chrome_api_test_impl.js',
'../../../webui/resources/js/assert.js',
'../../../webui/resources/js/cr.js',
'../../../webui/resources/js/cr/event_target.js',
'../../../webui/resources/js/cr/ui/array_data_model.js">',
'../../../webui/resources/js/load_time_data.js',
'../../../webui/resources/js/webui_resource_test.js">',
'js/strings.js',
'../common/js/util.js',
'../common/js/mock_entry.js',
'../common/js/volume_manager_common.js',
'../background/js/volume_info_impl.js',
'../background/js/volume_info_list_impl.js',
'../background/js/volume_manager_impl.js',
'../background/js/mock_volume_manager.js',
'js/chrome_file_manager.js',
'js/test_util.js',
'delete.js',
)]
# Convert all includes from:
# * foreground/js/main_scripts.js
......@@ -158,5 +173,3 @@ main_html = replaceline(main_html, 'foreground/js/ui/banners.js',
['<script src="js/ui/banners.js"></script>'])
write('test/main.html', GENERATED_HTML + '\n'.join(main_html))
print 'done'
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