Commit 941baa74 authored by Michael Hansen's avatar Michael Hansen Committed by Commit Bot

[Nearby] Use settings mojo to get and set device name.

This updates the Nearby Share subpage and device name dialog to call the
settings mojo for reading and writing the device name instead of
accessing prefs directly. This is in preparation for a follow-up CL
which will add validation and error checking when setting the device
name.

Bug: b:161297140
Change-Id: If7cad62416c2662e9c070ecaa91b47e43fe3dfae
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2420773
Commit-Queue: Michael Hansen <hansenmichael@google.com>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Reviewed-by: default avatarJames Vecore <vecore@google.com>
Cr-Commit-Position: refs/heads/master@{#809494}
parent 110b1bbc
......@@ -57,9 +57,7 @@ js_library("nearby_share_data_usage_dialog") {
js_library("nearby_share_device_name_dialog") {
deps = [
"../../prefs",
"../../prefs:prefs_behavior",
"../../prefs:prefs_types",
"//chrome/browser/resources/nearby_share/shared:nearby_share_settings_behavior",
"//ui/webui/resources/cr_elements/cr_button:cr_button",
"//ui/webui/resources/cr_elements/cr_dialog:cr_dialog",
"//ui/webui/resources/cr_elements/cr_input:cr_input",
......@@ -194,9 +192,7 @@ js_library("nearby_share_data_usage_dialog.m") {
js_library("nearby_share_device_name_dialog.m") {
sources = [ "$root_gen_dir/chrome/browser/resources/settings/chromeos/nearby_share_page/nearby_share_device_name_dialog.m.js" ]
deps = [
"../../prefs:prefs.m",
"../../prefs:prefs_behavior.m",
"../../prefs:prefs_types.m",
"//chrome/browser/resources/nearby_share/shared:nearby_share_settings_behavior.m",
"//ui/webui/resources/cr_elements/cr_button:cr_button.m",
"//ui/webui/resources/cr_elements/cr_dialog:cr_dialog.m",
"//ui/webui/resources/cr_elements/cr_input:cr_input.m",
......@@ -332,8 +328,10 @@ polymer_modulizer("nearby_share_device_name_dialog") {
js_file = "nearby_share_device_name_dialog.js"
html_file = "nearby_share_device_name_dialog.html"
html_type = "dom-module"
namespace_rewrites = os_settings_namespace_rewrites
auto_imports = os_settings_auto_imports
namespace_rewrites =
os_settings_namespace_rewrites + nearby_shared_namespace_rewrites
auto_imports =
os_settings_auto_imports + nearby_shared_auto_imports_closure_fix
}
polymer_modulizer("nearby_share_high_visibility_page") {
......
......@@ -5,8 +5,7 @@
<link rel="import" href="chrome://resources/cr_elements/cr_input/cr_input.html">
<link rel="import" href="chrome://resources/html/i18n_behavior.html">
<link rel="import" href="chrome://resources/polymer/v1_0/iron-flex-layout/iron-flex-layout-classes.html">
<link rel="import" href="../../prefs/prefs.html">
<link rel="import" href="../../prefs/prefs_behavior.html">
<link rel="import" href="../../shared/nearby_share_settings_behavior.html">
<dom-module id="nearby-share-device-name-dialog">
<template>
......@@ -17,7 +16,7 @@
$i18n{nearbyShareDeviceNameDialogTitle}
</div>
<div slot="body">
<cr-input value="[[prefs.nearby_sharing.device_name.value]]" autofocus>
<cr-input value="[[settings.deviceName]]" autofocus>
</cr-input>
</div>
<div class="layout horizontal center" slot="button-container">
......
......@@ -12,14 +12,12 @@ Polymer({
behaviors: [
I18nBehavior,
PrefsBehavior,
],
properties: {
/** Preferences state. */
prefs: {
/** @type {nearby_share.NearbySettings} */
settings: {
type: Object,
notify: true,
},
},
......@@ -48,7 +46,7 @@ Polymer({
/** @private */
onDoneTap_() {
this.setPrefValue('nearby_sharing.device_name', this.$$('cr-input').value);
this.set('settings.deviceName', this.$$('cr-input').value);
this.close();
},
});
......@@ -34,9 +34,9 @@
</div>
<div class="settings-box two-line">
<div class="start" aria-label="[[getAccountRowLabel(
prefs.nearby_sharing.device_name.value, profileLabel_)]]">
settings.deviceName, profileLabel_)]]">
<div id="accountRowDeviceName" role="heading" aria-hidden="true">
[[prefs.nearby_sharing.device_name.value]]
[[settings.deviceName]]
</div>
<div id="profileLabel" class="secondary" aria-hidden="true">
[[profileLabel_]]
......@@ -49,18 +49,18 @@
$i18n{nearbyShareDeviceNameRowTitle}
</div>
<div aria-hidden="true" class="secondary">
[[prefs.nearby_sharing.device_name.value]]
[[settings.deviceName]]
</div>
</div>
<cr-button id="editDeviceNameButton" on-click="onDeviceNameTap_"
aria-description="[[getEditNameButtonAriaDescription_(
prefs.nearby_sharing.device_name.value)]]">
settings.deviceName)]]">
$i18n{nearbyShareEditDeviceName}
</cr-button>
</div>
<template is="dom-if" if="[[showDeviceNameDialog_]]" restamp>
<nearby-share-device-name-dialog prefs="{{prefs}}" id="deviceNameDialog"
on-close="onDeviceNameDialogClose_">
<nearby-share-device-name-dialog settings="{{settings}}"
id="deviceNameDialog" on-close="onDeviceNameDialogClose_">
</nearby-share-device-name-dialog>
</template>
<div class="settings-box two-line">
......
......@@ -152,11 +152,14 @@ suite('NearbyShare', function() {
Polymer.dom.flush();
const dialog = subpage.$$('nearby-share-device-name-dialog');
const oldName = subpage.settings.deviceName;
const newName = 'NEW NAME';
dialog.$$('cr-input').value = newName;
dialog.$$('.action-button').click();
Polymer.dom.flush();
assertEquals(newName, subpage.prefs.nearby_sharing.device_name.value);
assertEquals(newName, subpage.settings.deviceName);
subpage.set('settings.deviceName', oldName);
});
test('update data usage preference', function() {
......@@ -192,7 +195,7 @@ suite('NearbyShare', function() {
const profileLabel = subpage.$$('#profileLabel');
assertEquals('primary@gmail.com', profileLabel.textContent.trim());
const deviceLabel = subpage.$$('#accountRowDeviceName');
assertEquals('', deviceLabel.textContent.trim());
assertEquals('testDevice', deviceLabel.textContent.trim());
});
test('show receive dialog', function() {
......
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