[Bug 621913] Re-enable the 'click' test for browser_forms.js [r=mbrubeck]
authorVivien Nicolas <21@vingtetun.org>
Thu, 30 Dec 2010 09:54:59 +0100
changeset 67185 c943e10b336d83fe226f90acbfa7fab233607ccd
parent 67184 91c5222180a6d0a1f665d1572ebcf87135333ece
child 67186 d63210d121e8e745e0fe78033b1889cab6d36c94
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmbrubeck
bugs621913
[Bug 621913] Re-enable the 'click' test for browser_forms.js [r=mbrubeck]
mobile/chrome/tests/browser_forms.js
mobile/chrome/tests/remote_forms.js
--- a/mobile/chrome/tests/browser_forms.js
+++ b/mobile/chrome/tests/browser_forms.js
@@ -23,21 +23,20 @@ function onTabLoaded() {
   BrowserUI.closeAutoComplete(true);
   testMouseEvents();
 }
 
 function testMouseEvents() {
   // Sending a synthesized event directly on content should not work - we
   // don't want web content to be able to open the form helper without the
   // user consent, so we have to pass throught the canvas tile-container
-/*
   AsyncTests.waitFor("Test:Click", {}, function(json) {
     is(json.result, false, "Form Assistant should stay closed");
   });
-*/
+
   AsyncTests.waitFor("Test:Open", { value: "*[tabindex='0']" }, function(json) {
     ok(FormHelperUI._open, "Form Assistant should be open");
     testShowUIForElements();
   });
 };
 
 function testShowUIForElements() {
   AsyncTests.waitFor("Test:CanShowUI", { value: "*[tabindex='1']" }, function(json) {
--- a/mobile/chrome/tests/remote_forms.js
+++ b/mobile/chrome/tests/remote_forms.js
@@ -1,12 +1,55 @@
 dump("====================== Content Script Loaded =======================\n");
 
 let assistant = contentObject._formAssistant;
 
+// Copied from http://mxr.mozilla.org/mozilla-central/source/testing/mochitest/tests/SimpleTest/EventUtils.js
+// except the netscape.security.PrivilegeManager.enablePrivilege call
+function sendMouseEvent(aEvent, aTarget, aWindow) {
+  if (['click', 'mousedown', 'mouseup', 'mouseover', 'mouseout'].indexOf(aEvent.type) == -1) {
+    throw new Error("sendMouseEvent doesn't know about event type '" + aEvent.type + "'");
+  }
+
+  if (!aWindow) {
+    aWindow = window;
+  }
+
+  if (!(aTarget instanceof Element)) {
+    aTarget = aWindow.document.getElementById(aTarget);
+  }
+
+  let event = aWindow.document.createEvent('MouseEvent');
+
+  let typeArg          = aEvent.type;
+  let canBubbleArg     = true;
+  let cancelableArg    = true;
+  let viewArg          = aWindow;
+  let detailArg        = aEvent.detail        || (aEvent.type == 'click'     ||
+                                                  aEvent.type == 'mousedown' ||
+                                                  aEvent.type == 'mouseup' ? 1 : 0);
+  let screenXArg       = aEvent.screenX       || 0;
+  let screenYArg       = aEvent.screenY       || 0;
+  let clientXArg       = aEvent.clientX       || 0;
+  let clientYArg       = aEvent.clientY       || 0;
+  let ctrlKeyArg       = aEvent.ctrlKey       || false;
+  let altKeyArg        = aEvent.altKey        || false;
+  let shiftKeyArg      = aEvent.shiftKey      || false;
+  let metaKeyArg       = aEvent.metaKey       || false;
+  let buttonArg        = aEvent.button        || 0;
+  let relatedTargetArg = aEvent.relatedTarget || null;
+
+  event.initMouseEvent(typeArg, canBubbleArg, cancelableArg, viewArg, detailArg,
+                       screenXArg, screenYArg, clientXArg, clientYArg,
+                       ctrlKeyArg, altKeyArg, shiftKeyArg, metaKeyArg,
+                       buttonArg, relatedTargetArg);
+
+  aTarget.dispatchEvent(event);
+}
+
 AsyncTests.add("Test:Click", function(aMessage, aJson) {
   sendMouseEvent({type: "click"}, "root", content);
   return assistant._open;
 });
 
 AsyncTests.add("Test:Open", function(aMessage, aJson) {
   let element = content.document.querySelector(aJson.value);
   return assistant.open(element);