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