Bug 1363723 - Preserve array in aria owns hash. r=surkov, a=gchang
authorEitan Isaacson <eitan@monotonous.org>
Fri, 18 Aug 2017 07:41:03 -0400
changeset 423633 a60be780c0d78f4a2bc16efda26795005d19dc7f
parent 423632 e4803d1bcef0c47559758aba652a1ac7761630c0
child 423634 9832bd5eb39dfba4f9c4be23bd010232bac59fac
push id1517
push userjlorenzo@mozilla.com
push dateThu, 14 Sep 2017 16:50:54 +0000
treeherdermozilla-release@3b41fd564418 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssurkov, gchang
bugs1363723
milestone56.0
Bug 1363723 - Preserve array in aria owns hash. r=surkov, a=gchang
accessible/generic/DocAccessible.cpp
--- a/accessible/generic/DocAccessible.cpp
+++ b/accessible/generic/DocAccessible.cpp
@@ -2150,18 +2150,20 @@ DocAccessible::DoARIAOwnsRelocation(Acce
       }
       // A referred child cannot be a parent of the owner.
       if (parent == child) {
         continue;
       }
     }
 
     if (MoveChild(child, aOwner, insertIdx)) {
+      nsTArray<RefPtr<Accessible> >* relocated = mARIAOwnsHash.LookupOrAdd(aOwner);
+      MOZ_ASSERT(relocated == owned);
       child->SetRelocated(true);
-      owned->InsertElementAt(idx, child);
+      relocated->InsertElementAt(idx, child);
       idx++;
     }
   }
 
   // Put back children that are not seized anymore.
   PutChildrenBack(owned, idx);
   if (owned->Length() == 0) {
     mARIAOwnsHash.Remove(aOwner);
@@ -2217,17 +2219,18 @@ DocAccessible::PutChildrenBack(nsTArray<
     // 1. It was the last ordinal child, and the first aria-owned child.
     //    given:      <ul id="list" aria-owns="b"><li id="a"></li><li id="b"></li></ul>
     //    after load: $("list").setAttribute("aria-owns", "");
     // 2. The preceding adopted children were just reclaimed, eg:
     //    given:      <ul id="list"><li id="b"></li></ul>
     //    after load: $("list").setAttribute("aria-owns", "a b");
     //    later:      $("list").setAttribute("aria-owns", "");
     if (origContainer != owner || child->IndexInParent() != idxInParent) {
-      MoveChild(child, origContainer, idxInParent);
+      DebugOnly<bool> moved = MoveChild(child, origContainer, idxInParent);
+      MOZ_ASSERT(moved, "Failed to put child back.");
     } else {
       MOZ_ASSERT(!child->PrevSibling() || !child->PrevSibling()->IsRelocated(),
                  "No relocated child should appear before this one");
       MOZ_ASSERT(!child->NextSibling() || child->NextSibling()->IsRelocated(),
                  "No ordinal child should appear after this one");
     }
   }
 
@@ -2238,16 +2241,20 @@ bool
 DocAccessible::MoveChild(Accessible* aChild, Accessible* aNewParent,
                          int32_t aIdxInParent)
 {
   MOZ_ASSERT(aChild, "No child");
   MOZ_ASSERT(aChild->Parent(), "No parent");
   MOZ_ASSERT(aIdxInParent <= static_cast<int32_t>(aNewParent->ChildCount()),
              "Wrong insertion point for a moving child");
 
+  if (!aNewParent->IsAcceptableChild(aChild->GetContent())) {
+    return false;
+  }
+
   Accessible* curParent = aChild->Parent();
 
 #ifdef A11Y_LOG
   logging::TreeInfo("move child", 0,
                     "old parent", curParent, "new parent", aNewParent,
                     "child", aChild, nullptr);
 #endif
 
@@ -2271,20 +2278,16 @@ DocAccessible::MoveChild(Accessible* aCh
 
 #ifdef A11Y_LOG
     logging::TreeInfo("move child: parent tree after",
                       logging::eVerbose, curParent);
 #endif
     return true;
   }
 
-  if (!aNewParent->IsAcceptableChild(aChild->GetContent())) {
-    return false;
-  }
-
   MOZ_ASSERT(aIdxInParent <= static_cast<int32_t>(aNewParent->ChildCount()),
              "Wrong insertion point for a moving child");
 
   // If the child cannot be re-inserted into the tree, then make sure to remove
   // it from its present parent and then shutdown it.
   bool hasInsertionPoint = (aIdxInParent != -1) ||
     (aIdxInParent <= static_cast<int32_t>(aNewParent->ChildCount()));