browser/metro/base/tests/mochitest/browser_selection_frame_inputs.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_frame_inputs.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,160 @@
     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 +var gInput = null;
    1.14 +
    1.15 +const kCommonWaitMs = 5000;
    1.16 +const kCommonPollMs = 100;
    1.17 +
    1.18 +///////////////////////////////////////////////////
    1.19 +// form input tests
    1.20 +///////////////////////////////////////////////////
    1.21 +
    1.22 +function setUpAndTearDown() {
    1.23 +  emptyClipboard();
    1.24 +  if (gWindow)
    1.25 +    clearSelection(gWindow);
    1.26 +  if (gFrame)
    1.27 +    clearSelection(gFrame);
    1.28 +  if (gInput)
    1.29 +    clearSelection(gInput);
    1.30 +  yield waitForCondition(function () {
    1.31 +      return !SelectionHelperUI.isSelectionUIVisible;
    1.32 +    }, kCommonWaitMs, kCommonPollMs);
    1.33 +  InputSourceHelper.isPrecise = false;
    1.34 +  InputSourceHelper.fireUpdate();
    1.35 +}
    1.36 +
    1.37 +gTests.push({
    1.38 +  desc: "normalize browser",
    1.39 +  setUp: setUpAndTearDown,
    1.40 +  tearDown: setUpAndTearDown,
    1.41 +  run: function test() {
    1.42 +    info(chromeRoot + "browser_selection_frame_inputs.html");
    1.43 +    yield addTab(chromeRoot + "browser_selection_frame_inputs.html");
    1.44 +
    1.45 +    yield waitForCondition(function () {
    1.46 +      return !BrowserUI.isStartTabVisible;
    1.47 +      }, 10000, 100);
    1.48 +
    1.49 +    yield hideContextUI();
    1.50 +
    1.51 +    gWindow = Browser.selectedTab.browser.contentWindow;
    1.52 +    gFrame = gWindow.document.getElementById("frame1");
    1.53 +    gInput = gFrame.contentDocument.getElementById("textinput");
    1.54 +
    1.55 +    ok(gWindow != null, "gWindow");
    1.56 +    ok(gFrame != null, "gFrame");
    1.57 +    ok(gInput != null, "gInput");
    1.58 +  },
    1.59 +});
    1.60 +
    1.61 +gTests.push({
    1.62 +  desc: "basic selection",
    1.63 +  setUp: setUpAndTearDown,
    1.64 +  tearDown: setUpAndTearDown,
    1.65 +  run: function test() {
    1.66 +    gInput.focus();
    1.67 +    gInput.selectionStart = gInput.selectionEnd = 0;
    1.68 +
    1.69 +    let promise = waitForEvent(document, "popupshown");
    1.70 +    sendContextMenuClickToElement(gWindow, gFrame, 135, 10);
    1.71 +    yield promise;
    1.72 +
    1.73 +    checkContextUIMenuItemVisibility(["context-select",
    1.74 +                                      "context-select-all"]);
    1.75 +
    1.76 +    let menuItem = document.getElementById("context-select");
    1.77 +    ok(menuItem, "menu item exists");
    1.78 +    ok(!menuItem.hidden, "menu item visible");
    1.79 +    let popupPromise = waitForEvent(document, "popuphidden");
    1.80 +    sendElementTap(gWindow, menuItem);
    1.81 +    yield popupPromise;
    1.82 +
    1.83 +    yield waitForCondition(function () {
    1.84 +        return SelectionHelperUI.isSelectionUIVisible;
    1.85 +      }, kCommonWaitMs, kCommonPollMs);
    1.86 +
    1.87 +    is(getTrimmedSelection(gInput).toString(), "straight", "selection test");
    1.88 +
    1.89 +    let rect = gFrame.getBoundingClientRect();
    1.90 +    checkMonoclePositionRange("start", rect.left + 125, rect.left + 135, rect.top + 20, rect.top + 30);
    1.91 +    checkMonoclePositionRange("end", rect.left + 165, rect.left + 175, rect.top + 20, rect.top + 30);
    1.92 +  },
    1.93 +});
    1.94 +
    1.95 +gTests.push({
    1.96 +  desc: "drag selection",
    1.97 +  setUp: setUpAndTearDown,
    1.98 +  tearDown: setUpAndTearDown,
    1.99 +  run: function test() {
   1.100 +    gInput.focus();
   1.101 +    gInput.selectionStart = gInput.selectionEnd = 0;
   1.102 +
   1.103 +    let promise = waitForEvent(document, "popupshown");
   1.104 +    sendContextMenuClickToElement(gWindow, gFrame, 135, 10);
   1.105 +    yield promise;
   1.106 +
   1.107 +    checkContextUIMenuItemVisibility(["context-select",
   1.108 +                                      "context-select-all"]);
   1.109 +
   1.110 +    let menuItem = document.getElementById("context-select");
   1.111 +    ok(menuItem, "menu item exists");
   1.112 +    ok(!menuItem.hidden, "menu item visible");
   1.113 +    let popupPromise = waitForEvent(document, "popuphidden");
   1.114 +    sendElementTap(gWindow, menuItem);
   1.115 +    yield popupPromise;
   1.116 +
   1.117 +    yield waitForCondition(function () {
   1.118 +        return SelectionHelperUI.isSelectionUIVisible;
   1.119 +      }, kCommonWaitMs, kCommonPollMs);
   1.120 +
   1.121 +    is(getTrimmedSelection(gInput).toString(), "straight", "selection test");
   1.122 +
   1.123 +    // end marker to the right
   1.124 +    let xpos = SelectionHelperUI.endMark.xPos;
   1.125 +    let ypos = SelectionHelperUI.endMark.yPos + 10;
   1.126 +    var touchdrag = new TouchDragAndHold();
   1.127 +    yield touchdrag.start(gWindow, xpos, ypos, xpos + 350, ypos);
   1.128 +    yield waitForCondition(function () {
   1.129 +      return getTrimmedSelection(gInput).toString() == 
   1.130 +        "straight on like a tunnel for some way and then dipped suddenly down";
   1.131 +    }, 6000, 2000);
   1.132 +    touchdrag.end();
   1.133 +
   1.134 +    yield waitForCondition(function () {
   1.135 +        return !SelectionHelperUI.hasActiveDrag;
   1.136 +      }, kCommonWaitMs, kCommonPollMs);
   1.137 +    yield SelectionHelperUI.pingSelectionHandler();
   1.138 +
   1.139 +    // start marker to the left
   1.140 +    let xpos = SelectionHelperUI.startMark.xPos;
   1.141 +    let ypos = SelectionHelperUI.startMark.yPos + 10;
   1.142 +    var touchdrag = new TouchDragAndHold();
   1.143 +    yield touchdrag.start(gWindow, xpos, ypos, 10, ypos);
   1.144 +    yield waitForCondition(function () {
   1.145 +      return getTrimmedSelection(gInput).toString() == 
   1.146 +        "The rabbit-hole went straight on like a tunnel for some way and then dipped suddenly down";
   1.147 +    }, 6000, 2000);
   1.148 +    touchdrag.end();
   1.149 +
   1.150 +    yield waitForCondition(function () {
   1.151 +        return !SelectionHelperUI.hasActiveDrag;
   1.152 +      }, kCommonWaitMs, kCommonPollMs);
   1.153 +    yield SelectionHelperUI.pingSelectionHandler();
   1.154 +  },
   1.155 +});
   1.156 +
   1.157 +function test() {
   1.158 +  if (!isLandscapeMode()) {
   1.159 +    todo(false, "browser_selection_tests need landscape mode to run.");
   1.160 +    return;
   1.161 +  }
   1.162 +  runTests();
   1.163 +}

mercurial