Bug 1371781 - Allow <select> accessible children to be put back in list accessible. r=surkov
authorEitan Isaacson <eitan@monotonous.org>
Tue, 01 Aug 2017 10:05:00 -0400
changeset 420931 7a7d0f16188847945f84b801fd8fa3ceb8875028
parent 420930 20344f0dbff988eddcec3387de3d1d575fbc9e89
child 420932 91c93c5ea5b2f1a340f78cab9dbbb64b74a23ea3
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssurkov
bugs1371781
milestone56.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 1371781 - Allow <select> accessible children to be put back in list accessible. r=surkov
accessible/generic/DocAccessible.cpp
accessible/tests/browser/tree/browser.ini
accessible/tests/browser/tree/browser_test_aria_owns_select.js
--- a/accessible/generic/DocAccessible.cpp
+++ b/accessible/generic/DocAccessible.cpp
@@ -2169,17 +2169,16 @@ DocAccessible::DoARIAOwnsRelocation(Acce
 }
 
 void
 DocAccessible::PutChildrenBack(nsTArray<RefPtr<Accessible> >* aChildren,
                                uint32_t aStartIdx)
 {
   MOZ_ASSERT(aStartIdx <= aChildren->Length(), "Wrong removal index");
 
-  nsTArray<RefPtr<Accessible> > containers;
   for (auto idx = aStartIdx; idx < aChildren->Length(); idx++) {
     Accessible* child = aChildren->ElementAt(idx);
     if (!child->IsInDocument()) {
       continue;
     }
 
     // Remove the child from the owner
     Accessible* owner = child->Parent();
@@ -2191,21 +2190,22 @@ DocAccessible::PutChildrenBack(nsTArray<
 #ifdef A11Y_LOG
     logging::TreeInfo("aria owns put child back", 0,
                       "old parent", owner, "child", child, nullptr);
 #endif
 
     // Unset relocated flag to find an insertion point for the child.
     child->SetRelocated(false);
 
+    nsIContent* content = child->GetContent();
     int32_t idxInParent = -1;
-    Accessible* origContainer = GetContainerAccessible(child->GetContent());
+    Accessible* origContainer = AccessibleOrTrueContainer(content->GetParentNode());
     if (origContainer) {
       TreeWalker walker(origContainer);
-      if (walker.Seek(child->GetContent())) {
+      if (walker.Seek(content)) {
         Accessible* prevChild = walker.Prev();
         if (prevChild) {
           idxInParent = prevChild->IndexInParent() + 1;
           MOZ_DIAGNOSTIC_ASSERT(origContainer == prevChild->Parent(), "Broken tree");
           origContainer = prevChild->Parent();
         }
         else {
           idxInParent = 0;
--- a/accessible/tests/browser/tree/browser.ini
+++ b/accessible/tests/browser/tree/browser.ini
@@ -2,8 +2,9 @@
 skip-if = e10s && os == 'win' && release_or_beta
 support-files =
   head.js
   !/accessible/tests/browser/events.js
   !/accessible/tests/browser/shared-head.js
   !/accessible/tests/mochitest/*.js
 
 [browser_test_aria_owns.js]
+[browser_test_aria_owns_select.js]
new file mode 100644
--- /dev/null
+++ b/accessible/tests/browser/tree/browser_test_aria_owns_select.js
@@ -0,0 +1,45 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+function testChildrenIds(acc, expectedIds) {
+  let ids = arrayFromChildren(acc).map(child => getAccessibleDOMNodeID(child));
+  Assert.deepEqual(ids, expectedIds,
+    `Children for ${getAccessibleDOMNodeID(acc)} are wrong.`);
+}
+
+async function runTests(browser, accDoc) {
+  let div = findAccessibleChildByID(accDoc, "div");
+  let select = findAccessibleChildByID(accDoc, "select");
+
+  testChildrenIds(div, ["b"]);
+  testChildrenIds(select.firstChild, ["a"]);
+
+  let onReorders = waitForEvents([
+    [EVENT_REORDER, "div"],
+    [EVENT_REORDER,
+      evt => getAccessibleDOMNodeID(evt.accessible.parent) == "select"]
+  ]);
+
+  await ContentTask.spawn(browser, null, async function() {
+    document.getElementById("div").removeAttribute("aria-owns");
+  });
+
+  await onReorders;
+
+  testChildrenIds(div, []);
+  testChildrenIds(select.firstChild, ["a", "b"]);
+}
+
+/**
+ * Test caching of accessible object states
+ */
+addAccessibleTask(`
+  <div id="div" role="group" aria-owns="b"></div>
+  <select id="select">
+    <option id="a"></option>
+    <option id="b"></option>
+  </select>
+    `, runTests);