browser/metro/base/tests/mochitest/browser_selection_basic.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_basic.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,360 @@
     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 kMarkerOffsetY = 6;
    1.15 +const kCommonWaitMs = 5000;
    1.16 +const kCommonPollMs = 100;
    1.17 +
    1.18 +///////////////////////////////////////////////////
    1.19 +// content (non-editable) 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 +  yield waitForCondition(function () {
    1.29 +      return !SelectionHelperUI.isSelectionUIVisible;
    1.30 +    }, kCommonWaitMs, kCommonPollMs);
    1.31 +  InputSourceHelper.isPrecise = false;
    1.32 +  InputSourceHelper.fireUpdate();
    1.33 +}
    1.34 +
    1.35 +gTests.push({
    1.36 +  desc: "normalize browser",
    1.37 +  setUp: setUpAndTearDown,
    1.38 +  tearDown: setUpAndTearDown,
    1.39 +  run: function test() {
    1.40 +    info(chromeRoot + "browser_selection_basic.html");
    1.41 +    yield addTab(chromeRoot + "browser_selection_basic.html");
    1.42 +
    1.43 +    yield waitForCondition(function () {
    1.44 +        return !BrowserUI.isStartTabVisible;
    1.45 +      }, 10000, 100);
    1.46 +
    1.47 +    yield hideContextUI();
    1.48 +
    1.49 +    gWindow = Browser.selectedTab.browser.contentWindow;
    1.50 +  },
    1.51 +});
    1.52 +
    1.53 +gTests.push({
    1.54 +  desc: "tap-hold to select",
    1.55 +  setUp: setUpAndTearDown,
    1.56 +  tearDown: setUpAndTearDown,
    1.57 +  run: function test() {
    1.58 +    sendContextMenuClick(30, 20);
    1.59 +
    1.60 +    yield waitForCondition(function () {
    1.61 +        return SelectionHelperUI.isSelectionUIVisible;
    1.62 +      }, kCommonWaitMs, kCommonPollMs);
    1.63 +
    1.64 +    is(getTrimmedSelection(gWindow).toString(), "There", "selection test");
    1.65 +  },
    1.66 +});
    1.67 +
    1.68 +gTests.push({
    1.69 +  desc: "appbar interactions",
    1.70 +  setUp: setUpAndTearDown,
    1.71 +  tearDown: setUpAndTearDown,
    1.72 +  run: function test() {
    1.73 +    sendContextMenuClick(100, 20);
    1.74 +
    1.75 +    yield waitForCondition(function () {
    1.76 +        return SelectionHelperUI.isSelectionUIVisible;
    1.77 +      }, kCommonWaitMs, kCommonPollMs);
    1.78 +
    1.79 +    is(SelectionHelperUI.isActive, true, "selection active");
    1.80 +    is(getTrimmedSelection(gWindow).toString(), "nothing", "selection test");
    1.81 +
    1.82 +    yield fireAppBarDisplayEvent();
    1.83 +
    1.84 +    ok(ContextUI.isVisible, true, "appbar visible");
    1.85 +
    1.86 +    yield hideContextUI();
    1.87 +
    1.88 +    ok(!ContextUI.isVisible, true, "appbar hidden");
    1.89 +  },
    1.90 +});
    1.91 +
    1.92 +gTests.push({
    1.93 +  desc: "simple drag selection",
    1.94 +  setUp: setUpAndTearDown,
    1.95 +  tearDown: setUpAndTearDown,
    1.96 +  run: function test() {
    1.97 +    yield waitForMs(100);
    1.98 +    sendContextMenuClick(100, 20);
    1.99 +
   1.100 +    yield waitForCondition(function () {
   1.101 +        return SelectionHelperUI.isSelectionUIVisible;
   1.102 +      }, kCommonWaitMs, kCommonPollMs);
   1.103 +
   1.104 +    is(SelectionHelperUI.isActive, true, "selection active");
   1.105 +    is(getTrimmedSelection(gWindow).toString(), "nothing", "selection test");
   1.106 +
   1.107 +    let ypos = SelectionHelperUI.endMark.yPos + kMarkerOffsetY;
   1.108 +
   1.109 +    let touchdrag = new TouchDragAndHold();
   1.110 +    yield touchdrag.start(gWindow, SelectionHelperUI.endMark.xPos, ypos, 190, ypos);
   1.111 +    touchdrag.end();
   1.112 +
   1.113 +    yield waitForCondition(function () {
   1.114 +        return !SelectionHelperUI.hasActiveDrag;
   1.115 +      }, kCommonWaitMs, kCommonPollMs);
   1.116 +    yield SelectionHelperUI.pingSelectionHandler();
   1.117 +
   1.118 +    is(SelectionHelperUI.isActive, true, "selection active");
   1.119 +    is(getTrimmedSelection(gWindow).toString(), "nothing so VERY", "selection test");
   1.120 +  },
   1.121 +});
   1.122 +
   1.123 +gTests.push({
   1.124 +  desc: "expand / collapse selection",
   1.125 +  setUp: setUpAndTearDown,
   1.126 +  tearDown: setUpAndTearDown,
   1.127 +  run: function test() {
   1.128 +    sendContextMenuClick(30, 20);
   1.129 +
   1.130 +    yield waitForCondition(function () {
   1.131 +        return SelectionHelperUI.isSelectionUIVisible;
   1.132 +      }, kCommonWaitMs, kCommonPollMs);
   1.133 +
   1.134 +    is(SelectionHelperUI.isActive, true, "initial active");
   1.135 +    is(getTrimmedSelection(gWindow).toString(), "There", "initial selection test");
   1.136 +
   1.137 +    for (let count = 0; count < 5; count++) {
   1.138 +      let ypos = SelectionHelperUI.endMark.yPos + kMarkerOffsetY;
   1.139 +
   1.140 +      let touchdrag = new TouchDragAndHold();
   1.141 +      yield touchdrag.start(gWindow, SelectionHelperUI.endMark.xPos, ypos, 550, ypos);
   1.142 +      touchdrag.end();
   1.143 +
   1.144 +      yield waitForCondition(function () {
   1.145 +          return !SelectionHelperUI.hasActiveDrag;
   1.146 +        }, kCommonWaitMs, kCommonPollMs);
   1.147 +      yield SelectionHelperUI.pingSelectionHandler();
   1.148 +
   1.149 +      is(getTrimmedSelection(gWindow).toString(),
   1.150 +        "There was nothing so VERY remarkable in that; nor did Alice think it so",
   1.151 +        "long selection test");
   1.152 +
   1.153 +      is(SelectionHelperUI.isActive, true, "selection active");
   1.154 +
   1.155 +      touchdrag = new TouchDragAndHold();
   1.156 +      yield touchdrag.start(gWindow, SelectionHelperUI.endMark.xPos, ypos, 40, ypos);
   1.157 +      touchdrag.end();
   1.158 +
   1.159 +      yield waitForCondition(function () {
   1.160 +          return !SelectionHelperUI.hasActiveDrag;
   1.161 +        }, kCommonWaitMs, kCommonPollMs);
   1.162 +      yield SelectionHelperUI.pingSelectionHandler();
   1.163 +
   1.164 +      is(SelectionHelperUI.isActive, true, "selection active");
   1.165 +      is(getTrimmedSelection(gWindow).toString(), "There was", "short selection test");
   1.166 +    }
   1.167 +  },
   1.168 +});
   1.169 +
   1.170 +gTests.push({
   1.171 +  desc: "expand / collapse selection scolled content",
   1.172 +  setUp: setUpAndTearDown,
   1.173 +  run: function test() {
   1.174 +    let scrollPromise = waitForEvent(gWindow, "scroll");
   1.175 +    gWindow.scrollBy(0, 200);
   1.176 +    yield scrollPromise;
   1.177 +    ok(scrollPromise && !(scrollPromise instanceof Error), "scrollPromise error");
   1.178 +
   1.179 +    sendContextMenuClick(106, 20);
   1.180 +
   1.181 +    yield waitForCondition(function () {
   1.182 +        return SelectionHelperUI.isSelectionUIVisible;
   1.183 +      }, kCommonWaitMs, kCommonPollMs);
   1.184 +
   1.185 +    is(SelectionHelperUI.isActive, true, "selection active");
   1.186 +    is(getTrimmedSelection(gWindow).toString(), "moment", "selection test");
   1.187 +
   1.188 +    let ypos = SelectionHelperUI.endMark.yPos + kMarkerOffsetY;
   1.189 +
   1.190 +    let touchdrag = new TouchDragAndHold();
   1.191 +    yield touchdrag.start(gWindow, SelectionHelperUI.endMark.xPos, ypos, 550, ypos);
   1.192 +    touchdrag.end();
   1.193 +
   1.194 +    yield waitForCondition(function () {
   1.195 +        return !SelectionHelperUI.hasActiveDrag;
   1.196 +      }, kCommonWaitMs, kCommonPollMs);
   1.197 +    yield SelectionHelperUI.pingSelectionHandler();
   1.198 +
   1.199 +    is(getTrimmedSelection(gWindow).toString(),
   1.200 +      "moment down went Alice after it, never once considering how in",
   1.201 +      "selection test");
   1.202 +
   1.203 +    is(SelectionHelperUI.isActive, true, "selection active");
   1.204 +
   1.205 +    touchdrag = new TouchDragAndHold();
   1.206 +    yield touchdrag.start(gWindow, SelectionHelperUI.endMark.xPos, ypos, 150, ypos);
   1.207 +    touchdrag.end();
   1.208 +    
   1.209 +    yield waitForCondition(function () {
   1.210 +        return !SelectionHelperUI.hasActiveDrag;
   1.211 +      }, kCommonWaitMs, kCommonPollMs);
   1.212 +    yield SelectionHelperUI.pingSelectionHandler();
   1.213 +
   1.214 +    is(getTrimmedSelection(gWindow).toString(), "moment down went", "selection test");
   1.215 +
   1.216 +    touchdrag = new TouchDragAndHold();
   1.217 +    yield touchdrag.start(gWindow, SelectionHelperUI.endMark.xPos, ypos, 550, ypos);
   1.218 +    touchdrag.end();
   1.219 +
   1.220 +    yield waitForCondition(function () {
   1.221 +        return !SelectionHelperUI.hasActiveDrag;
   1.222 +      }, kCommonWaitMs, kCommonPollMs);
   1.223 +    yield SelectionHelperUI.pingSelectionHandler();
   1.224 +
   1.225 +    is(getTrimmedSelection(gWindow).toString(),
   1.226 +      "moment down went Alice after it, never once considering how in",
   1.227 +      "selection test");
   1.228 +
   1.229 +    touchdrag = new TouchDragAndHold();
   1.230 +    yield touchdrag.start(gWindow, SelectionHelperUI.endMark.xPos, ypos, 160, ypos);
   1.231 +    touchdrag.end();
   1.232 +    
   1.233 +    yield waitForCondition(function () {
   1.234 +        return !SelectionHelperUI.hasActiveDrag;
   1.235 +      }, kCommonWaitMs, kCommonPollMs);
   1.236 +    yield SelectionHelperUI.pingSelectionHandler();
   1.237 +
   1.238 +    is(getTrimmedSelection(gWindow).toString(),
   1.239 +      "moment down went",
   1.240 +      "selection test");
   1.241 +  },
   1.242 +  tearDown: function tearDown() {
   1.243 +    let scrollPromise = waitForEvent(gWindow, "scroll");
   1.244 +    gWindow.scrollBy(0, -200);
   1.245 +    yield scrollPromise;
   1.246 +    emptyClipboard();
   1.247 +    if (gWindow)
   1.248 +      clearSelection(gWindow);
   1.249 +    if (gFrame)
   1.250 +      clearSelection(gFrame);
   1.251 +    yield waitForCondition(function () {
   1.252 +        return !SelectionHelperUI.isSelectionUIVisible;
   1.253 +      }, kCommonWaitMs, kCommonPollMs);
   1.254 +    yield hideContextUI();
   1.255 +  },
   1.256 +});
   1.257 +
   1.258 +gTests.push({
   1.259 +  desc: "tap on selection clears selection in content",
   1.260 +  setUp: setUpAndTearDown,
   1.261 +  run: function test() {
   1.262 +
   1.263 +    sendContextMenuClick(30, 20);
   1.264 +
   1.265 +    yield waitForCondition(function () {
   1.266 +        return SelectionHelperUI.isSelectionUIVisible;
   1.267 +      }, kCommonWaitMs, kCommonPollMs);
   1.268 +
   1.269 +    sendTap(gWindow, 30, 20);
   1.270 +
   1.271 +    yield waitForCondition(function () {
   1.272 +        return !SelectionHelperUI.isSelectionUIVisible;
   1.273 +      }, kCommonWaitMs, kCommonPollMs);
   1.274 +  },
   1.275 +  tearDown: setUpAndTearDown,
   1.276 +});
   1.277 +
   1.278 +gTests.push({
   1.279 +  desc: "tap off selection clears selection in content",
   1.280 +  setUp: setUpAndTearDown,
   1.281 +  run: function test() {
   1.282 +
   1.283 +    sendContextMenuClick(30, 20);
   1.284 +
   1.285 +    yield waitForCondition(function () {
   1.286 +        return SelectionHelperUI.isSelectionUIVisible;
   1.287 +      }, kCommonWaitMs, kCommonPollMs);
   1.288 +
   1.289 +    sendTap(gWindow, 30, 100);
   1.290 +
   1.291 +    yield waitForCondition(function () {
   1.292 +        return !SelectionHelperUI.isSelectionUIVisible;
   1.293 +      }, kCommonWaitMs, kCommonPollMs);
   1.294 +  },
   1.295 +  tearDown: setUpAndTearDown,
   1.296 +});
   1.297 +
   1.298 +gTests.push({
   1.299 +  desc: "bug 903737 - right click targeting",
   1.300 +  setUp: setUpAndTearDown,
   1.301 +  run: function test() {
   1.302 +    yield hideContextUI();
   1.303 +    let range = gWindow.document.createRange();
   1.304 +    range.selectNode(gWindow.document.getElementById("seldiv"));
   1.305 +    gWindow.getSelection().addRange(range);
   1.306 +    let promise = waitForEvent(document, "popupshown");
   1.307 +    sendContextMenuClickToElement(gWindow, gWindow.document.getElementById("seldiv"));
   1.308 +    yield promise;
   1.309 +    promise = waitForEvent(document, "popuphidden");
   1.310 +    ContextMenuUI.hide();
   1.311 +    yield promise;
   1.312 +    let emptydiv = gWindow.document.getElementById("emptydiv");
   1.313 +    let coords = logicalCoordsForElement(emptydiv);
   1.314 +    InputSourceHelper.isPrecise = true;
   1.315 +    sendContextMenuClick(coords.x, coords.y);
   1.316 +    yield waitForCondition(function () {
   1.317 +      return ContextUI.tabbarVisible;
   1.318 +    });
   1.319 +    yield hideContextUI();
   1.320 +  },
   1.321 +  tearDown: setUpAndTearDown,
   1.322 +});
   1.323 +
   1.324 +gTests.push({
   1.325 +  desc: "Bug 960886 - selection monocles being spilled over to other tabs " +
   1.326 +        "when switching.",
   1.327 +  setUp: setUpAndTearDown,
   1.328 +  run: function test() {
   1.329 +    let initialTab = Browser.selectedTab;
   1.330 +
   1.331 +    // Create additional tab to which we will switch later
   1.332 +    info(chromeRoot + "browser_selection_basic.html");
   1.333 +    let lastTab = yield addTab(chromeRoot + "browser_selection_basic.html");
   1.334 +
   1.335 +    // Switch back to the initial tab
   1.336 +    let tabSelectPromise = waitForEvent(Elements.tabList, "TabSelect");
   1.337 +    Browser.selectedTab = initialTab;
   1.338 +    yield tabSelectPromise;
   1.339 +    yield hideContextUI();
   1.340 +
   1.341 +    // Make selection
   1.342 +    sendContextMenuClick(30, 20);
   1.343 +    yield waitForCondition(()=>SelectionHelperUI.isSelectionUIVisible);
   1.344 +
   1.345 +    // Switch to another tab
   1.346 +    tabSelectPromise = waitForEvent(Elements.tabList, "TabSelect");
   1.347 +    Browser.selectedTab = lastTab;
   1.348 +    yield tabSelectPromise;
   1.349 +
   1.350 +    yield waitForCondition(()=>!SelectionHelperUI.isSelectionUIVisible);
   1.351 +
   1.352 +    Browser.closeTab(Browser.selectedTab, { forceClose: true });
   1.353 +  },
   1.354 +  tearDown: setUpAndTearDown
   1.355 +});
   1.356 +
   1.357 +function test() {
   1.358 +  if (!isLandscapeMode()) {
   1.359 +    todo(false, "browser_selection_tests need landscape mode to run.");
   1.360 +    return;
   1.361 +  }
   1.362 +  runTests();
   1.363 +}

mercurial