browser/metro/base/tests/mochitest/browser_selection_urlbar.js

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

     1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* vim: set ts=2 et sw=2 tw=80: */
     3 /* Any copyright is dedicated to the Public Domain.
     4    http://creativecommons.org/publicdomain/zero/1.0/ */
     6 "use strict";
     8 let gWindow = null;
     9 var gFrame = null;
    11 const kCommonWaitMs = 5000;
    12 const kCommonPollMs = 100;
    14 ///////////////////////////////////////////////////
    15 // text area tests
    16 ///////////////////////////////////////////////////
    18 gTests.push({
    19   desc: "normalize browser",
    20   run: function test() {
    21     info(chromeRoot + "res/textblock01.html");
    22     yield addTab(chromeRoot + "res/textblock01.html");
    24     yield waitForCondition(function () {
    25       return !BrowserUI.isStartTabVisible;
    26       });
    28     yield hideContextUI();
    30     InputSourceHelper.isPrecise = false;
    31     InputSourceHelper.fireUpdate();
    32   },
    33 });
    35 gTests.push({
    36   desc: "nav bar display",
    37   run: function test() {
    38     gWindow = window;
    40     yield showNavBar();
    42     let edit = document.getElementById("urlbar-edit");
    44     sendElementTap(window, edit, 100, 10);
    46     ok(SelectionHelperUI.isSelectionUIVisible, "selection ui active");
    48     sendElementTap(window, edit, 70, 10);
    50     ok(SelectionHelperUI.isCaretUIVisible, "caret ui active");
    52     // to the right
    53     let xpos = SelectionHelperUI.caretMark.xPos;
    54     let ypos = SelectionHelperUI.caretMark.yPos + 10;
    55     var touchdrag = new TouchDragAndHold();
    56     yield touchdrag.start(gWindow, xpos, ypos, 900, ypos);
    57     yield waitForCondition(function () {
    58       return getTrimmedSelection(edit).toString() ==
    59         "mochitests/content/metro/browser/metro/base/tests/mochitest/res/textblock01.html";
    60     }, kCommonWaitMs, kCommonPollMs);
    61     touchdrag.end();
    62     yield waitForMs(100);
    64     ok(SelectionHelperUI.isSelectionUIVisible, "selection ui active");
    65   },
    66 });
    68 gTests.push({
    69   desc: "bug 887120 - tap & hold to paste into urlbar",
    70   run: function() {
    71     gWindow = window;
    73     yield showNavBar();
    74     let edit = document.getElementById("urlbar-edit");
    76     SpecialPowers.clipboardCopyString("mozilla");
    77     sendContextMenuClickToElement(window, edit);
    78     yield waitForEvent(document, "popupshown");
    80     ok(ContextMenuUI._menuPopup.visible, "is visible");
    81     let paste = document.getElementById("context-paste");
    82     ok(!paste.hidden, "paste item is visible");
    84     sendElementTap(window, paste);
    85     ok(edit.popup.popupOpen, "bug: popup should be showing");
    87     clearSelection(edit);
    88     yield waitForCondition(function () {
    89       return !SelectionHelperUI.isSelectionUIVisible;
    90     });
    91   }
    92 });
    94 gTests.push({
    95   desc: "bug 895284 - tap selection",
    96   run: function() {
    97     gWindow = window;
    99     yield showNavBar();
   100     let edit = document.getElementById("urlbar-edit");
   101     edit.value = "wikipedia.org";
   102     edit.select();
   104     let editCoords = logicalCoordsForElement(edit);
   106     // wait for popup animation to complete, it interferes with edit selection testing
   107     let autocompletePopup = document.getElementById("urlbar-autocomplete-scroll");
   108     yield waitForEvent(autocompletePopup, "transitionend");
   110     SelectionHelperUI.attachEditSession(ChromeSelectionHandler, editCoords.x,
   111         editCoords.y, edit);
   112     ok(SelectionHelperUI.isSelectionUIVisible, "selection enabled");
   114     let selection = edit.QueryInterface(Components.interfaces.nsIDOMXULTextBoxElement)
   115                         .editor.selection;
   116     let rects = selection.getRangeAt(0).getClientRects();
   117     let midX = Math.ceil(((rects[0].right - rects[0].left) * .5) + rects[0].left);
   118     let midY = Math.ceil(((rects[0].bottom - rects[0].top) * .5) + rects[0].top);
   120     sendTap(window, midX, midY);
   122     ok(SelectionHelperUI.isCaretUIVisible, "caret browsing enabled");
   124     clearSelection(edit);
   125     yield waitForCondition(function () {
   126       return !SelectionHelperUI.isSelectionUIVisible;
   127     });
   128   }
   129 });
   131 gTests.push({
   132   desc: "bug 894713 - blur shuts down selection handling",
   133   run: function() {
   134     gWindow = window;
   135     yield showNavBar();
   136     let edit = document.getElementById("urlbar-edit");
   137     edit.value = "wikipedia.org";
   138     edit.select();
   139     let editCoords = logicalCoordsForElement(edit);
   140     SelectionHelperUI.attachEditSession(ChromeSelectionHandler, editCoords.x,
   141         editCoords.y, edit);
   142     edit.blur();
   143     ok(!SelectionHelperUI.isSelectionUIVisible, "selection no longer enabled");
   144     clearSelection(edit);
   145     yield waitForCondition(function () {
   146       return !SelectionHelperUI.isSelectionUIVisible;
   147     });
   148   }
   149 });
   151 function getClipboardCondition(aExpected) {
   152   return () => aExpected == SpecialPowers.getClipboardData("text/unicode");
   153 }
   155 gTests.push({
   156   desc: "bug 894715 - URLs selected by touch are copied with trimming",
   157   run: function () {
   158     gWindow = window;
   159     yield showNavBar();
   161     let edit = document.getElementById("urlbar-edit");
   162     edit.value = "http://www.wikipedia.org/";
   164     sendElementTap(window, edit);
   165     edit.select();
   167     let panel = ContextMenuUI._menuPopup._panel;
   168     let promise = waitForEvent(panel, "popupshown")
   169     sendContextMenuClickToElement(window, edit);
   170     ok((yield promise), "show context menu");
   172     let copy = document.getElementById("context-copy");
   173     ok(!copy.hidden, "copy menu item is visible")
   175     let condition = getClipboardCondition("http://www.wikipedia.org/");
   176     let promise = waitForCondition(condition);
   177     sendElementTap(window, copy);
   178     ok((yield promise), "copy text onto clipboard")
   180     clearSelection(edit);
   181     edit.blur();
   182   }
   183 })
   185 gTests.push({
   186   desc: "bug 965832 - selection monocles move with the nav bar",
   187   run: function() {
   188     yield showNavBar();
   190     let originalUtils = Services.metro;
   191     Services.metro = {
   192       keyboardHeight: 0,
   193       keyboardVisible: false
   194     };
   195     registerCleanupFunction(function() {
   196       Services.metro = originalUtils;
   197     });
   199     let edit = document.getElementById("urlbar-edit");
   200     edit.value = "http://www.wikipedia.org/";
   202     sendElementTap(window, edit);
   204     let promise = waitForEvent(window, "MozDeckOffsetChanged");
   205     Services.metro.keyboardHeight = 300;
   206     Services.metro.keyboardVisible = true;
   207     Services.obs.notifyObservers(null, "metro_softkeyboard_shown", null);
   208     yield promise;
   210     yield waitForCondition(function () {
   211       return SelectionHelperUI.isSelectionUIVisible;
   212     });
   214     promise = waitForEvent(window, "MozDeckOffsetChanged");
   215     Services.metro.keyboardHeight = 0;
   216     Services.metro.keyboardVisible = false;
   217     Services.obs.notifyObservers(null, "metro_softkeyboard_hidden", null);
   218     yield promise;
   220     yield waitForCondition(function () {
   221       return SelectionHelperUI.isSelectionUIVisible;
   222     });
   224     clearSelection(edit);
   225     edit.blur();
   227     yield waitForCondition(function () {
   228       return !SelectionHelperUI.isSelectionUIVisible;
   229     });
   230   }
   231 });
   233 gTests.push({
   234   desc: "Bug 957646 - Selection monocles sometimes don't display when tapping" +
   235         " text in the nav bar.",
   236   run: function() {
   237     yield showNavBar();
   239     let edit = document.getElementById("urlbar-edit");
   240     edit.value = "about:mozilla";
   242     let editRectangle = edit.getBoundingClientRect();
   244     // Tap outside the input but close enough for fluffing to take effect.
   245     sendTap(window, editRectangle.left + 50, editRectangle.top - 2);
   247     yield waitForCondition(function () {
   248       return SelectionHelperUI.isSelectionUIVisible;
   249     });
   250   }
   251 });
   253 gTests.push({
   254   desc: "Bug 972574 - Monocles not matching selection after double tap" +
   255         " in URL text field.",
   256   run: function() {
   257     yield showNavBar();
   259     let MARGIN_OF_ERROR = 15;
   260     let EST_URLTEXT_WIDTH = 125;
   262     let edit = document.getElementById("urlbar-edit");
   263     edit.value = "http://www.wikipedia.org/";
   265     // Determine a tap point centered on URL.
   266     let editRectangle = edit.getBoundingClientRect();
   267     let midX = editRectangle.left + Math.ceil(EST_URLTEXT_WIDTH / 2);
   268     let midY = editRectangle.top + Math.ceil(editRectangle.height / 2);
   270     // Tap inside the input for fluffing to take effect.
   271     sendTap(window, midX, midY);
   273     // Double-tap inside the input to selectALL.
   274     sendDoubleTap(window, midX, midY);
   276     // Check for start/end monocles positioned within accepted margins.
   277     checkMonoclePositionRange("start",
   278       Math.ceil(editRectangle.left - MARGIN_OF_ERROR),
   279       Math.ceil(editRectangle.left + MARGIN_OF_ERROR),
   280       Math.ceil(editRectangle.top + editRectangle.height - MARGIN_OF_ERROR),
   281       Math.ceil(editRectangle.top + editRectangle.height + MARGIN_OF_ERROR));
   282     checkMonoclePositionRange("end",
   283       Math.ceil(editRectangle.left + EST_URLTEXT_WIDTH - MARGIN_OF_ERROR),
   284       Math.ceil(editRectangle.left + EST_URLTEXT_WIDTH + MARGIN_OF_ERROR),
   285       Math.ceil(editRectangle.top + editRectangle.height - MARGIN_OF_ERROR),
   286       Math.ceil(editRectangle.top + editRectangle.height + MARGIN_OF_ERROR));
   287   }
   288 });
   290 gTests.push({
   291   desc: "Bug 972428 - grippers not appearing under the URL field when adding " +
   292         "text.",
   293   run: function() {
   294     let inputField = document.getElementById("urlbar-edit").inputField;
   295     let inputFieldRectangle = inputField.getBoundingClientRect();
   297     let chromeHandlerSpy = spyOnMethod(ChromeSelectionHandler, "msgHandler");
   299     // Reset URL to empty string
   300     inputField.value = "";
   301     inputField.blur();
   303     // Activate URL input
   304     sendTap(window, inputFieldRectangle.left + 50, inputFieldRectangle.top + 5);
   306     // Wait until ChromeSelectionHandler tries to attach selection
   307     yield waitForCondition(() => chromeHandlerSpy.argsForCall.some(
   308         (args) => args[0] == "Browser:SelectionAttach"));
   310     ok(!SelectHelperUI.isSelectionUIVisible && !SelectHelperUI.isCaretUIVisible,
   311         "Neither CaretUI nor SelectionUI is visible on empty input.");
   313     inputField.value = "Test text";
   315     sendTap(window, inputFieldRectangle.left + 10, inputFieldRectangle.top + 5);
   317     yield waitForCondition(() => SelectionHelperUI.isCaretUIVisible);
   318     chromeHandlerSpy.restore();
   319     inputField.blur();
   320   }
   321 });
   323 gTests.push({
   324   desc: "Bug 858206 - Drag selection monocles should not push other monocles " +
   325         "out of the way.",
   326   run: function test() {
   327     yield showNavBar();
   329     let edit = document.getElementById("urlbar-edit");
   330     edit.value = "about:mozilla";
   332     let editRectangle = edit.getBoundingClientRect();
   334     sendTap(window, editRectangle.left, editRectangle.top);
   336     yield waitForCondition(() => SelectionHelperUI.isSelectionUIVisible);
   338     let selection = edit.QueryInterface(
   339         Components.interfaces.nsIDOMXULTextBoxElement).editor.selection;
   340     let selectionRectangle = selection.getRangeAt(0).getClientRects()[0];
   342     // Place caret to the input start
   343     sendTap(window, selectionRectangle.left + 2, selectionRectangle.top + 2);
   344     yield waitForCondition(() => !SelectionHelperUI.isSelectionUIVisible &&
   345         SelectionHelperUI.isCaretUIVisible);
   347     let startXPos = SelectionHelperUI.caretMark.xPos;
   348     let startYPos = SelectionHelperUI.caretMark.yPos + 10;
   349     let touchDrag = new TouchDragAndHold();
   350     yield touchDrag.start(gWindow, startXPos, startYPos, startXPos + 200,
   351         startYPos);
   352     yield waitForCondition(() => getTrimmedSelection(edit).toString() ==
   353         "about:mozilla", kCommonWaitMs, kCommonPollMs);
   355     touchDrag.end();
   356     yield waitForCondition(() => !SelectionHelperUI.hasActiveDrag,
   357         kCommonWaitMs, kCommonPollMs);
   359     // Place caret to the input end
   360     sendTap(window, selectionRectangle.right - 2, selectionRectangle.top + 2);
   361     yield waitForCondition(() => !SelectionHelperUI.isSelectionUIVisible &&
   362         SelectionHelperUI.isCaretUIVisible);
   364     startXPos = SelectionHelperUI.caretMark.xPos;
   365     startYPos = SelectionHelperUI.caretMark.yPos + 10;
   366     yield touchDrag.start(gWindow, startXPos, startYPos, startXPos - 200,
   367         startYPos);
   368     yield waitForCondition(() => getTrimmedSelection(edit).toString() ==
   369         "about:mozilla", kCommonWaitMs, kCommonPollMs);
   371     touchDrag.end();
   372     yield waitForCondition(() => !SelectionHelperUI.hasActiveDrag,
   373         kCommonWaitMs, kCommonPollMs);
   375     // Place caret in the middle
   376     let midX = Math.ceil(((selectionRectangle.right - selectionRectangle.left) *
   377         .5) + selectionRectangle.left);
   378     let midY = Math.ceil(((selectionRectangle.bottom - selectionRectangle.top) *
   379         .5) + selectionRectangle.top);
   381     sendTap(window, midX, midY);
   382     yield waitForCondition(() => !SelectionHelperUI.isSelectionUIVisible &&
   383         SelectionHelperUI.isCaretUIVisible);
   385     startXPos = SelectionHelperUI.caretMark.xPos;
   386     startYPos = SelectionHelperUI.caretMark.yPos + 10;
   387     yield touchDrag.start(gWindow, startXPos, startYPos, startXPos - 200,
   388         startYPos);
   389     yield waitForCondition(() => getTrimmedSelection(edit).toString() ==
   390         "about:", kCommonWaitMs, kCommonPollMs);
   392     touchDrag.end();
   393     yield waitForCondition(() => !SelectionHelperUI.hasActiveDrag,
   394         kCommonWaitMs, kCommonPollMs);
   396     // Now try to swap monocles
   397     startXPos = SelectionHelperUI.startMark.xPos;
   398     startYPos = SelectionHelperUI.startMark.yPos + 10;
   399     yield touchDrag.start(gWindow, startXPos, startYPos, startXPos + 200,
   400         startYPos);
   401     yield waitForCondition(() => getTrimmedSelection(edit).toString() ==
   402         "mozilla", kCommonWaitMs, kCommonPollMs);
   403       touchDrag.end();
   404     yield waitForCondition(() => !SelectionHelperUI.hasActiveDrag &&
   405         SelectionHelperUI.isSelectionUIVisible, kCommonWaitMs, kCommonPollMs);
   406   }
   407 });
   409 function test() {
   410   if (!isLandscapeMode()) {
   411     todo(false, "browser_selection_tests need landscape mode to run.");
   412     return;
   413   }
   414   runTests();
   415 }

mercurial