Commit a416210a authored by Kyle Horimoto's avatar Kyle Horimoto Committed by Commit Bot

[CrOS MultiDevice] Make setup flow WebUI use MultiDeviceSetup service.

Previously, the setup flow used fake data and did not actually perform
setup. This CL integrates the WebUI dialog by:
(1) Adding Mojo bindings to the dialog's WebUIController.
(2) Adds externs for Mojo types to the Closure compiler pass.
(3) Updates WebUI code to use Mojo JS bindings.

Bug: 824568
Cq-Include-Trybots: luci.chromium.try:closure_compilation
Change-Id: I53acbc227b9d965f9337fbbdb84c90e285665745
Reviewed-on: https://chromium-review.googlesource.com/1139222
Commit-Queue: Kyle Horimoto <khorimoto@chromium.org>
Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#578887}
parent 35da6320
...@@ -8,6 +8,7 @@ js_type_check("closure_compile") { ...@@ -8,6 +8,7 @@ js_type_check("closure_compile") {
deps = [ deps = [
":button_bar", ":button_bar",
":fake_mojo_service", ":fake_mojo_service",
":mojo_api_behavior",
":multidevice_setup", ":multidevice_setup",
":multidevice_setup_dialog", ":multidevice_setup_dialog",
":setup_failed_page", ":setup_failed_page",
...@@ -25,18 +26,48 @@ js_library("fake_mojo_service") { ...@@ -25,18 +26,48 @@ js_library("fake_mojo_service") {
deps = [ deps = [
"//ui/webui/resources/js:cr", "//ui/webui/resources/js:cr",
] ]
extra_deps = [
"//chromeos/services/device_sync/public/mojom:mojom_js",
"//chromeos/services/multidevice_setup/public/mojom:mojom_js",
"//mojo/public/mojom/base:base_js",
]
externs_list = [
"$root_gen_dir/chromeos/services/device_sync/public/mojom/device_sync.mojom.externs.js",
"$root_gen_dir/chromeos/services/multidevice_setup/public/mojom/multidevice_setup.mojom.externs.js",
"$root_gen_dir/mojo/public/mojom/base/time.mojom.externs.js",
"$externs_path/mojo.js",
]
}
js_library("mojo_api_behavior") {
} }
js_library("multidevice_setup") { js_library("multidevice_setup") {
deps = [ deps = [
":button_bar", ":button_bar",
":fake_mojo_service", ":fake_mojo_service",
":mojo_api_behavior",
":setup_failed_page", ":setup_failed_page",
":setup_succeeded_page", ":setup_succeeded_page",
":start_setup_page", ":start_setup_page",
":ui_mode", ":ui_mode",
"//ui/webui/resources/js:cr", "//ui/webui/resources/js:cr",
] ]
extra_deps = [
"//chromeos/services/device_sync/public/mojom:mojom_js",
"//chromeos/services/multidevice_setup/public/mojom:mojom_js",
"//mojo/public/mojom/base:base_js",
]
externs_list = [
"$root_gen_dir/chromeos/services/device_sync/public/mojom/device_sync.mojom.externs.js",
"$root_gen_dir/chromeos/services/multidevice_setup/public/mojom/multidevice_setup.mojom.externs.js",
"$root_gen_dir/mojo/public/mojom/base/time.mojom.externs.js",
"$externs_path/mojo.js",
]
} }
js_library("multidevice_setup_dialog") { js_library("multidevice_setup_dialog") {
......
...@@ -2,55 +2,81 @@ ...@@ -2,55 +2,81 @@
// 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.
// TODO(jordynass): Delete these testing utilities when code is productionized. /**
* @implements {chromeos.multideviceSetup.mojom.MultiDeviceSetupImpl}
cr.define('multidevice_setup', function() { */
/** @enum {number} */ class FakeMojoService {
const SetBetterTogetherHostResponseCode = { constructor() {
SUCCESS: 1, /**
ERROR_OFFLINE: 2, * The number of devices to return in a getEligibleHostDevices() call.
ERROR_NETWORK_REQUEST_FAILED: 3, * @type {number}
}; */
this.deviceCount = 2;
class FakeMojoService {
constructor() {
this.deviceCount = 2;
this.responseCode = SetBetterTogetherHostResponseCode.SUCCESS;
this.settingHostInBackground = false;
}
getEligibleBetterTogetherHosts() { /**
const deviceNames = ['Pixel', 'Pixel XL', 'Nexus 5', 'Nexus 6P']; * Whether calls to setHostDevice() should succeed.
let devices = []; * @type {boolean}
for (let i = 0; i < this.deviceCount; i++) { */
const deviceName = deviceNames[i % 4]; this.shouldSetHostSucceed = true;
devices.push({name: deviceName, publicKey: deviceName + '--' + i}); }
}
return new Promise(function(resolve, reject) { /** @override */
resolve({devices: devices}); setAccountStatusChangeDelegate(delegate) {}
});
}
setBetterTogetherHost(publicKey) { /** @override */
if (this.responseCode == SetBetterTogetherHostResponseCode.SUCCESS) { addHostStatusObserver(observer) {}
console.log('Calling SetBetterTogetherHost on device ' + publicKey);
} else { /** @override */
console.warn('Unable to set host. Response code: ' + this.responseCode); getEligibleHostDevices() {
} const deviceNames = ['Pixel', 'Pixel XL', 'Nexus 5', 'Nexus 6P'];
return new Promise((resolve, reject) => { let devices = [];
resolve({responseCode: this.responseCode}); for (let i = 0; i < this.deviceCount; i++) {
}); const deviceName = deviceNames[i % 4];
devices.push({deviceName: deviceName, deviceId: deviceName + '--' + i});
} }
return new Promise(function(resolve, reject) {
resolve({eligibleHostDevices: devices});
});
}
setBetterTogetherHostInBackground(publicKey) { /** @override */
console.log('Setting host in background on device ' + publicKey); setHostDevice(deviceId) {
// For testing purposes only: if (this.shouldSetHostSucceed) {
this.settingHostInBackground = true; console.log(
'setHostDevice(' + deviceId + ') called; simulating ' +
'success.');
} else {
console.warn('setHostDevice() called; simulating failure.');
} }
return new Promise((resolve, reject) => {
resolve({success: this.shouldSetHostSucceed});
});
} }
return { /** @override */
SetBetterTogetherHostResponseCode: SetBetterTogetherHostResponseCode, removeHostDevice() {
FakeMojoService: FakeMojoService, // Unimplemented; never called from setup flow.
}; assertNotReached();
}); }
/** @override */
getHostStatus() {
return new Promise((resolve, reject) => {
reject('Unimplemented; never called from setup flow.');
});
}
/** @override */
retrySetHostNow() {
return new Promise((resolve, reject) => {
reject('Unimplemented; never called from setup flow.');
});
}
/** @override */
triggerEventForDebugging(type) {
return new Promise((resolve, reject) => {
reject('Unimplemented; never called from setup flow.');
});
}
}
<link rel="import" href="chrome://resources/html/cr.html">
<script src="chrome://resources/js/mojo_bindings.js"></script>
</script>
<script src="mojo/public/mojom/base/time.mojom.js"></script>
<script src="chromeos/services/device_sync/public/mojom/device_sync.mojom.js">
</script>
<script src="chromeos/services/multidevice_setup/public/mojom/multidevice_setup.mojom.js">
</script>
<script src="chromeos/services/multidevice_setup/public/mojom/multidevice_setup_constants.mojom.js">
</script>
<script src="mojo_api_behavior.js"></script>
// 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.
/** @polymerBehavior */
const MojoApiBehavior = {
properties: {
/**
* Provides access to the MultiDeviceSetup Mojo service.
* @type {!chromeos.multideviceSetup.mojom.MultiDeviceSetupImpl}
*/
multideviceSetup: {
type: Object,
value: function() {
let ptr = new chromeos.multideviceSetup.mojom.MultiDeviceSetupPtr();
Mojo.bindInterface(
chromeos.multideviceSetup.mojom.MultiDeviceSetup.name,
mojo.makeRequest(ptr).handle);
return ptr;
},
}
},
};
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
<link rel="import" href="button_bar.html"> <link rel="import" href="button_bar.html">
<link rel="import" href="fake_mojo_service.html"> <link rel="import" href="fake_mojo_service.html">
<link rel="import" href="i18n_setup.html"> <link rel="import" href="i18n_setup.html">
<link rel="import" href="mojo_api_behavior.html">
<link rel="import" href="setup_failed_page.html"> <link rel="import" href="setup_failed_page.html">
<link rel="import" href="setup_succeeded_page.html"> <link rel="import" href="setup_succeeded_page.html">
<link rel="import" href="start_setup_page.html"> <link rel="import" href="start_setup_page.html">
...@@ -30,7 +31,7 @@ ...@@ -30,7 +31,7 @@
<setup-failed-page></setup-failed-page> <setup-failed-page></setup-failed-page>
<setup-succeeded-page></setup-succeeded-page> <setup-succeeded-page></setup-succeeded-page>
<start-setup-page devices="[[devices_]]" <start-setup-page devices="[[devices_]]"
selected-public-key="{{selectedPublicKey_}}"> selected-device-id="{{selectedDeviceId_}}">
</start-setup-page> </start-setup-page>
</iron-pages> </iron-pages>
<button-bar forward-button-text="[[visiblePage_.forwardButtonText]]" <button-bar forward-button-text="[[visiblePage_.forwardButtonText]]"
......
...@@ -46,40 +46,45 @@ cr.define('multidevice_setup', function() { ...@@ -46,40 +46,45 @@ cr.define('multidevice_setup', function() {
visiblePage_: Object, visiblePage_: Object,
/** /**
* Array of objects representing all available MultiDevice hosts. Each * Array of objects representing all potential MultiDevice hosts.
* object contains the name of the device type (e.g. "Pixel XL") and its
* public key.
* *
* @private {Array<{name: string, publicKey: string}>} * @private {!Array<!chromeos.deviceSync.mojom.RemoteDevice>}
*/ */
devices_: Array, devices_: Array,
/** /**
* Public key for the currently selected host device. * Unique identifier for the currently selected host device.
* *
* Undefined if the no list of potential hosts has been received from mojo * Undefined if the no list of potential hosts has been received from mojo
* service. * service.
* *
* @private {string|undefined} * @private {string|undefined}
*/ */
selectedPublicKey_: String, selectedDeviceId_: String,
}, },
behaviors: [
MojoApiBehavior,
],
listeners: { listeners: {
'backward-navigation-requested': 'onBackwardNavigationRequested_', 'backward-navigation-requested': 'onBackwardNavigationRequested_',
'forward-navigation-requested': 'onForwardNavigationRequested_', 'forward-navigation-requested': 'onForwardNavigationRequested_',
}, },
ready: function() { /** @override */
this.mojoService_.getEligibleBetterTogetherHosts() attached: function() {
this.multideviceSetup.getEligibleHostDevices()
.then((responseParams) => { .then((responseParams) => {
if (responseParams['devices'].length >= 1) if (responseParams.eligibleHostDevices.length == 0) {
this.devices_ = responseParams['devices'];
else
console.warn('Potential host list is empty.'); console.warn('Potential host list is empty.');
return;
}
this.devices_ = responseParams.eligibleHostDevices;
}) })
.catch((error) => { .catch((error) => {
console.warn('Potential host list was not retrieved. ' + error); console.warn('Mojo service failure: ' + error);
}); });
}, },
...@@ -98,16 +103,28 @@ cr.define('multidevice_setup', function() { ...@@ -98,16 +103,28 @@ cr.define('multidevice_setup', function() {
this.exitSetupFlow_(); this.exitSetupFlow_();
return; return;
case PageName.START: case PageName.START:
switch (this.uiMode) { let deviceId = /** @type {string} */ (this.selectedDeviceId_);
case multidevice_setup.UiMode.OOBE: this.multideviceSetup.setHostDevice(deviceId)
this.mojoService_.setBetterTogetherHostInBackground( .then((responseParams) => {
this.selectedPublicKey_); if (!responseParams.success) {
this.exitSetupFlow_(); console.warn(
return; 'Failure setting device with device ID: ' +
case multidevice_setup.UiMode.POST_OOBE: this.selectedDeviceId_);
this.attemptToSetHostPostOobe_(); return;
return; }
}
switch (this.uiMode) {
case multidevice_setup.UiMode.OOBE:
this.exitSetupFlow_();
return;
case multidevice_setup.UiMode.POST_OOBE:
this.visiblePageName_ = PageName.SUCCESS;
return;
}
})
.catch((error) => {
console.warn('Mojo service failure: ' + error);
});
} }
}, },
...@@ -120,38 +137,6 @@ cr.define('multidevice_setup', function() { ...@@ -120,38 +137,6 @@ cr.define('multidevice_setup', function() {
console.log('Exiting Setup Flow'); console.log('Exiting Setup Flow');
this.fire('setup-exited'); this.fire('setup-exited');
}, },
/**
* Tries to set the device corresponding to the selected public key as the
* user's Better Together host and navigates the UI to the success or
* failure page depending on the response.
*
* @private
*/
attemptToSetHostPostOobe_: function() {
assert(this.uiMode == multidevice_setup.UiMode.POST_OOBE);
this.mojoService_.setBetterTogetherHost(this.selectedPublicKey_)
.then((responseParams) => {
if (responseParams['responseCode'] ==
multidevice_setup.SetBetterTogetherHostResponseCode.SUCCESS) {
this.visiblePageName_ = PageName.SUCCESS;
} else {
this.visiblePageName_ = PageName.FAILURE;
}
})
.catch((error) => {
console.warn('Mojo service failure. ' + error);
});
},
/**
* Fake Mojo Service to substitute for MultiDeviceSetup mojo service.
*
* @private
*/
// TODO(jordynass): Once mojo API is complete, make this into a real
// multidevice setup mojo service object and annotate it with that type.
mojoService_: new multidevice_setup.FakeMojoService(),
}); });
return { return {
......
...@@ -30,6 +30,12 @@ ...@@ -30,6 +30,12 @@
<structure name="IDR_MULTIDEVICE_SETUP_ICONS_HTML" <structure name="IDR_MULTIDEVICE_SETUP_ICONS_HTML"
file="icons.html" file="icons.html"
type="chrome_html" /> type="chrome_html" />
<structure name="IDR_MULTIDEVICE_SETUP_MOJO_API_BEHAVIOR_HTML"
file="mojo_api_behavior.html"
type="chrome_html" />
<structure name="IDR_MULTIDEVICE_SETUP_MOJO_API_BEHAVIOR_JS"
file="mojo_api_behavior.js"
type="chrome_html" />
<structure name="IDR_MULTIDEVICE_SETUP_MULTIDEVICE_SETUP_DIALOG_HTML" <structure name="IDR_MULTIDEVICE_SETUP_MULTIDEVICE_SETUP_DIALOG_HTML"
file="multidevice_setup_dialog.html" file="multidevice_setup_dialog.html"
flattenhtml="true" flattenhtml="true"
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
<dom-module id="start-setup-page"> <dom-module id="start-setup-page">
<template> <template>
<style include="iron-flex multidevice-setup-shared"> <style include="iron-flex multidevice-setup-shared">
#content-container { #selector-and-details-container {
@apply(--layout-horizontal); @apply(--layout-horizontal);
color: rgb(33, 33, 36); color: rgb(33, 33, 36);
font-family: Roboto-Regular, Roboto, sans-serif; font-family: Roboto-Regular, Roboto, sans-serif;
...@@ -66,7 +66,7 @@ ...@@ -66,7 +66,7 @@
<ui-page header-text="[[headerText]]" icon-name="google-g"> <ui-page header-text="[[headerText]]" icon-name="google-g">
<span slot="message" inner-h-t-m-l="[[messageHtml]]"></span> <span slot="message" inner-h-t-m-l="[[messageHtml]]"></span>
<div slot="additional-content"> <div slot="additional-content">
<div id="content-container"> <div id="selector-and-details-container">
<div class="flex"> <div class="flex">
[[getDeviceSelectionHeader_(devices)]] [[getDeviceSelectionHeader_(devices)]]
<div class="flex"></div> <div class="flex"></div>
...@@ -77,8 +77,8 @@ ...@@ -77,8 +77,8 @@
<select id="deviceDropdown" <select id="deviceDropdown"
on-change="onDeviceDropdownSelectionChanged_"> on-change="onDeviceDropdownSelectionChanged_">
<template is="dom-repeat" items="[[devices]]"> <template is="dom-repeat" items="[[devices]]">
<option value$="[[item.publicKey]]"> <option value$="[[item.deviceId]]">
[[item.name]] [[item.deviceName]]
</option> </option>
</template> </template>
</select> </select>
......
...@@ -31,11 +31,9 @@ Polymer({ ...@@ -31,11 +31,9 @@ Polymer({
}, },
/** /**
* Array of objects representing all available MultiDevice hosts. Each * Array of objects representing all potential MultiDevice hosts.
* object contains the name of the device type (e.g. "Pixel XL") and its
* public key.
* *
* @type {!Array<{name: string, publicKey: string}>} * @type {!Array<!chromeos.deviceSync.mojom.RemoteDevice>}
*/ */
devices: { devices: {
type: Array, type: Array,
...@@ -44,14 +42,14 @@ Polymer({ ...@@ -44,14 +42,14 @@ Polymer({
}, },
/** /**
* Public key for the currently selected host device. * Unique identifier for the currently selected host device.
* *
* Undefined if the no list of potential hosts has been received from mojo * Undefined if the no list of potential hosts has been received from mojo
* service. * service.
* *
* @type {string|undefined} * @type {string|undefined}
*/ */
selectedPublicKey: { selectedDeviceId: {
type: String, type: String,
notify: true, notify: true,
}, },
...@@ -63,7 +61,7 @@ Polymer({ ...@@ -63,7 +61,7 @@ Polymer({
], ],
/** /**
* @param {!Array<{name: string, publicKey: string}>} devices Device list. * @param {!Array<!chromeos.deviceSync.mojom.RemoteDevice>} devices
* @return {string} Label for devices selection content. * @return {string} Label for devices selection content.
* @private * @private
*/ */
...@@ -79,7 +77,7 @@ Polymer({ ...@@ -79,7 +77,7 @@ Polymer({
}, },
/** /**
* @param {!Array<{name: string, publicKey: string}>} devices Device list. * @param {!Array<!chromeos.deviceSync.mojom.RemoteDevice>} devices
* @return {boolean} True if there are more than one potential host devices. * @return {boolean} True if there are more than one potential host devices.
* @private * @private
*/ */
...@@ -88,7 +86,7 @@ Polymer({ ...@@ -88,7 +86,7 @@ Polymer({
}, },
/** /**
* @param {!Array<{name: string, publicKey: string}>} devices Device list. * @param {!Array<!chromeos.deviceSync.mojom.RemoteDevice>} devices
* @return {boolean} True if there is exactly one potential host device. * @return {boolean} True if there is exactly one potential host device.
* @private * @private
*/ */
...@@ -97,23 +95,23 @@ Polymer({ ...@@ -97,23 +95,23 @@ Polymer({
}, },
/** /**
* @param {!Array<{name: string, publicKey: string}>} devices Device list. * @param {!Array<!chromeos.deviceSync.mojom.RemoteDevice>} devices
* @return {string} Name of the first device in device list if there are any. * @return {string} Name of the first device in device list if there are any.
* Returns an empty string otherwise. * Returns an empty string otherwise.
* @private * @private
*/ */
getFirstDeviceNameInList_: function(devices) { getFirstDeviceNameInList_: function(devices) {
return devices[0] ? this.devices[0].name : ''; return devices[0] ? this.devices[0].deviceName : '';
}, },
/** @private */ /** @private */
devicesChanged_: function() { devicesChanged_: function() {
if (this.devices.length > 0) if (this.devices.length > 0)
this.selectedPublicKey = this.devices[0].publicKey; this.selectedDeviceId = this.devices[0].deviceId;
}, },
/** @private */ /** @private */
onDeviceDropdownSelectionChanged_: function() { onDeviceDropdownSelectionChanged_: function() {
this.selectedPublicKey = this.$.deviceDropdown.value; this.selectedDeviceId = this.$.deviceDropdown.value;
}, },
}); });
...@@ -2195,8 +2195,10 @@ jumbo_split_static_library("ui") { ...@@ -2195,8 +2195,10 @@ jumbo_split_static_library("ui") {
"//chromeos/components/proximity_auth/logging", "//chromeos/components/proximity_auth/logging",
"//chromeos/components/proximity_auth/webui", "//chromeos/components/proximity_auth/webui",
"//chromeos/components/tether", "//chromeos/components/tether",
"//chromeos/resources:resources_grit",
"//chromeos/services/assistant/public/mojom", "//chromeos/services/assistant/public/mojom",
"//chromeos/services/assistant/public/proto:proto", "//chromeos/services/assistant/public/proto:proto",
"//chromeos/services/multidevice_setup/public/mojom",
"//components/arc", "//components/arc",
"//components/captive_portal", "//components/captive_portal",
"//components/consent_auditor:consent_auditor", "//components/consent_auditor:consent_auditor",
......
...@@ -10,9 +10,12 @@ ...@@ -10,9 +10,12 @@
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "chrome/grit/multidevice_setup_resources.h" #include "chrome/grit/multidevice_setup_resources.h"
#include "chrome/grit/multidevice_setup_resources_map.h" #include "chrome/grit/multidevice_setup_resources_map.h"
#include "chromeos/grit/chromeos_resources.h"
#include "chromeos/services/multidevice_setup/public/mojom/constants.mojom.h"
#include "components/strings/grit/components_strings.h" #include "components/strings/grit/components_strings.h"
#include "content/public/browser/web_ui.h" #include "content/public/browser/web_ui.h"
#include "content/public/browser/web_ui_data_source.h" #include "content/public/browser/web_ui_data_source.h"
#include "services/service_manager/public/cpp/connector.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
namespace chromeos { namespace chromeos {
...@@ -114,7 +117,7 @@ void MultiDeviceSetupDialog::OnDialogClosed(const std::string& json_retval) { ...@@ -114,7 +117,7 @@ void MultiDeviceSetupDialog::OnDialogClosed(const std::string& json_retval) {
} }
MultiDeviceSetupDialogUI::MultiDeviceSetupDialogUI(content::WebUI* web_ui) MultiDeviceSetupDialogUI::MultiDeviceSetupDialogUI(content::WebUI* web_ui)
: ui::WebDialogUI(web_ui) { : ui::MojoWebDialogUI(web_ui) {
content::WebUIDataSource* source = content::WebUIDataSource* source =
content::WebUIDataSource::Create(chrome::kChromeUIMultiDeviceSetupHost); content::WebUIDataSource::Create(chrome::kChromeUIMultiDeviceSetupHost);
...@@ -122,6 +125,19 @@ MultiDeviceSetupDialogUI::MultiDeviceSetupDialogUI(content::WebUI* web_ui) ...@@ -122,6 +125,19 @@ MultiDeviceSetupDialogUI::MultiDeviceSetupDialogUI(content::WebUI* web_ui)
source->SetJsonPath("strings.js"); source->SetJsonPath("strings.js");
source->SetDefaultResource( source->SetDefaultResource(
IDR_MULTIDEVICE_SETUP_MULTIDEVICE_SETUP_DIALOG_HTML); IDR_MULTIDEVICE_SETUP_MULTIDEVICE_SETUP_DIALOG_HTML);
source->AddResourcePath("mojo/public/mojom/base/time.mojom.js",
IDR_TIME_MOJOM_JS);
source->AddResourcePath(
"chromeos/services/device_sync/public/mojom/device_sync.mojom.js",
IDR_DEVICE_SYNC_MOJOM_JS);
source->AddResourcePath(
"chromeos/services/multidevice_setup/public/mojom/"
"multidevice_setup.mojom.js",
IDR_MULTIDEVICE_SETUP_MOJOM_JS);
source->AddResourcePath(
"chromeos/services/multidevice_setup/public/mojom/"
"multidevice_setup_constants.mojom.js",
IDR_MULTIDEVICE_SETUP_CONSTANTS_MOJOM_JS);
// Note: The |kMultiDeviceSetupResourcesSize| and |kMultideviceSetupResources| // Note: The |kMultiDeviceSetupResourcesSize| and |kMultideviceSetupResources|
// fields are defined in the generated file // fields are defined in the generated file
...@@ -132,10 +148,25 @@ MultiDeviceSetupDialogUI::MultiDeviceSetupDialogUI(content::WebUI* web_ui) ...@@ -132,10 +148,25 @@ MultiDeviceSetupDialogUI::MultiDeviceSetupDialogUI(content::WebUI* web_ui)
} }
content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), source); content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), source);
// Add Mojo bindings to this WebUI so that Mojo calls can occur in JavaScript.
AddHandlerToRegistry(base::BindRepeating(
&MultiDeviceSetupDialogUI::BindMultiDeviceSetup, base::Unretained(this)));
} }
MultiDeviceSetupDialogUI::~MultiDeviceSetupDialogUI() = default; MultiDeviceSetupDialogUI::~MultiDeviceSetupDialogUI() = default;
void MultiDeviceSetupDialogUI::BindMultiDeviceSetup(
chromeos::multidevice_setup::mojom::MultiDeviceSetupRequest request) {
service_manager::Connector* connector =
content::BrowserContext::GetConnectorFor(
web_ui()->GetWebContents()->GetBrowserContext());
DCHECK(connector);
connector->BindInterface(chromeos::multidevice_setup::mojom::kServiceName,
std::move(request));
}
} // namespace multidevice_setup } // namespace multidevice_setup
} // namespace chromeos } // namespace chromeos
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "chrome/browser/ui/webui/chromeos/system_web_dialog_delegate.h" #include "chrome/browser/ui/webui/chromeos/system_web_dialog_delegate.h"
#include "chromeos/services/multidevice_setup/public/mojom/multidevice_setup.mojom.h"
#include "ui/web_dialogs/web_dialog_ui.h" #include "ui/web_dialogs/web_dialog_ui.h"
namespace chromeos { namespace chromeos {
...@@ -38,12 +39,15 @@ class MultiDeviceSetupDialog : public SystemWebDialogDelegate { ...@@ -38,12 +39,15 @@ class MultiDeviceSetupDialog : public SystemWebDialogDelegate {
DISALLOW_COPY_AND_ASSIGN(MultiDeviceSetupDialog); DISALLOW_COPY_AND_ASSIGN(MultiDeviceSetupDialog);
}; };
class MultiDeviceSetupDialogUI : public ui::WebDialogUI { class MultiDeviceSetupDialogUI : public ui::MojoWebDialogUI {
public: public:
explicit MultiDeviceSetupDialogUI(content::WebUI* web_ui); explicit MultiDeviceSetupDialogUI(content::WebUI* web_ui);
~MultiDeviceSetupDialogUI() override; ~MultiDeviceSetupDialogUI() override;
private: private:
void BindMultiDeviceSetup(
chromeos::multidevice_setup::mojom::MultiDeviceSetupRequest request);
DISALLOW_COPY_AND_ASSIGN(MultiDeviceSetupDialogUI); DISALLOW_COPY_AND_ASSIGN(MultiDeviceSetupDialogUI);
}; };
......
...@@ -107,7 +107,6 @@ js2gtest("browser_tests_js_webui") { ...@@ -107,7 +107,6 @@ js2gtest("browser_tests_js_webui") {
if (is_chromeos) { if (is_chromeos) {
sources += [ sources += [
"certificate_viewer_dialog_test.js", "certificate_viewer_dialog_test.js",
"multidevice_setup/multidevice_setup_browsertest.js",
"settings/easy_unlock_browsertest_chromeos.js", "settings/easy_unlock_browsertest_chromeos.js",
"sys_internals/sys_internals_browsertest.js", "sys_internals/sys_internals_browsertest.js",
] ]
...@@ -156,6 +155,10 @@ js2gtest("browser_tests_js_mojo_webui") { ...@@ -156,6 +155,10 @@ js2gtest("browser_tests_js_mojo_webui") {
sources += [ "discards/discards_browsertest.js" ] sources += [ "discards/discards_browsertest.js" ]
} }
if (is_chromeos) {
sources += [ "multidevice_setup/multidevice_setup_browsertest.js" ]
}
deps = [ deps = [
"//chrome/browser/ui", "//chrome/browser/ui",
"//skia", "//skia",
......
file://chromeos/services/multidevice_setup/OWNERS
...@@ -28,20 +28,12 @@ cr.define('multidevice_setup', () => { ...@@ -28,20 +28,12 @@ cr.define('multidevice_setup', () => {
const SUCCESS = 'setup-succeeded-page'; const SUCCESS = 'setup-succeeded-page';
const START = 'start-setup-page'; const START = 'start-setup-page';
// This is a safety check because it is easy to lost track of parameters.
let verifySetupParameters = function(uiMode, mojoResponseCode) {
assertEquals(multiDeviceSetupElement.uiMode, uiMode);
assertEquals(
multiDeviceSetupElement.mojoService_.responseCode,
mojoResponseCode);
};
setup(() => { setup(() => {
multiDeviceSetupElement = document.createElement('multidevice-setup'); multiDeviceSetupElement = document.createElement('multidevice-setup');
document.body.appendChild(multiDeviceSetupElement); multiDeviceSetupElement.multideviceSetup = new FakeMojoService();
multiDeviceSetupElement.mojoService_ =
new multidevice_setup.FakeMojoService();
multiDeviceSetupElement.uiMode = multidevice_setup.UiMode.POST_OOBE; multiDeviceSetupElement.uiMode = multidevice_setup.UiMode.POST_OOBE;
document.body.appendChild(multiDeviceSetupElement);
forwardButton = forwardButton =
multiDeviceSetupElement.$$('button-bar /deep/ #forward'); multiDeviceSetupElement.$$('button-bar /deep/ #forward');
backwardButton = backwardButton =
...@@ -79,14 +71,11 @@ cr.define('multidevice_setup', () => { ...@@ -79,14 +71,11 @@ cr.define('multidevice_setup', () => {
test('StartSetupPage backward button continues OOBE (OOBE)', done => { test('StartSetupPage backward button continues OOBE (OOBE)', done => {
multiDeviceSetupElement.addEventListener('setup-exited', () => { multiDeviceSetupElement.addEventListener('setup-exited', () => {
assertFalse(
multiDeviceSetupElement.mojoService_.settingHostInBackground);
done(); done();
}); });
multiDeviceSetupElement.visiblePageName_ = START; multiDeviceSetupElement.visiblePageName_ = START;
multiDeviceSetupElement.mojoService_.responseCode = multiDeviceSetupElement.multideviceSetup.shouldSetHostSucceed = true;
multidevice_setup.SetBetterTogetherHostResponseCode.SUCCESS;
multiDeviceSetupElement.uiMode = multidevice_setup.UiMode.OOBE; multiDeviceSetupElement.uiMode = multidevice_setup.UiMode.OOBE;
backwardButton.click(); backwardButton.click();
...@@ -97,14 +86,12 @@ cr.define('multidevice_setup', () => { ...@@ -97,14 +86,12 @@ cr.define('multidevice_setup', () => {
'continues OOBE (OOBE).', 'continues OOBE (OOBE).',
done => { done => {
multiDeviceSetupElement.addEventListener('setup-exited', () => { multiDeviceSetupElement.addEventListener('setup-exited', () => {
assertTrue(
multiDeviceSetupElement.mojoService_.settingHostInBackground);
done(); done();
}); });
multiDeviceSetupElement.visiblePageName_ = START; multiDeviceSetupElement.visiblePageName_ = START;
multiDeviceSetupElement.mojoService_.responseCode = multiDeviceSetupElement.multideviceSetup.shouldSetHostSucceed =
multidevice_setup.SetBetterTogetherHostResponseCode.SUCCESS; true;
multiDeviceSetupElement.uiMode = multidevice_setup.UiMode.OOBE; multiDeviceSetupElement.uiMode = multidevice_setup.UiMode.OOBE;
forwardButton.click(); forwardButton.click();
...@@ -116,8 +103,7 @@ cr.define('multidevice_setup', () => { ...@@ -116,8 +103,7 @@ cr.define('multidevice_setup', () => {
multiDeviceSetupElement.addEventListener('setup-exited', () => done()); multiDeviceSetupElement.addEventListener('setup-exited', () => done());
multiDeviceSetupElement.visiblePageName_ = START; multiDeviceSetupElement.visiblePageName_ = START;
multiDeviceSetupElement.mojoService_.responseCode = multiDeviceSetupElement.multideviceSetup.shouldSetHostSucceed = true;
multidevice_setup.SetBetterTogetherHostResponseCode.SUCCESS;
multiDeviceSetupElement.uiMode = multidevice_setup.UiMode.POST_OOBE; multiDeviceSetupElement.uiMode = multidevice_setup.UiMode.POST_OOBE;
backwardButton.click(); backwardButton.click();
...@@ -135,28 +121,8 @@ cr.define('multidevice_setup', () => { ...@@ -135,28 +121,8 @@ cr.define('multidevice_setup', () => {
}); });
multiDeviceSetupElement.visiblePageName_ = START; multiDeviceSetupElement.visiblePageName_ = START;
multiDeviceSetupElement.mojoService_.responseCode = multiDeviceSetupElement.multideviceSetup.shouldSetHostSucceed =
multidevice_setup.SetBetterTogetherHostResponseCode.SUCCESS; true;
multiDeviceSetupElement.uiMode = multidevice_setup.UiMode.POST_OOBE;
forwardButton.click();
});
test(
'StartSetupPage forward button goes to failure page if mojo fails' +
'(post-OOBE)',
done => {
multiDeviceSetupElement.addEventListener(
'visible-page-name_-changed', () => {
if (multiDeviceSetupElement.$$('iron-pages > .iron-selected')
.is == FAILURE)
done();
});
multiDeviceSetupElement.visiblePageName_ = START;
multiDeviceSetupElement.mojoService_.responseCode =
multidevice_setup.SetBetterTogetherHostResponseCode
.ERROR_NETWORK_REQUEST_FAILED;
multiDeviceSetupElement.uiMode = multidevice_setup.UiMode.POST_OOBE; multiDeviceSetupElement.uiMode = multidevice_setup.UiMode.POST_OOBE;
forwardButton.click(); forwardButton.click();
......
...@@ -15,8 +15,6 @@ cr.define('multidevice_setup', () => { ...@@ -15,8 +15,6 @@ cr.define('multidevice_setup', () => {
*/ */
let setupSucceededPageElement; let setupSucceededPageElement;
const SUCCESS = 'setup-succeeded-page';
setup(() => { setup(() => {
setupSucceededPageElement = setupSucceededPageElement =
document.createElement('setup-succeeded-page'); document.createElement('setup-succeeded-page');
......
...@@ -32,9 +32,9 @@ cr.define('multidevice_setup', () => { ...@@ -32,9 +32,9 @@ cr.define('multidevice_setup', () => {
const START = 'start-setup-page'; const START = 'start-setup-page';
const DEVICES = [ const DEVICES = [
{name: 'Pixel XL', publicKey: 'abcdxl'}, {deviceName: 'Pixel XL', deviceId: 'abcdxl'},
{name: 'Nexus 6P', publicKey: 'PpPpPp'}, {deviceName: 'Nexus 6P', deviceId: 'PpPpPp'},
{name: 'Nexus 5', publicKey: '12345'}, {deviceName: 'Nexus 5', deviceId: '12345'},
]; ];
setup(() => { setup(() => {
...@@ -63,18 +63,18 @@ cr.define('multidevice_setup', () => { ...@@ -63,18 +63,18 @@ cr.define('multidevice_setup', () => {
startSetupPageElement.querySelectorAll('* /deep/ option') startSetupPageElement.querySelectorAll('* /deep/ option')
.length, .length,
DEVICES.length); DEVICES.length);
assertEquals(startSetupPageElement.selectedPublicKey, 'abcdxl'); assertEquals(startSetupPageElement.selectedDeviceId, 'abcdxl');
}); });
test( test(
'selectedPublicKey changes when dropdown options are selected', 'selectedDeviceId changes when dropdown options are selected',
() => { () => {
selectOptionByTextContent('Nexus 6P'); selectOptionByTextContent('Nexus 6P');
assertEquals(startSetupPageElement.selectedPublicKey, 'PpPpPp'); assertEquals(startSetupPageElement.selectedDeviceId, 'PpPpPp');
selectOptionByTextContent('Nexus 5'); selectOptionByTextContent('Nexus 5');
assertEquals(startSetupPageElement.selectedPublicKey, '12345'); assertEquals(startSetupPageElement.selectedDeviceId, '12345');
selectOptionByTextContent('Pixel XL'); selectOptionByTextContent('Pixel XL');
assertEquals(startSetupPageElement.selectedPublicKey, 'abcdxl'); assertEquals(startSetupPageElement.selectedDeviceId, 'abcdxl');
}); });
}); });
} }
......
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