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.

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

mercurial