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

Settings: Migrate tests for settings-subpage, settings-animated-pages

- Add Polymer 3 versions of settings_page/* files to the grdp
- Autogenerate tests for Polymer 3 versions of settings-subpage and
  settings-animated-pages

Bug: 1026426
Change-Id: I73dd675aa3f2b765c1149679bd657a8d63c7aea6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2038456Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#738781}
parent 6296552d
......@@ -16,7 +16,10 @@ import './search_engines_page/omnibox_extension_entry.m.js';
import './search_engines_page/search_engine_dialog.m.js';
import './search_engines_page/search_engine_entry.m.js';
import './search_engines_page/search_engines_page.m.js';
import './settings_page/settings_subpage.m.js';
import './settings_page/settings_animated_pages.m.js';
export {ExtensionControlBrowserProxyImpl} from './extension_control_browser_proxy.m.js';
export {prefToString, stringToPrefValue} from './prefs/pref_util.m.js';
export {Route, Router} from './router.m.js';
export {SearchEnginesBrowserProxyImpl} from './search_engines_page/search_engines_browser_proxy.m.js';
......@@ -113,7 +113,7 @@ js_library("settings_subpage.m") {
import("//tools/polymer/polymer.gni")
group("polymer3_elements") {
deps = [
public_deps = [
":modulize",
":settings_animated_pages_module",
":settings_section_module",
......
<link rel="import" href="chrome://resources/html/polymer.html">
<link rel="import" href="chrome://resources/cr_elements/shared_vars_css.html">
<link rel="import" href="chrome://resources/html/util.html">
<dom-module id="settings-section">
<template>
......
......@@ -82,34 +82,6 @@
file="${root_gen_dir}/chrome/browser/resources/settings/router.m.js"
use_base_dir="false"
type="BINDATA" />
<include name="IDR_SETTINGS_SEARCH_SETTINGS_M_JS"
file="${root_gen_dir}/chrome/browser/resources/settings/search_settings.m.js"
use_base_dir="false"
type="BINDATA" />
<include name="IDR_SETTINGS_SETTINGS_ROUTES_M_JS"
file="${root_gen_dir}/chrome/browser/resources/settings/settings_routes.m.js"
use_base_dir="false"
type="BINDATA" />
<include name="IDR_SETTINGS_SETTINGS_SHARED_CSS_M_JS"
file="${root_gen_dir}/chrome/browser/resources/settings/settings_shared_css.m.js"
use_base_dir="false"
type="BINDATA"
preprocess="true" />
<include name="IDR_SETTINGS_SETTINGS_VARS_CSS_M_JS"
file="${root_gen_dir}/chrome/browser/resources/settings/settings_vars_css.m.js"
use_base_dir="false"
type="BINDATA"
preprocess="true" />
<include name="IDR_SETTINGS_SETTINGS_V3_HTML"
file="settings_v3.html"
type="BINDATA" />
<include name="IDR_SETTINGS_SETTINGS_V3_JS"
file="settings.js"
type="BINDATA" />
<include name="IDR_SETTINGS_SITE_FAVICON_M_JS"
file="${root_gen_dir}/chrome/browser/resources/settings/site_favicon.m.js"
use_base_dir="false"
type="BINDATA" />
<include name="IDR_SETTINGS_SEARCH_ENGINES_BROWSER_PROXY_M_JS"
file="${root_gen_dir}/chrome/browser/resources/settings/search_engines_page/search_engines_browser_proxy.m.js"
use_base_dir="false"
......@@ -139,4 +111,48 @@
file="${root_gen_dir}/chrome/browser/resources/settings/search_engines_page/search_engines_page.m.js"
use_base_dir="false"
type="BINDATA" />
<include name="IDR_SETTINGS_SEARCH_SETTINGS_M_JS"
file="${root_gen_dir}/chrome/browser/resources/settings/search_settings.m.js"
use_base_dir="false"
type="BINDATA" />
<include name="IDR_SETTINGS_SETTINGS_PAGE_MAIN_PAGE_BEHAVIOR_M_JS"
file="${root_gen_dir}/chrome/browser/resources/settings/settings_page/main_page_behavior.m.js"
use_base_dir="false"
type="BINDATA" />
<include name="IDR_SETTINGS_SETTINGS_PAGE_SETTINGS_ANIMATED_PAGES_M_JS"
file="${root_gen_dir}/chrome/browser/resources/settings/settings_page/settings_animated_pages.m.js"
use_base_dir="false"
type="BINDATA" />
<include name="IDR_SETTINGS_SETTINGS_PAGE_SETTINGS_SECTION_M_JS"
file="${root_gen_dir}/chrome/browser/resources/settings/settings_page/settings_section.m.js"
use_base_dir="false"
type="BINDATA" />
<include name="IDR_SETTINGS_SETTINGS_PAGE_SETTINGS_SUBPAGE_M_JS"
file="${root_gen_dir}/chrome/browser/resources/settings/settings_page/settings_subpage.m.js"
use_base_dir="false"
type="BINDATA" />
<include name="IDR_SETTINGS_SETTINGS_ROUTES_M_JS"
file="${root_gen_dir}/chrome/browser/resources/settings/settings_routes.m.js"
use_base_dir="false"
type="BINDATA" />
<include name="IDR_SETTINGS_SETTINGS_SHARED_CSS_M_JS"
file="${root_gen_dir}/chrome/browser/resources/settings/settings_shared_css.m.js"
use_base_dir="false"
type="BINDATA"
preprocess="true" />
<include name="IDR_SETTINGS_SETTINGS_VARS_CSS_M_JS"
file="${root_gen_dir}/chrome/browser/resources/settings/settings_vars_css.m.js"
use_base_dir="false"
type="BINDATA"
preprocess="true" />
<include name="IDR_SETTINGS_SETTINGS_V3_HTML"
file="settings_v3.html"
type="BINDATA" />
<include name="IDR_SETTINGS_SETTINGS_V3_JS"
file="settings.js"
type="BINDATA" />
<include name="IDR_SETTINGS_SITE_FAVICON_M_JS"
file="${root_gen_dir}/chrome/browser/resources/settings/site_favicon.m.js"
use_base_dir="false"
type="BINDATA" />
</grit-part>
......@@ -22,6 +22,7 @@ js2gtest("interactive_ui_tests_js_webui") {
"new_tab_page/new_tab_page_interactive_test.js",
"print_preview/print_preview_interactive_ui_tests.js",
"settings/cr_settings_interactive_ui_tests.js",
"settings/cr_settings_v3_interactive_ui_tests.js",
"settings/settings_ui_browsertest.js",
]
......@@ -46,6 +47,8 @@ js2gtest("interactive_ui_tests_js_webui") {
"$root_gen_dir/chrome/test/data/webui/cr_elements/iron_list_focus_test.m.js",
"$root_gen_dir/chrome/test/data/webui/cr_focus_row_behavior_test.m.js",
"$root_gen_dir/chrome/test/data/webui/mock_controller.m.js",
"$root_gen_dir/chrome/test/data/webui/settings/settings_animated_pages_test.m.js",
"$root_gen_dir/chrome/test/data/webui/settings/test_util.m.js",
"$root_gen_dir/chrome/test/data/webui/test_browser_proxy.m.js",
"$root_gen_dir/chrome/test/data/webui/test_store.m.js",
"$root_gen_dir/chrome/test/data/webui/test_util.m.js",
......@@ -214,11 +217,13 @@ js2gtest("browser_tests_js_webui") {
"$root_gen_dir/chrome/test/data/webui/settings/pref_util_tests.m.js",
"$root_gen_dir/chrome/test/data/webui/settings/search_engines_page_test.m.js",
"$root_gen_dir/chrome/test/data/webui/settings/settings_slider_tests.m.js",
"$root_gen_dir/chrome/test/data/webui/settings/settings_subpage_test.m.js",
"$root_gen_dir/chrome/test/data/webui/settings/settings_textarea_tests.m.js",
"$root_gen_dir/chrome/test/data/webui/settings/settings_toggle_button_tests.m.js",
"$root_gen_dir/chrome/test/data/webui/settings/site_favicon_test.m.js",
"$root_gen_dir/chrome/test/data/webui/settings/test_extension_control_browser_proxy.m.js",
"$root_gen_dir/chrome/test/data/webui/settings/test_search_engines_browser_proxy.m.js",
"$root_gen_dir/chrome/test/data/webui/settings/test_util.m.js",
"$root_gen_dir/chrome/test/data/webui/test_browser_proxy.m.js",
"$root_gen_dir/chrome/test/data/webui/test_store.m.js",
"$root_gen_dir/chrome/test/data/webui/test_util.m.js",
......
......@@ -12,18 +12,24 @@ js_modulizer("modulize") {
"dropdown_menu_tests.js",
"extension_controlled_indicator_tests.js",
"pref_util_tests.js",
"settings_animated_pages_test.js",
"search_engines_page_test.js",
"site_favicon_test.js",
"settings_slider_tests.js",
"settings_subpage_test.js",
"settings_textarea_tests.js",
"settings_toggle_button_tests.js",
"test_extension_control_browser_proxy.js",
"test_search_engines_browser_proxy.js",
"test_util.js",
]
namespace_rewrites = [
"settings.ExtensionControlBrowserProxyImpl|ExtensionControlBrowserProxyImpl",
"settings.Route|Route",
"settings.routes|routes",
"test_util.eventToPromise|eventToPromise",
"test_util.flushTasks|flushTasks",
"test_util.setupPopstateListener|setupPopstateListener",
"MockInteractions.keyDownOn|keyDownOn",
"MockInteractions.keyUpOn|keyUpOn",
"Settings.PrefUtil.prefToString|prefToString",
......
......@@ -121,6 +121,18 @@ TEST_F('CrSettingsSliderV3Test', 'All', function() {
mocha.run();
});
// eslint-disable-next-line no-var
var CrSettingsSubpageV3Test = class extends CrSettingsV3BrowserTest {
/** @override */
get browsePreload() {
return 'chrome://settings/test_loader.html?module=settings/settings_subpage_test.m.js';
}
};
TEST_F('CrSettingsSubpageV3Test', 'All', function() {
mocha.run();
});
// eslint-disable-next-line no-var
var CrSettingsTextareaV3Test = class extends CrSettingsV3BrowserTest {
/** @override */
......
// Copyright 2020 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 elements. */
// Polymer BrowserTest fixture.
GEN_INCLUDE(['//chrome/test/data/webui/polymer_interactive_ui_test.js']);
/** Test fixture for shared Polymer 3 elements. */
// eslint-disable-next-line no-var
var CrSettingsV3InteractiveUITest = class extends PolymerInteractiveUITest {
/** @override */
get browsePreload() {
return 'chrome://settings';
}
/** @override */
get extraLibraries() {
return [
'//third_party/mocha/mocha.js',
'//chrome/test/data/webui/mocha_adapter.js',
];
}
};
// eslint-disable-next-line no-var
var CrSettingsAnimatedPagesV3Test =
class extends CrSettingsV3InteractiveUITest {
/** @override */
get browsePreload() {
return 'chrome://settings/test_loader.html?module=settings/settings_animated_pages_test.m.js';
}
};
TEST_F('CrSettingsAnimatedPagesV3Test', 'All', function() {
mocha.run();
});
......@@ -2,24 +2,28 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// clang-format off
// #import {Route, Router} from 'chrome://settings/settings.js';
// #import {setupPopstateListener} from 'chrome://test/settings/test_util.m.js';
// clang-format on
suite('settings-animated-pages', function() {
test('focuses subpage trigger when exiting subpage', function(done) {
const routes = {
const testRoutes = {
BASIC: new settings.Route('/'),
};
routes.SEARCH = routes.BASIC.createSection('/search', 'search');
routes.SEARCH_ENGINES = routes.SEARCH.createChild('/searchEngines');
settings.Router.resetInstanceForTesting(new settings.Router(routes));
settings.routes = routes;
testRoutes.SEARCH = testRoutes.BASIC.createSection('/search', 'search');
testRoutes.SEARCH_ENGINES = testRoutes.SEARCH.createChild('/searchEngines');
settings.Router.resetInstanceForTesting(new settings.Router(testRoutes));
test_util.setupPopstateListener();
document.body.innerHTML = `
<settings-animated-pages
section="${settings.routes.SEARCH_ENGINES.section}">
section="${testRoutes.SEARCH_ENGINES.section}">
<div route-path="default">
<button id="subpage-trigger"></button>
</div>
<div route-path="${settings.routes.SEARCH_ENGINES.path}">
<div route-path="${testRoutes.SEARCH_ENGINES.path}">
<button id="subpage-trigger"></button>
</div>
</settings-animated-pages>`;
......@@ -28,7 +32,7 @@ suite('settings-animated-pages', function() {
document.body.querySelector('settings-animated-pages');
animatedPages.focusConfig = new Map();
animatedPages.focusConfig.set(
settings.routes.SEARCH_ENGINES.path, '#subpage-trigger');
testRoutes.SEARCH_ENGINES.path, '#subpage-trigger');
const trigger = document.body.querySelector('#subpage-trigger');
assertTrue(!!trigger);
......@@ -37,8 +41,8 @@ suite('settings-animated-pages', function() {
});
// Trigger subpage exit navigation.
settings.Router.getInstance().navigateTo(settings.routes.BASIC);
settings.Router.getInstance().navigateTo(settings.routes.SEARCH_ENGINES);
settings.Router.getInstance().navigateTo(testRoutes.BASIC);
settings.Router.getInstance().navigateTo(testRoutes.SEARCH_ENGINES);
settings.Router.getInstance().navigateToPreviousRoute();
});
});
......@@ -2,20 +2,29 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// clang-format off
// #import {flush} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
// #import {flushTasks} from 'chrome://test/test_util.m.js';
// #import {Route, Router} from 'chrome://settings/settings.js';
// #import {setupPopstateListener} from 'chrome://test/settings/test_util.m.js';
// clang-format on
suite('SettingsSubpage', function() {
let testRoutes;
setup(function() {
const routes = {
testRoutes = {
BASIC: new settings.Route('/'),
};
routes.SEARCH = routes.BASIC.createSection('/search', 'search');
routes.SEARCH_ENGINES = routes.SEARCH.createChild('/searchEngines');
routes.PEOPLE = routes.BASIC.createSection('/people', 'people');
routes.SYNC = routes.PEOPLE.createChild('/syncSetup');
routes.PRIVACY = routes.BASIC.createSection('/privacy', 'privacy');
routes.CERTIFICATES = routes.PRIVACY.createChild('/certificates');
settings.Router.resetInstanceForTesting(new settings.Router(routes));
settings.routes = routes;
testRoutes.SEARCH = testRoutes.BASIC.createSection('/search', 'search');
testRoutes.SEARCH_ENGINES = testRoutes.SEARCH.createChild('/searchEngines');
testRoutes.PEOPLE = testRoutes.BASIC.createSection('/people', 'people');
testRoutes.SYNC = testRoutes.PEOPLE.createChild('/syncSetup');
testRoutes.PRIVACY = testRoutes.BASIC.createSection('/privacy', 'privacy');
testRoutes.CERTIFICATES = testRoutes.PRIVACY.createChild('/certificates');
settings.Router.resetInstanceForTesting(new settings.Router(testRoutes));
test_util.setupPopstateListener();
PolymerTest.clearBody();
......@@ -53,11 +62,10 @@ suite('SettingsSubpage', function() {
test('navigates to parent when there is no history', function() {
// Pretend that we initially started on the CERTIFICATES route.
window.history.replaceState(
undefined, '', settings.routes.CERTIFICATES.path);
window.history.replaceState(undefined, '', testRoutes.CERTIFICATES.path);
settings.Router.getInstance().initializeRouteFromUrl();
assertEquals(
settings.routes.CERTIFICATES,
testRoutes.CERTIFICATES,
settings.Router.getInstance().getCurrentRoute());
const subpage = document.createElement('settings-subpage');
......@@ -65,15 +73,14 @@ suite('SettingsSubpage', function() {
subpage.$$('cr-icon-button').click();
assertEquals(
settings.routes.PRIVACY,
settings.Router.getInstance().getCurrentRoute());
testRoutes.PRIVACY, settings.Router.getInstance().getCurrentRoute());
});
test('navigates to any route via window.back()', function(done) {
settings.Router.getInstance().navigateTo(settings.routes.BASIC);
settings.Router.getInstance().navigateTo(settings.routes.SYNC);
settings.Router.getInstance().navigateTo(testRoutes.BASIC);
settings.Router.getInstance().navigateTo(testRoutes.SYNC);
assertEquals(
settings.routes.SYNC, settings.Router.getInstance().getCurrentRoute());
testRoutes.SYNC, settings.Router.getInstance().getCurrentRoute());
const subpage = document.createElement('settings-subpage');
document.body.appendChild(subpage);
......@@ -90,13 +97,13 @@ suite('SettingsSubpage', function() {
test('updates the title of the document when active', function() {
const expectedTitle = 'My Subpage Title';
settings.Router.getInstance().navigateTo(settings.routes.SEARCH);
settings.Router.getInstance().navigateTo(testRoutes.SEARCH);
const subpage = document.createElement('settings-subpage');
subpage.setAttribute('route-path', settings.routes.SEARCH_ENGINES.path);
subpage.setAttribute('route-path', testRoutes.SEARCH_ENGINES.path);
subpage.setAttribute('page-title', expectedTitle);
document.body.appendChild(subpage);
settings.Router.getInstance().navigateTo(settings.routes.SEARCH_ENGINES);
settings.Router.getInstance().navigateTo(testRoutes.SEARCH_ENGINES);
assertEquals(
document.title,
loadTimeData.getStringF('settingsAltPageTitle', expectedTitle));
......
......@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// #import {Router, Route} from 'chrome://settings/settings.js';
cr.define('test_util', function() {
/**
......@@ -202,7 +204,7 @@ cr.define('test_util', function() {
}
}
function setupPopstateListener() {
/* #export */ function setupPopstateListener() {
window.addEventListener('popstate', function(event) {
// On pop state, do not push the state onto the window.history again.
const routerInstance = settings.Router.getInstance();
......@@ -214,6 +216,7 @@ cr.define('test_util', function() {
});
}
// #cr_define_end
return {
createContentSettingTypeToValuePair: createContentSettingTypeToValuePair,
createDefaultContentSetting: createDefaultContentSetting,
......
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