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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/metro/base/tests/mochitest/browser_selection_textarea.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,115 @@
     1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim: set ts=2 et sw=2 tw=80: */
     1.6 +/* Any copyright is dedicated to the Public Domain.
     1.7 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.8 +
     1.9 +"use strict";
    1.10 +
    1.11 +let gWindow = null;
    1.12 +var gFrame = null;
    1.13 +
    1.14 +const kCommonWaitMs = 5000;
    1.15 +const kCommonPollMs = 100;
    1.16 +
    1.17 +///////////////////////////////////////////////////
    1.18 +// text area tests
    1.19 +///////////////////////////////////////////////////
    1.20 +
    1.21 +function setUpAndTearDown() {
    1.22 +  emptyClipboard();
    1.23 +  if (gWindow)
    1.24 +    clearSelection(gWindow);
    1.25 +  if (gFrame)
    1.26 +    clearSelection(gFrame);
    1.27 +  yield waitForCondition(function () {
    1.28 +      return !SelectionHelperUI.isSelectionUIVisible;
    1.29 +    }, kCommonWaitMs, kCommonPollMs);
    1.30 +  InputSourceHelper.isPrecise = false;
    1.31 +  InputSourceHelper.fireUpdate();
    1.32 +}
    1.33 +
    1.34 +gTests.push({
    1.35 +  desc: "normalize browser",
    1.36 +  setUp: setUpAndTearDown,
    1.37 +  tearDown: setUpAndTearDown,
    1.38 +  run: function test() {
    1.39 +    info(chromeRoot + "browser_selection_textarea.html");
    1.40 +    yield addTab(chromeRoot + "browser_selection_textarea.html");
    1.41 +
    1.42 +    yield waitForCondition(function () {
    1.43 +      return !BrowserUI.isStartTabVisible;
    1.44 +      }, 10000, 100);
    1.45 +
    1.46 +    yield hideContextUI();
    1.47 +
    1.48 +    gWindow = Browser.selectedTab.browser.contentWindow;
    1.49 +  },
    1.50 +});
    1.51 +
    1.52 +gTests.push({
    1.53 +  desc: "textarea selection and drag",
    1.54 +  setUp: setUpAndTearDown,
    1.55 +  tearDown: setUpAndTearDown,
    1.56 +  run: function test() {
    1.57 +    // work around for buggy context menu display
    1.58 +    yield waitForMs(100);
    1.59 +
    1.60 +    let textarea = gWindow.document.getElementById("inputtext");
    1.61 +    textarea.focus();
    1.62 +
    1.63 +    let promise = waitForEvent(document, "popupshown");
    1.64 +    sendContextMenuClickToElement(gWindow, textarea, 20, 10);
    1.65 +    yield promise;
    1.66 +
    1.67 +    checkContextUIMenuItemVisibility(["context-select",
    1.68 +                                      "context-select-all"]);
    1.69 +
    1.70 +    let menuItem = document.getElementById("context-select");
    1.71 +    ok(menuItem, "menu item exists");
    1.72 +    ok(!menuItem.hidden, "menu item visible");
    1.73 +    let popupPromise = waitForEvent(document, "popuphidden");
    1.74 +    sendElementTap(gWindow, menuItem);
    1.75 +    yield popupPromise;
    1.76 +    ok(popupPromise && !(popupPromise instanceof Error), "promise error");
    1.77 +
    1.78 +    yield waitForCondition(function () {
    1.79 +        return SelectionHelperUI.isSelectionUIVisible;
    1.80 +      }, kCommonWaitMs, kCommonPollMs);
    1.81 +
    1.82 +    is(SelectionHelperUI.isActive, true, "selection active");
    1.83 +    is(getTrimmedSelection(textarea).toString(), "Alice", "selection test");
    1.84 +
    1.85 +    let xpos = SelectionHelperUI.endMark.xPos;
    1.86 +    let ypos = SelectionHelperUI.endMark.yPos + 10;
    1.87 +
    1.88 +    var touchdrag = new TouchDragAndHold();
    1.89 +
    1.90 +    // end marker and off the text area to the right
    1.91 +    yield touchdrag.start(gWindow, xpos, ypos, 1200, 400);
    1.92 +    let token = "(end)";
    1.93 +    yield waitForCondition(function () {
    1.94 +      let selection = getTrimmedSelection(textarea).toString();
    1.95 +      if (selection.length < token.length ||
    1.96 +          selection.substring(selection.length - token.length) != token) {
    1.97 +        return false;
    1.98 +      }
    1.99 +      return true;
   1.100 +    }, 5000, 100);
   1.101 +
   1.102 +    touchdrag.end();
   1.103 +    touchdrag = null;
   1.104 +
   1.105 +    yield waitForCondition(function () {
   1.106 +        return !SelectionHelperUI.hasActiveDrag;
   1.107 +      }, kCommonWaitMs, kCommonPollMs);
   1.108 +    yield SelectionHelperUI.pingSelectionHandler();
   1.109 +  },
   1.110 +});
   1.111 +
   1.112 +function test() {
   1.113 +  if (!isLandscapeMode()) {
   1.114 +    todo(false, "browser_selection_tests need landscape mode to run.");
   1.115 +    return;
   1.116 +  }
   1.117 +  runTests();
   1.118 +}

mercurial