browser/metro/base/tests/mochitest/browser_link_click.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/metro/base/tests/mochitest/browser_link_click.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,97 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +"use strict";
     1.8 +
     1.9 +function test() {
    1.10 +  waitForExplicitFinish();
    1.11 +  runTests();
    1.12 +}
    1.13 +
    1.14 +gTests.push({
    1.15 +  desc: "regular link click",
    1.16 +  run: function () {
    1.17 +    let tab = yield addTab(chromeRoot + "browser_link_click.html");
    1.18 +    let tabCount = Browser.tabs.length;
    1.19 +
    1.20 +    EventUtils.sendMouseEvent({type: "click"}, "link", tab.browser.contentWindow);
    1.21 +    yield waitForCondition(() => tab.browser.currentURI.spec == "about:blank");
    1.22 +    is(Browser.tabs.length, tabCount, "link loaded in the same tab");
    1.23 +  }
    1.24 +});
    1.25 +
    1.26 +gTests.push({
    1.27 +  desc: "middle-click opens link in background tab",
    1.28 +  run: function () {
    1.29 +    let tab = yield addTab(chromeRoot + "browser_link_click.html");
    1.30 +
    1.31 +    let tabOpen = waitForEvent(window, "TabOpen");
    1.32 +    EventUtils.sendMouseEvent({type: "click", button: 1}, "link", tab.browser.contentWindow);
    1.33 +    let event = yield tabOpen;
    1.34 +
    1.35 +    let newTab = Browser.getTabFromChrome(event.originalTarget);
    1.36 +    yield waitForEvent(newTab.browser, "pageshow");
    1.37 +
    1.38 +    is(newTab.browser.currentURI.spec, "about:blank");
    1.39 +    ok(newTab != Browser.selectedTab, "new tab is in the background");
    1.40 +
    1.41 +    Browser.closeTab(newTab, { forceClose: true });
    1.42 +  }
    1.43 +});
    1.44 +
    1.45 +gTests.push({
    1.46 +  desc: "shift-middle-click opens link in background tab",
    1.47 +  run: function () {
    1.48 +    let tab = yield addTab(chromeRoot + "browser_link_click.html");
    1.49 +
    1.50 +    let tabOpen = waitForEvent(window, "TabOpen");
    1.51 +    EventUtils.sendMouseEvent({type: "click", button: 1, shiftKey: true}, "link", tab.browser.contentWindow);
    1.52 +    let event = yield tabOpen;
    1.53 +
    1.54 +    let newTab = Browser.getTabFromChrome(event.originalTarget);
    1.55 +    yield waitForEvent(newTab.browser, "pageshow");
    1.56 +
    1.57 +    is(newTab.browser.currentURI.spec, "about:blank");
    1.58 +    ok(newTab == Browser.selectedTab, "new tab is in the foreground");
    1.59 +
    1.60 +    Browser.closeTab(newTab, { forceClose: true });
    1.61 +  }
    1.62 +});
    1.63 +
    1.64 +gTests.push({
    1.65 +  desc: "ctrl-click opens link in background tab",
    1.66 +  run: function () {
    1.67 +    let tab = yield addTab(chromeRoot + "browser_link_click.html");
    1.68 +
    1.69 +    let tabOpen = waitForEvent(window, "TabOpen");
    1.70 +    EventUtils.sendMouseEvent({type: "click", ctrlKey: true}, "link", tab.browser.contentWindow);
    1.71 +    let event = yield tabOpen;
    1.72 +
    1.73 +    let newTab = Browser.getTabFromChrome(event.originalTarget);
    1.74 +    yield waitForEvent(newTab.browser, "pageshow");
    1.75 +
    1.76 +    is(newTab.browser.currentURI.spec, "about:blank");
    1.77 +    ok(newTab != Browser.selectedTab, "new tab is in the background");
    1.78 +
    1.79 +    Browser.closeTab(newTab, { forceClose: true });
    1.80 +  }
    1.81 +});
    1.82 +
    1.83 +gTests.push({
    1.84 +  desc: "shift-ctrl-click opens link in background tab",
    1.85 +  run: function () {
    1.86 +    let tab = yield addTab(chromeRoot + "browser_link_click.html");
    1.87 +
    1.88 +    let tabOpen = waitForEvent(window, "TabOpen");
    1.89 +    EventUtils.sendMouseEvent({type: "click", ctrlKey: true, shiftKey: true}, "link", tab.browser.contentWindow);
    1.90 +    let event = yield tabOpen;
    1.91 +
    1.92 +    let newTab = Browser.getTabFromChrome(event.originalTarget);
    1.93 +    yield waitForEvent(newTab.browser, "pageshow");
    1.94 +
    1.95 +    is(newTab.browser.currentURI.spec, "about:blank");
    1.96 +    ok(newTab == Browser.selectedTab, "new tab is in the foreground");
    1.97 +
    1.98 +    Browser.closeTab(newTab, { forceClose: true });
    1.99 +  }
   1.100 +});

mercurial