1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/content/tests/browser/browser_browserDrop.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,61 @@ 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(); 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 browser = gBrowser.selectedBrowser; 1.21 + 1.22 + var linkHandlerActivated = 0; 1.23 + // Don't worry about clobbering the droppedLinkHandler, since we're closing 1.24 + // this tab after the test anyways 1.25 + browser.droppedLinkHandler = function dlh(e, url, name) { 1.26 + linkHandlerActivated++; 1.27 + ok(!/(javascript|data)/i.test(url), "javascript link should not be dropped"); 1.28 + } 1.29 + 1.30 + var receivedDropCount = 0; 1.31 + function dropListener() { 1.32 + receivedDropCount++; 1.33 + if (receivedDropCount == triggeredDropCount) { 1.34 + // Wait for the browser's system-phase event handler to run. 1.35 + executeSoon(function () { 1.36 + is(linkHandlerActivated, validDropCount, 1.37 + "link handler was called correct number of times"); 1.38 + finish(); 1.39 + }) 1.40 + } 1.41 + } 1.42 + browser.addEventListener("drop", dropListener, false); 1.43 + registerCleanupFunction(function () { 1.44 + browser.removeEventListener("drop", dropListener, false); 1.45 + }); 1.46 + 1.47 + var triggeredDropCount = 0; 1.48 + var validDropCount = 0; 1.49 + function drop(text, valid) { 1.50 + triggeredDropCount++; 1.51 + if (valid) 1.52 + validDropCount++; 1.53 + executeSoon(function () { 1.54 + ChromeUtils.synthesizeDrop(browser, browser, [[{type: "text/plain", data: text}]], "copy", window); 1.55 + }); 1.56 + } 1.57 + 1.58 + drop("mochi.test/first", true); 1.59 + drop("javascript:'bad'"); 1.60 + drop("jAvascript:'also bad'"); 1.61 + drop("mochi.test/second", true); 1.62 + drop("data:text/html,bad"); 1.63 + drop("mochi.test/third", true); 1.64 +}