Bug 858206 - Part 3: Add mochitests. r=jimm
authorAleh Zasypkin <aleh.zasypkin@gmail.com>
Thu, 06 Mar 2014 22:38:32 +0100
changeset 190322 b1b516d5c5e6c2d884e57107101b1e1f9b29193c
parent 190321 1b636faa318773541a796c0081f641cbd03ca8bf
child 190323 4f50ba79c6fffdddc9add080f5d4c783d6cf5c12
push id3503
push userraliiev@mozilla.com
push dateMon, 28 Apr 2014 18:51:11 +0000
treeherdermozilla-beta@c95ac01e332e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimm
bugs858206
milestone30.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 858206 - Part 3: Add mochitests. r=jimm
browser/metro/base/tests/mochitest/browser_selection_contenteditable.js
browser/metro/base/tests/mochitest/browser_selection_inputs.js
browser/metro/base/tests/mochitest/browser_selection_urlbar.js
--- a/browser/metro/base/tests/mochitest/browser_selection_contenteditable.js
+++ b/browser/metro/base/tests/mochitest/browser_selection_contenteditable.js
@@ -32,17 +32,17 @@ gTests.push({
 });
 
 gTests.push({
   desc: "simple test to make sure content editable selection works",
   run: function test() {
     let div = gWindow.document.getElementById("testdiv");
     ok(div, "have the div");
 
-    sendElementTap(gWindow, div, 287); // end of 'outlook.com'
+    sendElementTap(gWindow, div, 284); // end of 'outlook.com'
 
     yield waitForCondition(function () {
         return SelectionHelperUI.isCaretUIVisible;
       }, kCommonWaitMs, kCommonPollMs);
 
     let xpos = SelectionHelperUI.caretMark.xPos;
     let ypos = SelectionHelperUI.caretMark.yPos + 10;
     var touchdrag = new TouchDragAndHold();
--- a/browser/metro/base/tests/mochitest/browser_selection_inputs.js
+++ b/browser/metro/base/tests/mochitest/browser_selection_inputs.js
@@ -190,16 +190,106 @@ gTests.push({
     yield touchdrag.move(135, ystartpos);
     touchdrag.end();
 
     yield SelectionHelperUI.pingSelectionHandler();
     is(getTrimmedSelection(gInput).toString(), "straight on like a tunnel for", "selection test");
   },
 });
 
+gTests.push({
+  desc: "Bug 858206 - Drag selection monocles should not push other monocles " +
+        "out of the way.",
+  setUp: setUpAndTearDown,
+  tearDown: setUpAndTearDown,
+  run: function test() {
+    let inputOriginalValue = gInput.value;
+
+    gInput.value = "The rabbit-hole went straight on";
+
+    let promise = waitForEvent(document, "popupshown");
+    sendContextMenuClickToElement(gWindow, gInput, 150);
+    yield promise;
+
+    // Make initial selection
+    promise = waitForEvent(document, "popuphidden");
+    sendElementTap(gWindow, document.getElementById("context-select"));
+    yield promise;
+
+    yield waitForCondition(() => SelectionHelperUI.isSelectionUIVisible,
+        kCommonWaitMs, kCommonPollMs);
+    is(getTrimmedSelection(gInput).toString(), "straight");
+
+    // Swap monocles when dragging with end monocle
+    let startXPos = SelectionHelperUI.endMark.xPos;
+    let startYPos = SelectionHelperUI.endMark.yPos + 10;
+    let touchDrag = new TouchDragAndHold();
+    yield touchDrag.start(gWindow, startXPos, startYPos, startXPos - 300,
+        startYPos);
+
+    yield waitForCondition(() => getTrimmedSelection(gInput).toString() ==
+        "The rabbit-hole went", kCommonWaitMs, kCommonPollMs);
+    touchDrag.end();
+    yield waitForCondition(() => !SelectionHelperUI.hasActiveDrag,
+        kCommonWaitMs, kCommonPollMs);
+    yield SelectionHelperUI.pingSelectionHandler();
+
+     // Swap monocles when dragging with start monocle
+    startXPos = SelectionHelperUI.startMark.xPos;
+    startYPos = SelectionHelperUI.startMark.yPos + 10;
+    yield touchDrag.start(gWindow, startXPos, startYPos, startXPos + 300,
+        startYPos);
+    yield waitForCondition(() => getTrimmedSelection(gInput).toString() ==
+        "straight on", kCommonWaitMs, kCommonPollMs);
+    touchDrag.end();
+    yield waitForCondition(() => !SelectionHelperUI.hasActiveDrag,
+        kCommonWaitMs, kCommonPollMs);
+    yield SelectionHelperUI.pingSelectionHandler();
+
+    // Swap monocles right after caret-to-selection mode switch from start
+    gInput.selectionStart = gInput.selectionEnd = 0;
+    sendElementTap(gWindow, gInput, 0, 0);
+
+    yield waitForCondition(() => !SelectionHelperUI.isSelectionUIVisible &&
+        SelectionHelperUI.isCaretUIVisible);
+
+    startXPos = SelectionHelperUI.caretMark.xPos;
+    startYPos = SelectionHelperUI.caretMark.yPos + 10;
+
+    yield touchDrag.start(gWindow, startXPos, startYPos, startXPos + 300,
+        startYPos);
+    yield waitForCondition(() => getTrimmedSelection(gInput).toString() ==
+        "The rabbit-hole went straight on", kCommonWaitMs, kCommonPollMs);
+    touchDrag.end();
+
+    sendTap(gWindow, 10, 10);
+    yield waitForCondition(() => !SelectionHelperUI.isSelectionUIVisible);
+
+    // Swap monocles right after caret-to-selection mode switch from end
+    gInput.selectionStart = gInput.selectionEnd = gInput.value.length;
+    let inputSelectionRectangle = gInput.QueryInterface(Ci.nsIDOMNSEditableElement).
+        editor.selection.getRangeAt(0).getClientRects()[0];
+    sendTap(gWindow, inputSelectionRectangle.right,
+        inputSelectionRectangle.top);
+
+    yield waitForCondition(() => SelectionHelperUI.isCaretUIVisible);
+
+    startXPos = SelectionHelperUI.caretMark.xPos;
+    startYPos = SelectionHelperUI.caretMark.yPos + 10;
+
+    yield touchDrag.start(gWindow, startXPos, startYPos, startXPos - 300,
+        startYPos);
+    yield waitForCondition(() => getTrimmedSelection(gInput).toString() ==
+        "The rabbit-hole went straight on", kCommonWaitMs, kCommonPollMs);
+    touchDrag.end();
+
+    gInput.value = inputOriginalValue;
+  }
+});
+
 function test() {
   if (!isLandscapeMode()) {
     todo(false, "browser_selection_tests need landscape mode to run.");
     return;
   }
   // XXX need this until bugs 886624 and 859742 are fully resolved
   setDevPixelEqualToPx();
   runTests();
--- a/browser/metro/base/tests/mochitest/browser_selection_urlbar.js
+++ b/browser/metro/base/tests/mochitest/browser_selection_urlbar.js
@@ -310,18 +310,104 @@ gTests.push({
     ok(!SelectHelperUI.isSelectionUIVisible && !SelectHelperUI.isCaretUIVisible,
         "Neither CaretUI nor SelectionUI is visible on empty input.");
 
     inputField.value = "Test text";
 
     sendTap(window, inputFieldRectangle.left + 10, inputFieldRectangle.top + 5);
 
     yield waitForCondition(() => SelectionHelperUI.isCaretUIVisible);
+    chromeHandlerSpy.restore();
+    inputField.blur();
+  }
+});
 
-    chromeHandlerSpy.restore();
+gTests.push({
+  desc: "Bug 858206 - Drag selection monocles should not push other monocles " +
+        "out of the way.",
+  run: function test() {
+    yield showNavBar();
+
+    let edit = document.getElementById("urlbar-edit");
+    edit.value = "about:mozilla";
+
+    let editRectangle = edit.getBoundingClientRect();
+
+    sendTap(window, editRectangle.left, editRectangle.top);
+
+    yield waitForCondition(() => SelectionHelperUI.isSelectionUIVisible);
+
+    let selection = edit.QueryInterface(
+        Components.interfaces.nsIDOMXULTextBoxElement).editor.selection;
+    let selectionRectangle = selection.getRangeAt(0).getClientRects()[0];
+
+    // Place caret to the input start
+    sendTap(window, selectionRectangle.left + 2, selectionRectangle.top + 2);
+    yield waitForCondition(() => !SelectionHelperUI.isSelectionUIVisible &&
+        SelectionHelperUI.isCaretUIVisible);
+
+    let startXPos = SelectionHelperUI.caretMark.xPos;
+    let startYPos = SelectionHelperUI.caretMark.yPos + 10;
+    let touchDrag = new TouchDragAndHold();
+    yield touchDrag.start(gWindow, startXPos, startYPos, startXPos + 200,
+        startYPos);
+    yield waitForCondition(() => getTrimmedSelection(edit).toString() ==
+        "about:mozilla", kCommonWaitMs, kCommonPollMs);
+
+    touchDrag.end();
+    yield waitForCondition(() => !SelectionHelperUI.hasActiveDrag,
+        kCommonWaitMs, kCommonPollMs);
+
+    // Place caret to the input end
+    sendTap(window, selectionRectangle.right - 2, selectionRectangle.top + 2);
+    yield waitForCondition(() => !SelectionHelperUI.isSelectionUIVisible &&
+        SelectionHelperUI.isCaretUIVisible);
+
+    startXPos = SelectionHelperUI.caretMark.xPos;
+    startYPos = SelectionHelperUI.caretMark.yPos + 10;
+    yield touchDrag.start(gWindow, startXPos, startYPos, startXPos - 200,
+        startYPos);
+    yield waitForCondition(() => getTrimmedSelection(edit).toString() ==
+        "about:mozilla", kCommonWaitMs, kCommonPollMs);
+
+    touchDrag.end();
+    yield waitForCondition(() => !SelectionHelperUI.hasActiveDrag,
+        kCommonWaitMs, kCommonPollMs);
+
+    // Place caret in the middle
+    let midX = Math.ceil(((selectionRectangle.right - selectionRectangle.left) *
+        .5) + selectionRectangle.left);
+    let midY = Math.ceil(((selectionRectangle.bottom - selectionRectangle.top) *
+        .5) + selectionRectangle.top);
+
+    sendTap(window, midX, midY);
+    yield waitForCondition(() => !SelectionHelperUI.isSelectionUIVisible &&
+        SelectionHelperUI.isCaretUIVisible);
+
+    startXPos = SelectionHelperUI.caretMark.xPos;
+    startYPos = SelectionHelperUI.caretMark.yPos + 10;
+    yield touchDrag.start(gWindow, startXPos, startYPos, startXPos - 200,
+        startYPos);
+    yield waitForCondition(() => getTrimmedSelection(edit).toString() ==
+        "about:", kCommonWaitMs, kCommonPollMs);
+
+    touchDrag.end();
+    yield waitForCondition(() => !SelectionHelperUI.hasActiveDrag,
+        kCommonWaitMs, kCommonPollMs);
+
+    // Now try to swap monocles
+    startXPos = SelectionHelperUI.startMark.xPos;
+    startYPos = SelectionHelperUI.startMark.yPos + 10;
+    yield touchDrag.start(gWindow, startXPos, startYPos, startXPos + 200,
+        startYPos);
+    yield waitForCondition(() => getTrimmedSelection(edit).toString() ==
+        "mozilla", kCommonWaitMs, kCommonPollMs);
+      touchDrag.end();
+    yield waitForCondition(() => !SelectionHelperUI.hasActiveDrag &&
+        SelectionHelperUI.isSelectionUIVisible, kCommonWaitMs, kCommonPollMs);
   }
 });
 
 function test() {
   if (!isLandscapeMode()) {
     todo(false, "browser_selection_tests need landscape mode to run.");
     return;
   }