Commit ed058d95 authored by Theo Johnson-kanu's avatar Theo Johnson-kanu Committed by Chromium LUCI CQ

[CrOS cellular] Add error message to remove eSim profile dialog

- Before this CL remove eSIM profile dialog, did not display any
  meaningful error if remove fails, this CL adds a meaningful error.

Screenshot: https://screenshot.googleplex.com/5JVxg2tdsLued8o.png

Bug: 1154787
Change-Id: Iee30704914ba582325ea9314e7a1a62736f778ca
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2602511Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Reviewed-by: default avatarAzeem Arshad <azeemarshad@chromium.org>
Commit-Queue: Nnamdi Theodore Johnson-kanu <tjohnsonkanu@google.com>
Cr-Commit-Position: refs/heads/master@{#839500}
parent a498e773
...@@ -2214,6 +2214,12 @@ Press an assigned switch to remove assignment. ...@@ -2214,6 +2214,12 @@ Press an assigned switch to remove assignment.
<message name="IDS_SETTINGS_INTERNET_NETWORK_REMOVE_PROFILE_DIALOG_REMOVE" desc="Settings > Internet > Network details > Remove profile dialog: The Label for the dialog remove button to remove an eSIM cellular network"> <message name="IDS_SETTINGS_INTERNET_NETWORK_REMOVE_PROFILE_DIALOG_REMOVE" desc="Settings > Internet > Network details > Remove profile dialog: The Label for the dialog remove button to remove an eSIM cellular network">
Remove Remove
</message> </message>
<message name="IDS_SETTINGS_INTERNET_NETWORK_REMOVE_PROFILE_DIALOG_OKAY" desc="Settings > Internet > Network details > Remove eSIM cellular profile dialog: The Label for the dialog okay button">
Okay
</message>
<message name="IDS_SETTINGS_INTERNET_NETWORK_REMOVE_PROFILE_DIALOG_ERROR_MESSAGE" desc="Settings > Internet > Network details > Remove eSIM cellular profile dialog: Error message shown when remove fails">
Profile could not be removed. Please try again or contact your carrier for technical support.
</message>
<message name="IDS_SETTINGS_INTERNET_BUTTON_ACTIVATE" desc="Settings > Internet > Network details: The label for the button to activate a Cellular network."> <message name="IDS_SETTINGS_INTERNET_BUTTON_ACTIVATE" desc="Settings > Internet > Network details: The label for the button to activate a Cellular network.">
Activate Activate
</message> </message>
......
...@@ -19,15 +19,29 @@ ...@@ -19,15 +19,29 @@
</style> </style>
<cr-dialog id="dialog" show-on-attach> <cr-dialog id="dialog" show-on-attach>
<div slot="title">[[getTitleString_(esimProfileName_)]]</div> <div slot="title">[[getTitleString_(esimProfileName_)]]</div>
<div slot="body">
<div id="errorMessage" hidden$="[[!errorMessage_]]">
[[errorMessage_]]
</div>
</div>
<div slot="button-container"> <div slot="button-container">
<template is="dom-if" if="[[!errorMessage_]]" restamp>
<cr-button id="cancel" on-click="onCancelTap_" <cr-button id="cancel" on-click="onCancelTap_"
class="cancel-button"> class="cancel-button">
$i18n{eSimRemoveProfileDialogCancel} $i18n{eSimRemoveProfileDialogCancel}
</cr-button> </cr-button>
<cr-button id="remove" on-click="onRemoveProfileTap_" <cr-button id="remove" on-click="onRemoveProfileTap_"
disabled="[[isRemoveInProgress_]]"
class="action-button"> class="action-button">
$i18n{eSimRemoveProfileDialogRemove} $i18n{eSimRemoveProfileDialogRemove}
</cr-button> </cr-button>
</template>
<template is="dom-if" if="[[errorMessage_]]" restamp>
<cr-button id="done" on-click="onCancelTap_"
class="action-button">
$i18n{eSimRemoveProfileDialogOkay}
</cr-button>
</template>
</div> </div>
</cr-dialog> </cr-dialog>
</template> </template>
......
...@@ -15,15 +15,27 @@ Polymer({ ...@@ -15,15 +15,27 @@ Polymer({
properties: { properties: {
/** @type {string} */ /** @type {string} */
esimProfileName_: { iccid: {
type: String, type: String,
value: '', value: '',
}, },
/** @type {string} */ /** @type {string} */
iccid: { esimProfileName_: {
type: String,
value: '',
},
/** @private {string} */
errorMessage_: {
type: String, type: String,
value: '', value: '',
},
/** @private {boolean} */
isRemoveInProgress_: {
type: Boolean,
value: false,
} }
}, },
...@@ -91,14 +103,23 @@ Polymer({ ...@@ -91,14 +103,23 @@ Polymer({
* @param {Event} event * @param {Event} event
* @private * @private
*/ */
async onRemoveProfileTap_(event) { onRemoveProfileTap_(event) {
const response = await this.esimProfileRemote_.uninstallProfile(); this.isRemoveInProgress_ = true;
if (response.result === this.esimProfileRemote_.uninstallProfile().then(response => {
chromeos.cellularSetup.mojom.ESimOperationResult.kFailure) { this.handleRemoveProfileResponse(response.result);
console.error('Unable to remove profile'); });
// TODO(crbug.com/1093185): Show useful error to user when uninstall fails },
}
/**
* @param {chromeos.cellularSetup.mojom.ESimOperationResult} result
* @private
*/
handleRemoveProfileResponse(result) {
this.isRemoveInProgress_ = false;
if (result === chromeos.cellularSetup.mojom.ESimOperationResult.kFailure) {
this.errorMessage_ = this.i18n('eSimRemoveProfileDialogError');
return;
}
this.$.dialog.close(); this.$.dialog.close();
}, },
......
...@@ -722,6 +722,10 @@ void InternetSection::AddLoadTimeData(content::WebUIDataSource* html_source) { ...@@ -722,6 +722,10 @@ void InternetSection::AddLoadTimeData(content::WebUIDataSource* html_source) {
IDS_SETTINGS_INTERNET_NETWORK_REMOVE_PROFILE_DIALOG_TITLE}, IDS_SETTINGS_INTERNET_NETWORK_REMOVE_PROFILE_DIALOG_TITLE},
{"eSimRemoveProfileDialogRemove", {"eSimRemoveProfileDialogRemove",
IDS_SETTINGS_INTERNET_NETWORK_REMOVE_PROFILE_DIALOG_REMOVE}, IDS_SETTINGS_INTERNET_NETWORK_REMOVE_PROFILE_DIALOG_REMOVE},
{"eSimRemoveProfileDialogError",
IDS_SETTINGS_INTERNET_NETWORK_REMOVE_PROFILE_DIALOG_ERROR_MESSAGE},
{"eSimRemoveProfileDialogOkay",
IDS_SETTINGS_INTERNET_NETWORK_REMOVE_PROFILE_DIALOG_OKAY},
}; };
AddLocalizedStringsBulk(html_source, kLocalizedStrings); AddLocalizedStringsBulk(html_source, kLocalizedStrings);
......
...@@ -81,7 +81,7 @@ cr.define('cellular_setup', function() { ...@@ -81,7 +81,7 @@ cr.define('cellular_setup', function() {
* @return {Object} * @return {Object}
* @private * @private
*/ */
deferedPromise_() { deferredPromise_() {
let deferred = {}; let deferred = {};
let promise = new Promise(function(resolve, reject) { let promise = new Promise(function(resolve, reject) {
deferred.resolve = resolve; deferred.resolve = resolve;
...@@ -104,7 +104,7 @@ cr.define('cellular_setup', function() { ...@@ -104,7 +104,7 @@ cr.define('cellular_setup', function() {
this.properties_.nickname = nickname; this.properties_.nickname = nickname;
} }
this.deferredSetProfileNicknamePromise_ = this.deferedPromise_(); this.deferredSetProfileNicknamePromise_ = this.deferredPromise_();
return this.deferredSetProfileNicknamePromise_.promise; return this.deferredSetProfileNicknamePromise_.promise;
} }
...@@ -119,17 +119,25 @@ cr.define('cellular_setup', function() { ...@@ -119,17 +119,25 @@ cr.define('cellular_setup', function() {
/** @override */ /** @override */
uninstallProfile() { uninstallProfile() {
return this.fakeEuicc_.removeProfileForTest(this.properties_.iccid) this.defferedUninstallProfilePromise_ = this.deferredPromise_();
.then(saved => { return this.defferedUninstallProfilePromise_.promise;
if (saved) {
return {
result:
chromeos.cellularSetup.mojom.ESimOperationResult.kSuccess
};
} }
return {
result: chromeos.cellularSetup.mojom.ESimOperationResult.kFailure /** @return {Promise<void>} */
}; async resolveUninstallProfilePromise() {
if (!this.esimOperationResult_ ||
this.esimOperationResult_ ===
chromeos.cellularSetup.mojom.ESimOperationResult.kSuccess) {
const removeProfileResult =
await this.fakeEuicc_.removeProfileForTest(this.properties_.iccid);
this.defferedUninstallProfilePromise_.resolve(removeProfileResult);
return;
}
this.defferedUninstallProfilePromise_.resolve({
result: this.esimOperationResult_ ?
this.esimOperationResult_ :
chromeos.cellularSetup.mojom.ESimOperationResult.kSuccess
}); });
} }
} }
...@@ -198,18 +206,25 @@ cr.define('cellular_setup', function() { ...@@ -198,18 +206,25 @@ cr.define('cellular_setup', function() {
*/ */
async removeProfileForTest(iccid) { async removeProfileForTest(iccid) {
const result = []; const result = [];
let resp = false; let profileRemoved = false;
for (let profile of this.profiles_) { for (let profile of this.profiles_) {
const property = await profile.getProperties(); const property = await profile.getProperties();
if (property.properties.iccid === iccid) { if (property.properties.iccid === iccid) {
resp = true; profileRemoved = true;
continue; continue;
} }
result.push(profile); result.push(profile);
} }
this.profiles_ = result; this.profiles_ = result;
return resp; if (profileRemoved) {
return {
result: chromeos.cellularSetup.mojom.ESimOperationResult.kSuccess
};
}
return {
result: chromeos.cellularSetup.mojom.ESimOperationResult.kFailure
};
} }
} }
......
...@@ -43,27 +43,69 @@ suite('EsimRemoveProfileDialog', function() { ...@@ -43,27 +43,69 @@ suite('EsimRemoveProfileDialog', function() {
return new Promise(resolve => setTimeout(resolve)); return new Promise(resolve => setTimeout(resolve));
} }
async function getProfileForIccid(profiles, iccid) {
for (const profile of profiles) {
const properties = await profile.getProperties();
if (properties.properties && properties.properties.iccid === iccid) {
return profile;
}
}
return null;
}
test('Remove esim profile', async function() { test('Remove esim profile', async function() {
eSimManagerRemote.addEuiccForTest(2); eSimManagerRemote.addEuiccForTest(2);
init('1'); init('1');
await flushAsync(); await flushAsync();
const euicc = (await eSimManagerRemote.getAvailableEuiccs()).euiccs[0];
let profiles = (await euicc.getProfileList()).profiles;
let foundProfile = await getProfileForIccid(profiles, '1');
assertTrue(!!foundProfile);
const removeBtn = esimRemoveProfileDialog.$$('#remove'); const removeBtn = esimRemoveProfileDialog.$$('#remove');
assertTrue(!!removeBtn); assertTrue(!!removeBtn);
removeBtn.click(); removeBtn.click();
await flushAsync(); await flushAsync();
foundProfile.resolveUninstallProfilePromise();
await flushAsync();
profiles = (await euicc.getProfileList()).profiles;
foundProfile = await getProfileForIccid(profiles, '1');
assertFalse(!!foundProfile);
});
test('Remove esim profile fails', async function() {
eSimManagerRemote.addEuiccForTest(2);
init('1');
await flushAsync();
assertTrue(esimRemoveProfileDialog.$$('#errorMessage').hidden);
const euicc = (await eSimManagerRemote.getAvailableEuiccs()).euiccs[0]; const euicc = (await eSimManagerRemote.getAvailableEuiccs()).euiccs[0];
const profiles = (await euicc.getProfileList()).profiles; let profiles = (await euicc.getProfileList()).profiles;
const foundProfile = null; let foundProfile = await getProfileForIccid(profiles, '1');
for (const profile of profiles) { assertTrue(!!foundProfile);
const properties = await profile.getProperties(); foundProfile.setEsimOperationResultForTest(
if (properties.properties && properties.properties.iccid === '1') { chromeos.cellularSetup.mojom.ESimOperationResult.kFailure);
foundProfile = profile;
} const removeBtn = esimRemoveProfileDialog.$$('#remove');
} assertTrue(!!removeBtn);
assertFalse(!!foundProfile); assertFalse(removeBtn.disabled);
removeBtn.click();
await flushAsync();
assertTrue(removeBtn.disabled);
foundProfile.resolveUninstallProfilePromise();
await flushAsync();
assertFalse(removeBtn.disabled);
profiles = (await euicc.getProfileList()).profiles;
foundProfile = await getProfileForIccid(profiles, '1');
assertTrue(!!foundProfile);
assertFalse(esimRemoveProfileDialog.$$('#errorMessage').hidden);
}); });
}); });
\ No newline at end of file
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