Commit 48282e63 authored by Jeremie Boulic's avatar Jeremie Boulic Committed by Commit Bot

Hide other users row when there is no other user on the current device

Before this change, when there's a single user on a device, the storage
handler immediately returns '0 B' as the "Other users" size.

This change hides the "Other users" row entirely on the storage page
instead.

Test: browser_tests --gtest_filter="*OSSettingsDevicePageTest.StorageTest"
Bug: 1056491
Change-Id: Ibbc587ff702c5cc419eab35e7c0129674a9f9897
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2076747Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Commit-Queue: Jeremie Boulic <jboulic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#745645}
parent 755ee637
...@@ -220,7 +220,7 @@ ...@@ -220,7 +220,7 @@
role-description="$i18n{subpageArrowRoleDescription}"> role-description="$i18n{subpageArrowRoleDescription}">
</cr-link-row> </cr-link-row>
</template> </template>
<template is="dom-if" if="[[!isGuest_]]"> <template is="dom-if" if="[[showOtherUsers_]]">
<cr-link-row id="otherUsersSize" class="hr" on-click="onOtherUsersTap_" <cr-link-row id="otherUsersSize" class="hr" on-click="onOtherUsersTap_"
label="$i18n{storageItemOtherUsers}" label="$i18n{storageItemOtherUsers}"
sub-label="$i18n{storageSizeComputing}" sub-label="$i18n{storageSizeComputing}"
......
...@@ -53,6 +53,15 @@ Polymer({ ...@@ -53,6 +53,15 @@ Polymer({
} }
}, },
/** @private */
showOtherUsers_: {
type: Boolean,
// Initialize showOtherUsers_ to false if the user is in guest mode.
value() {
return !loadTimeData.getBoolean('isGuest');
}
},
/** @private {settings.StorageSizeStat} */ /** @private {settings.StorageSizeStat} */
sizeStat_: Object, sizeStat_: Object,
}, },
...@@ -227,12 +236,17 @@ Polymer({ ...@@ -227,12 +236,17 @@ Polymer({
/** /**
* @param {string} size Formatted string representing the size of Other users. * @param {string} size Formatted string representing the size of Other users.
* @param {boolean} noOtherUsers True if there is no other registered users on
* the device.
* @private * @private
*/ */
handleOtherUsersSizeChanged_(size) { handleOtherUsersSizeChanged_(size, noOtherUsers) {
if (!this.isGuest_) { if (this.isGuest_ || noOtherUsers) {
this.$$('#otherUsersSize').subLabel = size; this.showOtherUsers_ = false;
return;
} }
this.showOtherUsers_ = true;
this.$$('#otherUsersSize').subLabel = size;
}, },
/** /**
......
...@@ -223,7 +223,13 @@ void StorageHandler::UpdateStorageItem(const std::string& event_name, ...@@ -223,7 +223,13 @@ void StorageHandler::UpdateStorageItem(const std::string& event_name,
message = ui::FormatBytes(total_bytes); message = ui::FormatBytes(total_bytes);
} }
FireWebUIListener(event_name, base::Value(message)); if (event_name == "storage-other-users-size-changed") {
bool no_other_users = (total_bytes == 0);
FireWebUIListener(event_name, base::Value(message),
base::Value(no_other_users));
} else {
FireWebUIListener(event_name, base::Value(message));
}
} }
void StorageHandler::UpdateSizeStat(const std::string& event_name, void StorageHandler::UpdateSizeStat(const std::string& event_name,
......
...@@ -1934,6 +1934,36 @@ cr.define('device_page_tests', function() { ...@@ -1934,6 +1934,36 @@ cr.define('device_page_tests', function() {
Polymer.dom.flush(); Polymer.dom.flush();
assertEquals('59.5 KB', getStorageItemSubLabelFromId('appsSize')); assertEquals('59.5 KB', getStorageItemSubLabelFromId('appsSize'));
}); });
test('other users size', async function() {
// The other users row is visible by default, displaying
// "calculating...".
assertFalse(isHidden(storagePage.$$('#otherUsersSize')));
assertEquals(
'Other users', getStorageItemLabelFromId('otherUsersSize'));
assertEquals(
'Calculating…', getStorageItemSubLabelFromId('otherUsersSize'));
// Simulate absence of other users.
cr.webUIListenerCallback(
'storage-other-users-size-changed', '0 B', true);
Polymer.dom.flush();
assertTrue(isHidden(storagePage.$$('#otherUsersSize')));
// Send other users callback with a size that is not null.
cr.webUIListenerCallback(
'storage-other-users-size-changed', '322 MB', false);
Polymer.dom.flush();
assertFalse(isHidden(storagePage.$$('#otherUsersSize')));
assertEquals('322 MB', getStorageItemSubLabelFromId('otherUsersSize'));
// If the user is in Guest mode, the row is not visible.
storagePage.isGuest_ = true;
cr.webUIListenerCallback(
'storage-other-users-size-changed', '322 MB', false);
Polymer.dom.flush();
assertTrue(isHidden(storagePage.$$('#otherUsersSize')));
});
}); });
}); });
......
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