Commit 4ade9400 authored by Jordy Greenblatt's avatar Jordy Greenblatt Committed by Commit Bot

[CrOS MultiDevice] Prepare settings UI infrastrcture for feature data.

This CL replaces some data types we had thought would be important for
displaying the multidevice settings page that wound up being redundant
with the data types we will need to receive individual feature updates
from the multidevice service.

Bug: 824568
Change-Id: I33b70cba332dec8cf7726630ccbf57bcf62b8655
Reviewed-on: https://chromium-review.googlesource.com/1173658
Commit-Queue: Kyle Horimoto <khorimoto@chromium.org>
Reviewed-by: default avatarHector Carmona <hcarmona@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#583724}
parent d6570450
...@@ -19,70 +19,47 @@ cr.define('settings', function() { ...@@ -19,70 +19,47 @@ cr.define('settings', function() {
}; };
/** /**
* MultiDevice software features. Note that this is copied from (and must * Possible states of MultiDevice features. Note that this is copied from (and
* include an analog of all values in) the enum of the same name in * must include an analog of all values in) the FeatureState enum in
* //components/cryptauth/proto/cryptauth_api.proto. * //chromeos/services/multidevice_setup/public/mojom/multidevice_setup.mojom.
* @enum {number} * @enum {number}
*/ */
MultiDeviceSoftwareFeature = { MultiDeviceFeatureState = {
UNKNOWN_FEATURE: 0, DISABLED_BY_POLICY: 0,
BETTER_TOGETHER_HOST: 1, DISABLED_BY_USER: 1,
BETTER_TOGETHER_CLIENT: 2, ENABLED_BY_USER: 2,
EASY_UNLOCK_HOST: 3, NOT_SUPPORTED_BY_CHROMEBOOK: 3,
EASY_UNLOCK_CLIENT: 4, NOT_SUPPORTED_BY_PHONE: 4,
MAGIC_TETHER_HOST: 5, UNAVAILABLE_NO_VERIFIED_HOST: 5,
MAGIC_TETHER_CLIENT: 6, UNAVAILABLE_INSUFFICIENT_SECURITY: 6,
SMS_CONNECT_HOST: 7,
SMS_CONNECT_CLIENT: 8,
};
/**
* Possible states of MultiDevice software features. Note that this is based
* on (and must include an analog of all values in) the enum of the same name
* in //components/cryptauth/software_feature_state.h.
* @enum {number}
*/
MultiDeviceSoftwareFeatureState = {
NOT_SUPPORTED: 0,
SUPPORTED: 1,
ENABLED: 2,
}; };
return { return {
MultiDeviceSettingsMode: MultiDeviceSettingsMode, MultiDeviceSettingsMode: MultiDeviceSettingsMode,
MultiDeviceSoftwareFeature: MultiDeviceSoftwareFeature, MultiDeviceFeatureState: MultiDeviceFeatureState,
MultiDeviceSoftwareFeatureState: MultiDeviceSoftwareFeatureState,
}; };
}); });
/**
* Represents a multidevice host, i.e. a phone set by the user to connect to
* their Chromebook(s). The type is a subset of the RemoteDevice structure
* defined by CryptAuth (components/cryptauth/remote_device.h). It contains the
* host device's name (e.g. Pixel, Nexus 5) and the map softwareFeatures
* sending each MultiDevice feature to the host device's state with regards to
* that feature.
*
* @typedef {{
* name: string,
* softwareFeatures:
* !Object<settings.MultiDeviceSoftwareFeature,
* settings.MultiDeviceSoftwareFeatureState>
* }}
*/
let RemoteDevice;
/** /**
* Container for the initial data that the page requires in order to display * Container for the initial data that the page requires in order to display
* the correct content. It is also used for receiving status updates during * the correct content. It is also used for receiving status updates during
* use. Note that the host may be verified (enabled or disabled), awaiting * use. Note that the host device may be verified (enabled or disabled),
* verification, or it may have failed setup because it was not able to connect * awaiting verification, or it may have failed setup because it was not able
* to the server. If the property is null or undefined, then no host has been * to connect to the server.
* set up, although there may be potential hosts on the account. *
* For each MultiDevice feature (including the "suite" feature, which acts as a
* gatekeeper for the others), the corresponding *State property is an enum
* containing the data necessary to display it. Note that hostDeviceName should
* be undefined if and only if no host has been set up, regardless of whether
* there are potential hosts on the account.
* *
* @typedef {{ * @typedef {{
* mode: !settings.MultiDeviceSettingsMode, * mode: !settings.MultiDeviceSettingsMode,
* hostDevice: (RemoteDevice|undefined) * hostDeviceName: (string|undefined),
* betterTogetherState: !settings.MultiDeviceFeatureState,
* instantTetheringState: !settings.MultiDeviceFeatureState,
* messagesState: !settings.MultiDeviceFeatureState,
* smartLockState: !settings.MultiDeviceFeatureState,
* }} * }}
*/ */
let MultiDevicePageContentData; let MultiDevicePageContentData;
...@@ -58,7 +58,7 @@ ...@@ -58,7 +58,7 @@
</neon-animatable> </neon-animatable>
<template is="dom-if" route-path="/multidevice/features"> <template is="dom-if" route-path="/multidevice/features">
<settings-subpage associated-control="[[$$('#multidevice-item')]]" <settings-subpage associated-control="[[$$('#multidevice-item')]]"
page-title="[[pageContentData.hostDevice.name]]"> page-title="[[pageContentData.hostDeviceName]]">
<settings-multidevice-subpage prefs="{{prefs}}" <settings-multidevice-subpage prefs="{{prefs}}"
page-content-data="[[pageContentData]]"> page-content-data="[[pageContentData]]">
</settings-multidevice-subpage> </settings-multidevice-subpage>
......
...@@ -49,8 +49,7 @@ Polymer({ ...@@ -49,8 +49,7 @@ Polymer({
* @private * @private
*/ */
getLabelText_: function() { getLabelText_: function() {
return !!this.pageContentData.hostDevice ? return this.pageContentData.hostDeviceName ||
this.pageContentData.hostDevice.name :
this.i18n('multideviceSetupItemHeading'); this.i18n('multideviceSetupItemHeading');
}, },
......
...@@ -71,8 +71,8 @@ Polymer({ ...@@ -71,8 +71,8 @@ Polymer({
/** /**
* If the new mode corresponds to no eligible host or unset potential hosts * If the new mode corresponds to no eligible host or unset potential hosts
* (i.e. NO_ELIGIBLE_HOSTS or NO_HOST_SET), then newHostDevice should be null * (i.e. NO_ELIGIBLE_HOSTS or NO_HOST_SET), then newHostDeviceName should be
* or undefined. Otherwise it should be defined and non-null. * falsy. Otherwise it should be truthy.
* @param {!MultiDevicePageContentData} newData * @param {!MultiDevicePageContentData} newData
* @private * @private
*/ */
...@@ -81,7 +81,7 @@ Polymer({ ...@@ -81,7 +81,7 @@ Polymer({
settings.MultiDeviceSettingsMode.NO_ELIGIBLE_HOSTS, settings.MultiDeviceSettingsMode.NO_ELIGIBLE_HOSTS,
settings.MultiDeviceSettingsMode.NO_HOST_SET, settings.MultiDeviceSettingsMode.NO_HOST_SET,
]; ];
return !newData.hostDevice == noHostModes.includes(newData.mode); return !newData.hostDeviceName === noHostModes.includes(newData.mode);
}, },
/** /**
......
...@@ -36,7 +36,7 @@ suite('Multidevice', function() { ...@@ -36,7 +36,7 @@ suite('Multidevice', function() {
function getFakePageContentData(mode) { function getFakePageContentData(mode) {
return { return {
mode: mode, mode: mode,
hostDevice: HOST_SET_MODES.includes(mode) ? {name: 'Pixel XL'} : null, hostDeviceName: HOST_SET_MODES.includes(mode) ? 'Pixel XL' : undefined,
}; };
} }
......
...@@ -25,14 +25,12 @@ suite('Multidevice', function() { ...@@ -25,14 +25,12 @@ suite('Multidevice', function() {
let multidevicePage = null; let multidevicePage = null;
let browserProxy = null; let browserProxy = null;
let HOST_SET_MODES; let HOST_SET_MODES;
const HOST_DEVICE = { const HOST_DEVICE = 'Pixel XL';
name: 'Pixel XL',
};
function setPageContentData(newMode, newHostDevice) { function setPageContentData(newMode, newHostDeviceName) {
multidevicePage.pageContentData = { multidevicePage.pageContentData = {
mode: newMode, mode: newMode,
hostDevice: newHostDevice, hostDeviceName: newHostDeviceName,
}; };
Polymer.dom.flush(); Polymer.dom.flush();
} }
...@@ -66,7 +64,7 @@ suite('Multidevice', function() { ...@@ -66,7 +64,7 @@ suite('Multidevice', function() {
const getSubpage = () => multidevicePage.$$('settings-multidevice-subpage'); const getSubpage = () => multidevicePage.$$('settings-multidevice-subpage');
test('clicking setup shows multidevice setup dialog', function() { test('clicking setup shows multidevice setup dialog', function() {
setPageContentData(settings.MultiDeviceSettingsMode.NO_HOST_SET, null); setPageContentData(settings.MultiDeviceSettingsMode.NO_HOST_SET, undefined);
const button = multidevicePage.$$('paper-button'); const button = multidevicePage.$$('paper-button');
assertTrue(!!button); assertTrue(!!button);
button.click(); button.click();
...@@ -76,25 +74,24 @@ suite('Multidevice', function() { ...@@ -76,25 +74,24 @@ suite('Multidevice', function() {
test('headings render based on mode and host', function() { test('headings render based on mode and host', function() {
for (let mode of HOST_SET_MODES) { for (let mode of HOST_SET_MODES) {
setPageContentData(mode, HOST_DEVICE); setPageContentData(mode, HOST_DEVICE);
assertEquals(getLabel(), HOST_DEVICE.name); assertEquals(getLabel(), HOST_DEVICE);
} }
setPageContentData(settings.MultiDeviceSettingsMode.NO_HOST_SET, null); setPageContentData(settings.MultiDeviceSettingsMode.NO_HOST_SET, undefined);
assertNotEquals(getLabel(), HOST_DEVICE.name); assertNotEquals(getLabel(), HOST_DEVICE);
}); });
test('changing host device and fixing mode changes header', function() { test('changing host device and fixing mode changes header', function() {
setPageContentData( setPageContentData(
settings.MultiDeviceSettingsMode.HOST_SET_VERIFIED, HOST_DEVICE); settings.MultiDeviceSettingsMode.HOST_SET_VERIFIED, HOST_DEVICE);
assertEquals(getLabel(), HOST_DEVICE.name); assertEquals(getLabel(), HOST_DEVICE);
const anotherHost = const anotherHost = 'Super Duper ' + HOST_DEVICE;
Object.assign(HOST_DEVICE, {name: 'Super Duper ' + HOST_DEVICE.name});
setPageContentData( setPageContentData(
settings.MultiDeviceSettingsMode.HOST_SET_VERIFIED, anotherHost); settings.MultiDeviceSettingsMode.HOST_SET_VERIFIED, anotherHost);
assertEquals(getLabel(), anotherHost.name); assertEquals(getLabel(), anotherHost);
}); });
test('item is actionable if and only if a host is set', function() { test('item is actionable if and only if a host is set', function() {
setPageContentData(settings.MultiDeviceSettingsMode.NO_HOST_SET, null); setPageContentData(settings.MultiDeviceSettingsMode.NO_HOST_SET, undefined);
assertFalse( assertFalse(
multidevicePage.$$('#multidevice-item').hasAttribute('actionable')); multidevicePage.$$('#multidevice-item').hasAttribute('actionable'));
for (let mode of HOST_SET_MODES) { for (let mode of HOST_SET_MODES) {
......
...@@ -8,14 +8,11 @@ suite('Multidevice', function() { ...@@ -8,14 +8,11 @@ suite('Multidevice', function() {
// enum settings.MultiDeviceSettingsMode from here so its initialization is // enum settings.MultiDeviceSettingsMode from here so its initialization is
// deferred to the suiteSetup function. // deferred to the suiteSetup function.
let HOST_SET_MODES; let HOST_SET_MODES;
const HOST_DEVICE = {
name: 'Pixel XL',
};
function setPageContentData(newMode) { function setPageContentData(newMode) {
multideviceSubpage.pageContentData = { multideviceSubpage.pageContentData = {
mode: newMode, mode: newMode,
hostDevice: HOST_DEVICE, hostDeviceName: 'Pixel XL',
}; };
Polymer.dom.flush(); Polymer.dom.flush();
} }
......
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