Commit d10652fa authored by Yunke Zhou's avatar Yunke Zhou Committed by Commit Bot

Oobe: refactor DemoPreferencesScreen to use LoginScreenBehavior

Bug: 1132228
Change-Id: I00c0c60ef117afd28aaf2cf10ed1324227552be1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2431425
Commit-Queue: Yunke Zhou <yunkez@google.com>
Reviewed-by: default avatarDenis Kuznetsov [CET] <antrim@chromium.org>
Reviewed-by: default avatarRoman Sorokin [CET] <rsorokin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#811996}
parent 5366cb54
......@@ -258,9 +258,7 @@ IN_PROC_BROWSER_TEST_F(OobeConfigurationTest, TestDemoModeAcceptArcTos) {
test::OobeJS().Evaluate(
"login.ArcTermsOfServiceScreen.setTosForTesting('Test "
"Play Store Terms of Service');");
test::OobeJS().Evaluate(
"$('demo-preferences-content').$$('oobe-dialog')."
"querySelector('oobe-text-button').click();");
test::OobeJS().ClickOnPath({"demo-preferences", "nextButton"});
OobeScreenWaiter(DemoSetupScreenView::kScreenId).Wait();
}
......
......@@ -121,7 +121,7 @@ std::string DialogToStringId(DemoSetupDialog dialog) {
// string if the |screen| is not a part of Demo Mode setup flow.
std::string ScreenToContentQuery(OobeScreenId screen) {
if (screen == DemoPreferencesScreenView::kScreenId)
return "$('demo-preferences-content')";
return "$('demo-preferences')";
if (screen == NetworkScreenView::kScreenId)
return "$('network-selection')";
if (screen == EulaView::kScreenId)
......
......@@ -104,6 +104,7 @@ js_library("arc_terms_of_service") {
js_library("demo_preferences") {
deps = [
"components:login_screen_behavior",
"components:oobe_dialog_host_behavior",
"components:oobe_i18n_behavior",
]
......
......@@ -2,11 +2,11 @@
<link rel="import" href="chrome://resources/polymer/v1_0/paper-styles/color.html">
<link rel="import" href="chrome://resources/polymer/v1_0/iron-icon/iron-icon.html">
<dom-module id="demo-preferences-md">
<dom-module id="demo-preferences">
<template>
<style include="oobe-dialog-host"></style>
<link rel="stylesheet" href="demo_preferences.css">
<oobe-dialog role="dialog" has-buttons
<oobe-dialog id="demoPreferencesDialog" role="dialog" has-buttons
aria-label$="[[i18nDynamic(locale, 'demoPreferencesScreenTitle')]]"
title-key="demoPreferencesScreenTitle">
<hd-iron-icon slot="oobe-icon"
......@@ -49,7 +49,7 @@
</div>
<div slot="bottom-buttons" class="layout horizontal justified">
<oobe-back-button on-click="onBackClicked_"></oobe-back-button>
<oobe-text-button inverse on-tap="onNextClicked_"
<oobe-text-button id="nextButton" inverse on-tap="onNextClicked_"
text-key="demoPreferencesNextButtonLabel"></oobe-text-button>
</div>
</oobe-dialog>
......
......@@ -3,9 +3,11 @@
// found in the LICENSE file.
Polymer({
is: 'demo-preferences-md',
is: 'demo-preferences',
behaviors: [OobeI18nBehavior, OobeDialogHostBehavior],
behaviors: [OobeI18nBehavior, OobeDialogHostBehavior, LoginScreenBehavior],
EXTERNAL_API: ['setSelectedKeyboard'],
properties: {
/**
......@@ -32,17 +34,6 @@ Polymer({
type: Array,
},
/**
* Reference to OOBE screen object.
* @type {!{
* onCountrySelected_: function(string),
* onKeyboardSelected_: function(string),
* onLanguageSelected_: function(string),
* }}
*/
screen: {
type: Object,
},
},
/**
......@@ -51,6 +42,18 @@ Polymer({
*/
configuration_applied_: false,
ready() {
this.initializeLoginScreen('DemoPreferencesScreen', {
resetAllowed: false,
});
this.updateLocalizedContent();
},
/** Returns a control which should receive an initial focus. */
get defaultControl() {
return this.$.demoPreferencesDialog;
},
/** Called when dialog is shown */
onBeforeShow() {
window.setTimeout(this.applyOobeConfiguration_.bind(this), 0);
......@@ -144,7 +147,7 @@ Polymer({
onLanguageSelected_(event) {
var item = event.detail;
var languageId = item.value;
this.screen.onLanguageSelected_(languageId);
chrome.send('DemoPreferencesScreen.setLocaleId', [languageId]);
},
/**
......@@ -155,7 +158,7 @@ Polymer({
onKeyboardSelected_(event) {
var item = event.detail;
var inputMethodId = item.value;
this.screen.onKeyboardSelected_(inputMethodId);
chrome.send('DemoPreferencesScreen.setInputMethodId', [inputMethodId]);
},
/**
......@@ -164,7 +167,8 @@ Polymer({
* @private
*/
onCountrySelected_(event) {
this.screen.onCountrySelected_(event.detail.value);
chrome.send(
'DemoPreferencesScreen.setDemoModeCountry', [event.detail.value]);
},
/**
......@@ -172,7 +176,7 @@ Polymer({
* @private
*/
onBackClicked_() {
chrome.send('login.DemoPreferencesScreen.userActed', ['close-setup']);
this.userActed('close-setup');
},
/**
......@@ -180,7 +184,7 @@ Polymer({
* @private
*/
onNextClicked_() {
chrome.send('login.DemoPreferencesScreen.userActed', ['continue-setup']);
this.userActed('continue-setup');
},
});
......@@ -33,7 +33,6 @@
// <include src="../../gaia_auth_host/authenticator.js">
// <include src="oobe_screen_auto_enrollment_check.js">
// <include src="oobe_screen_demo_preferences.js">
// <include src="oobe_screen_enable_debugging.js">
// <include src="multi_tap_detector.js">
// <include src="web_view_helper.js">
......@@ -54,7 +53,6 @@ cr.define('cr.ui.Oobe', function() {
login.ArcTermsOfServiceScreen.register();
login.AppLaunchSplashScreen.register();
login.FatalErrorScreen.register();
login.DemoPreferencesScreen.register();
login.DiscoverScreen.register();
login.AssistantOptInFlowScreen.register();
login.MultiDeviceSetupScreen.register();
......
<div class="step hidden right" id="demo-preferences" role="group" hidden>
<demo-preferences-md id="demo-preferences-content"></demo-preferences-md>
</div>
// 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.
/**
* @fileoverview Demo mode preferences screen implementation.
*/
login.createScreen('DemoPreferencesScreen', 'demo-preferences', function() {
var demoPreferencesModule = null;
return {
EXTERNAL_API: ['setInputMethodIdFromBackend'],
/** @override */
decorate() {
demoPreferencesModule = $('demo-preferences-content');
demoPreferencesModule.screen = this;
this.updateLocalizedContent();
},
/** Update the current input method. Called from C++. */
setInputMethodIdFromBackend(inputMethodId) {
$('demo-preferences-content').setSelectedKeyboard(inputMethodId);
},
/** Returns a control which should receive an initial focus. */
get defaultControl() {
return demoPreferencesModule;
},
/** Called after resources are updated. */
updateLocalizedContent() {
demoPreferencesModule.updateLocalizedContent();
},
/**
* Called when language was selected.
* @param {string} languageId Id of the selected language.
*/
onLanguageSelected_(languageId) {
chrome.send('DemoPreferencesScreen.setLocaleId', [languageId]);
},
/**
* Called when keyboard was selected.
* @param {string} inputMethodId Id of the selected input method.
*/
onKeyboardSelected_(inputMethodId) {
chrome.send('DemoPreferencesScreen.setInputMethodId', [inputMethodId]);
},
/**
* Called when country was selected.
* @param {string} countryId Id of the selected country.
*/
onCountrySelected_(countryId) {
chrome.send('DemoPreferencesScreen.setDemoModeCountry', [countryId]);
},
};
});
......@@ -17,7 +17,8 @@
<oobe-update id="oobe-update" class="step hidden" hidden>
</oobe-update>
<include src="../oobe_screen_auto_enrollment_check.html">
<include src="../oobe_screen_demo_preferences.html">
<demo-preferences id="demo-preferences" class="step hidden" hidden>
</demo-preferences>
<enterprise-enrollment id="enterprise-enrollment" class="step hidden" hidden>
</enterprise-enrollment>
<packaged-license-screen id="packaged-license" class="step hidden">
......
......@@ -39,8 +39,7 @@ void DemoPreferencesScreenHandler::Bind(DemoPreferencesScreen* screen) {
void DemoPreferencesScreenHandler::SetInputMethodId(
const std::string& input_method) {
CallJS("login.DemoPreferencesScreen.setInputMethodIdFromBackend",
input_method);
CallJS("login.DemoPreferencesScreen.setSelectedKeyboard", input_method);
}
void DemoPreferencesScreenHandler::Initialize() {}
......@@ -59,7 +58,8 @@ void DemoPreferencesScreenHandler::DeclareLocalizedValues(
builder->Add("countryDropdownLabel", IDS_COUNTRY_DROPDOWN_LABEL);
}
void DemoPreferencesScreenHandler::DeclareJSCallbacks() {
void DemoPreferencesScreenHandler::RegisterMessages() {
BaseScreenHandler::RegisterMessages();
AddCallback("DemoPreferencesScreen.setLocaleId",
&DemoPreferencesScreenHandler::HandleSetLocaleId);
AddCallback("DemoPreferencesScreen.setInputMethodId",
......
......@@ -52,7 +52,9 @@ class DemoPreferencesScreenHandler : public BaseScreenHandler,
void Initialize() override;
void DeclareLocalizedValues(
::login::LocalizedValuesBuilder* builder) override;
void DeclareJSCallbacks() override;
// content::WebUIMessageHandler:
void RegisterMessages() override;
private:
void HandleSetLocaleId(const std::string& language_id);
......
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