|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 * http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 function test() { |
|
5 waitForExplicitFinish(); |
|
6 |
|
7 let newTab = gBrowser.selectedTab = gBrowser.addTab(); |
|
8 registerCleanupFunction(function () { |
|
9 gBrowser.removeTab(newTab); |
|
10 }); |
|
11 |
|
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); |
|
16 |
|
17 let browser = gBrowser.selectedBrowser; |
|
18 |
|
19 var linkHandlerActivated = 0; |
|
20 // Don't worry about clobbering the droppedLinkHandler, since we're closing |
|
21 // this tab after the test anyways |
|
22 browser.droppedLinkHandler = function dlh(e, url, name) { |
|
23 linkHandlerActivated++; |
|
24 ok(!/(javascript|data)/i.test(url), "javascript link should not be dropped"); |
|
25 } |
|
26 |
|
27 var receivedDropCount = 0; |
|
28 function dropListener() { |
|
29 receivedDropCount++; |
|
30 if (receivedDropCount == triggeredDropCount) { |
|
31 // Wait for the browser's system-phase event handler to run. |
|
32 executeSoon(function () { |
|
33 is(linkHandlerActivated, validDropCount, |
|
34 "link handler was called correct number of times"); |
|
35 finish(); |
|
36 }) |
|
37 } |
|
38 } |
|
39 browser.addEventListener("drop", dropListener, false); |
|
40 registerCleanupFunction(function () { |
|
41 browser.removeEventListener("drop", dropListener, false); |
|
42 }); |
|
43 |
|
44 var triggeredDropCount = 0; |
|
45 var validDropCount = 0; |
|
46 function drop(text, valid) { |
|
47 triggeredDropCount++; |
|
48 if (valid) |
|
49 validDropCount++; |
|
50 executeSoon(function () { |
|
51 ChromeUtils.synthesizeDrop(browser, browser, [[{type: "text/plain", data: text}]], "copy", window); |
|
52 }); |
|
53 } |
|
54 |
|
55 drop("mochi.test/first", true); |
|
56 drop("javascript:'bad'"); |
|
57 drop("jAvascript:'also bad'"); |
|
58 drop("mochi.test/second", true); |
|
59 drop("data:text/html,bad"); |
|
60 drop("mochi.test/third", true); |
|
61 } |