[
Bug 621913] Re-enable the 'click' test for browser_forms.js [r=mbrubeck]
--- 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);