Commit 9604c580 authored by rbpotter's avatar rbpotter Committed by Commit Bot

Web UI Polymer 3: Port managed-footnote

- Autogenerate Polymer 3 version of managed-footnote and tests
- Add to demo page
- Add new build targets and browser test files as needed since this is
the first CrComponent to be ported.
- Also adding a way for the TestDataSource to serve an empty version
of strings.m.js, for tests that need to override values in loadTimeData

Bug: 965770
Change-Id: Id8ce7b102c8cb86d84e606a6bc9046cecd6f284c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1809747Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#697748}
parent 43dd14a5
......@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'chrome://resources/cr_components/managed_footnote/managed_footnote.m.js';
import 'chrome://resources/cr_elements/action_link_css.m.js';
import 'chrome://resources/cr_elements/cr_action_menu/cr_action_menu.m.js';
import 'chrome://resources/cr_elements/cr_button/cr_button.m.js';
......@@ -25,6 +26,7 @@ import 'chrome://resources/cr_elements/md_select_css.m.js';
import 'chrome://resources/cr_elements/policy/cr_tooltip_icon.m.js';
import 'chrome://resources/js/action_link.js';
import 'chrome://resources/polymer/v3_0/iron-icon/iron-icon.js';
import '../strings.m.js';
import * as crToastManager from 'chrome://resources/cr_elements/cr_toast/cr_toast_manager.m.js';
import {html, PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
......@@ -156,6 +158,10 @@ class HelloPolymer3Element extends PolymerElement {
Show toast for 2s
</cr-button>
</div>
<div>
<managed-footnote></managed-footnote>
</div>
`;
}
......
......@@ -66,6 +66,10 @@
#include "base/enterprise_util.h"
#endif
#if !BUILDFLAG(OPTIMIZE_WEBUI)
#include "chrome/browser/ui/webui/managed_ui_handler.h"
#endif
using content::WebContents;
namespace printing {
......@@ -471,7 +475,12 @@ PrintPreviewUI::PrintPreviewUI(content::WebUI* web_ui)
handler_(CreatePrintPreviewHandlers(web_ui)) {
// Set up the chrome://print/ data source.
Profile* profile = Profile::FromWebUI(web_ui);
content::WebUIDataSource::Add(profile, CreatePrintPreviewUISource(profile));
content::WebUIDataSource* source = CreatePrintPreviewUISource(profile);
#if !BUILDFLAG(OPTIMIZE_WEBUI)
// For the Polymer 3 demo page.
ManagedUIHandler::Initialize(web_ui, source);
#endif
content::WebUIDataSource::Add(profile, source);
// Set up the chrome://theme/ source.
content::URLDataSource::Add(profile, std::make_unique<ThemeSource>(profile));
......
......@@ -33,6 +33,15 @@ void TestDataSource::StartDataRequest(
const std::string& path,
const content::WebContents::Getter& wc_getter,
const content::URLDataSource::GotDataCallback& callback) {
if (path == "strings.m.js") {
std::string output = "import {loadTimeData} from ";
output.append("'chrome://resources/js/load_time_data.m.js';\n");
output.append("loadTimeData.data = {};");
scoped_refptr<base::RefCountedString> response =
base::RefCountedString::TakeString(&output);
callback.Run(response.get());
return;
}
base::PostTask(
FROM_HERE,
{base::ThreadPool(), base::MayBlock(), base::TaskPriority::USER_BLOCKING},
......
......@@ -4,6 +4,7 @@
#include "chrome/test/base/test_chrome_web_ui_controller_factory.h"
#include "base/bind_helpers.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/test_data_source.h"
#include "content/public/browser/url_data_source.h"
......@@ -62,6 +63,8 @@ TestChromeWebUIControllerFactory::CreateWebUIControllerForURL(
provider ? provider->NewWebUI(web_ui, webui_url)
: ChromeWebUIControllerFactory::CreateWebUIControllerForURL(
web_ui, webui_url);
// Add an empty callback since managed-footnote always sends this message.
web_ui->RegisterMessageCallback("observeManagedUI", base::DoNothing());
content::URLDataSource::Add(profile, std::make_unique<TestDataSource>());
return controller;
}
......
......@@ -63,6 +63,7 @@ js2gtest("browser_tests_js_webui") {
"bookmarks/bookmarks_browsertest.js",
"chrome_send_browsertest.js",
"cr_components/cr_components_browsertest.js",
"cr_components/cr_components_v3_browsertest.js",
"cr_elements/cr_elements_browsertest.js",
"cr_elements/cr_elements_v3_browsertest.js",
"find_shortcut_behavior_browsertest.js",
......@@ -164,6 +165,7 @@ js2gtest("browser_tests_js_webui") {
"//skia",
]
data = [
"$root_gen_dir/chrome/test/data/webui/cr_components/managed_footnote_test.m.js",
"$root_gen_dir/chrome/test/data/webui/cr_elements/cr_button_tests.m.js",
"$root_gen_dir/chrome/test/data/webui/cr_elements/cr_container_shadow_behavior_test.m.js",
"$root_gen_dir/chrome/test/data/webui/cr_elements/cr_dialog_test.m.js",
......@@ -262,6 +264,7 @@ js2gtest("unit_tests_js") {
group("modulize") {
deps = [
":modulize_local",
"./cr_components:modulize",
"./cr_elements:modulize",
]
}
......
# 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.
import("//ui/webui/resources/tools/js_modulizer.gni")
js_modulizer("modulize") {
input_files = [ "managed_footnote_test.js" ]
namespace_rewrites = [ "cr.isChromeOS|isChromeOS" ]
}
// 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.
/** @fileoverview Tests for shared Polymer 3 components. */
// Polymer BrowserTest fixture.
GEN_INCLUDE(['//chrome/test/data/webui/polymer_browser_test_base.js']);
/** Test fixture for shared Polymer 3 components. */
// eslint-disable-next-line no-var
var CrComponentsV3BrowserTest = class extends PolymerTest {
/** @override */
get browsePreload() {
return 'chrome://dummyurl';
}
/** @override */
get extraLibraries() {
return [
'//third_party/mocha/mocha.js',
'//chrome/test/data/webui/mocha_adapter.js',
];
}
/** @override */
get webuiHost() {
return 'dummyurl';
}
/** @override */
get runAccessibilityChecks() {
return false;
}
/** @override */
setUp() {
PolymerTest.prototype.setUp.call(this);
// We aren't loading the main document.
this.accessibilityAuditConfig.ignoreSelectors('humanLangMissing', 'html');
}
};
// eslint-disable-next-line no-var
var CrComponentsManagedFootnoteV3Test =
class extends CrComponentsV3BrowserTest {
/** @override */
get browsePreload() {
return 'chrome://test?module=cr_components/managed_footnote_test.m.js';
}
};
TEST_F('CrComponentsManagedFootnoteV3Test', 'All', function() {
mocha.run();
});
......@@ -3,6 +3,16 @@
// found in the LICENSE file.
/** @fileoverview Suite of tests for managed-footnote. */
// clang-format off
// #import 'chrome://resources/cr_components/managed_footnote/managed_footnote.m.js';
//
// #import '../strings.m.js';
// #import {flush} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
// #import {isChromeOS} from 'chrome://resources/js/cr.m.js';
// #import {loadTimeData} from 'chrome://resources/js/load_time_data.m.js';
// clang-format on
cr.define('managed_footnote_test', function() {
/** @enum {string} */
const TestNames = {
......@@ -69,20 +79,23 @@ cr.define('managed_footnote_test', function() {
assertNotEquals('none', getComputedStyle(footnote).display);
});
test('Reads Attributes From loadTimeData device message', function() {
const browserMessage = 'the quick brown fox jumps over the lazy dog';
const deviceMessage = 'the lazy dog jumps over the quick brown fox';
const footnote =
setupTestElement(true, browserMessage, deviceMessage, '');
if (cr.isChromeOS) {
test('Reads Attributes From loadTimeData device message', function() {
const browserMessage = 'the quick brown fox jumps over the lazy dog';
const deviceMessage = 'the lazy dog jumps over the quick brown fox';
const footnote =
setupTestElement(true, browserMessage, deviceMessage, '');
assertNotEquals('none', getComputedStyle(footnote).display);
assertTrue(footnote.shadowRoot.textContent.includes(browserMessage));
assertNotEquals('none', getComputedStyle(footnote).display);
assertTrue(footnote.shadowRoot.textContent.includes(browserMessage));
footnote.showDeviceInfo = true;
assertTrue(footnote.shadowRoot.textContent.includes(deviceMessage));
});
footnote.showDeviceInfo = true;
assertTrue(footnote.shadowRoot.textContent.includes(deviceMessage));
});
}
});
// #cr_define_end
return {
suiteName: suiteName,
TestNames: TestNames,
......
......@@ -15,6 +15,7 @@ group("closure_compile") {
group("modulize") {
deps = [
"cr_components:polymer3_elements",
"cr_elements:polymer3_elements",
"js:modulize",
]
......
......@@ -8,9 +8,16 @@ group("closure_compile") {
deps = [
"certificate_manager:closure_compile",
"managed_footnote:closure_compile",
"managed_footnote:closure_compile_module",
]
if (is_chromeos) {
deps += [ "chromeos:closure_compile" ]
}
}
group("polymer3_elements") {
deps = [
"managed_footnote:managed_footnote_module",
]
}
<?xml version="1.0" encoding="utf-8"?>
<grit-part>
<include name="IDR_WEBUI_MANAGED_FOOTNOTE_M_JS"
file="${root_gen_dir}/ui/webui/resources/cr_components/managed_footnote/managed_footnote.m.js"
use_base_dir="false"
type="BINDATA"
compress="gzip" />
</grit-part>
......@@ -3,6 +3,7 @@
# found in the LICENSE file.
import("//third_party/closure_compiler/compile_js.gni")
import("//tools/polymer/polymer.gni")
js_type_check("closure_compile") {
deps = [
......@@ -17,3 +18,34 @@ js_library("managed_footnote") {
"//ui/webui/resources/js:web_ui_listener_behavior",
]
}
polymer_modulizer("managed_footnote") {
js_file = "managed_footnote.js"
html_file = "managed_footnote.html"
html_type = "dom-module"
auto_imports = [
"ui/webui/resources/html/web_ui_listener_behavior.html|WebUIListenerBehavior",
"ui/webui/resources/html/i18n_behavior.html|I18nBehavior",
"ui/webui/resources/html/load_time_data.html|loadTimeData",
]
}
js_type_check("closure_compile_module") {
is_polymer3 = true
deps = [
":managed_footnote.m",
]
}
js_library("managed_footnote.m") {
sources = [
"$root_gen_dir/ui/webui/resources/cr_components/managed_footnote/managed_footnote.m.js",
]
deps = [
"//third_party/polymer/v3_0/components-chromium/polymer:polymer_bundled",
"//ui/webui/resources/js:i18n_behavior.m",
"//ui/webui/resources/js:load_time_data.m",
"//ui/webui/resources/js:web_ui_listener_behavior.m",
]
extra_deps = [ ":managed_footnote_module" ]
}
......@@ -126,6 +126,7 @@ without changes to the corresponding grd file. -->
</if>
<if expr="not is_android and not is_ios">
<part file="cr_components/cr_components_resources_v3.grdp" />
<part file="cr_elements_resources_v3.grdp" />
<part file="cr_polymer_resources_v3.grdp" />
</if>
......
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