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(); 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 browser = gBrowser.selectedBrowser; michael@0: michael@0: var linkHandlerActivated = 0; michael@0: // Don't worry about clobbering the droppedLinkHandler, since we're closing michael@0: // this tab after the test anyways michael@0: browser.droppedLinkHandler = function dlh(e, url, name) { michael@0: linkHandlerActivated++; michael@0: ok(!/(javascript|data)/i.test(url), "javascript link should not be dropped"); michael@0: } michael@0: michael@0: var receivedDropCount = 0; michael@0: function dropListener() { michael@0: receivedDropCount++; michael@0: if (receivedDropCount == triggeredDropCount) { michael@0: // Wait for the browser's system-phase event handler to run. michael@0: executeSoon(function () { michael@0: is(linkHandlerActivated, validDropCount, michael@0: "link handler was called correct number of times"); michael@0: finish(); michael@0: }) michael@0: } michael@0: } michael@0: browser.addEventListener("drop", dropListener, false); michael@0: registerCleanupFunction(function () { michael@0: browser.removeEventListener("drop", dropListener, 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: ChromeUtils.synthesizeDrop(browser, browser, [[{type: "text/plain", data: text}]], "copy", window); michael@0: }); michael@0: } michael@0: michael@0: drop("mochi.test/first", true); michael@0: drop("javascript:'bad'"); michael@0: drop("jAvascript:'also bad'"); michael@0: drop("mochi.test/second", true); michael@0: drop("data:text/html,bad"); michael@0: drop("mochi.test/third", true); michael@0: }