browser/metro/base/tests/mochitest/browser_selection_frame_textarea.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;
    10 var gTextArea = null;
    12 const kCommonWaitMs = 5000;
    13 const kCommonPollMs = 100;
    15 ///////////////////////////////////////////////////
    16 // form input tests
    17 ///////////////////////////////////////////////////
    19 function setUpAndTearDown() {
    20   emptyClipboard();
    21   if (gWindow)
    22     clearSelection(gWindow);
    23   if (gFrame)
    24     clearSelection(gFrame);
    25   if (gTextArea)
    26     clearSelection(gTextArea);
    27   yield waitForCondition(function () {
    28       return !SelectionHelperUI.isSelectionUIVisible;
    29     }, kCommonWaitMs, kCommonPollMs);
    30   InputSourceHelper.isPrecise = false;
    31   InputSourceHelper.fireUpdate();
    32 }
    34 gTests.push({
    35   desc: "normalize browser",
    36   setUp: setUpAndTearDown,
    37   tearDown: setUpAndTearDown,
    38   run: function test() {
    39     info(chromeRoot + "browser_selection_frame_textarea.html");
    40     yield addTab(chromeRoot + "browser_selection_frame_textarea.html");
    42     yield waitForCondition(function () {
    43       return !BrowserUI.isStartTabVisible;
    44       }, 10000, 100);
    46     yield hideContextUI();
    48     gWindow = Browser.selectedTab.browser.contentWindow;
    49     gFrame = gWindow.document.getElementById("frame1");
    50     gTextArea = gFrame.contentDocument.getElementById("textarea");
    51     ok(gWindow != null, "gWindow");
    52     ok(gFrame != null, "gFrame");
    53     ok(gTextArea != null, "gTextArea");
    54   },
    55 });
    57 gTests.push({
    58   desc: "basic selection",
    59   setUp: setUpAndTearDown,
    60   tearDown: setUpAndTearDown,
    61   run: function test() {
    62     gTextArea.focus();
    63     gTextArea.selectionStart = gTextArea.selectionEnd = 0;
    65     let promise = waitForEvent(document, "popupshown");
    66     sendContextMenuClickToElement(gWindow, gFrame, 220, 80);
    67     yield promise;
    69     checkContextUIMenuItemVisibility(["context-select",
    70                                       "context-select-all"]);
    72     let menuItem = document.getElementById("context-select");
    73     ok(menuItem, "menu item exists");
    74     ok(!menuItem.hidden, "menu item visible");
    75     let popupPromise = waitForEvent(document, "popuphidden");
    76     sendElementTap(gWindow, menuItem);
    77     yield popupPromise;
    79     yield waitForCondition(function () {
    80         return SelectionHelperUI.isSelectionUIVisible;
    81       }, kCommonWaitMs, kCommonPollMs);
    83     is(getTrimmedSelection(gTextArea).toString(), "wondered", "selection test");
    85     checkMonoclePositionRange("start", 260, 280, 675, 690);
    86     checkMonoclePositionRange("end", 320, 340, 675, 690);
    87   },
    88 });
    90 gTests.push({
    91   desc: "drag selection 1",
    92   setUp: setUpAndTearDown,
    93   tearDown: setUpAndTearDown,
    94   run: function test() {
    95     gTextArea.focus();
    96     gTextArea.selectionStart = gTextArea.selectionEnd = 0;
    98     let promise = waitForEvent(document, "popupshown");
    99     sendContextMenuClickToElement(gWindow, gFrame, 220, 80);
   100     yield promise;
   102     checkContextUIMenuItemVisibility(["context-select",
   103                                       "context-select-all"]);
   105     let menuItem = document.getElementById("context-select");
   106     ok(menuItem, "menu item exists");
   107     ok(!menuItem.hidden, "menu item visible");
   108     let popupPromise = waitForEvent(document, "popuphidden");
   109     sendElementTap(gWindow, menuItem);
   110     yield popupPromise;
   112     yield waitForCondition(function () {
   113         return SelectionHelperUI.isSelectionUIVisible;
   114       }, kCommonWaitMs, kCommonPollMs);
   116     is(getTrimmedSelection(gTextArea).toString(), "wondered", "selection test");
   118     // end marker to the right
   119     let xpos = SelectionHelperUI.endMark.xPos;
   120     let ypos = SelectionHelperUI.endMark.yPos + 10;
   121     var touchdrag = new TouchDragAndHold();
   122     yield touchdrag.start(gWindow, xpos, ypos, xpos + 150, ypos);
   123     yield waitForCondition(function () {
   124       return getTrimmedSelection(gTextArea).toString() == 
   125         "wondered at this,";
   126     }, 6000, 2000);
   127     touchdrag.end();
   129     yield waitForCondition(function () {
   130         return !SelectionHelperUI.hasActiveDrag;
   131       }, kCommonWaitMs, kCommonPollMs);
   132     yield SelectionHelperUI.pingSelectionHandler();
   134     // start marker up and to the left
   135     let xpos = SelectionHelperUI.startMark.xPos;
   136     let ypos = SelectionHelperUI.startMark.yPos + 10;
   137     var touchdrag = new TouchDragAndHold();
   138     yield touchdrag.start(gWindow, xpos, ypos, 40, 500);
   139     yield waitForCondition(function () {
   140       return getTrimmedSelection(gTextArea).toString().substring(0, 17) == 
   141         "There was nothing";
   142     }, 6000, 2000);
   143     touchdrag.end();
   145     let promise = waitForEvent(document, "popupshown");
   146     sendContextMenuClick(250, 640);
   147     yield promise;
   149     checkContextUIMenuItemVisibility(["context-cut",
   150                                       "context-copy"]);
   152     let menuItem = document.getElementById("context-copy");
   153     ok(menuItem, "menu item exists");
   154     ok(!menuItem.hidden, "menu item visible");
   155     let popupPromise = waitForEvent(document, "popuphidden");
   156     sendElementTap(gWindow, menuItem);
   157     yield popupPromise;
   159     let string = "";
   160     yield waitForCondition(function () {
   161       string = SpecialPowers.getClipboardData("text/unicode");
   162       return string.substring(0, 17) === "There was nothing";
   163     });
   164   },
   165 });
   167 gTests.push({
   168   desc: "drag selection 2",
   169   setUp: setUpAndTearDown,
   170   tearDown: setUpAndTearDown,
   171   run: function test() {
   172     gTextArea.focus();
   173     gTextArea.selectionStart = gTextArea.selectionEnd = 0;
   175     let scrollPromise = waitForEvent(gWindow, "scroll");
   176     gWindow.scrollBy(0, 200);
   177     yield scrollPromise;
   179     let promise = waitForEvent(document, "popupshown");
   180     sendContextMenuClickToElement(gWindow, gFrame, 220, 80);
   181     yield promise;
   183     checkContextUIMenuItemVisibility(["context-select",
   184                                       "context-select-all"]);
   186     let menuItem = document.getElementById("context-select");
   187     ok(menuItem, "menu item exists");
   188     ok(!menuItem.hidden, "menu item visible");
   189     let popupPromise = waitForEvent(document, "popuphidden");
   190     sendElementTap(gWindow, menuItem);
   191     yield popupPromise;
   193     yield waitForCondition(function () {
   194         return SelectionHelperUI.isSelectionUIVisible;
   195       }, kCommonWaitMs, kCommonPollMs);
   197     is(getTrimmedSelection(gTextArea).toString(), "wondered", "selection test");
   199     // end marker to the right
   200     let xpos = SelectionHelperUI.endMark.xPos;
   201     let ypos = SelectionHelperUI.endMark.yPos + 10;
   202     var touchdrag = new TouchDragAndHold();
   203     yield touchdrag.start(gWindow, xpos, ypos, xpos + 150, ypos);
   204     yield waitForCondition(function () {
   205       return getTrimmedSelection(gTextArea).toString() == 
   206         "wondered at this,";
   207     }, 6000, 2000);
   208     touchdrag.end();
   210     yield waitForCondition(function () {
   211         return !SelectionHelperUI.hasActiveDrag;
   212       }, kCommonWaitMs, kCommonPollMs);
   213     yield SelectionHelperUI.pingSelectionHandler();
   215     // start marker up and to the left
   216     let xpos = SelectionHelperUI.startMark.xPos;
   217     let ypos = SelectionHelperUI.startMark.yPos + 10;
   218     var touchdrag = new TouchDragAndHold();
   219     yield touchdrag.start(gWindow, xpos, ypos, 40, 300);
   220     yield waitForCondition(function () {
   221       return getTrimmedSelection(gTextArea).toString().substring(0, 17) == 
   222         "There was nothing";
   223     }, 6000, 2000);
   224     touchdrag.end();
   226     let promise = waitForEvent(document, "popupshown");
   227     sendContextMenuClick(250, 440);
   228     yield promise;
   230     checkContextUIMenuItemVisibility(["context-cut",
   231                                       "context-copy"]);
   233     let menuItem = document.getElementById("context-copy");
   234     ok(menuItem, "menu item exists");
   235     ok(!menuItem.hidden, "menu item visible");
   236     let popupPromise = waitForEvent(document, "popuphidden");
   237     sendElementTap(gWindow, menuItem);
   238     yield popupPromise;
   240     let string = "";
   241     yield waitForCondition(function () {
   242       string = SpecialPowers.getClipboardData("text/unicode");
   243       return string.substring(0, 17) === "There was nothing";
   244     });
   245   },
   246 });
   248 function test() {
   249   if (!isLandscapeMode()) {
   250     todo(false, "browser_selection_tests need landscape mode to run.");
   251     return;
   252   }
   253   // XXX need this until bugs 886624 and 859742 are fully resolved
   254   setDevPixelEqualToPx();
   255   runTests();
   256 }

mercurial