Commit 61d8ad80 authored by Luciano Pacheco's avatar Luciano Pacheco Committed by Commit Bot

Gallery & Image editor, Audio & Video players: Move unittest to chrome://

Move apps in //ui/file_manager/ to use chrome:// URL in unittest.

After moving these apps, js_unit_tests build template and script aren't
needed anymore, thus removing it.

This is a follow up of CL:1767297.

Bug: 991105
Change-Id: I51553b7dda063b35e8f957838e96f7599cd6df17
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1775854
Commit-Queue: calamity <calamity@chromium.org>
Auto-Submit: Luciano Pacheco <lucmult@chromium.org>
Reviewed-by: default avatarTrent Apted <tapted@chromium.org>
Reviewed-by: default avatarcalamity <calamity@chromium.org>
Cr-Commit-Position: refs/heads/master@{#693041}
parent 4f3ffefb
......@@ -12,5 +12,5 @@ class FileManagerBaseJsTest : public FileManagerJsTestBase {
};
IN_PROC_BROWSER_TEST_F(FileManagerBaseJsTest, VolumeManagerTypesTest) {
RunGeneratedTest("/volume_manager_types_unittest.html");
RunTestURL("volume_manager_types_unittest_gen.html");
}
......@@ -12,7 +12,7 @@ class GalleryJsTest : public FileManagerJsTestBase {
};
IN_PROC_BROWSER_TEST_F(GalleryJsTest, ImageEncoderTest) {
RunGeneratedTest("/image_editor/image_encoder_unittest.html");
RunTestURL("image_editor/image_encoder_unittest_gen.html");
}
// Disabled on ASan builds due to a consistent failure. https://crbug.com/762831
......@@ -22,37 +22,37 @@ IN_PROC_BROWSER_TEST_F(GalleryJsTest, ImageEncoderTest) {
#define MAYBE_ExifEncoderTest ExifEncoderTest
#endif
IN_PROC_BROWSER_TEST_F(GalleryJsTest, MAYBE_ExifEncoderTest) {
RunGeneratedTest("/image_editor/exif_encoder_unittest.html");
RunTestURL("image_editor/exif_encoder_unittest_gen.html");
}
IN_PROC_BROWSER_TEST_F(GalleryJsTest, ImageViewTest) {
RunGeneratedTest("/image_editor/image_view_unittest.html");
RunTestURL("image_editor/image_view_unittest_gen.html");
}
IN_PROC_BROWSER_TEST_F(GalleryJsTest, EntryListWatcherTest) {
RunGeneratedTest("/entry_list_watcher_unittest.html");
RunTestURL("entry_list_watcher_unittest_gen.html");
}
IN_PROC_BROWSER_TEST_F(GalleryJsTest, GalleryUtilTest) {
RunGeneratedTest("/gallery_util_unittest.html");
RunTestURL("gallery_util_unittest_gen.html");
}
IN_PROC_BROWSER_TEST_F(GalleryJsTest, GalleryItemTest) {
RunGeneratedTest("/gallery_item_unittest.html");
RunTestURL("gallery_item_unittest_gen.html");
}
IN_PROC_BROWSER_TEST_F(GalleryJsTest, GalleryDataModelTest) {
RunGeneratedTest("/gallery_data_model_unittest.html");
RunTestURL("gallery_data_model_unittest_gen.html");
}
IN_PROC_BROWSER_TEST_F(GalleryJsTest, RibbonTest) {
RunGeneratedTest("/ribbon_unittest.html");
RunTestURL("ribbon_unittest_gen.html");
}
IN_PROC_BROWSER_TEST_F(GalleryJsTest, SlideModeTest) {
RunGeneratedTest("/slide_mode_unittest.html");
RunTestURL("slide_mode_unittest_gen.html");
}
IN_PROC_BROWSER_TEST_F(GalleryJsTest, DimmableUIControllerTest) {
RunGeneratedTest("/dimmable_ui_controller_unittest.html");
RunTestURL("dimmable_ui_controller_unittest_gen.html");
}
......@@ -11,17 +11,17 @@ class ImageLoaderJsTest : public FileManagerJsTestBase {
};
IN_PROC_BROWSER_TEST_F(ImageLoaderJsTest, ImageLoaderClientTest) {
RunGeneratedTest("/image_loader_client_unittest.html");
RunTestURL("image_loader_client_unittest_gen.html");
}
IN_PROC_BROWSER_TEST_F(ImageLoaderJsTest, CacheTest) {
RunGeneratedTest("/cache_unittest.html");
RunTestURL("cache_unittest_gen.html");
}
IN_PROC_BROWSER_TEST_F(ImageLoaderJsTest, ImageLoaderTest) {
RunGeneratedTest("/image_loader_unittest.html");
RunTestURL("image_loader_unittest_gen.html");
}
IN_PROC_BROWSER_TEST_F(ImageLoaderJsTest, PiexLoaderTest) {
RunGeneratedTest("/piex_loader_unittest.html");
RunTestURL("piex_loader_unittest_gen.html");
}
......@@ -12,5 +12,5 @@ class VideoPlayerJsTest : public FileManagerJsTestBase {
};
IN_PROC_BROWSER_TEST_F(VideoPlayerJsTest, SaveResumePlaybackTest) {
RunGeneratedTest("/video_player_native_controls_unittest.html");
RunTestURL("video_player_native_controls_unittest_gen.html");
}
# Copyright 2018 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.
"""
This script takes in a file created by js_library.py and any supplementary js
files to build an html file used for js unit tests.
"""
from argparse import ArgumentParser
from js_binary import CrawlDepsTree
def Flatten(deps):
"""
Recursively follows a list of dep files and returns source files in
dependency order. Ignores externs.
"""
sources, externs = CrawlDepsTree(deps)
return sources
def main():
parser = ArgumentParser()
parser.add_argument('-i', '--input',
help='Input dependency file generated by js_library.py')
parser.add_argument('-m', '--mocks', nargs='*', default=[],
help='List of additional js files to load before others')
parser.add_argument('-o', '--output',
help='Generated html output with flattened dependencies')
parser.add_argument('-I', '--include_prefix', default='',
help='Prefix added to src= paths to find .js files')
args = parser.parse_args()
uniquedeps = Flatten([args.input])
with open(args.output, 'w') as out:
out.write('<!DOCTYPE html>\n<html>\n<body>\n')
out.write(
"""
<script>
// Basic include checker.
window.addEventListener('error', function(e) {
if ((e.target instanceof HTMLScriptElement)) {
console.log('ERROR loading <script> element (does it exist?):\\n\\t' +
e.srcElement.src + '\\n\\tIncluded from: ' +
e.srcElement.baseURI);
}
}, true /* useCapture */);
</script>
""")
for file in args.mocks:
out.write('<script src="%s%s"></script>\n' % (args.include_prefix, file))
for file in uniquedeps:
out.write('<script src="%s%s"></script>\n' % (args.include_prefix, file))
out.write('</body>\n</html>\n')
if __name__ == '__main__':
main()
......@@ -4,103 +4,6 @@
import("//third_party/closure_compiler/compile_js.gni")
# Describes a list of js_library targets that will each have an html file
# written listing all its (flattened) js dependencies, for loading as a test.
#
# A companion group target with a "_type_check" suffix is also generated with
# this template. This depends on a list of js_type_check(..) targets -- one for
# each test -- that will type check the test js file and its dependency subtree.
#
# Must be declared after the js_library targets it depends on.
#
# Note js_type_check(..) is a no-op unless `closure_compile` is set in gn args.
#
# Variables:
# deps:
# List of js_library targets to depend on
#
# mocks:
# An optional list of .js files to load before any other scripts
#
# Example:
# js_unit_tests("folder_tests") {
# deps = [
# ":foo_unittest",
# ":bar_unittest",
# ":baz_unittest",
# ]
# mocks = [ "my_mocks.js" ]
# }
# group("closure_compile") {
# # ...
# ":folder_tests_type_check".
# }
# test("browser_tests") {
# # ...
# data_deps += [ "//folder:folder_tests" ]
# }
template("js_unit_tests") {
html_gen_target_name = target_name + "_html_gen"
action_foreach(html_gen_target_name) {
script_path = "//third_party/closure_compiler"
script = "$script_path/js_unit_test.py"
forward_variables_from(invoker,
[
"deps",
"mocks",
])
testonly = true
sources = []
foreach(dep, deps) {
sources += get_target_outputs(dep)
}
outputs = [
"$target_gen_dir/{{source_name_part}}.html",
]
args = [ "--output" ] + rebase_path(outputs, root_build_dir)
args += [ "--input" ] + [ "{{source}}" ]
# js_unit_test.py needs to walk .js_library dependency files relative to the
# gen_dir, but we'd like to reference the corresponding .js source files
# in the source dir, not the gen dir. Pass a prefix to remap --input args.
args += [
"--include_prefix",
rebase_path("//", "{{root_gen_dir}}", "//"),
]
if (defined(mocks)) {
args += [ "--mocks" ] + rebase_path(mocks, root_build_dir)
data = mocks
}
}
type_check_deps = []
foreach(dep, invoker.deps) {
type_check_target_name = target_name + "_" + dep + "_type_check"
type_check_deps += [ ":$type_check_target_name" ]
js_type_check(type_check_target_name) {
testonly = true
forward_variables_from(invoker, [ "closure_flags" ])
deps = [
dep,
]
}
}
type_check_group_name = target_name + "_type_check"
group(type_check_group_name) {
testonly = true
deps = type_check_deps
}
group(target_name) {
data = get_target_outputs(":$html_gen_target_name")
testonly = true
deps = [
":$html_gen_target_name",
]
}
}
# Simple wrapper around js_library to describe a unit test.
template("js_unittest") {
js_library(target_name) {
......
......@@ -56,16 +56,16 @@ group("closure_compile") {
group("unit_test_data") {
testonly = true
deps = [
"base/js:unit_tests",
"base/js:js_test_gen_html",
"file_manager/background/js:js_test_gen_html",
"file_manager/common/js:js_test_gen_html",
"file_manager/foreground/elements:js_test_gen_html",
"file_manager/foreground/js:js_test_gen_html",
"file_manager/foreground/js/metadata:js_test_gen_html",
"file_manager/foreground/js/ui:js_test_gen_html",
"gallery/js:unit_tests",
"gallery/js/image_editor:unit_tests",
"image_loader:unit_tests",
"video_player/js:unit_tests",
"gallery/js:js_test_gen_html",
"gallery/js/image_editor:js_test_gen_html",
"image_loader:js_test_gen_html",
"video_player/js:js_test_gen_html",
]
}
......@@ -136,9 +136,9 @@ def main():
# Append closure path to sys.path to be able to import js_unit_test.
sys.path.append(os.path.join(args.src_path, 'third_party/closure_compiler'))
from js_unit_test import Flatten
from js_binary import CrawlDepsTree
deps = Flatten([args.input])
deps, _ = CrawlDepsTree([args.input])
return _process(deps, args.output, args.mocks, args.html_import,
args.target_name)
......
......@@ -4,6 +4,7 @@
import("//third_party/closure_compiler/compile_js.gni")
import("//third_party/closure_compiler/js_unit_tests.gni")
import("//ui/file_manager/base/gn/js_test_gen_html.gni")
visibility = [ "//ui/file_manager/*" ]
......@@ -11,6 +12,7 @@ group("closure_compile") {
testonly = true
deps = [
":closure_compile_module",
":js_test_gen_html_type_check_auto",
":test_support_type_check",
]
}
......@@ -78,7 +80,7 @@ js_unittest("volume_manager_types_unittest") {
]
}
js_unit_tests("unit_tests") {
js_test_gen_html("js_test_gen_html") {
deps = [
":volume_manager_types_unittest",
]
......
......@@ -4,6 +4,7 @@
import("//third_party/closure_compiler/compile_js.gni")
import("//third_party/closure_compiler/js_unit_tests.gni")
import("//ui/file_manager/base/gn/js_test_gen_html.gni")
js_type_check("closure_compile_module") {
deps = [
......@@ -225,7 +226,7 @@ js_library("thumbnail_mode") {
]
}
js_unit_tests("unit_tests") {
js_test_gen_html("js_test_gen_html") {
deps = [
":dimmable_ui_controller_unittest",
":entry_list_watcher_unittest",
......@@ -241,6 +242,6 @@ group("closure_compile") {
testonly = true
deps = [
":closure_compile_module",
":unit_tests_type_check",
":js_test_gen_html_type_check_auto",
]
}
......@@ -4,6 +4,7 @@
import("//third_party/closure_compiler/compile_js.gni")
import("//third_party/closure_compiler/js_unit_tests.gni")
import("//ui/file_manager/base/gn/js_test_gen_html.gni")
js_type_check("closure_compile_module") {
deps = [
......@@ -197,7 +198,7 @@ js_library("viewport") {
]
}
js_unit_tests("unit_tests") {
js_test_gen_html("js_test_gen_html") {
deps = [
":exif_encoder_unittest",
":image_encoder_unittest",
......@@ -210,6 +211,6 @@ group("closure_compile") {
testonly = true
deps = [
":closure_compile_module",
":unit_tests_type_check",
":js_test_gen_html_type_check_auto",
]
}
......@@ -4,6 +4,7 @@
import("//third_party/closure_compiler/compile_js.gni")
import("//third_party/closure_compiler/js_unit_tests.gni")
import("//ui/file_manager/base/gn/js_test_gen_html.gni")
js_type_check("closure_compile_module") {
closure_flags = default_closure_args + [ "jscomp_error=strictCheckTypes" ]
......@@ -124,7 +125,7 @@ js_library("scheduler") {
]
}
js_unit_tests("unit_tests") {
js_test_gen_html("js_test_gen_html") {
closure_flags = default_closure_args + [ "jscomp_error=strictCheckTypes" ]
deps = [
":cache_unittest",
......@@ -138,6 +139,6 @@ group("closure_compile") {
testonly = true
deps = [
":closure_compile_module",
":unit_tests_type_check",
":js_test_gen_html_type_check_auto",
]
}
......@@ -4,6 +4,7 @@
import("//third_party/closure_compiler/compile_js.gni")
import("//third_party/closure_compiler/js_unit_tests.gni")
import("//ui/file_manager/base/gn/js_test_gen_html.gni")
js_type_check("closure_compile_module") {
deps = [
......@@ -98,7 +99,7 @@ js_library("video_player_metrics") {
]
}
js_unit_tests("unit_tests") {
js_test_gen_html("js_test_gen_html") {
deps = [
":video_player_native_controls_unittest",
]
......@@ -108,6 +109,6 @@ group("closure_compile") {
testonly = true
deps = [
":closure_compile_module",
":unit_tests_type_check",
":js_test_gen_html_type_check_auto",
]
}
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