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

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

mercurial