Commit 7a6bab7a authored by James Cook's avatar James Cook Committed by Commit Bot

SplitSettings: Show GAIA avatar in browser settings People section

UX wants to show the GAIA avatar instead of the device account image.

Bug: 990528
Test: added to browser_tests
Change-Id: If56b065154b0690b7ce4ff9b3d520250575395cc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1750100Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: James Cook <jamescook@chromium.org>
Cr-Commit-Position: refs/heads/master@{#686450}
parent b5378632
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
<if expr="chromeos"> <if expr="chromeos">
<link rel="import" href="account_manager.html"> <link rel="import" href="account_manager.html">
<link rel="import" href="account_manager_browser_proxy.html">
<link rel="import" href="change_picture.html"> <link rel="import" href="change_picture.html">
<link rel="import" href="chrome://resources/cr_elements/chromeos/cr_picture/cr_png_behavior.html"> <link rel="import" href="chrome://resources/cr_elements/chromeos/cr_picture/cr_png_behavior.html">
<link rel="import" href="fingerprint_list.html"> <link rel="import" href="fingerprint_list.html">
......
...@@ -233,10 +233,24 @@ Polymer({ ...@@ -233,10 +233,24 @@ Polymer({
/** @override */ /** @override */
attached: function() { attached: function() {
const profileInfoProxy = settings.ProfileInfoBrowserProxyImpl.getInstance(); let useProfileNameAndIcon = true;
profileInfoProxy.getProfileInfo().then(this.handleProfileInfo_.bind(this)); // <if expr="chromeos">
this.addWebUIListener( if (!loadTimeData.getBoolean('showOSSettings') &&
'profile-info-changed', this.handleProfileInfo_.bind(this)); this.isAccountManagerEnabled_) {
// If this is SplitSettings and we have the Google Account manager,
// prefer the GAIA name and icon.
useProfileNameAndIcon = false;
this.addWebUIListener(
'accounts-changed', this.updateAccounts_.bind(this));
this.updateAccounts_();
}
// </if>
if (useProfileNameAndIcon) {
settings.ProfileInfoBrowserProxyImpl.getInstance().getProfileInfo().then(
this.handleProfileInfo_.bind(this));
this.addWebUIListener(
'profile-info-changed', this.handleProfileInfo_.bind(this));
}
this.syncBrowserProxy_ = settings.SyncBrowserProxyImpl.getInstance(); this.syncBrowserProxy_ = settings.SyncBrowserProxyImpl.getInstance();
this.syncBrowserProxy_.getSyncStatus().then( this.syncBrowserProxy_.getSyncStatus().then(
...@@ -318,6 +332,27 @@ Polymer({ ...@@ -318,6 +332,27 @@ Polymer({
this.profileIconUrl_ = info.iconUrl; this.profileIconUrl_ = info.iconUrl;
}, },
// <if expr="chromeos">
/**
* @private
* @suppress {checkTypes} The types only exists in Chrome OS builds, but
* Closure doesn't understand the <if> above.
*/
updateAccounts_: async function() {
const /** @type {!Array<{settings.Account}>} */ accounts =
await settings.AccountManagerBrowserProxyImpl.getInstance()
.getAccounts();
// The user might not have any GAIA accounts (e.g. guest mode, Kerberos,
// Active Directory). In these cases the profile row is hidden, so there's
// nothing to do.
if (accounts.length == 0) {
return;
}
this.profileName_ = accounts[0].fullName;
this.profileIconUrl_ = accounts[0].pic;
},
// </if>
/** /**
* Handler for when the sync state is pushed from the browser. * Handler for when the sync state is pushed from the browser.
* @param {?settings.SyncStatus} syncStatus * @param {?settings.SyncStatus} syncStatus
......
...@@ -33,9 +33,15 @@ cr.define('settings_people_page', function() { ...@@ -33,9 +33,15 @@ cr.define('settings_people_page', function() {
// UnifiedConsentUITest suite. // UnifiedConsentUITest suite.
unifiedConsentEnabled: false, unifiedConsentEnabled: false,
}); });
if (cr.isChromeOS) {
loadTimeData.overrideValues({
// Account Manager is tested in the Chrome OS-specific section below.
isAccountManagerEnabled: false,
});
}
}); });
setup(function() { setup(async function() {
browserProxy = new TestProfileInfoBrowserProxy(); browserProxy = new TestProfileInfoBrowserProxy();
settings.ProfileInfoBrowserProxyImpl.instance_ = browserProxy; settings.ProfileInfoBrowserProxyImpl.instance_ = browserProxy;
...@@ -47,14 +53,9 @@ cr.define('settings_people_page', function() { ...@@ -47,14 +53,9 @@ cr.define('settings_people_page', function() {
peoplePage.pageVisibility = settings.pageVisibility; peoplePage.pageVisibility = settings.pageVisibility;
document.body.appendChild(peoplePage); document.body.appendChild(peoplePage);
return Promise await syncBrowserProxy.whenCalled('getSyncStatus');
.all([ await browserProxy.whenCalled('getProfileInfo');
browserProxy.whenCalled('getProfileInfo'), Polymer.dom.flush();
syncBrowserProxy.whenCalled('getSyncStatus')
])
.then(function() {
Polymer.dom.flush();
});
}); });
teardown(function() { teardown(function() {
...@@ -587,18 +588,70 @@ cr.define('settings_people_page', function() { ...@@ -587,18 +588,70 @@ cr.define('settings_people_page', function() {
}); });
if (cr.isChromeOS) { if (cr.isChromeOS) {
suite('Chrome OS with SplitSettings', function() { /** @implements {settings.AccountManagerBrowserProxy} */
class TestAccountManagerBrowserProxy extends TestBrowserProxy {
constructor() {
super([
'getAccounts',
'addAccount',
'reauthenticateAccount',
'removeAccount',
'showWelcomeDialogIfRequired',
]);
}
/** @override */
getAccounts() {
this.methodCalled('getAccounts');
return Promise.resolve([{
id: '123',
accountType: 1,
isDeviceAccount: false,
isSignedIn: true,
unmigrated: false,
fullName: 'Primary Account',
email: 'user@gmail.com',
pic: 'data:image/png;base64,primaryAccountPicData',
}]);
}
/** @override */
addAccount() {
this.methodCalled('addAccount');
}
/** @override */
reauthenticateAccount(account_email) {
this.methodCalled('reauthenticateAccount', account_email);
}
/** @override */
removeAccount(account) {
this.methodCalled('removeAccount', account);
}
/** @override */
showWelcomeDialogIfRequired() {
this.methodCalled('showWelcomeDialogIfRequired');
}
}
suite('Chrome OS', function() {
/** @type {SettingsPeoplePageElement} */ /** @type {SettingsPeoplePageElement} */
let peoplePage = null; let peoplePage = null;
/** @type {settings.SyncBrowserProxy} */ /** @type {settings.SyncBrowserProxy} */
let browserProxy = null; let browserProxy = null;
/** @type {settings.ProfileInfoBrowserProxy} */ /** @type {settings.ProfileInfoBrowserProxy} */
let profileInfoBrowserProxy = null; let profileInfoBrowserProxy = null;
/** @type {settings.AccountManagerBrowserProxy} */
let accountManagerBrowserProxy = null;
suiteSetup(function() { suiteSetup(function() {
loadTimeData.overrideValues({ loadTimeData.overrideValues({
// Simulate SplitSettings (OS settings in their own surface). // Simulate SplitSettings (OS settings in their own surface).
showOSSettings: false, showOSSettings: false,
// Simulate ChromeOSAccountManager (Google Accounts support).
isAccountManagerEnabled: true,
}); });
}); });
...@@ -610,19 +663,33 @@ cr.define('settings_people_page', function() { ...@@ -610,19 +663,33 @@ cr.define('settings_people_page', function() {
settings.ProfileInfoBrowserProxyImpl.instance_ = settings.ProfileInfoBrowserProxyImpl.instance_ =
profileInfoBrowserProxy; profileInfoBrowserProxy;
accountManagerBrowserProxy = new TestAccountManagerBrowserProxy();
settings.AccountManagerBrowserProxyImpl.instance_ =
accountManagerBrowserProxy;
PolymerTest.clearBody(); PolymerTest.clearBody();
peoplePage = document.createElement('settings-people-page'); peoplePage = document.createElement('settings-people-page');
peoplePage.pageVisibility = settings.pageVisibility; peoplePage.pageVisibility = settings.pageVisibility;
document.body.appendChild(peoplePage); document.body.appendChild(peoplePage);
Polymer.dom.flush(); await accountManagerBrowserProxy.whenCalled('getAccounts');
await browserProxy.whenCalled('getSyncStatus'); await browserProxy.whenCalled('getSyncStatus');
Polymer.dom.flush();
}); });
teardown(function() { teardown(function() {
peoplePage.remove(); peoplePage.remove();
}); });
test('GAIA name and picture', async () => {
chai.assert.include(
peoplePage.$$('#profile-icon').style.backgroundImage,
'data:image/png;base64,primaryAccountPicData');
assertEquals(
'Primary Account',
peoplePage.$$('#profile-name').textContent.trim());
});
test('clicking profile row does not open change picture page', () => { test('clicking profile row does not open change picture page', () => {
// Simulate a signed-in user. // Simulate a signed-in user.
sync_test_util.simulateSyncStatus({ sync_test_util.simulateSyncStatus({
......
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