michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: let newTab = gBrowser.selectedTab = gBrowser.addTab("about:blank", {skipAnimation: true}); michael@0: registerCleanupFunction(function () { michael@0: gBrowser.removeTab(newTab); michael@0: }); michael@0: michael@0: let scriptLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"]. michael@0: getService(Ci.mozIJSSubScriptLoader); michael@0: let ChromeUtils = {}; michael@0: scriptLoader.loadSubScript("chrome://mochikit/content/tests/SimpleTest/ChromeUtils.js", ChromeUtils); michael@0: michael@0: let tabContainer = gBrowser.tabContainer; michael@0: var receivedDropCount = 0; michael@0: function dropListener() { michael@0: receivedDropCount++; michael@0: if (receivedDropCount == triggeredDropCount) { michael@0: is(openedTabs, validDropCount, "correct number of tabs were opened"); michael@0: executeSoon(finish); michael@0: } michael@0: } michael@0: tabContainer.addEventListener("drop", dropListener, false); michael@0: registerCleanupFunction(function () { michael@0: tabContainer.removeEventListener("drop", dropListener, false); michael@0: }); michael@0: michael@0: var openedTabs = 0; michael@0: function tabOpenListener(e) { michael@0: openedTabs++; michael@0: let tab = e.target; michael@0: executeSoon(function () { michael@0: gBrowser.removeTab(tab); michael@0: }); michael@0: } michael@0: michael@0: tabContainer.addEventListener("TabOpen", tabOpenListener, false); michael@0: registerCleanupFunction(function () { michael@0: tabContainer.removeEventListener("TabOpen", tabOpenListener, false); michael@0: }); michael@0: michael@0: var triggeredDropCount = 0; michael@0: var validDropCount = 0; michael@0: function drop(text, valid) { michael@0: triggeredDropCount++; michael@0: if (valid) michael@0: validDropCount++; michael@0: executeSoon(function () { michael@0: // A drop type of "link" onto an existing tab would normally trigger a michael@0: // load in that same tab, but tabbrowser code in _getDragTargetTab treats michael@0: // drops on the outer edges of a tab differently (loading a new tab michael@0: // instead). The events created by synthesizeDrop have all of their michael@0: // coordinates set to 0 (screenX/screenY), so they're treated as drops michael@0: // on the outer edge of the tab, thus they open new tabs. michael@0: ChromeUtils.synthesizeDrop(newTab, newTab, [[{type: "text/plain", data: text}]], "link", window); michael@0: }); michael@0: } michael@0: michael@0: // Begin and end with valid drops to make sure we wait for all drops before michael@0: // ending the test michael@0: drop("mochi.test/first", true); michael@0: drop("javascript:'bad'"); michael@0: drop("jAvascript:'bad'"); michael@0: drop("search this", true); michael@0: drop("mochi.test/second", true); michael@0: drop("data:text/html,bad"); michael@0: drop("mochi.test/third", true); michael@0: }