Commit fd4c83c4 authored by rbpotter's avatar rbpotter Committed by Commit Bot

Web UI: Autogenerate modulized FindShortcutBehavior

Autogenerate a JS module version of FindShortcutBehavior, its
dependencies (KeyboardShortcutList), and its browser test. This is a
prerequisite for migrating pages that depend on this behavior to
Polymer 3 (e.g. bookmarks).

Bug: 1022213
Change-Id: Ifbf2680c5f044474de68b11da9a434c96a13381e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1913510
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#715102}
parent 4644ed25
...@@ -69,6 +69,7 @@ js2gtest("browser_tests_js_webui") { ...@@ -69,6 +69,7 @@ js2gtest("browser_tests_js_webui") {
"cr_elements/cr_elements_browsertest.js", "cr_elements/cr_elements_browsertest.js",
"cr_elements/cr_elements_v3_browsertest.js", "cr_elements/cr_elements_v3_browsertest.js",
"find_shortcut_behavior_browsertest.js", "find_shortcut_behavior_browsertest.js",
"find_shortcut_behavior_v3_browsertest.js",
"history/history_browsertest.js", "history/history_browsertest.js",
"js/webui_resource_module_async_browsertest.js", "js/webui_resource_module_async_browsertest.js",
"js2gtest_browsertest.js", "js2gtest_browsertest.js",
...@@ -195,6 +196,7 @@ js2gtest("browser_tests_js_webui") { ...@@ -195,6 +196,7 @@ js2gtest("browser_tests_js_webui") {
"$root_gen_dir/chrome/test/data/webui/cr_elements/cr_toolbar_search_field_tests.m.js", "$root_gen_dir/chrome/test/data/webui/cr_elements/cr_toolbar_search_field_tests.m.js",
"$root_gen_dir/chrome/test/data/webui/cr_elements/cr_view_manager_test.m.js", "$root_gen_dir/chrome/test/data/webui/cr_elements/cr_view_manager_test.m.js",
"$root_gen_dir/chrome/test/data/webui/fake_chrome_event.m.js", "$root_gen_dir/chrome/test/data/webui/fake_chrome_event.m.js",
"$root_gen_dir/chrome/test/data/webui/find_shortcut_behavior_test.m.js",
"$root_gen_dir/chrome/test/data/webui/mock_controller.m.js", "$root_gen_dir/chrome/test/data/webui/mock_controller.m.js",
"$root_gen_dir/chrome/test/data/webui/mock_timer.m.js", "$root_gen_dir/chrome/test/data/webui/mock_timer.m.js",
"$root_gen_dir/chrome/test/data/webui/resources/list_property_update_behavior_tests.m.js", "$root_gen_dir/chrome/test/data/webui/resources/list_property_update_behavior_tests.m.js",
...@@ -293,12 +295,13 @@ group("modulize") { ...@@ -293,12 +295,13 @@ group("modulize") {
js_modulizer("modulize_local") { js_modulizer("modulize_local") {
input_files = [ input_files = [
"cr_focus_row_behavior_test.js",
"fake_chrome_event.js", "fake_chrome_event.js",
"find_shortcut_behavior_test.js",
"mock_controller.js", "mock_controller.js",
"mock_timer.js", "mock_timer.js",
"test_browser_proxy.js", "test_browser_proxy.js",
"test_util.js", "test_util.js",
"cr_focus_row_behavior_test.js",
] ]
namespace_rewrites = [ namespace_rewrites = [
"cr.ui.FocusRowBehavior|FocusRowBehavior", "cr.ui.FocusRowBehavior|FocusRowBehavior",
......
...@@ -2,11 +2,23 @@ ...@@ -2,11 +2,23 @@
// 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.
// clang-format off
// #import 'chrome://resources/cr_elements/cr_dialog/cr_dialog.m.js';
// #import {assert} from 'chrome://resources/js/assert.m.js';
// #import {eventToPromise} from 'chrome://test/test_util.m.js';
// #import {FindShortcutBehavior, FindShortcutManager} from 'chrome://resources/js/find_shortcut_behavior.m.js';
// #import {isMac} from 'chrome://resources/js/cr.m.js';
// #import {Polymer, html} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
// #import {pressAndReleaseKeyOn} from 'chrome://resources/polymer/v3_0/iron-test-helpers/mock-interactions.js';
// #import {PromiseResolver} from 'chrome://resources/js/promise_resolver.m.js';
// clang-format on
suite('find-shortcut', () => { suite('find-shortcut', () => {
/** @override */ /** @override */
suiteSetup( /* #ignore */ suiteSetup(
() => PolymerTest.importHtml( /* #ignore */ () => PolymerTest.importHtml(
'chrome://resources/cr_elements/cr_dialog/cr_dialog.html')); /* #ignore */ 'chrome://resources/cr_elements/cr_dialog/' +
/* #ignore */ 'cr_dialog.html'));
/** /**
* @type {PromiseResolver<!{modalContextOpen: boolean, self: HTMLElement}>} * @type {PromiseResolver<!{modalContextOpen: boolean, self: HTMLElement}>}
......
// Copyright 2019 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.
// Polymer BrowserTest fixture.
GEN_INCLUDE(['//chrome/test/data/webui/polymer_browser_test_base.js']);
/**
* Test fixture for FindShortcutBehavior.
* @constructor
* @extends {PolymerTest}
*/
var FindShortcutBehaviorV3Test = class extends PolymerTest {
/** @override */
get browsePreload() {
return 'chrome://test?module=find_shortcut_behavior_test.m.js';
}
/** @override */
get webuiHost() {
return 'dummyurl';
}
/** @override */
get extraLibraries() {
return [
'//third_party/mocha/mocha.js',
'//chrome/test/data/webui/mocha_adapter.js',
];
}
};
TEST_F('FindShortcutBehaviorV3Test', 'All', function() {
mocha.run();
});
...@@ -3,6 +3,9 @@ ...@@ -3,6 +3,9 @@
<include name="IDR_WEBUI_JS_CR_UI_FOCUS_ROW_BEHAVIOR_M_JS" <include name="IDR_WEBUI_JS_CR_UI_FOCUS_ROW_BEHAVIOR_M_JS"
file="${root_gen_dir}/ui/webui/resources/js/cr/ui/focus_row_behavior.m.js" file="${root_gen_dir}/ui/webui/resources/js/cr/ui/focus_row_behavior.m.js"
use_base_dir="false" type="BINDATA" compress="gzip" /> use_base_dir="false" type="BINDATA" compress="gzip" />
<include name="IDR_WEBUI_JS_FIND_SHORTCUT_BEHAVIOR_M_JS"
file="${root_gen_dir}/ui/webui/resources/js/find_shortcut_behavior.m.js"
use_base_dir="false" type="BINDATA" compress="gzip" />
<include name="IDR_WEBUI_JS_I18N_BEHAVIOR_M_JS" <include name="IDR_WEBUI_JS_I18N_BEHAVIOR_M_JS"
file="${root_gen_dir}/ui/webui/resources/js/i18n_behavior.m.js" file="${root_gen_dir}/ui/webui/resources/js/i18n_behavior.m.js"
use_base_dir="false" type="BINDATA" compress="gzip" /> use_base_dir="false" type="BINDATA" compress="gzip" />
......
...@@ -143,6 +143,7 @@ js_modulizer("modulize") { ...@@ -143,6 +143,7 @@ js_modulizer("modulize") {
input_files = [ input_files = [
"assert.js", "assert.js",
"event_tracker.js", "event_tracker.js",
"find_shortcut_behavior.js",
"icon.js", "icon.js",
"i18n_behavior.js", "i18n_behavior.js",
"list_property_update_behavior.js", "list_property_update_behavior.js",
...@@ -153,8 +154,10 @@ js_modulizer("modulize") { ...@@ -153,8 +154,10 @@ js_modulizer("modulize") {
"util.js", "util.js",
"web_ui_listener_behavior.js", "web_ui_listener_behavior.js",
] ]
namespace_rewrites = namespace_rewrites = [
[ "Polymer.ArraySplice.calculateSplices|calculateSplices" ] "cr.ui.KeyboardShortcutList|KeyboardShortcutList",
"Polymer.ArraySplice.calculateSplices|calculateSplices",
]
deps = [ deps = [
"cr:modulize", "cr:modulize",
] ]
...@@ -173,6 +176,7 @@ js_type_check("js_resources_modules") { ...@@ -173,6 +176,7 @@ js_type_check("js_resources_modules") {
":assert.m", ":assert.m",
":cr.m", ":cr.m",
":event_tracker.m", ":event_tracker.m",
":find_shortcut_behavior.m",
":i18n_behavior.m", ":i18n_behavior.m",
":icon.m", ":icon.m",
":list_property_update_behavior.m", ":list_property_update_behavior.m",
...@@ -207,6 +211,19 @@ js_library("event_tracker.m") { ...@@ -207,6 +211,19 @@ js_library("event_tracker.m") {
extra_deps = [ ":modulize" ] extra_deps = [ ":modulize" ]
} }
js_library("find_shortcut_behavior.m") {
sources = [
"$root_gen_dir/ui/webui/resources/js/find_shortcut_behavior.m.js",
]
deps = [
":assert.m",
":cr.m",
":util.m",
"cr/ui:keyboard_shortcut_list.m",
]
extra_deps = [ ":modulize" ]
}
js_library("icon.m") { js_library("icon.m") {
sources = [ sources = [
"$root_gen_dir/ui/webui/resources/js/icon.m.js", "$root_gen_dir/ui/webui/resources/js/icon.m.js",
......
...@@ -272,6 +272,7 @@ js_modulizer("modulize") { ...@@ -272,6 +272,7 @@ js_modulizer("modulize") {
"focus_row.js", "focus_row.js",
"focus_row_behavior.js", "focus_row_behavior.js",
"focus_without_ink.js", "focus_without_ink.js",
"keyboard_shortcut_list.js",
"store.js", "store.js",
"store_client.js", "store_client.js",
] ]
...@@ -294,6 +295,7 @@ js_type_check("ui_resources_modules") { ...@@ -294,6 +295,7 @@ js_type_check("ui_resources_modules") {
":focus_row.m", ":focus_row.m",
":focus_row_behavior.m", ":focus_row_behavior.m",
":focus_without_ink.m", ":focus_without_ink.m",
":keyboard_shortcut_list.m",
":store.m", ":store.m",
":store_client.m", ":store_client.m",
] ]
...@@ -349,6 +351,13 @@ js_library("focus_without_ink.m") { ...@@ -349,6 +351,13 @@ js_library("focus_without_ink.m") {
extra_deps = [ ":modulize" ] extra_deps = [ ":modulize" ]
} }
js_library("keyboard_shortcut_list.m") {
sources = [
"$root_gen_dir/ui/webui/resources/js/cr/ui/keyboard_shortcut_list.m.js",
]
extra_deps = [ ":modulize" ]
}
js_library("store.m") { js_library("store.m") {
sources = [ sources = [
"$root_gen_dir/ui/webui/resources/js/cr/ui/store.m.js", "$root_gen_dir/ui/webui/resources/js/cr/ui/store.m.js",
......
...@@ -66,7 +66,7 @@ cr.define('cr.ui', function() { ...@@ -66,7 +66,7 @@ cr.define('cr.ui', function() {
} }
/** A list of keyboard shortcuts which all perform one command. */ /** A list of keyboard shortcuts which all perform one command. */
class KeyboardShortcutList { /* #export */ class KeyboardShortcutList {
/** /**
* @param {string} shortcuts Text-based representation of one or more * @param {string} shortcuts Text-based representation of one or more
* keyboard shortcuts, separated by spaces. * keyboard shortcuts, separated by spaces.
...@@ -90,7 +90,7 @@ cr.define('cr.ui', function() { ...@@ -90,7 +90,7 @@ cr.define('cr.ui', function() {
} }
} }
// Export // #cr_define_end
return { return {
KeyboardShortcutList: KeyboardShortcutList, KeyboardShortcutList: KeyboardShortcutList,
}; };
......
...@@ -2,13 +2,18 @@ ...@@ -2,13 +2,18 @@
// 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.
// #import {assert, assertNotReached} from './assert.m.js';
// #import {isMac} from './cr.m.js';
// #import {isTextInputElement} from './util.m.js';
// #import {KeyboardShortcutList} from './cr/ui/keyboard_shortcut_list.m.js';
/** /**
* @fileoverview Listens for a find keyboard shortcut (i.e. Ctrl/Cmd+f or /) * @fileoverview Listens for a find keyboard shortcut (i.e. Ctrl/Cmd+f or /)
* and keeps track of an stack of potential listeners. Only the listener at the * and keeps track of an stack of potential listeners. Only the listener at the
* top of the stack will be notified that a find shortcut has been invoked. * top of the stack will be notified that a find shortcut has been invoked.
*/ */
const FindShortcutManager = (() => { /* #export */ const FindShortcutManager = (() => {
/** /**
* Stack of listeners. Only the top listener will handle the shortcut. * Stack of listeners. Only the top listener will handle the shortcut.
* @type {!Array} * @type {!Array}
...@@ -71,7 +76,7 @@ const FindShortcutManager = (() => { ...@@ -71,7 +76,7 @@ const FindShortcutManager = (() => {
* Used to determine how to handle find shortcut invocations. * Used to determine how to handle find shortcut invocations.
* @polymerBehavior * @polymerBehavior
*/ */
const FindShortcutBehavior = { /* #export */ const FindShortcutBehavior = {
/** /**
* @type {boolean} * @type {boolean}
* @protected * @protected
......
...@@ -488,6 +488,6 @@ if (!('key' in KeyboardEvent.prototype)) { ...@@ -488,6 +488,6 @@ if (!('key' in KeyboardEvent.prototype)) {
* @param {!Element} el * @param {!Element} el
* @return {boolean} Whether the element is interactive via text input. * @return {boolean} Whether the element is interactive via text input.
*/ */
function isTextInputElement(el) { /* #export */ function isTextInputElement(el) {
return el.tagName == 'INPUT' || el.tagName == 'TEXTAREA'; return el.tagName == 'INPUT' || el.tagName == 'TEXTAREA';
} }
...@@ -103,6 +103,9 @@ without changes to the corresponding grd file. --> ...@@ -103,6 +103,9 @@ without changes to the corresponding grd file. -->
<include name="IDR_WEBUI_JS_CR_UI_FOCUS_WITHOUT_INK_M_JS" <include name="IDR_WEBUI_JS_CR_UI_FOCUS_WITHOUT_INK_M_JS"
file="${root_gen_dir}/ui/webui/resources/js/cr/ui/focus_without_ink.m.js" file="${root_gen_dir}/ui/webui/resources/js/cr/ui/focus_without_ink.m.js"
use_base_dir="false" type="BINDATA" compress="gzip" /> use_base_dir="false" type="BINDATA" compress="gzip" />
<include name="IDR_WEBUI_JS_CR_UI_KEYBOARD_SHORTCUT_LIST_M_JS"
file="${root_gen_dir}/ui/webui/resources/js/cr/ui/keyboard_shortcut_list.m.js"
use_base_dir="false" type="BINDATA" compress="gzip" />
<include name="IDR_WEBUI_JS_CR_UI_STORE_M_JS" <include name="IDR_WEBUI_JS_CR_UI_STORE_M_JS"
file="${root_gen_dir}/ui/webui/resources/js/cr/ui/store.m.js" file="${root_gen_dir}/ui/webui/resources/js/cr/ui/store.m.js"
use_base_dir="false" type="BINDATA" compress="gzip" /> use_base_dir="false" type="BINDATA" compress="gzip" />
......
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