From 2cf3e9c3285c46f0c20866c971e8a01d58687467 Mon Sep 17 00:00:00 2001 From: Mark Hammond Date: Fri, 8 Feb 2013 10:59:10 +1100 Subject: [PATCH] Bug 824785 - social toolbar buttons should have an aria-label. r=jaws --- browser/base/content/browser-social.js | 9 +++++++-- .../base/content/test/social/browser_social_toolbar.js | 4 ++++ browser/locales/en-US/chrome/browser/browser.properties | 3 +++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/browser/base/content/browser-social.js b/browser/base/content/browser-social.js index db37320e5ef6..199f65816530 100644 --- a/browser/base/content/browser-social.js +++ b/browser/base/content/browser-social.js @@ -908,8 +908,13 @@ var SocialToolbar = { toolbarButton.setAttribute("tooltiptext", icon.label); let badge = icon.counter || ""; - if (toolbarButton.getAttribute("badge") != badge) - toolbarButton.setAttribute("badge", badge); + toolbarButton.setAttribute("badge", badge); + let ariaLabel = icon.label; + // if there is a badge value, we must use a localizable string to insert it. + if (badge) + ariaLabel = gNavigatorBundle.getFormattedString("social.aria.toolbarButtonBadgeText", + [ariaLabel, badge]); + toolbarButton.setAttribute("aria-label", ariaLabel); } let socialToolbarItem = document.getElementById("social-toolbar-item"); socialToolbarItem.appendChild(toolbarButtons); diff --git a/browser/base/content/test/social/browser_social_toolbar.js b/browser/base/content/test/social/browser_social_toolbar.js index 3ca232a2d284..b3fbf6e99a70 100644 --- a/browser/base/content/test/social/browser_social_toolbar.js +++ b/browser/base/content/test/social/browser_social_toolbar.js @@ -110,11 +110,15 @@ var tests = { }, function () { let badge = statusIcon.getAttribute("badge"); is(badge, "42", "status value is correct"); + // If there is a counter, the aria-label should reflect it. + is(statusIcon.getAttribute("aria-label"), "Test Ambient 1 \u2046 (42)"); ambience.counter = 0; Social.provider.setAmbientNotification(ambience); badge = statusIcon.getAttribute("badge"); is(badge, "", "status value is correct"); + // If there is no counter, the aria-label should be the same as the label + is(statusIcon.getAttribute("aria-label"), "Test Ambient 1 \u2046"); // The menu bar isn't as easy to instrument on Mac. if (navigator.platform.contains("Mac")) diff --git a/browser/locales/en-US/chrome/browser/browser.properties b/browser/locales/en-US/chrome/browser/browser.properties index a1f0884bffc2..ef24d3a4cac2 100644 --- a/browser/locales/en-US/chrome/browser/browser.properties +++ b/browser/locales/en-US/chrome/browser/browser.properties @@ -399,6 +399,9 @@ social.error.ok.accesskey=O social.error.closeSidebar.label=Close This Sidebar social.error.closeSidebar.accesskey=C +# LOCALIZATION NOTE: %1$S is the label for the toolbar button, %2$S is the associated badge numbering that the social provider may provide. +social.aria.toolbarButtonBadgeText=%1$S (%2$S) + # Identity notifications popups identity.termsOfService = Terms of Service identity.privacyPolicy = Privacy Policy