browser/base/content/test/general/browser_tabDrop.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/base/content/test/general/browser_tabDrop.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,71 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +function test() {
     1.8 +  waitForExplicitFinish();
     1.9 +
    1.10 +  let newTab = gBrowser.selectedTab = gBrowser.addTab("about:blank", {skipAnimation: true});
    1.11 +  registerCleanupFunction(function () {
    1.12 +    gBrowser.removeTab(newTab);
    1.13 +  });
    1.14 +
    1.15 +  let scriptLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
    1.16 +                     getService(Ci.mozIJSSubScriptLoader);
    1.17 +  let ChromeUtils = {};
    1.18 +  scriptLoader.loadSubScript("chrome://mochikit/content/tests/SimpleTest/ChromeUtils.js", ChromeUtils);
    1.19 +
    1.20 +  let tabContainer = gBrowser.tabContainer;
    1.21 +  var receivedDropCount = 0;
    1.22 +  function dropListener() {
    1.23 +    receivedDropCount++;
    1.24 +    if (receivedDropCount == triggeredDropCount) {
    1.25 +      is(openedTabs, validDropCount, "correct number of tabs were opened");
    1.26 +      executeSoon(finish);
    1.27 +    }
    1.28 +  }
    1.29 +  tabContainer.addEventListener("drop", dropListener, false);
    1.30 +  registerCleanupFunction(function () {
    1.31 +    tabContainer.removeEventListener("drop", dropListener, false);
    1.32 +  });
    1.33 +
    1.34 +  var openedTabs = 0;
    1.35 +  function tabOpenListener(e) {
    1.36 +    openedTabs++;
    1.37 +    let tab = e.target;
    1.38 +    executeSoon(function () {
    1.39 +      gBrowser.removeTab(tab);
    1.40 +    });
    1.41 +  }
    1.42 +
    1.43 +  tabContainer.addEventListener("TabOpen", tabOpenListener, false);
    1.44 +  registerCleanupFunction(function () {
    1.45 +    tabContainer.removeEventListener("TabOpen", tabOpenListener, false);
    1.46 +  });
    1.47 +
    1.48 +  var triggeredDropCount = 0;
    1.49 +  var validDropCount = 0;
    1.50 +  function drop(text, valid) {
    1.51 +    triggeredDropCount++;
    1.52 +    if (valid)
    1.53 +      validDropCount++;
    1.54 +    executeSoon(function () {
    1.55 +      // A drop type of "link" onto an existing tab would normally trigger a
    1.56 +      // load in that same tab, but tabbrowser code in _getDragTargetTab treats
    1.57 +      // drops on the outer edges of a tab differently (loading a new tab
    1.58 +      // instead). The events created by synthesizeDrop have all of their
    1.59 +      // coordinates set to 0 (screenX/screenY), so they're treated as drops
    1.60 +      // on the outer edge of the tab, thus they open new tabs.
    1.61 +      ChromeUtils.synthesizeDrop(newTab, newTab, [[{type: "text/plain", data: text}]], "link", window);
    1.62 +    });
    1.63 +  }
    1.64 +
    1.65 +  // Begin and end with valid drops to make sure we wait for all drops before
    1.66 +  // ending the test
    1.67 +  drop("mochi.test/first", true);
    1.68 +  drop("javascript:'bad'");
    1.69 +  drop("jAvascript:'bad'");
    1.70 +  drop("search this", true);
    1.71 +  drop("mochi.test/second", true);
    1.72 +  drop("data:text/html,bad");
    1.73 +  drop("mochi.test/third", true);
    1.74 +}

mercurial