Commit 041865f6 authored by Joel Hockey's avatar Joel Hockey Committed by Commit Bot

CrOS FilesApp move test/main.html to test.html

Change to use test.html rather than test/main.html.  Having the
file in the regular dir makes it much better for many files
that load other resources assuming that relative paths of
'foreground/foo/bar' will be valid.  This has simplified the
create_test_main.py script.

Bug: 813477
Cq-Include-Trybots: master.tryserver.chromium.linux:closure_compilation
Change-Id: I388b3a914fde3cc99b76503251cbf6ffdd659e81
Reviewed-on: https://chromium-review.googlesource.com/972222Reviewed-by: default avatarNaoki Fukino <fukino@chromium.org>
Commit-Queue: Joel Hockey <joelhockey@chromium.org>
Cr-Commit-Position: refs/heads/master@{#545029}
parent b62383e3
...@@ -25,9 +25,9 @@ class FileManagerUITest : public InProcessBrowserTest { ...@@ -25,9 +25,9 @@ class FileManagerUITest : public InProcessBrowserTest {
base::FilePath root_path; base::FilePath root_path;
ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &root_path)); ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &root_path));
// Load test/main.html. // Load test.html.
const GURL url = net::FilePathToFileURL(root_path.Append( const GURL url = net::FilePathToFileURL(root_path.Append(
FILE_PATH_LITERAL("ui/file_manager/file_manager/test/main.html"))); FILE_PATH_LITERAL("ui/file_manager/file_manager/test.html")));
content::WebContents* const web_contents = content::WebContents* const web_contents =
browser()->tab_strip_model()->GetActiveWebContents(); browser()->tab_strip_model()->GetActiveWebContents();
ASSERT_TRUE(web_contents); ASSERT_TRUE(web_contents);
......
css/
js/elements_importer.js
js/ui/
main.html
...@@ -27,8 +27,7 @@ function loadData() { ...@@ -27,8 +27,7 @@ function loadData() {
resolve(); resolve();
}; };
req.open( req.open(
'GET', 'GET', '../../../chrome/test/data/chromeos/file_manager/' + filename);
'../../../../chrome/test/data/chromeos/file_manager/' + filename);
req.send(); req.send();
}); });
})); }));
......
...@@ -4,10 +4,10 @@ ...@@ -4,10 +4,10 @@
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
"""Copies file_manager/main.html to file_manager/test/main.html. """Copies file_manager/main.html to file_manager/test.html.
Modifies it to be able to run the CrOS FileManager app Modifies it to be able to run the CrOS FileManager app
as a regular webapp. as a regular web page in a single renderer.
""" """
...@@ -27,7 +27,8 @@ if args.output: ...@@ -27,7 +27,8 @@ if args.output:
output.write('') output.write('')
root = os.path.abspath(os.path.join(sys.path[0], '../..')) # ROOT=//ui/file_manager/file_manager
ROOT = os.path.abspath(os.path.join(sys.path[0], '../..'))
scripts = [] scripts = []
GENERATED_HTML = ('<!-- Generated by:\n -- ui/file_manager/file_manager/' GENERATED_HTML = ('<!-- Generated by:\n -- ui/file_manager/file_manager/'
'tests/scripts/create_test_main.py\n -->\n\n') 'tests/scripts/create_test_main.py\n -->\n\n')
...@@ -36,26 +37,18 @@ GENERATED_JS = ('// Generated by:\n// ui/file_manager/file_manager/' ...@@ -36,26 +37,18 @@ GENERATED_JS = ('// Generated by:\n// ui/file_manager/file_manager/'
def read(path): def read(path):
with open(os.path.join(root, path)) as f: with open(os.path.join(ROOT, path)) as f:
return f.read() return f.read()
def write(path, content): def write(path, content):
fullpath = os.path.join(root, path) fullpath = os.path.join(ROOT, path)
if not os.path.exists(os.path.dirname(fullpath)): if not os.path.exists(os.path.dirname(fullpath)):
os.makedirs(os.path.dirname(fullpath)) os.makedirs(os.path.dirname(fullpath))
with open(fullpath, 'w') as f: with open(fullpath, 'w') as f:
f.write(content) f.write(content)
def insertbeforeline(f, match, lines):
"""Insert lines into file before matching line."""
for i in range(len(f)):
if match in f[i]:
return f[:i] + lines + f[i:]
return f
def replaceline(f, match, lines): def replaceline(f, match, lines):
"""Replace matching line in file with lines.""" """Replace matching line in file with lines."""
for i in range(len(f)): for i in range(len(f)):
...@@ -64,13 +57,16 @@ def replaceline(f, match, lines): ...@@ -64,13 +57,16 @@ def replaceline(f, match, lines):
return f return f
def includes2scripts(f, prefix): def includes2scripts(include_filename):
"""Convert <include src='foo'> to <script src='<prefix>foo'></script>.""" """Convert <include src='foo'> to <script src='<prefix>foo'></script>."""
scripts.append('<!-- %s -->' % include_filename)
prefix = include_filename[:include_filename.rindex('/')+1]
f = read(include_filename).split('\n')
for i in range(len(f)): for i in range(len(f)):
l = f[i] l = f[i]
# Join back any include with a line-break. # Join back any include with a line-break.
if l == '// <include' and main_scripts[i+1].startswith('// src='): if l == '// <include' and f[i+1].startswith('// src='):
main_scripts[i+1] = l + main_scripts[i+1][2:] f[i+1] = l + f[i+1][2:]
continue continue
if l.startswith('// <include '): if l.startswith('// <include '):
l = l.replace('// <include ', '<script ') l = l.replace('// <include ', '<script ')
...@@ -81,95 +77,74 @@ def includes2scripts(f, prefix): ...@@ -81,95 +77,74 @@ def includes2scripts(f, prefix):
# main.js should be defer. # main.js should be defer.
if 'src="main.js"' in l: if 'src="main.js"' in l:
l = l.replace('src="main.js"', 'src="main.js" defer') l = l.replace('src="main.js"', 'src="main.js" defer')
# Fix the path for scripts to be relative to file_manager/test/main.html. # Fix the path for scripts to be relative to ROOT.
if 'src="../../' in l: if 'src="../../' in l:
l = l.replace('src="../../', 'src="../') l = l.replace('src="../../', 'src="')
else: else:
l = l.replace('src="', 'src="../' + prefix) l = l.replace('src="', 'src="' + prefix)
tag = l + '</script>' tag = l + '</script>'
if tag not in scripts: if tag not in scripts:
scripts.append(tag) scripts.append(tag)
# Add / fix js libs in main.html.
# Change src="foreground/..." to src="../foreground/...".
# Fix link to action_link.css and text_defaults.css. # Fix link to action_link.css and text_defaults.css.
main_html = (read('main.html') main_html = (read('main.html')
.replace('="foreground/', '="../foreground/')
.replace('chrome://resources/css/action_link.css', .replace('chrome://resources/css/action_link.css',
'../../../webui/resources/css/action_link.css') '../../webui/resources/css/action_link.css')
.replace('chrome://resources/css/text_defaults.css', .replace('chrome://resources/css/text_defaults.css',
'css/text_defaults.css') 'test/gen/css/text_defaults.css')
.split('\n')) .split('\n'))
# Fix text_defaults.css. Copy and replace placeholders. # Fix text_defaults.css. Copy and replace placeholders.
text_defaults = (read('../../webui/resources/css/text_defaults.css') text_defaults = (read('../../webui/resources/css/text_defaults.css')
.replace('$i18n{textDirection}', 'ltr') .replace('$i18n{textDirection}', 'ltr')
.replace('$i18nRaw{fontFamily}', 'Roboto, sans-serif') .replace('$i18nRaw{fontFamily}', 'Roboto, sans-serif')
.replace('$i18nRaw{fontSize}', '75%')) .replace('$i18nRaw{fontSize}', '75%'))
write('test/css/text_defaults.css', GENERATED_HTML + text_defaults) write('test/gen/css/text_defaults.css', GENERATED_HTML + text_defaults)
# Fix stylesheet from extension. # Fix stylesheet from extension.
main_html = replaceline( main_html = replaceline(
main_html, main_html,
('chrome-extension://fbjakikfhfdajcamjleinfciajelkpek/' ('chrome-extension://fbjakikfhfdajcamjleinfciajelkpek/'
'cws_widget/cws_widget_container.css'), 'cws_widget/cws_widget_container.css'),
[('<link rel="stylesheet" href="../../../../components/chrome_apps/' [('<link rel="stylesheet" href="../../../components/chrome_apps/'
'webstore_widget/cws_widget/cws_widget_container.css">')]) 'webstore_widget/cws_widget/cws_widget_container.css">')])
# Replace elements_importer.js to use updated path, add polymer js. # Add scripts required for testing, and the test files (test/*.js).
elements_importer = read('foreground/js/elements_importer.js').replace( scripts.append('<!-- required for testing -->')
"'foreground/", "'../foreground/") scripts += ['<script src="%s"></script>' % s for s in [
write('test/js/elements_importer.js', GENERATED_JS + elements_importer) 'test/js/chrome_api_test_impl.js',
main_html = replaceline( '../../webui/resources/js/assert.js',
main_html, '../../webui/resources/js/cr.js',
'foreground/js/elements_importer.js', '../../webui/resources/js/cr/event_target.js',
[ '../../webui/resources/js/cr/ui/array_data_model.js">',
'<script src="js/elements_importer.js"></script>', '../../webui/resources/js/load_time_data.js',
('<link rel="import" href="../../../../third_party/polymer/v1_0/' '../../webui/resources/js/webui_resource_test.js">',
'components-chromium/polymer/polymer.html">'), 'test/js/strings.js',
]) 'common/js/util.js',
'common/js/mock_entry.js',
# Add scripts for testing. 'common/js/volume_manager_common.js',
scripts += ['<script src="%s"></script>' % s for s in ( 'background/js/volume_info_impl.js',
'js/chrome_api_test_impl.js', 'background/js/volume_info_list_impl.js',
'../../../webui/resources/js/assert.js', 'background/js/volume_manager_impl.js',
'../../../webui/resources/js/cr.js', 'background/js/mock_volume_manager.js',
'../../../webui/resources/js/cr/event_target.js', 'foreground/js/constants.js',
'../../../webui/resources/js/cr/ui/array_data_model.js">', 'test/js/chrome_file_manager.js',
'../../../webui/resources/js/load_time_data.js', 'test/js/test_util.js',
'../../../webui/resources/js/webui_resource_test.js">', ] + ['test/' + s for s in os.listdir(os.path.join(ROOT, 'test'))
'js/strings.js', if s.endswith('.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: # Convert all includes from:
# * foreground/js/main_scripts.js # * foreground/js/main_scripts.js
# * background/js/background_common_scripts.js # * background/js/background_common_scripts.js
# * background/js/background_scripts.js # * background/js/background_scripts.js
# into <script> tags in main.html. # into <script> tags in main.html.
main_scripts = read('foreground/js/main_scripts.js').split('\n') # Add polymer lib at start.
bg_common_scripts = read(
'background/js/background_common_scripts.js').split('\n')
bg_scripts = read('background/js/background_scripts.js').split('\n') bg_scripts = read('background/js/background_scripts.js').split('\n')
includes2scripts(main_scripts, 'foreground/js/') includes2scripts('foreground/js/main_scripts.js')
includes2scripts(bg_common_scripts + bg_scripts, 'background/js/') includes2scripts('background/js/background_common_scripts.js')
main_html = replaceline(main_html, 'foreground/js/main_scripts.js', scripts) includes2scripts('background/js/background_scripts.js')
main_html = replaceline(main_html, 'foreground/js/main_scripts.js', [
# Replace banners.js to use updated path. ('<link rel="import" href="../../../third_party/polymer/v1_0/'
banners = (read('foreground/js/ui/banners.js') 'components-chromium/polymer/polymer.html">')] + scripts)
.replace("'foreground/", "'../foreground/"))
write('test/js/ui/banners.js', GENERATED_JS + banners) write('test.html', GENERATED_HTML + '\n'.join(main_html))
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))
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