Bug 1327097 - Part II, Allow a11y test harness to listen event on the DOM element r=smaug,surkov
authorTimothy Guan-tin Chien <timdream@gmail.com>
Tue, 14 Nov 2017 17:02:45 +0800
changeset 436998 45520c6ace4e91772d80e431f3f564133b40fb14
parent 436997 400bffaca3646dfb4b6c85be8f464425713c92dc
child 436999 194be07f3d4b8a5988e730eb984eaf5c87685782
push id117
push userfmarier@mozilla.com
push dateTue, 28 Nov 2017 20:17:16 +0000
reviewerssmaug, surkov
bugs1327097
milestone59.0a1
Bug 1327097 - Part II, Allow a11y test harness to listen event on the DOM element r=smaug,surkov MozReview-Commit-ID: 6DA2vyHXwZN
accessible/tests/mochitest/actions.js
accessible/tests/mochitest/actions/test_media.html
accessible/tests/mochitest/events.js
--- a/accessible/tests/mochitest/actions.js
+++ b/accessible/tests/mochitest/actions.js
@@ -59,26 +59,26 @@ function testActions(aArray) {
     var events = actionObj.events;
     var accOrElmOrIDOfTarget = actionObj.targetID ?
       actionObj.targetID : accOrElmOrID;
 
     var eventSeq = [];
     if (events) {
       var elm = getNode(accOrElmOrIDOfTarget);
       if (events & MOUSEDOWN_EVENT)
-        eventSeq.push(new checkerOfActionInvoker("mousedown", elm));
+        eventSeq.push(new checkerOfActionInvoker("mousedown", elm, actionObj));
 
       if (events & MOUSEUP_EVENT)
-        eventSeq.push(new checkerOfActionInvoker("mouseup", elm));
+        eventSeq.push(new checkerOfActionInvoker("mouseup", elm, actionObj));
 
       if (events & CLICK_EVENT)
         eventSeq.push(new checkerOfActionInvoker("click", elm, actionObj));
 
       if (events & COMMAND_EVENT)
-        eventSeq.push(new checkerOfActionInvoker("command", elm));
+        eventSeq.push(new checkerOfActionInvoker("command", elm, actionObj));
 
       if (events & FOCUS_EVENT)
         eventSeq.push(new focusChecker(elm));
     }
 
     if (actionObj.eventSeq)
       eventSeq = eventSeq.concat(actionObj.eventSeq);
 
@@ -143,24 +143,28 @@ function actionInvoker(aAccOrElmOrId, aA
   };
 }
 
 function checkerOfActionInvoker(aType, aTarget, aActionObj) {
   this.type = aType;
 
   this.target = aTarget;
 
+  if (aActionObj && "eventTarget" in aActionObj) {
+    this.eventTarget = aActionObj.eventTarget;
+  }
+
   this.phase = false;
 
   this.getID = function getID() {
     return aType + " event handling";
   };
 
   this.check = function check(aEvent) {
-    if (aActionObj && "checkOnClickEvent" in aActionObj)
+    if (aType == "click" && aActionObj && "checkOnClickEvent" in aActionObj)
       aActionObj.checkOnClickEvent(aEvent);
   };
 }
 
 var gActionDescrMap =
 {
   jump: "Jump",
   press: "Press",
--- a/accessible/tests/mochitest/actions/test_media.html
+++ b/accessible/tests/mochitest/actions/test_media.html
@@ -59,32 +59,34 @@ https://bugzilla.mozilla.org/show_bug.cg
       var playBtn = audioElm.firstChild;
       // var scrubber = playBtn.nextSibling.nextSibling.nextSibling;
       var muteBtn = audioElm.lastChild.previousSibling;
 
       var actions = [
         {
           ID: muteBtn,
           actionName: "press",
+          eventTarget: "element",
           eventSeq: [
      //       new focusChecker(muteBtn),
             new nameChecker(muteBtn, "Unmute"),
           ]
         },
      //   {
      //     ID: scrubber,
      //     actionName: "activate",
      //     events: null,
      //     eventSeq: [
      //       new focusChecker(scrubber)
      //     ]
      //   },
         {
           ID: playBtn,
           actionName: "press",
+          eventTarget: "element",
           eventSeq: [
      //       new focusChecker(playBtn),
             new nameChecker(playBtn, "Pause"),
           ]
         }
       ];
 
       testActions(actions); // Will call SimpleTest.finish();
--- a/accessible/tests/mochitest/events.js
+++ b/accessible/tests/mochitest/events.js
@@ -741,23 +741,23 @@ function eventQueue(aEventType) {
 
           gLogger.logToConsole(msg);
           gLogger.logToDOM(msg, true);
         }
 
         var eventType = eventSeq[idx].type;
         if (typeof eventType == "string") {
           // DOM event
-          var target = eventSeq[idx].target;
+          var target = eventQueue.getEventTarget(eventSeq[idx]);
           if (!target) {
             ok(false, "no target for DOM event!");
             return false;
           }
           var phase = eventQueue.getEventPhase(eventSeq[idx]);
-          target.ownerDocument.addEventListener(eventType, this, phase);
+          target.addEventListener(eventType, this, phase);
 
         } else {
           // A11y event
           addA11yEventListener(eventType, this);
         }
       }
     }
 
@@ -769,19 +769,19 @@ function eventQueue(aEventType) {
       return;
 
     for (var scnIdx = 0; scnIdx < this.mScenarios.length; scnIdx++) {
       var eventSeq = this.mScenarios[scnIdx];
       for (var idx = 0; idx < eventSeq.length; idx++) {
         var eventType = eventSeq[idx].type;
         if (typeof eventType == "string") {
           // DOM event
-          var target = eventSeq[idx].target;
+          var target = eventQueue.getEventTarget(eventSeq[idx]);
           var phase = eventQueue.getEventPhase(eventSeq[idx]);
-          target.ownerDocument.removeEventListener(eventType, this, phase);
+          target.removeEventListener(eventType, this, phase);
 
         } else {
           // A11y event
           removeA11yEventListener(eventType, this);
         }
       }
     }
     this.mScenarios = null;
@@ -848,16 +848,29 @@ eventQueue.getEventTargetDescr =
   var target = ("target" in aEventOrChecker) ? aEventOrChecker.target : null;
   return prettyName(target);
 };
 
 eventQueue.getEventPhase = function eventQueue_getEventPhase(aChecker) {
   return ("phase" in aChecker) ? aChecker.phase : true;
 };
 
+eventQueue.getEventTarget = function eventQueue_getEventTarget(aChecker) {
+  if ("eventTarget" in aChecker) {
+    switch (aChecker.eventTarget) {
+      case "element":
+        return aChecker.target;
+      case "document":
+      default:
+        return aChecker.target.ownerDocument;
+    }
+  }
+  return aChecker.target.ownerDocument;
+};
+
 eventQueue.compareEventTypes =
   function eventQueue_compareEventTypes(aChecker, aEvent) {
   var eventType = (aEvent instanceof nsIDOMEvent) ?
     aEvent.type : aEvent.eventType;
   return aChecker.type == eventType;
 };
 
 eventQueue.compareEvents = function eventQueue_compareEvents(aChecker, aEvent) {