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.
<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
</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.">
Activate
</message>
......
......@@ -19,15 +19,29 @@
</style>
<cr-dialog id="dialog" show-on-attach>
<div slot="title">[[getTitleString_(esimProfileName_)]]</div>
<div slot="body">
<div id="errorMessage" hidden$="[[!errorMessage_]]">
[[errorMessage_]]
</div>
</div>
<div slot="button-container">
<cr-button id="cancel" on-click="onCancelTap_"
class="cancel-button">
$i18n{eSimRemoveProfileDialogCancel}
</cr-button>
<cr-button id="remove" on-click="onRemoveProfileTap_"
class="action-button">
$i18n{eSimRemoveProfileDialogRemove}
</cr-button>
<template is="dom-if" if="[[!errorMessage_]]" restamp>
<cr-button id="cancel" on-click="onCancelTap_"
class="cancel-button">
$i18n{eSimRemoveProfileDialogCancel}
</cr-button>
<cr-button id="remove" on-click="onRemoveProfileTap_"
disabled="[[isRemoveInProgress_]]"
class="action-button">
$i18n{eSimRemoveProfileDialogRemove}
</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>
</cr-dialog>
</template>
......
......@@ -15,15 +15,27 @@ Polymer({
properties: {
/** @type {string} */
esimProfileName_: {
iccid: {
type: String,
value: '',
},
/** @type {string} */
iccid: {
esimProfileName_: {
type: String,
value: '',
},
/** @private {string} */
errorMessage_: {
type: String,
value: '',
},
/** @private {boolean} */
isRemoveInProgress_: {
type: Boolean,
value: false,
}
},
......@@ -91,14 +103,23 @@ Polymer({
* @param {Event} event
* @private
*/
async onRemoveProfileTap_(event) {
const response = await this.esimProfileRemote_.uninstallProfile();
if (response.result ===
chromeos.cellularSetup.mojom.ESimOperationResult.kFailure) {
console.error('Unable to remove profile');
// TODO(crbug.com/1093185): Show useful error to user when uninstall fails
}
onRemoveProfileTap_(event) {
this.isRemoveInProgress_ = true;
this.esimProfileRemote_.uninstallProfile().then(response => {
this.handleRemoveProfileResponse(response.result);
});
},
/**
* @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();
},
......
......@@ -722,6 +722,10 @@ void InternetSection::AddLoadTimeData(content::WebUIDataSource* html_source) {
IDS_SETTINGS_INTERNET_NETWORK_REMOVE_PROFILE_DIALOG_TITLE},
{"eSimRemoveProfileDialogRemove",
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);
......
......@@ -81,7 +81,7 @@ cr.define('cellular_setup', function() {
* @return {Object}
* @private
*/
deferedPromise_() {
deferredPromise_() {
let deferred = {};
let promise = new Promise(function(resolve, reject) {
deferred.resolve = resolve;
......@@ -104,7 +104,7 @@ cr.define('cellular_setup', function() {
this.properties_.nickname = nickname;
}
this.deferredSetProfileNicknamePromise_ = this.deferedPromise_();
this.deferredSetProfileNicknamePromise_ = this.deferredPromise_();
return this.deferredSetProfileNicknamePromise_.promise;
}
......@@ -119,18 +119,26 @@ cr.define('cellular_setup', function() {
/** @override */
uninstallProfile() {
return this.fakeEuicc_.removeProfileForTest(this.properties_.iccid)
.then(saved => {
if (saved) {
return {
result:
chromeos.cellularSetup.mojom.ESimOperationResult.kSuccess
};
}
return {
result: chromeos.cellularSetup.mojom.ESimOperationResult.kFailure
};
});
this.defferedUninstallProfilePromise_ = this.deferredPromise_();
return this.defferedUninstallProfilePromise_.promise;
}
/** @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() {
*/
async removeProfileForTest(iccid) {
const result = [];
let resp = false;
let profileRemoved = false;
for (let profile of this.profiles_) {
const property = await profile.getProperties();
if (property.properties.iccid === iccid) {
resp = true;
profileRemoved = true;
continue;
}
result.push(profile);
}
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() {
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() {
eSimManagerRemote.addEuiccForTest(2);
init('1');
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');
assertTrue(!!removeBtn);
removeBtn.click();
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 profiles = (await euicc.getProfileList()).profiles;
let profiles = (await euicc.getProfileList()).profiles;
const foundProfile = null;
for (const profile of profiles) {
const properties = await profile.getProperties();
if (properties.properties && properties.properties.iccid === '1') {
foundProfile = profile;
}
}
assertFalse(!!foundProfile);
let foundProfile = await getProfileForIccid(profiles, '1');
assertTrue(!!foundProfile);
foundProfile.setEsimOperationResultForTest(
chromeos.cellularSetup.mojom.ESimOperationResult.kFailure);
const removeBtn = esimRemoveProfileDialog.$$('#remove');
assertTrue(!!removeBtn);
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