browser/metro/base/tests/mochitest/browser_selection_frame_content.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 kMarkerOffsetY = 6;
michael@0 12 const kCommonWaitMs = 5000;
michael@0 13 const kCommonPollMs = 100;
michael@0 14
michael@0 15 ///////////////////////////////////////////////////
michael@0 16 // sub frame content tests
michael@0 17 ///////////////////////////////////////////////////
michael@0 18
michael@0 19 function setUpAndTearDown() {
michael@0 20 emptyClipboard();
michael@0 21 if (gWindow)
michael@0 22 clearSelection(gWindow);
michael@0 23 if (gFrame)
michael@0 24 clearSelection(gFrame);
michael@0 25 yield waitForCondition(function () {
michael@0 26 return !SelectionHelperUI.isSelectionUIVisible;
michael@0 27 }, kCommonWaitMs, kCommonPollMs);
michael@0 28 InputSourceHelper.isPrecise = false;
michael@0 29 InputSourceHelper.fireUpdate();
michael@0 30 }
michael@0 31
michael@0 32 gTests.push({
michael@0 33 desc: "normalize browser",
michael@0 34 setUp: setUpAndTearDown,
michael@0 35 tearDown: setUpAndTearDown,
michael@0 36 run: function test() {
michael@0 37 info(chromeRoot + "browser_selection_frame_content.html");
michael@0 38 yield addTab(chromeRoot + "browser_selection_frame_content.html");
michael@0 39
michael@0 40 yield waitForCondition(function () {
michael@0 41 return !BrowserUI.isStartTabVisible;
michael@0 42 }, 10000, 100);
michael@0 43
michael@0 44 yield hideContextUI();
michael@0 45
michael@0 46 gWindow = Browser.selectedTab.browser.contentWindow;
michael@0 47 gFrame = gWindow.document.getElementById("frame1");
michael@0 48 },
michael@0 49 });
michael@0 50
michael@0 51 gTests.push({
michael@0 52 desc: "iframe basic selection",
michael@0 53 setUp: setUpAndTearDown,
michael@0 54 tearDown: setUpAndTearDown,
michael@0 55 run: function test() {
michael@0 56 gFrame.focus();
michael@0 57
michael@0 58 sendContextMenuClick(165, 35);
michael@0 59
michael@0 60 yield waitForCondition(function () {
michael@0 61 return SelectionHelperUI.isSelectionUIVisible;
michael@0 62 }, kCommonWaitMs, kCommonPollMs);
michael@0 63
michael@0 64 // active state
michael@0 65 is(SelectionHelperUI.isActive, true, "selection active");
michael@0 66 // check text selection
michael@0 67 is(getTrimmedSelection(gFrame).toString(), "Alice", "selection test");
michael@0 68 },
michael@0 69 });
michael@0 70
michael@0 71 gTests.push({
michael@0 72 desc: "iframe expand / collapse selection",
michael@0 73 setUp: setUpAndTearDown,
michael@0 74 tearDown: setUpAndTearDown,
michael@0 75 run: function test() {
michael@0 76 gFrame.focus();
michael@0 77
michael@0 78 sendContextMenuClick(162, 180);
michael@0 79
michael@0 80 yield waitForCondition(function () {
michael@0 81 return SelectionHelperUI.isSelectionUIVisible;
michael@0 82 }, kCommonWaitMs, kCommonPollMs);
michael@0 83
michael@0 84 // active state
michael@0 85 is(SelectionHelperUI.isActive, true, "selection active");
michael@0 86 is(getTrimmedSelection(gFrame).toString(), "Alice", "selection test");
michael@0 87
michael@0 88 let ypos = SelectionHelperUI.endMark.yPos + kMarkerOffsetY;
michael@0 89
michael@0 90 let touchdrag = new TouchDragAndHold();
michael@0 91 yield touchdrag.start(gWindow, SelectionHelperUI.endMark.xPos, ypos, 640, ypos);
michael@0 92 touchdrag.end();
michael@0 93
michael@0 94 yield waitForCondition(function () {
michael@0 95 return !SelectionHelperUI.hasActiveDrag;
michael@0 96 }, kCommonWaitMs, kCommonPollMs);
michael@0 97 yield SelectionHelperUI.pingSelectionHandler();
michael@0 98
michael@0 99 is(SelectionHelperUI.isActive, true, "selection active");
michael@0 100 is(getTrimmedSelection(gFrame).toString(), "Alice was beginning to get very tired of sitting by her sister on the bank",
michael@0 101 "selection test");
michael@0 102
michael@0 103 touchdrag = new TouchDragAndHold();
michael@0 104 yield touchdrag.start(gWindow, SelectionHelperUI.endMark.xPos, ypos, 320, ypos);
michael@0 105 touchdrag.end();
michael@0 106
michael@0 107 yield waitForCondition(function () {
michael@0 108 return !SelectionHelperUI.hasActiveDrag;
michael@0 109 }, kCommonWaitMs, kCommonPollMs);
michael@0 110 yield SelectionHelperUI.pingSelectionHandler();
michael@0 111
michael@0 112 is(SelectionHelperUI.isActive, true, "selection active");
michael@0 113 is(getTrimmedSelection(gFrame).toString(), "Alice was beginning to get very", "selection test");
michael@0 114 },
michael@0 115 });
michael@0 116
michael@0 117 gTests.push({
michael@0 118 desc: "scrolled iframe selection",
michael@0 119 setUp: setUpAndTearDown,
michael@0 120 run: function test() {
michael@0 121 gFrame.focus();
michael@0 122
michael@0 123 let scrollPromise = waitForEvent(gFrame.contentDocument.defaultView, "scroll");
michael@0 124 gFrame.contentDocument.defaultView.scrollBy(0, 200);
michael@0 125 yield scrollPromise;
michael@0 126
michael@0 127 sendContextMenuClick(30, 240);
michael@0 128
michael@0 129 yield waitForCondition(function () {
michael@0 130 return SelectionHelperUI.isSelectionUIVisible;
michael@0 131 }, kCommonWaitMs, kCommonPollMs);
michael@0 132
michael@0 133 is(SelectionHelperUI.isActive, true, "selection active");
michael@0 134 is(getTrimmedSelection(gFrame).toString(), "started", "selection test");
michael@0 135
michael@0 136 let promise = waitForEvent(document, "popupshown");
michael@0 137 sendContextMenuClickToSelection(gFrame.contentDocument.defaultView);
michael@0 138
michael@0 139 yield promise;
michael@0 140 ok(promise && !(promise instanceof Error), "promise error");
michael@0 141 ok(ContextMenuUI._menuPopup.visible, "is visible");
michael@0 142
michael@0 143 let menuItem = document.getElementById("context-copy");
michael@0 144 ok(menuItem, "menu item exists");
michael@0 145 ok(!menuItem.hidden, "menu item visible");
michael@0 146 let popupPromise = waitForEvent(document, "popuphidden");
michael@0 147 sendElementTap(gWindow, menuItem);
michael@0 148 yield popupPromise;
michael@0 149 ok(popupPromise && !(popupPromise instanceof Error), "promise error");
michael@0 150
michael@0 151 // The wait is needed to give time to populate the clipboard.
michael@0 152 let string = "";
michael@0 153 yield waitForCondition(function () {
michael@0 154 string = SpecialPowers.getClipboardData("text/unicode");
michael@0 155 return string === "started";
michael@0 156 });
michael@0 157 is(string, "started", "copy text");
michael@0 158
michael@0 159 },
michael@0 160 tearDown: function tearDown() {
michael@0 161 emptyClipboard();
michael@0 162 let scrollPromise = waitForEvent(gFrame.contentDocument.defaultView, "scroll");
michael@0 163 gFrame.contentDocument.defaultView.scrollBy(0, -200);
michael@0 164 yield scrollPromise;
michael@0 165 clearSelection(gWindow);
michael@0 166 clearSelection(gFrame);
michael@0 167 yield waitForCondition(function () {
michael@0 168 return !SelectionHelperUI.isSelectionUIVisible;
michael@0 169 }, kCommonWaitMs, kCommonPollMs);
michael@0 170 yield hideContextUI();
michael@0 171 },
michael@0 172 });
michael@0 173
michael@0 174 gTests.push({
michael@0 175 desc: "iframe within scrolled page selection",
michael@0 176 setUp: setUpAndTearDown,
michael@0 177 run: function test() {
michael@0 178 gFrame.focus();
michael@0 179
michael@0 180 let scrollPromise = waitForEvent(gWindow, "scroll");
michael@0 181 gWindow.scrollBy(0, 200);
michael@0 182 yield scrollPromise;
michael@0 183
michael@0 184 scrollPromise = waitForEvent(gFrame.contentDocument.defaultView, "scroll");
michael@0 185 gFrame.contentDocument.defaultView.scrollBy(0, 200);
michael@0 186 yield scrollPromise;
michael@0 187
michael@0 188 sendContextMenuClick(114, 130);
michael@0 189
michael@0 190 yield waitForCondition(function () {
michael@0 191 return SelectionHelperUI.isSelectionUIVisible;
michael@0 192 }, kCommonWaitMs, kCommonPollMs);
michael@0 193
michael@0 194 is(SelectionHelperUI.isActive, true, "selection active");
michael@0 195 is(getTrimmedSelection(gFrame).toString(), "moment", "selection test");
michael@0 196 },
michael@0 197 tearDown: function tearDown() {
michael@0 198 emptyClipboard();
michael@0 199 clearSelection(gWindow);
michael@0 200 clearSelection(gFrame);
michael@0 201 let scrollPromise = waitForEvent(gFrame.contentDocument.defaultView, "scroll");
michael@0 202 gFrame.contentDocument.defaultView.scrollBy(0, -200);
michael@0 203 yield scrollPromise;
michael@0 204 scrollPromise = waitForEvent(gWindow, "scroll");
michael@0 205 gWindow.scrollBy(0, -200);
michael@0 206 yield scrollPromise;
michael@0 207 yield waitForCondition(function () {
michael@0 208 return !SelectionHelperUI.isSelectionUIVisible;
michael@0 209 }, kCommonWaitMs, kCommonPollMs);
michael@0 210 yield hideContextUI();
michael@0 211 },
michael@0 212 });
michael@0 213
michael@0 214 function test() {
michael@0 215 if (!isLandscapeMode()) {
michael@0 216 todo(false, "browser_selection_tests need landscape mode to run.");
michael@0 217 return;
michael@0 218 }
michael@0 219 runTests();
michael@0 220 }

mercurial