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