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

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:64a2a19e0c2d
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=2 et sw=2 tw=80: */
3 /* Any copyright is dedicated to the Public Domain.
4 http://creativecommons.org/publicdomain/zero/1.0/ */
5
6 "use strict";
7
8 let gWindow = null;
9 var gFrame = null;
10
11 const kCommonWaitMs = 5000;
12 const kCommonPollMs = 100;
13
14 ///////////////////////////////////////////////////
15 // text area tests
16 ///////////////////////////////////////////////////
17
18 function setUpAndTearDown() {
19 emptyClipboard();
20 if (gWindow)
21 clearSelection(gWindow);
22 if (gFrame)
23 clearSelection(gFrame);
24 yield waitForCondition(function () {
25 return !SelectionHelperUI.isSelectionUIVisible;
26 }, kCommonWaitMs, kCommonPollMs);
27 InputSourceHelper.isPrecise = false;
28 InputSourceHelper.fireUpdate();
29 }
30
31 gTests.push({
32 desc: "normalize browser",
33 setUp: setUpAndTearDown,
34 tearDown: setUpAndTearDown,
35 run: function test() {
36 info(chromeRoot + "browser_selection_textarea.html");
37 yield addTab(chromeRoot + "browser_selection_textarea.html");
38
39 yield waitForCondition(function () {
40 return !BrowserUI.isStartTabVisible;
41 }, 10000, 100);
42
43 yield hideContextUI();
44
45 gWindow = Browser.selectedTab.browser.contentWindow;
46 },
47 });
48
49 gTests.push({
50 desc: "textarea selection and drag",
51 setUp: setUpAndTearDown,
52 tearDown: setUpAndTearDown,
53 run: function test() {
54 // work around for buggy context menu display
55 yield waitForMs(100);
56
57 let textarea = gWindow.document.getElementById("inputtext");
58 textarea.focus();
59
60 let promise = waitForEvent(document, "popupshown");
61 sendContextMenuClickToElement(gWindow, textarea, 20, 10);
62 yield promise;
63
64 checkContextUIMenuItemVisibility(["context-select",
65 "context-select-all"]);
66
67 let menuItem = document.getElementById("context-select");
68 ok(menuItem, "menu item exists");
69 ok(!menuItem.hidden, "menu item visible");
70 let popupPromise = waitForEvent(document, "popuphidden");
71 sendElementTap(gWindow, menuItem);
72 yield popupPromise;
73 ok(popupPromise && !(popupPromise instanceof Error), "promise error");
74
75 yield waitForCondition(function () {
76 return SelectionHelperUI.isSelectionUIVisible;
77 }, kCommonWaitMs, kCommonPollMs);
78
79 is(SelectionHelperUI.isActive, true, "selection active");
80 is(getTrimmedSelection(textarea).toString(), "Alice", "selection test");
81
82 let xpos = SelectionHelperUI.endMark.xPos;
83 let ypos = SelectionHelperUI.endMark.yPos + 10;
84
85 var touchdrag = new TouchDragAndHold();
86
87 // end marker and off the text area to the right
88 yield touchdrag.start(gWindow, xpos, ypos, 1200, 400);
89 let token = "(end)";
90 yield waitForCondition(function () {
91 let selection = getTrimmedSelection(textarea).toString();
92 if (selection.length < token.length ||
93 selection.substring(selection.length - token.length) != token) {
94 return false;
95 }
96 return true;
97 }, 5000, 100);
98
99 touchdrag.end();
100 touchdrag = null;
101
102 yield waitForCondition(function () {
103 return !SelectionHelperUI.hasActiveDrag;
104 }, kCommonWaitMs, kCommonPollMs);
105 yield SelectionHelperUI.pingSelectionHandler();
106 },
107 });
108
109 function test() {
110 if (!isLandscapeMode()) {
111 todo(false, "browser_selection_tests need landscape mode to run.");
112 return;
113 }
114 runTests();
115 }

mercurial