browser/metro/base/tests/mochitest/browser_selection_urlbar.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_urlbar.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,415 @@
     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 +gTests.push({
    1.22 +  desc: "normalize browser",
    1.23 +  run: function test() {
    1.24 +    info(chromeRoot + "res/textblock01.html");
    1.25 +    yield addTab(chromeRoot + "res/textblock01.html");
    1.26 +
    1.27 +    yield waitForCondition(function () {
    1.28 +      return !BrowserUI.isStartTabVisible;
    1.29 +      });
    1.30 +
    1.31 +    yield hideContextUI();
    1.32 +
    1.33 +    InputSourceHelper.isPrecise = false;
    1.34 +    InputSourceHelper.fireUpdate();
    1.35 +  },
    1.36 +});
    1.37 +
    1.38 +gTests.push({
    1.39 +  desc: "nav bar display",
    1.40 +  run: function test() {
    1.41 +    gWindow = window;
    1.42 +
    1.43 +    yield showNavBar();
    1.44 +
    1.45 +    let edit = document.getElementById("urlbar-edit");
    1.46 +
    1.47 +    sendElementTap(window, edit, 100, 10);
    1.48 +
    1.49 +    ok(SelectionHelperUI.isSelectionUIVisible, "selection ui active");
    1.50 +
    1.51 +    sendElementTap(window, edit, 70, 10);
    1.52 +
    1.53 +    ok(SelectionHelperUI.isCaretUIVisible, "caret ui active");
    1.54 +
    1.55 +    // to the right
    1.56 +    let xpos = SelectionHelperUI.caretMark.xPos;
    1.57 +    let ypos = SelectionHelperUI.caretMark.yPos + 10;
    1.58 +    var touchdrag = new TouchDragAndHold();
    1.59 +    yield touchdrag.start(gWindow, xpos, ypos, 900, ypos);
    1.60 +    yield waitForCondition(function () {
    1.61 +      return getTrimmedSelection(edit).toString() ==
    1.62 +        "mochitests/content/metro/browser/metro/base/tests/mochitest/res/textblock01.html";
    1.63 +    }, kCommonWaitMs, kCommonPollMs);
    1.64 +    touchdrag.end();
    1.65 +    yield waitForMs(100);
    1.66 +
    1.67 +    ok(SelectionHelperUI.isSelectionUIVisible, "selection ui active");
    1.68 +  },
    1.69 +});
    1.70 +
    1.71 +gTests.push({
    1.72 +  desc: "bug 887120 - tap & hold to paste into urlbar",
    1.73 +  run: function() {
    1.74 +    gWindow = window;
    1.75 +
    1.76 +    yield showNavBar();
    1.77 +    let edit = document.getElementById("urlbar-edit");
    1.78 +
    1.79 +    SpecialPowers.clipboardCopyString("mozilla");
    1.80 +    sendContextMenuClickToElement(window, edit);
    1.81 +    yield waitForEvent(document, "popupshown");
    1.82 +
    1.83 +    ok(ContextMenuUI._menuPopup.visible, "is visible");
    1.84 +    let paste = document.getElementById("context-paste");
    1.85 +    ok(!paste.hidden, "paste item is visible");
    1.86 +
    1.87 +    sendElementTap(window, paste);
    1.88 +    ok(edit.popup.popupOpen, "bug: popup should be showing");
    1.89 +
    1.90 +    clearSelection(edit);
    1.91 +    yield waitForCondition(function () {
    1.92 +      return !SelectionHelperUI.isSelectionUIVisible;
    1.93 +    });
    1.94 +  }
    1.95 +});
    1.96 +
    1.97 +gTests.push({
    1.98 +  desc: "bug 895284 - tap selection",
    1.99 +  run: function() {
   1.100 +    gWindow = window;
   1.101 +
   1.102 +    yield showNavBar();
   1.103 +    let edit = document.getElementById("urlbar-edit");
   1.104 +    edit.value = "wikipedia.org";
   1.105 +    edit.select();
   1.106 +
   1.107 +    let editCoords = logicalCoordsForElement(edit);
   1.108 +
   1.109 +    // wait for popup animation to complete, it interferes with edit selection testing
   1.110 +    let autocompletePopup = document.getElementById("urlbar-autocomplete-scroll");
   1.111 +    yield waitForEvent(autocompletePopup, "transitionend");
   1.112 +
   1.113 +    SelectionHelperUI.attachEditSession(ChromeSelectionHandler, editCoords.x,
   1.114 +        editCoords.y, edit);
   1.115 +    ok(SelectionHelperUI.isSelectionUIVisible, "selection enabled");
   1.116 +
   1.117 +    let selection = edit.QueryInterface(Components.interfaces.nsIDOMXULTextBoxElement)
   1.118 +                        .editor.selection;
   1.119 +    let rects = selection.getRangeAt(0).getClientRects();
   1.120 +    let midX = Math.ceil(((rects[0].right - rects[0].left) * .5) + rects[0].left);
   1.121 +    let midY = Math.ceil(((rects[0].bottom - rects[0].top) * .5) + rects[0].top);
   1.122 +
   1.123 +    sendTap(window, midX, midY);
   1.124 +
   1.125 +    ok(SelectionHelperUI.isCaretUIVisible, "caret browsing enabled");
   1.126 +
   1.127 +    clearSelection(edit);
   1.128 +    yield waitForCondition(function () {
   1.129 +      return !SelectionHelperUI.isSelectionUIVisible;
   1.130 +    });
   1.131 +  }
   1.132 +});
   1.133 +
   1.134 +gTests.push({
   1.135 +  desc: "bug 894713 - blur shuts down selection handling",
   1.136 +  run: function() {
   1.137 +    gWindow = window;
   1.138 +    yield showNavBar();
   1.139 +    let edit = document.getElementById("urlbar-edit");
   1.140 +    edit.value = "wikipedia.org";
   1.141 +    edit.select();
   1.142 +    let editCoords = logicalCoordsForElement(edit);
   1.143 +    SelectionHelperUI.attachEditSession(ChromeSelectionHandler, editCoords.x,
   1.144 +        editCoords.y, edit);
   1.145 +    edit.blur();
   1.146 +    ok(!SelectionHelperUI.isSelectionUIVisible, "selection no longer enabled");
   1.147 +    clearSelection(edit);
   1.148 +    yield waitForCondition(function () {
   1.149 +      return !SelectionHelperUI.isSelectionUIVisible;
   1.150 +    });
   1.151 +  }
   1.152 +});
   1.153 +
   1.154 +function getClipboardCondition(aExpected) {
   1.155 +  return () => aExpected == SpecialPowers.getClipboardData("text/unicode");
   1.156 +}
   1.157 +
   1.158 +gTests.push({
   1.159 +  desc: "bug 894715 - URLs selected by touch are copied with trimming",
   1.160 +  run: function () {
   1.161 +    gWindow = window;
   1.162 +    yield showNavBar();
   1.163 +
   1.164 +    let edit = document.getElementById("urlbar-edit");
   1.165 +    edit.value = "http://www.wikipedia.org/";
   1.166 +
   1.167 +    sendElementTap(window, edit);
   1.168 +    edit.select();
   1.169 +
   1.170 +    let panel = ContextMenuUI._menuPopup._panel;
   1.171 +    let promise = waitForEvent(panel, "popupshown")
   1.172 +    sendContextMenuClickToElement(window, edit);
   1.173 +    ok((yield promise), "show context menu");
   1.174 +
   1.175 +    let copy = document.getElementById("context-copy");
   1.176 +    ok(!copy.hidden, "copy menu item is visible")
   1.177 +
   1.178 +    let condition = getClipboardCondition("http://www.wikipedia.org/");
   1.179 +    let promise = waitForCondition(condition);
   1.180 +    sendElementTap(window, copy);
   1.181 +    ok((yield promise), "copy text onto clipboard")
   1.182 +
   1.183 +    clearSelection(edit);
   1.184 +    edit.blur();
   1.185 +  }
   1.186 +})
   1.187 +
   1.188 +gTests.push({
   1.189 +  desc: "bug 965832 - selection monocles move with the nav bar",
   1.190 +  run: function() {
   1.191 +    yield showNavBar();
   1.192 +
   1.193 +    let originalUtils = Services.metro;
   1.194 +    Services.metro = {
   1.195 +      keyboardHeight: 0,
   1.196 +      keyboardVisible: false
   1.197 +    };
   1.198 +    registerCleanupFunction(function() {
   1.199 +      Services.metro = originalUtils;
   1.200 +    });
   1.201 +
   1.202 +    let edit = document.getElementById("urlbar-edit");
   1.203 +    edit.value = "http://www.wikipedia.org/";
   1.204 +
   1.205 +    sendElementTap(window, edit);
   1.206 +    
   1.207 +    let promise = waitForEvent(window, "MozDeckOffsetChanged");
   1.208 +    Services.metro.keyboardHeight = 300;
   1.209 +    Services.metro.keyboardVisible = true;
   1.210 +    Services.obs.notifyObservers(null, "metro_softkeyboard_shown", null);
   1.211 +    yield promise;
   1.212 +
   1.213 +    yield waitForCondition(function () {
   1.214 +      return SelectionHelperUI.isSelectionUIVisible;
   1.215 +    });
   1.216 +
   1.217 +    promise = waitForEvent(window, "MozDeckOffsetChanged");
   1.218 +    Services.metro.keyboardHeight = 0;
   1.219 +    Services.metro.keyboardVisible = false;
   1.220 +    Services.obs.notifyObservers(null, "metro_softkeyboard_hidden", null);
   1.221 +    yield promise;
   1.222 +
   1.223 +    yield waitForCondition(function () {
   1.224 +      return SelectionHelperUI.isSelectionUIVisible;
   1.225 +    });
   1.226 +
   1.227 +    clearSelection(edit);
   1.228 +    edit.blur();
   1.229 +
   1.230 +    yield waitForCondition(function () {
   1.231 +      return !SelectionHelperUI.isSelectionUIVisible;
   1.232 +    });
   1.233 +  }
   1.234 +});
   1.235 +
   1.236 +gTests.push({
   1.237 +  desc: "Bug 957646 - Selection monocles sometimes don't display when tapping" +
   1.238 +        " text in the nav bar.",
   1.239 +  run: function() {
   1.240 +    yield showNavBar();
   1.241 +
   1.242 +    let edit = document.getElementById("urlbar-edit");
   1.243 +    edit.value = "about:mozilla";
   1.244 +
   1.245 +    let editRectangle = edit.getBoundingClientRect();
   1.246 +
   1.247 +    // Tap outside the input but close enough for fluffing to take effect.
   1.248 +    sendTap(window, editRectangle.left + 50, editRectangle.top - 2);
   1.249 +
   1.250 +    yield waitForCondition(function () {
   1.251 +      return SelectionHelperUI.isSelectionUIVisible;
   1.252 +    });
   1.253 +  }
   1.254 +});
   1.255 +
   1.256 +gTests.push({
   1.257 +  desc: "Bug 972574 - Monocles not matching selection after double tap" +
   1.258 +        " in URL text field.",
   1.259 +  run: function() {
   1.260 +    yield showNavBar();
   1.261 +
   1.262 +    let MARGIN_OF_ERROR = 15;
   1.263 +    let EST_URLTEXT_WIDTH = 125;
   1.264 +
   1.265 +    let edit = document.getElementById("urlbar-edit");
   1.266 +    edit.value = "http://www.wikipedia.org/";
   1.267 +
   1.268 +    // Determine a tap point centered on URL.
   1.269 +    let editRectangle = edit.getBoundingClientRect();
   1.270 +    let midX = editRectangle.left + Math.ceil(EST_URLTEXT_WIDTH / 2);
   1.271 +    let midY = editRectangle.top + Math.ceil(editRectangle.height / 2);
   1.272 +
   1.273 +    // Tap inside the input for fluffing to take effect.
   1.274 +    sendTap(window, midX, midY);
   1.275 +
   1.276 +    // Double-tap inside the input to selectALL.
   1.277 +    sendDoubleTap(window, midX, midY);
   1.278 +
   1.279 +    // Check for start/end monocles positioned within accepted margins.
   1.280 +    checkMonoclePositionRange("start",
   1.281 +      Math.ceil(editRectangle.left - MARGIN_OF_ERROR),
   1.282 +      Math.ceil(editRectangle.left + MARGIN_OF_ERROR),
   1.283 +      Math.ceil(editRectangle.top + editRectangle.height - MARGIN_OF_ERROR),
   1.284 +      Math.ceil(editRectangle.top + editRectangle.height + MARGIN_OF_ERROR));
   1.285 +    checkMonoclePositionRange("end",
   1.286 +      Math.ceil(editRectangle.left + EST_URLTEXT_WIDTH - MARGIN_OF_ERROR),
   1.287 +      Math.ceil(editRectangle.left + EST_URLTEXT_WIDTH + MARGIN_OF_ERROR),
   1.288 +      Math.ceil(editRectangle.top + editRectangle.height - MARGIN_OF_ERROR),
   1.289 +      Math.ceil(editRectangle.top + editRectangle.height + MARGIN_OF_ERROR));
   1.290 +  }
   1.291 +});
   1.292 +
   1.293 +gTests.push({
   1.294 +  desc: "Bug 972428 - grippers not appearing under the URL field when adding " +
   1.295 +        "text.",
   1.296 +  run: function() {
   1.297 +    let inputField = document.getElementById("urlbar-edit").inputField;
   1.298 +    let inputFieldRectangle = inputField.getBoundingClientRect();
   1.299 +
   1.300 +    let chromeHandlerSpy = spyOnMethod(ChromeSelectionHandler, "msgHandler");
   1.301 +
   1.302 +    // Reset URL to empty string
   1.303 +    inputField.value = "";
   1.304 +    inputField.blur();
   1.305 +
   1.306 +    // Activate URL input
   1.307 +    sendTap(window, inputFieldRectangle.left + 50, inputFieldRectangle.top + 5);
   1.308 +
   1.309 +    // Wait until ChromeSelectionHandler tries to attach selection
   1.310 +    yield waitForCondition(() => chromeHandlerSpy.argsForCall.some(
   1.311 +        (args) => args[0] == "Browser:SelectionAttach"));
   1.312 +
   1.313 +    ok(!SelectHelperUI.isSelectionUIVisible && !SelectHelperUI.isCaretUIVisible,
   1.314 +        "Neither CaretUI nor SelectionUI is visible on empty input.");
   1.315 +
   1.316 +    inputField.value = "Test text";
   1.317 +
   1.318 +    sendTap(window, inputFieldRectangle.left + 10, inputFieldRectangle.top + 5);
   1.319 +
   1.320 +    yield waitForCondition(() => SelectionHelperUI.isCaretUIVisible);
   1.321 +    chromeHandlerSpy.restore();
   1.322 +    inputField.blur();
   1.323 +  }
   1.324 +});
   1.325 +
   1.326 +gTests.push({
   1.327 +  desc: "Bug 858206 - Drag selection monocles should not push other monocles " +
   1.328 +        "out of the way.",
   1.329 +  run: function test() {
   1.330 +    yield showNavBar();
   1.331 +
   1.332 +    let edit = document.getElementById("urlbar-edit");
   1.333 +    edit.value = "about:mozilla";
   1.334 +
   1.335 +    let editRectangle = edit.getBoundingClientRect();
   1.336 +
   1.337 +    sendTap(window, editRectangle.left, editRectangle.top);
   1.338 +
   1.339 +    yield waitForCondition(() => SelectionHelperUI.isSelectionUIVisible);
   1.340 +
   1.341 +    let selection = edit.QueryInterface(
   1.342 +        Components.interfaces.nsIDOMXULTextBoxElement).editor.selection;
   1.343 +    let selectionRectangle = selection.getRangeAt(0).getClientRects()[0];
   1.344 +
   1.345 +    // Place caret to the input start
   1.346 +    sendTap(window, selectionRectangle.left + 2, selectionRectangle.top + 2);
   1.347 +    yield waitForCondition(() => !SelectionHelperUI.isSelectionUIVisible &&
   1.348 +        SelectionHelperUI.isCaretUIVisible);
   1.349 +
   1.350 +    let startXPos = SelectionHelperUI.caretMark.xPos;
   1.351 +    let startYPos = SelectionHelperUI.caretMark.yPos + 10;
   1.352 +    let touchDrag = new TouchDragAndHold();
   1.353 +    yield touchDrag.start(gWindow, startXPos, startYPos, startXPos + 200,
   1.354 +        startYPos);
   1.355 +    yield waitForCondition(() => getTrimmedSelection(edit).toString() ==
   1.356 +        "about:mozilla", kCommonWaitMs, kCommonPollMs);
   1.357 +
   1.358 +    touchDrag.end();
   1.359 +    yield waitForCondition(() => !SelectionHelperUI.hasActiveDrag,
   1.360 +        kCommonWaitMs, kCommonPollMs);
   1.361 +
   1.362 +    // Place caret to the input end
   1.363 +    sendTap(window, selectionRectangle.right - 2, selectionRectangle.top + 2);
   1.364 +    yield waitForCondition(() => !SelectionHelperUI.isSelectionUIVisible &&
   1.365 +        SelectionHelperUI.isCaretUIVisible);
   1.366 +
   1.367 +    startXPos = SelectionHelperUI.caretMark.xPos;
   1.368 +    startYPos = SelectionHelperUI.caretMark.yPos + 10;
   1.369 +    yield touchDrag.start(gWindow, startXPos, startYPos, startXPos - 200,
   1.370 +        startYPos);
   1.371 +    yield waitForCondition(() => getTrimmedSelection(edit).toString() ==
   1.372 +        "about:mozilla", kCommonWaitMs, kCommonPollMs);
   1.373 +
   1.374 +    touchDrag.end();
   1.375 +    yield waitForCondition(() => !SelectionHelperUI.hasActiveDrag,
   1.376 +        kCommonWaitMs, kCommonPollMs);
   1.377 +
   1.378 +    // Place caret in the middle
   1.379 +    let midX = Math.ceil(((selectionRectangle.right - selectionRectangle.left) *
   1.380 +        .5) + selectionRectangle.left);
   1.381 +    let midY = Math.ceil(((selectionRectangle.bottom - selectionRectangle.top) *
   1.382 +        .5) + selectionRectangle.top);
   1.383 +
   1.384 +    sendTap(window, midX, midY);
   1.385 +    yield waitForCondition(() => !SelectionHelperUI.isSelectionUIVisible &&
   1.386 +        SelectionHelperUI.isCaretUIVisible);
   1.387 +
   1.388 +    startXPos = SelectionHelperUI.caretMark.xPos;
   1.389 +    startYPos = SelectionHelperUI.caretMark.yPos + 10;
   1.390 +    yield touchDrag.start(gWindow, startXPos, startYPos, startXPos - 200,
   1.391 +        startYPos);
   1.392 +    yield waitForCondition(() => getTrimmedSelection(edit).toString() ==
   1.393 +        "about:", kCommonWaitMs, kCommonPollMs);
   1.394 +
   1.395 +    touchDrag.end();
   1.396 +    yield waitForCondition(() => !SelectionHelperUI.hasActiveDrag,
   1.397 +        kCommonWaitMs, kCommonPollMs);
   1.398 +
   1.399 +    // Now try to swap monocles
   1.400 +    startXPos = SelectionHelperUI.startMark.xPos;
   1.401 +    startYPos = SelectionHelperUI.startMark.yPos + 10;
   1.402 +    yield touchDrag.start(gWindow, startXPos, startYPos, startXPos + 200,
   1.403 +        startYPos);
   1.404 +    yield waitForCondition(() => getTrimmedSelection(edit).toString() ==
   1.405 +        "mozilla", kCommonWaitMs, kCommonPollMs);
   1.406 +      touchDrag.end();
   1.407 +    yield waitForCondition(() => !SelectionHelperUI.hasActiveDrag &&
   1.408 +        SelectionHelperUI.isSelectionUIVisible, kCommonWaitMs, kCommonPollMs);
   1.409 +  }
   1.410 +});
   1.411 +
   1.412 +function test() {
   1.413 +  if (!isLandscapeMode()) {
   1.414 +    todo(false, "browser_selection_tests need landscape mode to run.");
   1.415 +    return;
   1.416 +  }
   1.417 +  runTests();
   1.418 +}

mercurial