Bug 818407 - changing the HTML body doesn't pick up ARIA role, r=tbsaunde
authorAlexander Surkov <surkov.alexander@gmail.com>
Mon, 24 Dec 2012 21:40:15 +0900
changeset 116998 7192d0dae605a7b24bf4871a1fac2df0fad13ab8
parent 116997 e097dd1a2c38bc7a63430bb7163ab1a51d5d0f8a
child 116999 ab4c7ba485010d58b468d8f2a4e7f60828325a29
push id24079
push userryanvm@gmail.com
push dateWed, 26 Dec 2012 12:59:56 +0000
treeherdermozilla-central@f5ed2691d901 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstbsaunde
bugs818407
milestone20.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 818407 - changing the HTML body doesn't pick up ARIA role, r=tbsaunde
accessible/src/generic/DocAccessible.cpp
accessible/tests/mochitest/treeupdate/test_doc.html
--- a/accessible/src/generic/DocAccessible.cpp
+++ b/accessible/src/generic/DocAccessible.cpp
@@ -1512,18 +1512,20 @@ void
 DocAccessible::DoInitialUpdate()
 {
   mLoadState |= eTreeConstructed;
 
   // The content element may be changed before the initial update and then we
   // miss the notification (since content tree change notifications are ignored
   // prior to initial update). Make sure the content element is valid.
   nsIContent* contentElm = nsCoreUtils::GetRoleContent(mDocumentNode);
-  if (mContent != contentElm)
+  if (mContent != contentElm) {
     mContent = contentElm;
+    SetRoleMapEntry(aria::GetRoleMap(mContent));
+  }
 
   // Build initial tree.
   CacheChildrenInSubtree(this);
 
   // Fire reorder event after the document tree is constructed. Note, since
   // this reorder event is processed by parent document then events targeted to
   // this document may be fired prior to this reorder event. If this is
   // a problem then consider to keep event processing per tab document.
@@ -1734,18 +1736,20 @@ DocAccessible::ProcessContentInserted(Ac
       continue;
 
     if (containerNotUpdated) {
       containerNotUpdated = false;
 
       if (aContainer == this) {
         // If new root content has been inserted then update it.
         nsIContent* rootContent = nsCoreUtils::GetRoleContent(mDocumentNode);
-        if (rootContent != mContent)
+        if (rootContent != mContent) {
           mContent = rootContent;
+          SetRoleMapEntry(aria::GetRoleMap(mContent));
+        }
 
         // Continue to update the tree even if we don't have root content.
         // For example, elements may be inserted under the document element while
         // there is no HTML body element.
       }
 
       // XXX: Invalidate parent-child relations for container accessible and its
       // children because there's no good way to find insertion point of new child
--- a/accessible/tests/mochitest/treeupdate/test_doc.html
+++ b/accessible/tests/mochitest/treeupdate/test_doc.html
@@ -27,27 +27,27 @@
     {
       return getNode(aID).contentDocument;
     }
     function getDocChildNode(aID)
     {
       return getDocNode(aID).body.firstChild;
     }
 
-    function rootContentReplaced(aID, aTextName)
+    function rootContentReplaced(aID, aTextName, aRootContentRole)
     {
       this.eventSeq = [
         new invokerChecker(EVENT_SHOW, getDocChildNode, aID),
         new invokerChecker(EVENT_REORDER, getDocNode, aID)
       ];
 
       this.finalCheck = function rootContentReplaced_finalCheck()
       {
         var tree = {
-          role: ROLE_DOCUMENT,
+          role: aRootContentRole || ROLE_DOCUMENT,
           children: [
             {
               role: ROLE_TEXT_LEAF,
               name: aTextName
             }
           ]
         };
         testAccessibleTree(getDocNode(aID), tree);
@@ -137,59 +137,69 @@
         var newHTMLNode = docNode.createElement("html");
         var newBodyNode = docNode.createElement("body");
         var newTextNode = docNode.createTextNode("New Wave");
         newBodyNode.appendChild(newTextNode);
         newHTMLNode.appendChild(newBodyNode);
         docNode.replaceChild(newHTMLNode, docNode.documentElement);
       }
 
-      this.getID = function replaceIFrameBody_getID()
+      this.getID = function replaceIFrameHTMLElm_getID()
       {
         return "replace HTML element";
       }
     }
 
     /**
-     * Replace HTML body.
+     * Replace HTML body on new body having ARIA role.
      */
     function replaceIFrameBody(aID)
     {
       this.__proto__ = new rootContentReplaced(aID, "New Hello");
 
       this.invoke = function replaceIFrameBody_invoke()
       {
         var docNode = getDocNode(aID);
         var newBodyNode = docNode.createElement("body");
         var newTextNode = docNode.createTextNode("New Hello");
         newBodyNode.appendChild(newTextNode);
         docNode.documentElement.replaceChild(newBodyNode, docNode.body);
       }
 
-      this.finalCheck = function replaceIFrameBody_finalCheck()
-      {
-        var tree = {
-          role: ROLE_DOCUMENT,
-          children: [
-            {
-              role: ROLE_TEXT_LEAF,
-              name: "New Hello"
-            }
-          ]
-        };
-        testAccessibleTree(getDocNode(aID), tree);
-      }
-
       this.getID = function replaceIFrameBody_getID()
       {
         return "replace body";
       }
     }
 
     /**
+     * Replace HTML body on new body having ARIA role.
+     */
+    function replaceIFrameBodyOnARIARoleBody(aID)
+    {
+      this.__proto__ = new rootContentReplaced(aID, "New Hello",
+                                               ROLE_PUSHBUTTON);
+
+      this.invoke = function replaceIFrameBodyOnARIARoleBody_invoke()
+      {
+        var docNode = getDocNode(aID);
+        var newBodyNode = docNode.createElement("body");
+        var newTextNode = docNode.createTextNode("New Hello");
+        newBodyNode.appendChild(newTextNode);
+        newBodyNode.setAttribute("role", "button");
+        docNode.documentElement.replaceChild(newBodyNode, docNode.body);
+      }
+
+      this.getID = function replaceIFrameBodyOnARIARoleBody_getID()
+      {
+        return "replace body on body having ARIA role";
+      }
+    }
+
+    /**
      * Open/close document pair.
      */
     function openIFrameDoc(aID)
     {
       this.__proto__ = new rootContentRemoved(aID);
 
       this.invoke = function openIFrameDoc_invoke()
       {
@@ -396,16 +406,17 @@
       gQueue.push(new openIFrameDoc("iframe"));
       gQueue.push(new closeIFrameDoc("iframe"));
       gQueue.push(new removeHTMLFromIFrameDoc("iframe"));
       gQueue.push(new insertHTMLToIFrameDoc("iframe"));
       gQueue.push(new removeBodyFromIFrameDoc("iframe"));
       gQueue.push(new insertElmUnderDocElmWhileBodyMissed("iframe"));
       gQueue.push(new insertBodyToIFrameDoc("iframe"));
       gQueue.push(new changeSrc("iframe"));
+      gQueue.push(new replaceIFrameBodyOnARIARoleBody("iframe"));
 
       gQueue.invoke(); // SimpleTest.finish() will be called in the end
     }
 
     SimpleTest.waitForExplicitFinish();
     addA11yLoadEvent(doTest);
   </script>
 </head>
@@ -415,16 +426,19 @@
      title="Update accessible tree when root element is changed"
      href="https://bugzilla.mozilla.org/show_bug.cgi?id=606082">Mozilla Bug 606082</a>
   <a target="_blank"
      title="Elements inserted outside the body aren't accessible"
      href="https://bugzilla.mozilla.org/show_bug.cgi?id=608887">Mozilla Bug 608887</a>
   <a target="_blank"
      title="Reorder event for document must be fired after document initial tree creation"
      href="https://bugzilla.mozilla.org/show_bug.cgi?id=669263">Mozilla Bug 669263</a>
+  <a target="_blank"
+     title="Changing the HTML body doesn't pick up ARIA role"
+     href="https://bugzilla.mozilla.org/show_bug.cgi?id=818407">Mozilla Bug 818407</a>
 
   <p id="display"></p>
   <div id="content" style="display: none"></div>
   <pre id="test">
   </pre>
 
   <iframe id="iframe"></iframe>