Commit 74817954 authored by Joel Hockey's avatar Joel Hockey Committed by Commit Bot

FilesApp UI Tests allow multiple tests from gen dir

* Run from gen/ui/file_manager/file_manager/test.html when testing
  on the bots rather than src.  The change here is for the
  create_test_main.py script to use correct relative paths from
  gen dir for resources that are loaded.
* Group tests into multiple scopes to be run separately.

Bug: 813477
Cq-Include-Trybots: master.tryserver.chromium.linux:closure_compilation
Change-Id: Ia9a354ea6cf7a6f765fb0cdf73d7041a8286e1ec
Reviewed-on: https://chromium-review.googlesource.com/1092212Reviewed-by: default avatarAlexey Baskakov <loyso@chromium.org>
Commit-Queue: Joel Hockey <joelhockey@chromium.org>
Cr-Commit-Position: refs/heads/master@{#566356}
parent ab40ae54
......@@ -23,13 +23,13 @@ class FileManagerUITest : public InProcessBrowserTest {
command_line->AppendSwitch(switches::kDisableWebSecurity);
}
void RunTest() {
void RunTest(std::string test_scope) {
base::FilePath root_path;
ASSERT_TRUE(base::PathService::Get(base::DIR_SOURCE_ROOT, &root_path));
ASSERT_TRUE(base::PathService::Get(base::DIR_MODULE, &root_path));
// Load test.html.
const GURL url = net::FilePathToFileURL(root_path.Append(
FILE_PATH_LITERAL("ui/file_manager/file_manager/test.html")));
FILE_PATH_LITERAL("gen/ui/file_manager/file_manager/test.html")));
content::WebContents* const web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
......@@ -44,7 +44,8 @@ class FileManagerUITest : public InProcessBrowserTest {
// Load and run specified test file.
content::DOMMessageQueue message_queue;
ExecuteScriptAsync(web_contents, "runTests()");
ExecuteScriptAsync(web_contents,
base::StringPrintf("runTests(%s)", test_scope.c_str()));
// Wait for JS to call domAutomationController.send("SUCCESS").
std::string message;
......@@ -56,8 +57,16 @@ class FileManagerUITest : public InProcessBrowserTest {
}
};
IN_PROC_BROWSER_TEST_F(FileManagerUITest, UI) {
RunTest();
IN_PROC_BROWSER_TEST_F(FileManagerUITest, CheckSelect) {
RunTest("checkselect");
}
IN_PROC_BROWSER_TEST_F(FileManagerUITest, Crostini) {
RunTest("crostini");
}
IN_PROC_BROWSER_TEST_F(FileManagerUITest, UMA) {
RunTest("uma");
}
} // namespace file_manager
......@@ -410,6 +410,7 @@ test("browser_tests") {
"//ui/file_manager/integration_tests/",
"//third_party/analytics/",
"//third_party/polymer/v1_0/components-chromium/polymer/",
"$root_gen_dir/ui/file_manager/file_manager/",
"$root_gen_dir/ui/login/login_resources.pak",
"$root_out_dir/chromevox_test_data/",
"$root_out_dir/content_shell.pak",
......
......@@ -5,9 +5,17 @@
action("create_test_main") {
script = "//ui/file_manager/file_manager/test/scripts/create_test_main.py"
output = "$target_gen_dir/../test.html"
deps = ["//ui/file_manager:resources"]
deps = [
"//ui/file_manager:resources",
]
args = [ "--output=" + rebase_path(output, root_build_dir) ]
outputs = [
output,
"$target_gen_dir/gen/css/text_defaults.css",
"$target_gen_dir/gen/elements/elements_bundle.html",
"$target_gen_dir/gen/elements/files_quick_view.html",
"$target_gen_dir/gen/elements/files_safe_media.html",
"$target_gen_dir/gen/elements/files_safe_media.js",
"$target_gen_dir/gen/js/elements_importer.js",
]
}
......@@ -3,26 +3,22 @@ This is a testing system and development tool for CrOS FileManager.
Contact joelhockey@ or sashab@ before adding any dependencies or new tests.
Usage:
1/ Run ./scripts/create_test_main.py
This can be done via cmdline, or by building browser_tests target for chromeos.
This script generates file ui/file_manager/file_manager/test.html
and other related files under ./gen dir.
1/ Build browser_tests target for target_os chromeos.
This script generates file <out>/gen/ui/file_manager/file_manager/test.html
ui/file_manager/file_manager/test/scripts/create_test_main.py
2/ Load ui/file_manager/file_manager/test.html in browser.
2/ Load <out>/gen/ui/file_manager/file_manager/test.html in browser.
Note, the --disable-web-security flag is required in order to load
chrome://resources URLs. Using this flag also requires --user-data-dir flag.
/opt/google/chrome-unstable/chrome \
--user-data-dir=/tmp/chrome-user-data-dir \
--disable-web-security \
ui/file_manager/file_manager/test.html
out/Release/gen/ui/file_manager/file_manager/test.html
3/ Open devtools and explore. Some helpful JS functions to run:
test.setupAndWaitUntilReady() // generates some test files
runTests() // executes all test cases
runTests(<test-scope>) // executes test cases in the given scope
Tests reside in this directory.
Supporting files are in subdirs.
......@@ -2,7 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
function testCancelCheckSelectModeAfterAction(done) {
const checkselect = {};
checkselect.testCancelCheckSelectModeAfterAction = (done) => {
test.setupAndWaitUntilReady()
.then(() => {
// Click 2nd last file on checkmark to start check-select-mode.
......@@ -45,4 +47,4 @@ function testCancelCheckSelectModeAfterAction(done) {
1, document.querySelectorAll('#file-list li[selected]').length);
done();
});
}
};
......@@ -2,7 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
function testCrostiniNotEnabled(done) {
const crostini = {};
crostini.testCrostiniNotEnabled = (done) => {
chrome.fileManagerPrivate.crostiniEnabled_ = false;
fileManager.setupCrostini_();
test.setupAndWaitUntilReady()
......@@ -13,9 +15,9 @@ function testCrostiniNotEnabled(done) {
.then(() => {
done();
});
}
};
function testCrostiniSuccess(done) {
crostini.testCrostiniSuccess = (done) => {
chrome.fileManagerPrivate.crostiniEnabled_ = true;
var oldMount = chrome.fileManagerPrivate.mountCrostiniContainer;
var mountCallback = null;
......@@ -71,9 +73,9 @@ function testCrostiniSuccess(done) {
.then(() => {
done();
});
}
};
function testCrostiniError(done) {
crostini.testCrostiniError = (done) => {
chrome.fileManagerPrivate.crostiniEnabled_ = true;
var oldMount = chrome.fileManagerPrivate.mountCrostiniContainer;
// Override fileManagerPrivate.mountCrostiniContainer to return error.
......@@ -104,4 +106,4 @@ function testCrostiniError(done) {
chrome.fileManagerPrivate.mountCrostiniContainer = oldMount;
done();
});
}
};
......@@ -33,7 +33,9 @@ test.loadData = function() {
resolve();
};
req.open(
'GET', '../../../chrome/test/data/chromeos/file_manager/' + filename);
'GET',
FILE_MANAGER_ROOT +
'../../../chrome/test/data/chromeos/file_manager/' + filename);
req.send();
});
}));
......
......@@ -14,6 +14,7 @@ as a regular web page in a single renderer.
import argparse
import os
import sys
import time
assert __name__ == '__main__'
......@@ -22,22 +23,28 @@ parser = argparse.ArgumentParser()
parser.add_argument('--output')
args = parser.parse_args()
# ROOT=//ui/file_manager/file_manager
ROOT = os.path.abspath(os.path.join(sys.path[0], '../..'))
# If --output is not provided, write to local test.html.
output = args.output or os.path.abspath(
os.path.join(sys.path[0], '../../test.html'))
# ROOT_SRC: Absolute path to src //ui/file_manager/file_manager.
# ROOT_GEN: Absolute path to $target_gen_dir of ROOT_SRC.
# ROOT : Relative path from ROOT_GEN to ROOT_SRC.
ROOT_SRC = os.path.abspath(os.path.join(sys.path[0], '../..'))
ROOT_GEN = os.path.dirname(os.path.abspath(output))
ROOT = os.path.relpath(ROOT_SRC, ROOT_GEN) + '/'
scripts = []
GENERATED_HTML = ('<!-- Generated by:\n -- ui/file_manager/file_manager/'
'tests/scripts/create_test_main.py\n -->\n\n')
GENERATED_JS = ('// Generated by:\n// ui/file_manager/file_manager/'
'tests/scripts/create_test_main.py\n\n')
GENERATED = 'Generated at %s by: %s' % (time.ctime(), sys.path[0])
GENERATED_HTML = '<!-- %s -->\n\n' % GENERATED
def read(path):
with open(os.path.join(ROOT, path)) as f:
with open(os.path.join(ROOT_SRC, path)) as f:
return f.read()
def write(path, content):
fullpath = os.path.join(ROOT, path)
fullpath = os.path.join(ROOT_GEN, path)
if not os.path.exists(os.path.dirname(fullpath)):
os.makedirs(os.path.dirname(fullpath))
with open(fullpath, 'w') as f:
......@@ -55,7 +62,7 @@ def replaceline(f, match, lines):
def includes2scripts(include_filename):
"""Convert <include src='foo'> to <script src='<prefix>foo'></script>."""
scripts.append('<!-- %s -->' % include_filename)
prefix = include_filename[:include_filename.rindex('/')+1]
prefix = ROOT + include_filename[:include_filename.rindex('/')+1]
f = read(include_filename).split('\n')
for i in range(len(f)):
l = f[i]
......@@ -74,19 +81,27 @@ def includes2scripts(include_filename):
l = l.replace('src="main.js"', 'src="main.js" defer')
# Fix the path for scripts to be relative to ROOT.
if 'src="../../' in l:
l = l.replace('src="../../', 'src="')
l = l.replace('src="../../', 'src="' + ROOT)
else:
l = l.replace('src="', 'src="' + prefix)
tag = l + '</script>'
if tag not in scripts:
scripts.append(tag)
# Update relative paths.
# Fix link to action_link.css and text_defaults.css.
# Fix stylesheet from extension.
main_html = (read('main.html')
.replace('chrome://resources/css/action_link.css',
'../../webui/resources/css/action_link.css')
.replace('chrome://resources/css/text_defaults.css',
.replace('href="', 'href="' + ROOT)
.replace('src="', 'src="' + ROOT)
.replace(ROOT + 'chrome://resources/css/text_defaults.css',
'test/gen/css/text_defaults.css')
.replace(('chrome-extension://fbjakikfhfdajcamjleinfciajelkpek/'
'cws_widget/cws_widget_container.css'),
('../../../components/chrome_apps/'
'webstore_widget/cws_widget/cws_widget_container.css">'))
.split('\n'))
# Fix text_defaults.css. Copy and replace placeholders.
......@@ -94,19 +109,11 @@ text_defaults = (read('../../webui/resources/css/text_defaults.css')
.replace('$i18n{textDirection}', 'ltr')
.replace('$i18nRaw{fontFamily}', 'Roboto, sans-serif')
.replace('$i18nRaw{fontSize}', '75%'))
write('test/gen/css/text_defaults.css', GENERATED_HTML + text_defaults)
# Fix stylesheet from extension.
main_html = replaceline(
main_html,
('chrome-extension://fbjakikfhfdajcamjleinfciajelkpek/'
'cws_widget/cws_widget_container.css'),
[('<link rel="stylesheet" href="../../../components/chrome_apps/'
'webstore_widget/cws_widget/cws_widget_container.css">')])
write('test/gen/css/text_defaults.css', text_defaults)
# Add scripts required for testing, and the test files (test/*.js).
scripts.append('<!-- required for testing -->')
scripts += ['<script src="%s"></script>' % s for s in [
scripts += ['<script src="%s%s"></script>' % (ROOT, s) for s in [
'test/js/chrome_api_test_impl.js',
'../../webui/resources/js/assert.js',
'../../webui/resources/js/cr.js',
......@@ -125,7 +132,7 @@ scripts += ['<script src="%s"></script>' % s for s in [
'foreground/js/constants.js',
'test/js/chrome_file_manager.js',
'test/js/test_util.js',
] + ['test/' + s for s in os.listdir(os.path.join(ROOT, 'test'))
] + ['test/' + s for s in os.listdir(os.path.join(ROOT_SRC, 'test'))
if s.endswith('.js')]]
# Convert all includes from:
......@@ -134,28 +141,44 @@ scripts += ['<script src="%s"></script>' % s for s in [
# * background/js/background_scripts.js
# into <script> tags in main.html.
# Add polymer libs at start.
# Define FILE_MANAGER_ROOT which is required to locate test data files.
bg_scripts = read('background/js/background_scripts.js').split('\n')
includes2scripts('foreground/js/main_scripts.js')
includes2scripts('background/js/background_common_scripts.js')
includes2scripts('background/js/background_scripts.js')
main_html = replaceline(main_html, 'foreground/js/main_scripts.js', [
('<link rel="import" href="../../../third_party/polymer/v1_0/'
'components-chromium/polymer/polymer.html">'),
('<link rel="import" href="../../../third_party/polymer/v1_0/'
'components-chromium/paper-progress/paper-progress.html">'),
('<link rel="import" href="%s../../../third_party/polymer/v1_0/'
'components-chromium/polymer/polymer.html">' % ROOT),
('<link rel="import" href="%s../../../third_party/polymer/v1_0/'
'components-chromium/paper-progress/paper-progress.html">' % ROOT),
"<script>var FILE_MANAGER_ROOT = '%s';</script>" % ROOT,
] + scripts)
def elements_path(elements_filename):
return '="../../../%sforeground/elements/%s' % (ROOT, elements_filename)
# Fix relative file paths in elements_bundle.html
# Load QuickView in iframe rather than webview.
# Change references in files_quick_view.html to use updated
# files_safe_media.html which will use webview rather than iframe,
# and sets src directly on iframe.
for filename, substitutions in (
('elements/elements_bundle.html', (
('="files_ripple', elements_path('files_ripple')),
('="files_toggle_ripple', elements_path('files_toggle_ripple')),
('="files_tooltip', elements_path('files_tooltip')),
('="icons', elements_path('icons')),
)),
('js/elements_importer.js', (
("= 'foreground", "= 'test/gen"),
)),
('elements/files_quick_view.html', (
('="files_icon', '="../../../foreground/elements/files_icon'),
('="files_metadata', '="../../../foreground/elements/files_metadata'),
('="files_tooltip', '="../../../foreground/elements/files_tooltip'),
('="files_quick', '="../../../foreground/elements/files_quick'),
('="icons', '="../../../foreground/elements/icons'),
('="files_icon', elements_path('files_icon')),
('="files_metadata', elements_path('files_metadata')),
('="files_tooltip', elements_path('files_tooltip')),
('="files_quick', elements_path('files_quick')),
('="icons', elements_path('icons')),
('webview', 'iframe'),
)),
('elements/files_safe_media.html', (('webview', 'iframe'),)),
......@@ -170,14 +193,9 @@ for filename, substitutions in (
buf = read('foreground/' + filename)
for old, new in substitutions:
buf = buf.replace(old, new)
write('test/gen/' + filename, GENERATED_JS + buf)
write('test/gen/' + filename, buf)
main_html = replaceline(main_html, 'foreground/' + filename,
['<script src="test/gen/%s"></script>' % filename])
test_html = GENERATED_HTML + '\n'.join(main_html)
write('test.html', test_html)
# If --output is provided, also create specified file.
if args.output:
with open(args.output, 'w') as output:
output.write(test_html)
......@@ -2,7 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
function testClickBreadcrumb(done) {
const uma = {};
uma.testClickBreadcrumb = (done) => {
test.setupAndWaitUntilReady()
.then(() => {
// Reset metrics.
......@@ -25,4 +27,4 @@ function testClickBreadcrumb(done) {
chrome.metricsPrivate.userActions_);
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