Bug 1642258: Allow role="alert" on the body of chrome documents (but not content documents). r=MarcoZ
authorJames Teh <jteh@mozilla.com>
Tue, 02 Jun 2020 05:53:52 +0000
changeset 597505 5bbbf98b5a9c58e47f23b767ca7bd4c828bc6354
parent 597504 c8a7ccb337cce55055ef3a7727df44c85b1abea8
child 597506 3260905f68d15d2991157be3123ec164537892c5
push id13310
push userffxbld-merge
push dateMon, 29 Jun 2020 14:50:06 +0000
treeherdermozilla-beta@15a59a0afa5c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMarcoZ
bugs1642258
milestone79.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1642258: Allow role="alert" on the body of chrome documents (but not content documents). r=MarcoZ Also fixes a typo in an existing test that meant we weren't actually testing as intended. Differential Revision: https://phabricator.services.mozilla.com/D77628
accessible/generic/DocAccessible.cpp
accessible/tests/mochitest/role/a11y.ini
accessible/tests/mochitest/role/chrome_body_role_alert.xhtml
accessible/tests/mochitest/role/test_aria.html
--- a/accessible/generic/DocAccessible.cpp
+++ b/accessible/generic/DocAccessible.cpp
@@ -2647,15 +2647,19 @@ void DocAccessible::ARIAActiveDescendant
   // tree yet. Therefore, schedule this async to ensure the tree is up to date.
   mNotificationController->ScheduleNotification<DocAccessible, Accessible>(
       this, &DocAccessible::ARIAActiveDescendantChanged, acc);
 }
 
 void DocAccessible::SetRoleMapEntryForDoc(dom::Element* aElement) {
   const nsRoleMapEntry* entry = aria::GetRoleMap(aElement);
   if (!entry || entry->role == roles::APPLICATION ||
-      entry->role == roles::DIALOG) {
+      entry->role == roles::DIALOG ||
+      // Role alert isn't valid on the body element according to the ARIA spec,
+      // but it's useful for our UI; e.g. the WebRTC sharing indicator.
+      (entry->role == roles::ALERT &&
+       !nsCoreUtils::IsContentDocument(mDocumentNode))) {
     SetRoleMapEntry(entry);
     return;
   }
   // No other ARIA roles are valid on body elements.
   SetRoleMapEntry(nullptr);
 }
--- a/accessible/tests/mochitest/role/a11y.ini
+++ b/accessible/tests/mochitest/role/a11y.ini
@@ -1,10 +1,11 @@
 [DEFAULT]
 support-files =
+  chrome_body_role_alert.xhtml
   !/accessible/tests/mochitest/*.js
   !/accessible/tests/mochitest/moz.png
 
 [test_aria.html]
 [test_aria.xhtml]
 [test_dpub_aria.html]
 [test_general.html]
 [test_general.xhtml]
new file mode 100644
--- /dev/null
+++ b/accessible/tests/mochitest/role/chrome_body_role_alert.xhtml
@@ -0,0 +1,6 @@
+<?xml version="1.0"?>
+<!DOCTYPE html>
+<html xmlns="http://www.w3.org/1999/xhtml">
+  <body role="alert">
+  </body>
+</html>
--- a/accessible/tests/mochitest/role/test_aria.html
+++ b/accessible/tests/mochitest/role/test_aria.html
@@ -17,17 +17,17 @@
     // To test initial roles on body elements, we need to use an iframe.
     function testBodyRole(iframeId, role) {
       let iframe = getNode(iframeId);
       let doc = iframe.contentDocument;
       let docAcc = getAccessible(doc);
       testRole(docAcc, role);
     }
 
-    function doTest() {
+    async function doTest() {
       // ARIA role map.
       testRole("aria_alert", ROLE_ALERT);
       testRole("aria_alertdialog", ROLE_DIALOG);
       testRole("aria_application", ROLE_APPLICATION);
       testRole("aria_article", ROLE_ARTICLE);
       testRole("aria_blockquote", ROLE_BLOCKQUOTE);
       testRole("aria_button", ROLE_PUSHBUTTON);
       testRole("aria_caption", ROLE_CAPTION);
@@ -185,20 +185,33 @@
       testRole("img_eq", ROLE_FLAT_EQUATION);
 
       // Test textual equation
       testRole("txt_eq", ROLE_FLAT_EQUATION);
 
       // Test initial ARIA roles on the body element.
       testBodyRole("iframe_aria_application", ROLE_APPLICATION);
       testBodyRole("iframe_aria_dialog", ROLE_DIALOG);
+      // role="alert" is valid on the body of chrome documents.
+      let win = Services.ww.openWindow(
+        null,
+        "chrome://mochitests/content/a11y/accessible/tests/mochitest/role/chrome_body_role_alert.xhtml",
+        "_blank",
+        "chrome",
+        []
+      );
+      await SimpleTest.promiseFocus(win);
+      testRole(win.document, ROLE_ALERT);
+      win.close();
       // Other roles aren't valid on body elements.
       testBodyRole("iframe_aria_document", ROLE_DOCUMENT);
       testBodyRole("iframe_aria_button", ROLE_DOCUMENT);
-      testBodyRole("iframe_aria_button", ROLE_DOCUMENT);
+      testBodyRole("iframe_aria_main", ROLE_DOCUMENT);
+      // role="alert" is not valid on the body of content documents.
+      testBodyRole("iframe_aria_alert", ROLE_DOCUMENT);
 
       SimpleTest.finish();
     }
 
     SimpleTest.waitForExplicitFinish();
     addA11yLoadEvent(doTest);
   </script>
 </head>
@@ -415,10 +428,12 @@
   <iframe id="iframe_aria_dialog"
     src="data:text/html,<body role='dialog'>"></iframe>
   <iframe id="iframe_aria_document"
     src="data:text/html,<body role='document'>"></iframe>
   <iframe id="iframe_aria_button"
     src="data:text/html,<body role='button'>"></iframe>
   <iframe id="iframe_aria_main"
     src="data:text/html,<body role='main'>"></iframe>
+  <iframe id="iframe_aria_alert"
+    src="data:text/html,<body role='alert'>"></iframe>
 </body>
 </html>