Commit 1163e83e authored by Hector Carmona's avatar Hector Carmona Committed by Commit Bot

A11y: Show toast when reloading extensions.

Refactored how the toolbar shows toast to avoid having two toasts.
Also noticed bug in cr-toast-manager that would try to announce an
element instead of its textContent.

Bug: 27175
Change-Id: I1128106498f159242c5e0011d5e879641cf863fa
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1740652Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Commit-Queue: Hector Carmona <hcarmona@chromium.org>
Cr-Commit-Position: refs/heads/master@{#686161}
parent db47ab94
...@@ -277,6 +277,12 @@ ...@@ -277,6 +277,12 @@
<message name="IDS_EXTENSIONS_ITEM_VERSION" desc="The label above an extension's version."> <message name="IDS_EXTENSIONS_ITEM_VERSION" desc="The label above an extension's version.">
Version Version
</message> </message>
<message name="IDS_EXTENSIONS_ITEM_RELOADED" desc="Text displayed in a toast popup message when an extension has been reloaded.">
Reloaded
</message>
<message name="IDS_EXTENSIONS_ITEM_RELOADING" desc="Text displayed in a toast popup message when an extension is reloading.">
Reloading...
</message>
<message name="IDS_EXTENSIONS_LOAD_ERROR_HEADING" desc="The title of the dialog displaying the error when loading an unpacked extension fails."> <message name="IDS_EXTENSIONS_LOAD_ERROR_HEADING" desc="The title of the dialog displaying the error when loading an unpacked extension fails.">
Failed to load extension Failed to load extension
</message> </message>
...@@ -382,7 +388,7 @@ ...@@ -382,7 +388,7 @@
<message name="IDS_EXTENSIONS_TOOLBAR_UPDATE_NOW_TOOLTIP" desc="Text displayed over the 'update' menu that provides more context as a tooltip."> <message name="IDS_EXTENSIONS_TOOLBAR_UPDATE_NOW_TOOLTIP" desc="Text displayed over the 'update' menu that provides more context as a tooltip.">
Update extensions now Update extensions now
</message> </message>
<message name="IDS_EXTENSIONS_TOOLBAR_UPDATE_DONE" desc="Text used to announce when extensions have been updated. This is for accessibility."> <message name="IDS_EXTENSIONS_TOOLBAR_UPDATE_DONE" desc="Text displayed in a toast popup message when extensions have been updated.">
Extensions updated Extensions updated
</message> </message>
<message name="IDS_EXTENSIONS_TOOLBAR_UPDATING_TOAST" desc="Text displayed in a toast popup message while extensions are updating."> <message name="IDS_EXTENSIONS_TOOLBAR_UPDATING_TOAST" desc="Text displayed in a toast popup message while extensions are updating.">
......
...@@ -165,6 +165,7 @@ js_library("item") { ...@@ -165,6 +165,7 @@ js_library("item") {
":item_behavior", ":item_behavior",
":item_util", ":item_util",
":navigation_helper", ":navigation_helper",
"//ui/webui/resources/cr_elements/cr_toast:cr_toast_manager",
"//ui/webui/resources/js:assert", "//ui/webui/resources/js:assert",
"//ui/webui/resources/js:cr", "//ui/webui/resources/js:cr",
"//ui/webui/resources/js:i18n_behavior", "//ui/webui/resources/js:i18n_behavior",
...@@ -370,7 +371,7 @@ js_library("sidebar") { ...@@ -370,7 +371,7 @@ js_library("sidebar") {
js_library("toolbar") { js_library("toolbar") {
deps = [ deps = [
"//third_party/polymer/v1_0/components-chromium/iron-a11y-announcer:iron-a11y-announcer-extracted", "//third_party/polymer/v1_0/components-chromium/iron-a11y-announcer:iron-a11y-announcer-extracted",
"//ui/webui/resources/cr_elements/cr_toast:cr_toast", "//ui/webui/resources/cr_elements/cr_toast:cr_toast_manager",
"//ui/webui/resources/js:cr", "//ui/webui/resources/js:cr",
"//ui/webui/resources/js:i18n_behavior", "//ui/webui/resources/js:i18n_behavior",
"//ui/webui/resources/js:util", "//ui/webui/resources/js:util",
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
<link rel="import" href="chrome://resources/cr_elements/cr_button/cr_button.html"> <link rel="import" href="chrome://resources/cr_elements/cr_button/cr_button.html">
<link rel="import" href="chrome://resources/cr_elements/cr_icon_button/cr_icon_button.html"> <link rel="import" href="chrome://resources/cr_elements/cr_icon_button/cr_icon_button.html">
<link rel="import" href="chrome://resources/cr_elements/cr_icons_css.html"> <link rel="import" href="chrome://resources/cr_elements/cr_icons_css.html">
<link rel="import" href="chrome://resources/cr_elements/cr_toast/cr_toast_manager.html">
<link rel="import" href="chrome://resources/cr_elements/cr_toggle/cr_toggle.html"> <link rel="import" href="chrome://resources/cr_elements/cr_toggle/cr_toggle.html">
<link rel="import" href="chrome://resources/cr_elements/hidden_style_css.html"> <link rel="import" href="chrome://resources/cr_elements/hidden_style_css.html">
<link rel="import" href="chrome://resources/cr_elements/icons.html"> <link rel="import" href="chrome://resources/cr_elements/icons.html">
......
...@@ -117,6 +117,9 @@ cr.define('extensions', function() { ...@@ -117,6 +117,9 @@ cr.define('extensions', function() {
}, },
}, },
/** Prevents reloading the same item while it's already being reloaded. */
isReloading_: false,
observers: [ observers: [
'observeIdVisibility_(inDevMode, showingDetails_, data.id)', 'observeIdVisibility_(inDevMode, showingDetails_, data.id)',
], ],
...@@ -213,9 +216,30 @@ cr.define('extensions', function() { ...@@ -213,9 +216,30 @@ cr.define('extensions', function() {
/** @private */ /** @private */
onReloadTap_: function() { onReloadTap_: function() {
this.delegate.reloadItem(this.data.id).catch(loadError => { // Don't reload if in the middle of an update.
this.fire('load-error', loadError); if (this.isReloading_) {
}); return;
}
this.isReloading_ = true;
const toastManager = cr.toastManager.getInstance();
// Keep the toast open indefinitely.
toastManager.duration = 0;
toastManager.show(this.i18n('itemReloading'), false);
this.delegate.reloadItem(this.data.id)
.then(
() => {
toastManager.hide();
toastManager.duration = 3000;
toastManager.show(this.i18n('itemReloaded'), false);
this.isReloading_ = false;
},
loadError => {
this.fire('load-error', loadError);
toastManager.hide();
this.isReloading_ = false;
});
}, },
/** @private */ /** @private */
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
<link rel="import" href="chrome://resources/cr_elements/cr_drawer/cr_drawer.html"> <link rel="import" href="chrome://resources/cr_elements/cr_drawer/cr_drawer.html">
<link rel="import" href="chrome://resources/cr_elements/cr_lazy_render/cr_lazy_render.html"> <link rel="import" href="chrome://resources/cr_elements/cr_lazy_render/cr_lazy_render.html">
<link rel="import" href="chrome://resources/cr_elements/cr_toast/cr_toast_manager.html">
<link rel="import" href="chrome://resources/cr_elements/cr_toolbar/cr_toolbar.html"> <link rel="import" href="chrome://resources/cr_elements/cr_toolbar/cr_toolbar.html">
<link rel="import" href="chrome://resources/cr_elements/cr_view_manager/cr_view_manager.html"> <link rel="import" href="chrome://resources/cr_elements/cr_view_manager/cr_view_manager.html">
<link rel="import" href="chrome://resources/cr_elements/hidden_style_css.html"> <link rel="import" href="chrome://resources/cr_elements/hidden_style_css.html">
...@@ -138,6 +139,7 @@ ...@@ -138,6 +139,7 @@
install-warnings="[[installWarnings_]]"> install-warnings="[[installWarnings_]]">
</extensions-install-warnings-dialog> </extensions-install-warnings-dialog>
</template> </template>
<cr-toast-manager></cr-toast-manager>
</template> </template>
<script src="manager.js"></script> <script src="manager.js"></script>
</dom-module> </dom-module>
<link rel="import" href="chrome://resources/html/polymer.html"> <link rel="import" href="chrome://resources/html/polymer.html">
<link rel="import" href="chrome://resources/cr_elements/cr_button/cr_button.html"> <link rel="import" href="chrome://resources/cr_elements/cr_button/cr_button.html">
<link rel="import" href="chrome://resources/cr_elements/cr_toast/cr_toast.html"> <link rel="import" href="chrome://resources/cr_elements/cr_toast/cr_toast_manager.html">
<link rel="import" href="chrome://resources/cr_elements/cr_toggle/cr_toggle.html"> <link rel="import" href="chrome://resources/cr_elements/cr_toggle/cr_toggle.html">
<link rel="import" href="chrome://resources/cr_elements/cr_toolbar/cr_toolbar.html"> <link rel="import" href="chrome://resources/cr_elements/cr_toolbar/cr_toolbar.html">
<link rel="import" href="chrome://resources/cr_elements/hidden_style_css.html"> <link rel="import" href="chrome://resources/cr_elements/hidden_style_css.html">
...@@ -91,14 +91,6 @@ ...@@ -91,14 +91,6 @@
.more-actions span { .more-actions span {
margin-inline-end: 16px; margin-inline-end: 16px;
} }
cr-toast > div {
display: flex;
flex: 1;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
</style> </style>
<cr-toolbar page-name="$i18n{toolbarTitle}" search-prompt="$i18n{search}" <cr-toolbar page-name="$i18n{toolbarTitle}" search-prompt="$i18n{search}"
clear-label="$i18n{clearSearch}" menu-label="$i18n{mainMenu}" show-menu clear-label="$i18n{clearSearch}" menu-label="$i18n{mainMenu}" show-menu
...@@ -143,9 +135,6 @@ ...@@ -143,9 +135,6 @@
</if> </if>
</div> </div>
</div> </div>
<cr-toast>
<div>[[toastLabel_]]</div>
</cr-toast>
</template> </template>
<script src="toolbar.js"></script> <script src="toolbar.js"></script>
</dom-module> </dom-module>
...@@ -54,12 +54,6 @@ cr.define('extensions', function() { ...@@ -54,12 +54,6 @@ cr.define('extensions', function() {
/** @private */ /** @private */
showPackDialog_: Boolean, showPackDialog_: Boolean,
/**
* Text to display in update toast
* @private
*/
toastLabel_: String,
/** /**
* Prevents initiating update while update is in progress. * Prevents initiating update while update is in progress.
* @private * @private
...@@ -73,14 +67,6 @@ cr.define('extensions', function() { ...@@ -73,14 +67,6 @@ cr.define('extensions', function() {
role: 'banner', role: 'banner',
}, },
/** @override */
detached: function() {
const openToastElement = this.$$('cr-toast[open]');
if (openToastElement) {
openToastElement.hide();
}
},
/** /**
* @return {boolean} * @return {boolean}
* @private * @private
...@@ -163,23 +149,20 @@ cr.define('extensions', function() { ...@@ -163,23 +149,20 @@ cr.define('extensions', function() {
} }
this.isUpdating_ = true; this.isUpdating_ = true;
const toastElement = this.$$('cr-toast');
this.toastLabel_ = this.i18n('toolbarUpdatingToast');
const toastManager = cr.toastManager.getInstance();
// Keep the toast open indefinitely. // Keep the toast open indefinitely.
toastElement.duration = 0; toastManager.duration = 0;
toastElement.show(); toastManager.show(this.i18n('toolbarUpdatingToast'), false);
this.delegate.updateAllExtensions() this.delegate.updateAllExtensions().then(
.then(() => { () => {
Polymer.IronA11yAnnouncer.requestAvailability(); toastManager.hide();
const doneText = this.i18n('toolbarUpdateDone'); toastManager.duration = 3000;
this.fire('iron-announce', {text: doneText}); toastManager.show(this.i18n('toolbarUpdateDone'), false);
this.toastLabel_ = doneText;
toastElement.show(3000);
this.isUpdating_ = false; this.isUpdating_ = false;
}) },
.catch(function() { () => {
toastElement.hide(); toastManager.hide();
this.isUpdating_ = false; this.isUpdating_ = false;
}); });
}, },
......
...@@ -178,6 +178,8 @@ content::WebUIDataSource* CreateMdExtensionsSource(Profile* profile, ...@@ -178,6 +178,8 @@ content::WebUIDataSource* CreateMdExtensionsSource(Profile* profile,
{"itemSourceUnpacked", IDS_EXTENSIONS_ITEM_SOURCE_UNPACKED}, {"itemSourceUnpacked", IDS_EXTENSIONS_ITEM_SOURCE_UNPACKED},
{"itemSourceWebstore", IDS_EXTENSIONS_ITEM_SOURCE_WEBSTORE}, {"itemSourceWebstore", IDS_EXTENSIONS_ITEM_SOURCE_WEBSTORE},
{"itemVersion", IDS_EXTENSIONS_ITEM_VERSION}, {"itemVersion", IDS_EXTENSIONS_ITEM_VERSION},
{"itemReloaded", IDS_EXTENSIONS_ITEM_RELOADED},
{"itemReloading", IDS_EXTENSIONS_ITEM_RELOADING},
// TODO(dpapad): Replace this with an Extensions specific string. // TODO(dpapad): Replace this with an Extensions specific string.
{"itemSize", IDS_DIRECTORY_LISTING_SIZE}, {"itemSize", IDS_DIRECTORY_LISTING_SIZE},
{"itemAllowOnFileUrls", IDS_EXTENSIONS_ALLOW_FILE_ACCESS}, {"itemAllowOnFileUrls", IDS_EXTENSIONS_ALLOW_FILE_ACCESS},
......
...@@ -99,6 +99,8 @@ cr.define('extension_item_tests', function() { ...@@ -99,6 +99,8 @@ cr.define('extension_item_tests', function() {
item.set('data', extensionData); item.set('data', extensionData);
item.set('delegate', mockDelegate); item.set('delegate', mockDelegate);
document.body.appendChild(item); document.body.appendChild(item);
const toastManager = document.createElement('cr-toast-manager');
document.body.appendChild(toastManager);
}); });
test(assert(TestNames.ElementVisibilityNormalState), function() { test(assert(TestNames.ElementVisibilityNormalState), function() {
......
...@@ -92,11 +92,12 @@ cr.define('extension_toolbar_tests', function() { ...@@ -92,11 +92,12 @@ cr.define('extension_toolbar_tests', function() {
return mockDelegate.whenCalled('loadUnpacked'); return mockDelegate.whenCalled('loadUnpacked');
}) })
.then(function() { .then(function() {
assertFalse(toolbar.$$('cr-toast').open); const toastManager = cr.toastManager.getInstance();
assertFalse(toastManager.isToastOpen);
toolbar.$.updateNow.click(); toolbar.$.updateNow.click();
// Simulate user rapidly clicking update button multiple times. // Simulate user rapidly clicking update button multiple times.
toolbar.$.updateNow.click(); toolbar.$.updateNow.click();
assertTrue(toolbar.$$('cr-toast').open); assertTrue(toastManager.isToastOpen);
return mockDelegate.whenCalled('updateAllExtensions'); return mockDelegate.whenCalled('updateAllExtensions');
}) })
.then(function() { .then(function() {
......
...@@ -95,7 +95,7 @@ Polymer({ ...@@ -95,7 +95,7 @@ Polymer({
this.showUndo_ = showUndo; this.showUndo_ = showUndo;
Polymer.IronA11yAnnouncer.requestAvailability(); Polymer.IronA11yAnnouncer.requestAvailability();
this.fire('iron-announce', { this.fire('iron-announce', {
text: this.$.content, text: this.$.content.textContent,
}); });
if (showUndo && this.undoDescription) { if (showUndo && this.undoDescription) {
this.fire('iron-announce', { this.fire('iron-announce', {
......
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