browser/metro/base/tests/mochitest/browser_selection_urlbar.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

michael@0 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* vim: set ts=2 et sw=2 tw=80: */
michael@0 3 /* Any copyright is dedicated to the Public Domain.
michael@0 4 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 5
michael@0 6 "use strict";
michael@0 7
michael@0 8 let gWindow = null;
michael@0 9 var gFrame = null;
michael@0 10
michael@0 11 const kCommonWaitMs = 5000;
michael@0 12 const kCommonPollMs = 100;
michael@0 13
michael@0 14 ///////////////////////////////////////////////////
michael@0 15 // text area tests
michael@0 16 ///////////////////////////////////////////////////
michael@0 17
michael@0 18 gTests.push({
michael@0 19 desc: "normalize browser",
michael@0 20 run: function test() {
michael@0 21 info(chromeRoot + "res/textblock01.html");
michael@0 22 yield addTab(chromeRoot + "res/textblock01.html");
michael@0 23
michael@0 24 yield waitForCondition(function () {
michael@0 25 return !BrowserUI.isStartTabVisible;
michael@0 26 });
michael@0 27
michael@0 28 yield hideContextUI();
michael@0 29
michael@0 30 InputSourceHelper.isPrecise = false;
michael@0 31 InputSourceHelper.fireUpdate();
michael@0 32 },
michael@0 33 });
michael@0 34
michael@0 35 gTests.push({
michael@0 36 desc: "nav bar display",
michael@0 37 run: function test() {
michael@0 38 gWindow = window;
michael@0 39
michael@0 40 yield showNavBar();
michael@0 41
michael@0 42 let edit = document.getElementById("urlbar-edit");
michael@0 43
michael@0 44 sendElementTap(window, edit, 100, 10);
michael@0 45
michael@0 46 ok(SelectionHelperUI.isSelectionUIVisible, "selection ui active");
michael@0 47
michael@0 48 sendElementTap(window, edit, 70, 10);
michael@0 49
michael@0 50 ok(SelectionHelperUI.isCaretUIVisible, "caret ui active");
michael@0 51
michael@0 52 // to the right
michael@0 53 let xpos = SelectionHelperUI.caretMark.xPos;
michael@0 54 let ypos = SelectionHelperUI.caretMark.yPos + 10;
michael@0 55 var touchdrag = new TouchDragAndHold();
michael@0 56 yield touchdrag.start(gWindow, xpos, ypos, 900, ypos);
michael@0 57 yield waitForCondition(function () {
michael@0 58 return getTrimmedSelection(edit).toString() ==
michael@0 59 "mochitests/content/metro/browser/metro/base/tests/mochitest/res/textblock01.html";
michael@0 60 }, kCommonWaitMs, kCommonPollMs);
michael@0 61 touchdrag.end();
michael@0 62 yield waitForMs(100);
michael@0 63
michael@0 64 ok(SelectionHelperUI.isSelectionUIVisible, "selection ui active");
michael@0 65 },
michael@0 66 });
michael@0 67
michael@0 68 gTests.push({
michael@0 69 desc: "bug 887120 - tap & hold to paste into urlbar",
michael@0 70 run: function() {
michael@0 71 gWindow = window;
michael@0 72
michael@0 73 yield showNavBar();
michael@0 74 let edit = document.getElementById("urlbar-edit");
michael@0 75
michael@0 76 SpecialPowers.clipboardCopyString("mozilla");
michael@0 77 sendContextMenuClickToElement(window, edit);
michael@0 78 yield waitForEvent(document, "popupshown");
michael@0 79
michael@0 80 ok(ContextMenuUI._menuPopup.visible, "is visible");
michael@0 81 let paste = document.getElementById("context-paste");
michael@0 82 ok(!paste.hidden, "paste item is visible");
michael@0 83
michael@0 84 sendElementTap(window, paste);
michael@0 85 ok(edit.popup.popupOpen, "bug: popup should be showing");
michael@0 86
michael@0 87 clearSelection(edit);
michael@0 88 yield waitForCondition(function () {
michael@0 89 return !SelectionHelperUI.isSelectionUIVisible;
michael@0 90 });
michael@0 91 }
michael@0 92 });
michael@0 93
michael@0 94 gTests.push({
michael@0 95 desc: "bug 895284 - tap selection",
michael@0 96 run: function() {
michael@0 97 gWindow = window;
michael@0 98
michael@0 99 yield showNavBar();
michael@0 100 let edit = document.getElementById("urlbar-edit");
michael@0 101 edit.value = "wikipedia.org";
michael@0 102 edit.select();
michael@0 103
michael@0 104 let editCoords = logicalCoordsForElement(edit);
michael@0 105
michael@0 106 // wait for popup animation to complete, it interferes with edit selection testing
michael@0 107 let autocompletePopup = document.getElementById("urlbar-autocomplete-scroll");
michael@0 108 yield waitForEvent(autocompletePopup, "transitionend");
michael@0 109
michael@0 110 SelectionHelperUI.attachEditSession(ChromeSelectionHandler, editCoords.x,
michael@0 111 editCoords.y, edit);
michael@0 112 ok(SelectionHelperUI.isSelectionUIVisible, "selection enabled");
michael@0 113
michael@0 114 let selection = edit.QueryInterface(Components.interfaces.nsIDOMXULTextBoxElement)
michael@0 115 .editor.selection;
michael@0 116 let rects = selection.getRangeAt(0).getClientRects();
michael@0 117 let midX = Math.ceil(((rects[0].right - rects[0].left) * .5) + rects[0].left);
michael@0 118 let midY = Math.ceil(((rects[0].bottom - rects[0].top) * .5) + rects[0].top);
michael@0 119
michael@0 120 sendTap(window, midX, midY);
michael@0 121
michael@0 122 ok(SelectionHelperUI.isCaretUIVisible, "caret browsing enabled");
michael@0 123
michael@0 124 clearSelection(edit);
michael@0 125 yield waitForCondition(function () {
michael@0 126 return !SelectionHelperUI.isSelectionUIVisible;
michael@0 127 });
michael@0 128 }
michael@0 129 });
michael@0 130
michael@0 131 gTests.push({
michael@0 132 desc: "bug 894713 - blur shuts down selection handling",
michael@0 133 run: function() {
michael@0 134 gWindow = window;
michael@0 135 yield showNavBar();
michael@0 136 let edit = document.getElementById("urlbar-edit");
michael@0 137 edit.value = "wikipedia.org";
michael@0 138 edit.select();
michael@0 139 let editCoords = logicalCoordsForElement(edit);
michael@0 140 SelectionHelperUI.attachEditSession(ChromeSelectionHandler, editCoords.x,
michael@0 141 editCoords.y, edit);
michael@0 142 edit.blur();
michael@0 143 ok(!SelectionHelperUI.isSelectionUIVisible, "selection no longer enabled");
michael@0 144 clearSelection(edit);
michael@0 145 yield waitForCondition(function () {
michael@0 146 return !SelectionHelperUI.isSelectionUIVisible;
michael@0 147 });
michael@0 148 }
michael@0 149 });
michael@0 150
michael@0 151 function getClipboardCondition(aExpected) {
michael@0 152 return () => aExpected == SpecialPowers.getClipboardData("text/unicode");
michael@0 153 }
michael@0 154
michael@0 155 gTests.push({
michael@0 156 desc: "bug 894715 - URLs selected by touch are copied with trimming",
michael@0 157 run: function () {
michael@0 158 gWindow = window;
michael@0 159 yield showNavBar();
michael@0 160
michael@0 161 let edit = document.getElementById("urlbar-edit");
michael@0 162 edit.value = "http://www.wikipedia.org/";
michael@0 163
michael@0 164 sendElementTap(window, edit);
michael@0 165 edit.select();
michael@0 166
michael@0 167 let panel = ContextMenuUI._menuPopup._panel;
michael@0 168 let promise = waitForEvent(panel, "popupshown")
michael@0 169 sendContextMenuClickToElement(window, edit);
michael@0 170 ok((yield promise), "show context menu");
michael@0 171
michael@0 172 let copy = document.getElementById("context-copy");
michael@0 173 ok(!copy.hidden, "copy menu item is visible")
michael@0 174
michael@0 175 let condition = getClipboardCondition("http://www.wikipedia.org/");
michael@0 176 let promise = waitForCondition(condition);
michael@0 177 sendElementTap(window, copy);
michael@0 178 ok((yield promise), "copy text onto clipboard")
michael@0 179
michael@0 180 clearSelection(edit);
michael@0 181 edit.blur();
michael@0 182 }
michael@0 183 })
michael@0 184
michael@0 185 gTests.push({
michael@0 186 desc: "bug 965832 - selection monocles move with the nav bar",
michael@0 187 run: function() {
michael@0 188 yield showNavBar();
michael@0 189
michael@0 190 let originalUtils = Services.metro;
michael@0 191 Services.metro = {
michael@0 192 keyboardHeight: 0,
michael@0 193 keyboardVisible: false
michael@0 194 };
michael@0 195 registerCleanupFunction(function() {
michael@0 196 Services.metro = originalUtils;
michael@0 197 });
michael@0 198
michael@0 199 let edit = document.getElementById("urlbar-edit");
michael@0 200 edit.value = "http://www.wikipedia.org/";
michael@0 201
michael@0 202 sendElementTap(window, edit);
michael@0 203
michael@0 204 let promise = waitForEvent(window, "MozDeckOffsetChanged");
michael@0 205 Services.metro.keyboardHeight = 300;
michael@0 206 Services.metro.keyboardVisible = true;
michael@0 207 Services.obs.notifyObservers(null, "metro_softkeyboard_shown", null);
michael@0 208 yield promise;
michael@0 209
michael@0 210 yield waitForCondition(function () {
michael@0 211 return SelectionHelperUI.isSelectionUIVisible;
michael@0 212 });
michael@0 213
michael@0 214 promise = waitForEvent(window, "MozDeckOffsetChanged");
michael@0 215 Services.metro.keyboardHeight = 0;
michael@0 216 Services.metro.keyboardVisible = false;
michael@0 217 Services.obs.notifyObservers(null, "metro_softkeyboard_hidden", null);
michael@0 218 yield promise;
michael@0 219
michael@0 220 yield waitForCondition(function () {
michael@0 221 return SelectionHelperUI.isSelectionUIVisible;
michael@0 222 });
michael@0 223
michael@0 224 clearSelection(edit);
michael@0 225 edit.blur();
michael@0 226
michael@0 227 yield waitForCondition(function () {
michael@0 228 return !SelectionHelperUI.isSelectionUIVisible;
michael@0 229 });
michael@0 230 }
michael@0 231 });
michael@0 232
michael@0 233 gTests.push({
michael@0 234 desc: "Bug 957646 - Selection monocles sometimes don't display when tapping" +
michael@0 235 " text in the nav bar.",
michael@0 236 run: function() {
michael@0 237 yield showNavBar();
michael@0 238
michael@0 239 let edit = document.getElementById("urlbar-edit");
michael@0 240 edit.value = "about:mozilla";
michael@0 241
michael@0 242 let editRectangle = edit.getBoundingClientRect();
michael@0 243
michael@0 244 // Tap outside the input but close enough for fluffing to take effect.
michael@0 245 sendTap(window, editRectangle.left + 50, editRectangle.top - 2);
michael@0 246
michael@0 247 yield waitForCondition(function () {
michael@0 248 return SelectionHelperUI.isSelectionUIVisible;
michael@0 249 });
michael@0 250 }
michael@0 251 });
michael@0 252
michael@0 253 gTests.push({
michael@0 254 desc: "Bug 972574 - Monocles not matching selection after double tap" +
michael@0 255 " in URL text field.",
michael@0 256 run: function() {
michael@0 257 yield showNavBar();
michael@0 258
michael@0 259 let MARGIN_OF_ERROR = 15;
michael@0 260 let EST_URLTEXT_WIDTH = 125;
michael@0 261
michael@0 262 let edit = document.getElementById("urlbar-edit");
michael@0 263 edit.value = "http://www.wikipedia.org/";
michael@0 264
michael@0 265 // Determine a tap point centered on URL.
michael@0 266 let editRectangle = edit.getBoundingClientRect();
michael@0 267 let midX = editRectangle.left + Math.ceil(EST_URLTEXT_WIDTH / 2);
michael@0 268 let midY = editRectangle.top + Math.ceil(editRectangle.height / 2);
michael@0 269
michael@0 270 // Tap inside the input for fluffing to take effect.
michael@0 271 sendTap(window, midX, midY);
michael@0 272
michael@0 273 // Double-tap inside the input to selectALL.
michael@0 274 sendDoubleTap(window, midX, midY);
michael@0 275
michael@0 276 // Check for start/end monocles positioned within accepted margins.
michael@0 277 checkMonoclePositionRange("start",
michael@0 278 Math.ceil(editRectangle.left - MARGIN_OF_ERROR),
michael@0 279 Math.ceil(editRectangle.left + MARGIN_OF_ERROR),
michael@0 280 Math.ceil(editRectangle.top + editRectangle.height - MARGIN_OF_ERROR),
michael@0 281 Math.ceil(editRectangle.top + editRectangle.height + MARGIN_OF_ERROR));
michael@0 282 checkMonoclePositionRange("end",
michael@0 283 Math.ceil(editRectangle.left + EST_URLTEXT_WIDTH - MARGIN_OF_ERROR),
michael@0 284 Math.ceil(editRectangle.left + EST_URLTEXT_WIDTH + MARGIN_OF_ERROR),
michael@0 285 Math.ceil(editRectangle.top + editRectangle.height - MARGIN_OF_ERROR),
michael@0 286 Math.ceil(editRectangle.top + editRectangle.height + MARGIN_OF_ERROR));
michael@0 287 }
michael@0 288 });
michael@0 289
michael@0 290 gTests.push({
michael@0 291 desc: "Bug 972428 - grippers not appearing under the URL field when adding " +
michael@0 292 "text.",
michael@0 293 run: function() {
michael@0 294 let inputField = document.getElementById("urlbar-edit").inputField;
michael@0 295 let inputFieldRectangle = inputField.getBoundingClientRect();
michael@0 296
michael@0 297 let chromeHandlerSpy = spyOnMethod(ChromeSelectionHandler, "msgHandler");
michael@0 298
michael@0 299 // Reset URL to empty string
michael@0 300 inputField.value = "";
michael@0 301 inputField.blur();
michael@0 302
michael@0 303 // Activate URL input
michael@0 304 sendTap(window, inputFieldRectangle.left + 50, inputFieldRectangle.top + 5);
michael@0 305
michael@0 306 // Wait until ChromeSelectionHandler tries to attach selection
michael@0 307 yield waitForCondition(() => chromeHandlerSpy.argsForCall.some(
michael@0 308 (args) => args[0] == "Browser:SelectionAttach"));
michael@0 309
michael@0 310 ok(!SelectHelperUI.isSelectionUIVisible && !SelectHelperUI.isCaretUIVisible,
michael@0 311 "Neither CaretUI nor SelectionUI is visible on empty input.");
michael@0 312
michael@0 313 inputField.value = "Test text";
michael@0 314
michael@0 315 sendTap(window, inputFieldRectangle.left + 10, inputFieldRectangle.top + 5);
michael@0 316
michael@0 317 yield waitForCondition(() => SelectionHelperUI.isCaretUIVisible);
michael@0 318 chromeHandlerSpy.restore();
michael@0 319 inputField.blur();
michael@0 320 }
michael@0 321 });
michael@0 322
michael@0 323 gTests.push({
michael@0 324 desc: "Bug 858206 - Drag selection monocles should not push other monocles " +
michael@0 325 "out of the way.",
michael@0 326 run: function test() {
michael@0 327 yield showNavBar();
michael@0 328
michael@0 329 let edit = document.getElementById("urlbar-edit");
michael@0 330 edit.value = "about:mozilla";
michael@0 331
michael@0 332 let editRectangle = edit.getBoundingClientRect();
michael@0 333
michael@0 334 sendTap(window, editRectangle.left, editRectangle.top);
michael@0 335
michael@0 336 yield waitForCondition(() => SelectionHelperUI.isSelectionUIVisible);
michael@0 337
michael@0 338 let selection = edit.QueryInterface(
michael@0 339 Components.interfaces.nsIDOMXULTextBoxElement).editor.selection;
michael@0 340 let selectionRectangle = selection.getRangeAt(0).getClientRects()[0];
michael@0 341
michael@0 342 // Place caret to the input start
michael@0 343 sendTap(window, selectionRectangle.left + 2, selectionRectangle.top + 2);
michael@0 344 yield waitForCondition(() => !SelectionHelperUI.isSelectionUIVisible &&
michael@0 345 SelectionHelperUI.isCaretUIVisible);
michael@0 346
michael@0 347 let startXPos = SelectionHelperUI.caretMark.xPos;
michael@0 348 let startYPos = SelectionHelperUI.caretMark.yPos + 10;
michael@0 349 let touchDrag = new TouchDragAndHold();
michael@0 350 yield touchDrag.start(gWindow, startXPos, startYPos, startXPos + 200,
michael@0 351 startYPos);
michael@0 352 yield waitForCondition(() => getTrimmedSelection(edit).toString() ==
michael@0 353 "about:mozilla", kCommonWaitMs, kCommonPollMs);
michael@0 354
michael@0 355 touchDrag.end();
michael@0 356 yield waitForCondition(() => !SelectionHelperUI.hasActiveDrag,
michael@0 357 kCommonWaitMs, kCommonPollMs);
michael@0 358
michael@0 359 // Place caret to the input end
michael@0 360 sendTap(window, selectionRectangle.right - 2, selectionRectangle.top + 2);
michael@0 361 yield waitForCondition(() => !SelectionHelperUI.isSelectionUIVisible &&
michael@0 362 SelectionHelperUI.isCaretUIVisible);
michael@0 363
michael@0 364 startXPos = SelectionHelperUI.caretMark.xPos;
michael@0 365 startYPos = SelectionHelperUI.caretMark.yPos + 10;
michael@0 366 yield touchDrag.start(gWindow, startXPos, startYPos, startXPos - 200,
michael@0 367 startYPos);
michael@0 368 yield waitForCondition(() => getTrimmedSelection(edit).toString() ==
michael@0 369 "about:mozilla", kCommonWaitMs, kCommonPollMs);
michael@0 370
michael@0 371 touchDrag.end();
michael@0 372 yield waitForCondition(() => !SelectionHelperUI.hasActiveDrag,
michael@0 373 kCommonWaitMs, kCommonPollMs);
michael@0 374
michael@0 375 // Place caret in the middle
michael@0 376 let midX = Math.ceil(((selectionRectangle.right - selectionRectangle.left) *
michael@0 377 .5) + selectionRectangle.left);
michael@0 378 let midY = Math.ceil(((selectionRectangle.bottom - selectionRectangle.top) *
michael@0 379 .5) + selectionRectangle.top);
michael@0 380
michael@0 381 sendTap(window, midX, midY);
michael@0 382 yield waitForCondition(() => !SelectionHelperUI.isSelectionUIVisible &&
michael@0 383 SelectionHelperUI.isCaretUIVisible);
michael@0 384
michael@0 385 startXPos = SelectionHelperUI.caretMark.xPos;
michael@0 386 startYPos = SelectionHelperUI.caretMark.yPos + 10;
michael@0 387 yield touchDrag.start(gWindow, startXPos, startYPos, startXPos - 200,
michael@0 388 startYPos);
michael@0 389 yield waitForCondition(() => getTrimmedSelection(edit).toString() ==
michael@0 390 "about:", kCommonWaitMs, kCommonPollMs);
michael@0 391
michael@0 392 touchDrag.end();
michael@0 393 yield waitForCondition(() => !SelectionHelperUI.hasActiveDrag,
michael@0 394 kCommonWaitMs, kCommonPollMs);
michael@0 395
michael@0 396 // Now try to swap monocles
michael@0 397 startXPos = SelectionHelperUI.startMark.xPos;
michael@0 398 startYPos = SelectionHelperUI.startMark.yPos + 10;
michael@0 399 yield touchDrag.start(gWindow, startXPos, startYPos, startXPos + 200,
michael@0 400 startYPos);
michael@0 401 yield waitForCondition(() => getTrimmedSelection(edit).toString() ==
michael@0 402 "mozilla", kCommonWaitMs, kCommonPollMs);
michael@0 403 touchDrag.end();
michael@0 404 yield waitForCondition(() => !SelectionHelperUI.hasActiveDrag &&
michael@0 405 SelectionHelperUI.isSelectionUIVisible, kCommonWaitMs, kCommonPollMs);
michael@0 406 }
michael@0 407 });
michael@0 408
michael@0 409 function test() {
michael@0 410 if (!isLandscapeMode()) {
michael@0 411 todo(false, "browser_selection_tests need landscape mode to run.");
michael@0 412 return;
michael@0 413 }
michael@0 414 runTests();
michael@0 415 }

mercurial