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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* Any copyright is dedicated to the Public Domain.
     2  * http://creativecommons.org/publicdomain/zero/1.0/ */
     4 function test() {
     5   waitForExplicitFinish();
     7   let newTab = gBrowser.selectedTab = gBrowser.addTab("about:blank", {skipAnimation: true});
     8   registerCleanupFunction(function () {
     9     gBrowser.removeTab(newTab);
    10   });
    12   let scriptLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
    13                      getService(Ci.mozIJSSubScriptLoader);
    14   let ChromeUtils = {};
    15   scriptLoader.loadSubScript("chrome://mochikit/content/tests/SimpleTest/ChromeUtils.js", ChromeUtils);
    17   let tabContainer = gBrowser.tabContainer;
    18   var receivedDropCount = 0;
    19   function dropListener() {
    20     receivedDropCount++;
    21     if (receivedDropCount == triggeredDropCount) {
    22       is(openedTabs, validDropCount, "correct number of tabs were opened");
    23       executeSoon(finish);
    24     }
    25   }
    26   tabContainer.addEventListener("drop", dropListener, false);
    27   registerCleanupFunction(function () {
    28     tabContainer.removeEventListener("drop", dropListener, false);
    29   });
    31   var openedTabs = 0;
    32   function tabOpenListener(e) {
    33     openedTabs++;
    34     let tab = e.target;
    35     executeSoon(function () {
    36       gBrowser.removeTab(tab);
    37     });
    38   }
    40   tabContainer.addEventListener("TabOpen", tabOpenListener, false);
    41   registerCleanupFunction(function () {
    42     tabContainer.removeEventListener("TabOpen", tabOpenListener, false);
    43   });
    45   var triggeredDropCount = 0;
    46   var validDropCount = 0;
    47   function drop(text, valid) {
    48     triggeredDropCount++;
    49     if (valid)
    50       validDropCount++;
    51     executeSoon(function () {
    52       // A drop type of "link" onto an existing tab would normally trigger a
    53       // load in that same tab, but tabbrowser code in _getDragTargetTab treats
    54       // drops on the outer edges of a tab differently (loading a new tab
    55       // instead). The events created by synthesizeDrop have all of their
    56       // coordinates set to 0 (screenX/screenY), so they're treated as drops
    57       // on the outer edge of the tab, thus they open new tabs.
    58       ChromeUtils.synthesizeDrop(newTab, newTab, [[{type: "text/plain", data: text}]], "link", window);
    59     });
    60   }
    62   // Begin and end with valid drops to make sure we wait for all drops before
    63   // ending the test
    64   drop("mochi.test/first", true);
    65   drop("javascript:'bad'");
    66   drop("jAvascript:'bad'");
    67   drop("search this", true);
    68   drop("mochi.test/second", true);
    69   drop("data:text/html,bad");
    70   drop("mochi.test/third", true);
    71 }

mercurial