Bug 1016184 - Part 3f: Fix test_paste_selection.html. r=ehsan
authorTing-Yu Lin <tlin@mozilla.com>
Sun, 27 Jul 2014 00:20:00 +0200
changeset 198011 a0497472946e6358fa55cdbbd9533bf2e950a7c0
parent 198010 122020a322551c8a06a36f9d105ac2e71cbf00b0
child 198012 5de01e536c0d3464feb7b86dfa64825f3fd2e7cb
push id1036
push userrnewman@mozilla.com
push dateWed, 06 Aug 2014 02:14:58 +0000
treeherderservices-central@3fd543e150c8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs1016184
milestone34.0a1
Bug 1016184 - Part 3f: Fix test_paste_selection.html. r=ehsan Thank Olli Pettay <bugs@pettay.fi> for suggesting sendMouseEventToWindow(). This is a tremendous help!
dom/tests/mochitest/general/test_paste_selection.html
--- a/dom/tests/mochitest/general/test_paste_selection.html
+++ b/dom/tests/mochitest/general/test_paste_selection.html
@@ -55,25 +55,31 @@ function selectArea()
 }
 
 var selectionPasted = false;
 var globalPasted = false;
 
 function pasteArea()
 {
   var pasteArea = document.getElementById("paste-selection-area");
+  var pasteAreaRect = pasteArea.getBoundingClientRect();
+  var pasteAreaCenterX = pasteAreaRect.left + pasteAreaRect.width/2;
+  var pasteAreaCenterY = pasteAreaRect.top + pasteAreaRect.height/2;
+  var util = SpecialPowers.getDOMWindowUtils(window);
+
   pasteArea.focus();
-  synthesizeMouse(pasteArea, 8, 8, { button: 1 });
+  util.sendMouseEventToWindow("mousedown", pasteAreaCenterX, pasteAreaCenterY, 1, 1, 0, true);
+  util.sendMouseEventToWindow("mouseup",   pasteAreaCenterX, pasteAreaCenterY, 1, 1, 0, true);
 
   var usesMouseButtonPaste = SpecialPowers.getBoolPref("middlemouse.paste");
   if (usesMouseButtonPaste) {
     // The data transfer should contain the selection data when the selection clipboard is supported,
     // not the global clipboard data.
     var expectedText = supportsSelectionClipboard ? "COPY TEXT" : "CLIPBOARD";
-    is(document.getElementById("paste-selection-area").value, expectedText, "data pasted properly from selection");
+    is(document.getElementById("paste-selection-area").value, expectedText, "In pasteArea(): data pasted properly from selection");
     ok(selectionPasted, "selection event fired");
   }
   else {
     is(pasteArea.value, "", "data not pasted when middle click not supported");
   }
 
   var pasteArea = document.getElementById("paste-global-area");
   pasteArea.focus();
@@ -87,17 +93,17 @@ function pasteArea()
 function pastedSelection(event)
 {
   ok(SpecialPowers.getBoolPref("middlemouse.paste"), "paste on middle click is valid");
 
   // Mac and Windows shouldn't get here as the middle mouse preference is false by default
   ok(navigator.platform.indexOf("Mac") == -1 && navigator.platform.indexOf("Win") == -1, "middle click enabled on right platforms");
 
   var expectedText = supportsSelectionClipboard ? "COPY TEXT" : "CLIPBOARD";
-  is(event.clipboardData.getData("text/plain"), expectedText, "data pasted properly from selection");
+  is(event.clipboardData.getData("text/plain"), expectedText, "In pastedSelection(): data pasted properly from selection");
 
   selectionPasted = true;
 }
 
 function pastedGlobal(event)
 {
   // The data transfer should contain the global data.
   is(event.clipboardData.getData("text/plain"), "CLIPBOARD", "data correct in global clipboard data transfer");