|
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 var gInput = null; |
|
11 |
|
12 const kCommonWaitMs = 5000; |
|
13 const kCommonPollMs = 100; |
|
14 |
|
15 /////////////////////////////////////////////////// |
|
16 // form input tests |
|
17 /////////////////////////////////////////////////// |
|
18 |
|
19 function setUpAndTearDown() { |
|
20 emptyClipboard(); |
|
21 if (gWindow) |
|
22 clearSelection(gWindow); |
|
23 if (gFrame) |
|
24 clearSelection(gFrame); |
|
25 if (gInput) |
|
26 clearSelection(gInput); |
|
27 yield waitForCondition(function () { |
|
28 return !SelectionHelperUI.isSelectionUIVisible; |
|
29 }, kCommonWaitMs, kCommonPollMs); |
|
30 InputSourceHelper.isPrecise = false; |
|
31 InputSourceHelper.fireUpdate(); |
|
32 } |
|
33 |
|
34 gTests.push({ |
|
35 desc: "normalize browser", |
|
36 setUp: setUpAndTearDown, |
|
37 tearDown: setUpAndTearDown, |
|
38 run: function test() { |
|
39 info(chromeRoot + "browser_selection_frame_inputs.html"); |
|
40 yield addTab(chromeRoot + "browser_selection_frame_inputs.html"); |
|
41 |
|
42 yield waitForCondition(function () { |
|
43 return !BrowserUI.isStartTabVisible; |
|
44 }, 10000, 100); |
|
45 |
|
46 yield hideContextUI(); |
|
47 |
|
48 gWindow = Browser.selectedTab.browser.contentWindow; |
|
49 gFrame = gWindow.document.getElementById("frame1"); |
|
50 gInput = gFrame.contentDocument.getElementById("textinput"); |
|
51 |
|
52 ok(gWindow != null, "gWindow"); |
|
53 ok(gFrame != null, "gFrame"); |
|
54 ok(gInput != null, "gInput"); |
|
55 }, |
|
56 }); |
|
57 |
|
58 gTests.push({ |
|
59 desc: "basic selection", |
|
60 setUp: setUpAndTearDown, |
|
61 tearDown: setUpAndTearDown, |
|
62 run: function test() { |
|
63 gInput.focus(); |
|
64 gInput.selectionStart = gInput.selectionEnd = 0; |
|
65 |
|
66 let promise = waitForEvent(document, "popupshown"); |
|
67 sendContextMenuClickToElement(gWindow, gFrame, 135, 10); |
|
68 yield promise; |
|
69 |
|
70 checkContextUIMenuItemVisibility(["context-select", |
|
71 "context-select-all"]); |
|
72 |
|
73 let menuItem = document.getElementById("context-select"); |
|
74 ok(menuItem, "menu item exists"); |
|
75 ok(!menuItem.hidden, "menu item visible"); |
|
76 let popupPromise = waitForEvent(document, "popuphidden"); |
|
77 sendElementTap(gWindow, menuItem); |
|
78 yield popupPromise; |
|
79 |
|
80 yield waitForCondition(function () { |
|
81 return SelectionHelperUI.isSelectionUIVisible; |
|
82 }, kCommonWaitMs, kCommonPollMs); |
|
83 |
|
84 is(getTrimmedSelection(gInput).toString(), "straight", "selection test"); |
|
85 |
|
86 let rect = gFrame.getBoundingClientRect(); |
|
87 checkMonoclePositionRange("start", rect.left + 125, rect.left + 135, rect.top + 20, rect.top + 30); |
|
88 checkMonoclePositionRange("end", rect.left + 165, rect.left + 175, rect.top + 20, rect.top + 30); |
|
89 }, |
|
90 }); |
|
91 |
|
92 gTests.push({ |
|
93 desc: "drag selection", |
|
94 setUp: setUpAndTearDown, |
|
95 tearDown: setUpAndTearDown, |
|
96 run: function test() { |
|
97 gInput.focus(); |
|
98 gInput.selectionStart = gInput.selectionEnd = 0; |
|
99 |
|
100 let promise = waitForEvent(document, "popupshown"); |
|
101 sendContextMenuClickToElement(gWindow, gFrame, 135, 10); |
|
102 yield promise; |
|
103 |
|
104 checkContextUIMenuItemVisibility(["context-select", |
|
105 "context-select-all"]); |
|
106 |
|
107 let menuItem = document.getElementById("context-select"); |
|
108 ok(menuItem, "menu item exists"); |
|
109 ok(!menuItem.hidden, "menu item visible"); |
|
110 let popupPromise = waitForEvent(document, "popuphidden"); |
|
111 sendElementTap(gWindow, menuItem); |
|
112 yield popupPromise; |
|
113 |
|
114 yield waitForCondition(function () { |
|
115 return SelectionHelperUI.isSelectionUIVisible; |
|
116 }, kCommonWaitMs, kCommonPollMs); |
|
117 |
|
118 is(getTrimmedSelection(gInput).toString(), "straight", "selection test"); |
|
119 |
|
120 // end marker to the right |
|
121 let xpos = SelectionHelperUI.endMark.xPos; |
|
122 let ypos = SelectionHelperUI.endMark.yPos + 10; |
|
123 var touchdrag = new TouchDragAndHold(); |
|
124 yield touchdrag.start(gWindow, xpos, ypos, xpos + 350, ypos); |
|
125 yield waitForCondition(function () { |
|
126 return getTrimmedSelection(gInput).toString() == |
|
127 "straight on like a tunnel for some way and then dipped suddenly down"; |
|
128 }, 6000, 2000); |
|
129 touchdrag.end(); |
|
130 |
|
131 yield waitForCondition(function () { |
|
132 return !SelectionHelperUI.hasActiveDrag; |
|
133 }, kCommonWaitMs, kCommonPollMs); |
|
134 yield SelectionHelperUI.pingSelectionHandler(); |
|
135 |
|
136 // start marker to the left |
|
137 let xpos = SelectionHelperUI.startMark.xPos; |
|
138 let ypos = SelectionHelperUI.startMark.yPos + 10; |
|
139 var touchdrag = new TouchDragAndHold(); |
|
140 yield touchdrag.start(gWindow, xpos, ypos, 10, ypos); |
|
141 yield waitForCondition(function () { |
|
142 return getTrimmedSelection(gInput).toString() == |
|
143 "The rabbit-hole went straight on like a tunnel for some way and then dipped suddenly down"; |
|
144 }, 6000, 2000); |
|
145 touchdrag.end(); |
|
146 |
|
147 yield waitForCondition(function () { |
|
148 return !SelectionHelperUI.hasActiveDrag; |
|
149 }, kCommonWaitMs, kCommonPollMs); |
|
150 yield SelectionHelperUI.pingSelectionHandler(); |
|
151 }, |
|
152 }); |
|
153 |
|
154 function test() { |
|
155 if (!isLandscapeMode()) { |
|
156 todo(false, "browser_selection_tests need landscape mode to run."); |
|
157 return; |
|
158 } |
|
159 runTests(); |
|
160 } |