1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/metro/base/tests/mochitest/browser_selection_frame_content.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,220 @@ 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 kMarkerOffsetY = 6; 1.15 +const kCommonWaitMs = 5000; 1.16 +const kCommonPollMs = 100; 1.17 + 1.18 +/////////////////////////////////////////////////// 1.19 +// sub frame content tests 1.20 +/////////////////////////////////////////////////// 1.21 + 1.22 +function setUpAndTearDown() { 1.23 + emptyClipboard(); 1.24 + if (gWindow) 1.25 + clearSelection(gWindow); 1.26 + if (gFrame) 1.27 + clearSelection(gFrame); 1.28 + yield waitForCondition(function () { 1.29 + return !SelectionHelperUI.isSelectionUIVisible; 1.30 + }, kCommonWaitMs, kCommonPollMs); 1.31 + InputSourceHelper.isPrecise = false; 1.32 + InputSourceHelper.fireUpdate(); 1.33 +} 1.34 + 1.35 +gTests.push({ 1.36 + desc: "normalize browser", 1.37 + setUp: setUpAndTearDown, 1.38 + tearDown: setUpAndTearDown, 1.39 + run: function test() { 1.40 + info(chromeRoot + "browser_selection_frame_content.html"); 1.41 + yield addTab(chromeRoot + "browser_selection_frame_content.html"); 1.42 + 1.43 + yield waitForCondition(function () { 1.44 + return !BrowserUI.isStartTabVisible; 1.45 + }, 10000, 100); 1.46 + 1.47 + yield hideContextUI(); 1.48 + 1.49 + gWindow = Browser.selectedTab.browser.contentWindow; 1.50 + gFrame = gWindow.document.getElementById("frame1"); 1.51 + }, 1.52 +}); 1.53 + 1.54 +gTests.push({ 1.55 + desc: "iframe basic selection", 1.56 + setUp: setUpAndTearDown, 1.57 + tearDown: setUpAndTearDown, 1.58 + run: function test() { 1.59 + gFrame.focus(); 1.60 + 1.61 + sendContextMenuClick(165, 35); 1.62 + 1.63 + yield waitForCondition(function () { 1.64 + return SelectionHelperUI.isSelectionUIVisible; 1.65 + }, kCommonWaitMs, kCommonPollMs); 1.66 + 1.67 + // active state 1.68 + is(SelectionHelperUI.isActive, true, "selection active"); 1.69 + // check text selection 1.70 + is(getTrimmedSelection(gFrame).toString(), "Alice", "selection test"); 1.71 + }, 1.72 +}); 1.73 + 1.74 +gTests.push({ 1.75 + desc: "iframe expand / collapse selection", 1.76 + setUp: setUpAndTearDown, 1.77 + tearDown: setUpAndTearDown, 1.78 + run: function test() { 1.79 + gFrame.focus(); 1.80 + 1.81 + sendContextMenuClick(162, 180); 1.82 + 1.83 + yield waitForCondition(function () { 1.84 + return SelectionHelperUI.isSelectionUIVisible; 1.85 + }, kCommonWaitMs, kCommonPollMs); 1.86 + 1.87 + // active state 1.88 + is(SelectionHelperUI.isActive, true, "selection active"); 1.89 + is(getTrimmedSelection(gFrame).toString(), "Alice", "selection test"); 1.90 + 1.91 + let ypos = SelectionHelperUI.endMark.yPos + kMarkerOffsetY; 1.92 + 1.93 + let touchdrag = new TouchDragAndHold(); 1.94 + yield touchdrag.start(gWindow, SelectionHelperUI.endMark.xPos, ypos, 640, ypos); 1.95 + touchdrag.end(); 1.96 + 1.97 + yield waitForCondition(function () { 1.98 + return !SelectionHelperUI.hasActiveDrag; 1.99 + }, kCommonWaitMs, kCommonPollMs); 1.100 + yield SelectionHelperUI.pingSelectionHandler(); 1.101 + 1.102 + is(SelectionHelperUI.isActive, true, "selection active"); 1.103 + is(getTrimmedSelection(gFrame).toString(), "Alice was beginning to get very tired of sitting by her sister on the bank", 1.104 + "selection test"); 1.105 + 1.106 + touchdrag = new TouchDragAndHold(); 1.107 + yield touchdrag.start(gWindow, SelectionHelperUI.endMark.xPos, ypos, 320, ypos); 1.108 + touchdrag.end(); 1.109 + 1.110 + yield waitForCondition(function () { 1.111 + return !SelectionHelperUI.hasActiveDrag; 1.112 + }, kCommonWaitMs, kCommonPollMs); 1.113 + yield SelectionHelperUI.pingSelectionHandler(); 1.114 + 1.115 + is(SelectionHelperUI.isActive, true, "selection active"); 1.116 + is(getTrimmedSelection(gFrame).toString(), "Alice was beginning to get very", "selection test"); 1.117 + }, 1.118 +}); 1.119 + 1.120 +gTests.push({ 1.121 + desc: "scrolled iframe selection", 1.122 + setUp: setUpAndTearDown, 1.123 + run: function test() { 1.124 + gFrame.focus(); 1.125 + 1.126 + let scrollPromise = waitForEvent(gFrame.contentDocument.defaultView, "scroll"); 1.127 + gFrame.contentDocument.defaultView.scrollBy(0, 200); 1.128 + yield scrollPromise; 1.129 + 1.130 + sendContextMenuClick(30, 240); 1.131 + 1.132 + yield waitForCondition(function () { 1.133 + return SelectionHelperUI.isSelectionUIVisible; 1.134 + }, kCommonWaitMs, kCommonPollMs); 1.135 + 1.136 + is(SelectionHelperUI.isActive, true, "selection active"); 1.137 + is(getTrimmedSelection(gFrame).toString(), "started", "selection test"); 1.138 + 1.139 + let promise = waitForEvent(document, "popupshown"); 1.140 + sendContextMenuClickToSelection(gFrame.contentDocument.defaultView); 1.141 + 1.142 + yield promise; 1.143 + ok(promise && !(promise instanceof Error), "promise error"); 1.144 + ok(ContextMenuUI._menuPopup.visible, "is visible"); 1.145 + 1.146 + let menuItem = document.getElementById("context-copy"); 1.147 + ok(menuItem, "menu item exists"); 1.148 + ok(!menuItem.hidden, "menu item visible"); 1.149 + let popupPromise = waitForEvent(document, "popuphidden"); 1.150 + sendElementTap(gWindow, menuItem); 1.151 + yield popupPromise; 1.152 + ok(popupPromise && !(popupPromise instanceof Error), "promise error"); 1.153 + 1.154 + // The wait is needed to give time to populate the clipboard. 1.155 + let string = ""; 1.156 + yield waitForCondition(function () { 1.157 + string = SpecialPowers.getClipboardData("text/unicode"); 1.158 + return string === "started"; 1.159 + }); 1.160 + is(string, "started", "copy text"); 1.161 + 1.162 + }, 1.163 + tearDown: function tearDown() { 1.164 + emptyClipboard(); 1.165 + let scrollPromise = waitForEvent(gFrame.contentDocument.defaultView, "scroll"); 1.166 + gFrame.contentDocument.defaultView.scrollBy(0, -200); 1.167 + yield scrollPromise; 1.168 + clearSelection(gWindow); 1.169 + clearSelection(gFrame); 1.170 + yield waitForCondition(function () { 1.171 + return !SelectionHelperUI.isSelectionUIVisible; 1.172 + }, kCommonWaitMs, kCommonPollMs); 1.173 + yield hideContextUI(); 1.174 + }, 1.175 +}); 1.176 + 1.177 +gTests.push({ 1.178 + desc: "iframe within scrolled page selection", 1.179 + setUp: setUpAndTearDown, 1.180 + run: function test() { 1.181 + gFrame.focus(); 1.182 + 1.183 + let scrollPromise = waitForEvent(gWindow, "scroll"); 1.184 + gWindow.scrollBy(0, 200); 1.185 + yield scrollPromise; 1.186 + 1.187 + scrollPromise = waitForEvent(gFrame.contentDocument.defaultView, "scroll"); 1.188 + gFrame.contentDocument.defaultView.scrollBy(0, 200); 1.189 + yield scrollPromise; 1.190 + 1.191 + sendContextMenuClick(114, 130); 1.192 + 1.193 + yield waitForCondition(function () { 1.194 + return SelectionHelperUI.isSelectionUIVisible; 1.195 + }, kCommonWaitMs, kCommonPollMs); 1.196 + 1.197 + is(SelectionHelperUI.isActive, true, "selection active"); 1.198 + is(getTrimmedSelection(gFrame).toString(), "moment", "selection test"); 1.199 + }, 1.200 + tearDown: function tearDown() { 1.201 + emptyClipboard(); 1.202 + clearSelection(gWindow); 1.203 + clearSelection(gFrame); 1.204 + let scrollPromise = waitForEvent(gFrame.contentDocument.defaultView, "scroll"); 1.205 + gFrame.contentDocument.defaultView.scrollBy(0, -200); 1.206 + yield scrollPromise; 1.207 + scrollPromise = waitForEvent(gWindow, "scroll"); 1.208 + gWindow.scrollBy(0, -200); 1.209 + yield scrollPromise; 1.210 + yield waitForCondition(function () { 1.211 + return !SelectionHelperUI.isSelectionUIVisible; 1.212 + }, kCommonWaitMs, kCommonPollMs); 1.213 + yield hideContextUI(); 1.214 + }, 1.215 +}); 1.216 + 1.217 +function test() { 1.218 + if (!isLandscapeMode()) { 1.219 + todo(false, "browser_selection_tests need landscape mode to run."); 1.220 + return; 1.221 + } 1.222 + runTests(); 1.223 +}