|
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("about:blank", {skipAnimation: true}); |
|
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 tabContainer = gBrowser.tabContainer; |
|
18 var receivedDropCount = 0; |
|
19 function dropListener() { |
|
20 receivedDropCount++; |
|
21 if (receivedDropCount == triggeredDropCount) { |
|
22 is(openedTabs, validDropCount, "correct number of tabs were opened"); |
|
23 executeSoon(finish); |
|
24 } |
|
25 } |
|
26 tabContainer.addEventListener("drop", dropListener, false); |
|
27 registerCleanupFunction(function () { |
|
28 tabContainer.removeEventListener("drop", dropListener, false); |
|
29 }); |
|
30 |
|
31 var openedTabs = 0; |
|
32 function tabOpenListener(e) { |
|
33 openedTabs++; |
|
34 let tab = e.target; |
|
35 executeSoon(function () { |
|
36 gBrowser.removeTab(tab); |
|
37 }); |
|
38 } |
|
39 |
|
40 tabContainer.addEventListener("TabOpen", tabOpenListener, false); |
|
41 registerCleanupFunction(function () { |
|
42 tabContainer.removeEventListener("TabOpen", tabOpenListener, false); |
|
43 }); |
|
44 |
|
45 var triggeredDropCount = 0; |
|
46 var validDropCount = 0; |
|
47 function drop(text, valid) { |
|
48 triggeredDropCount++; |
|
49 if (valid) |
|
50 validDropCount++; |
|
51 executeSoon(function () { |
|
52 // A drop type of "link" onto an existing tab would normally trigger a |
|
53 // load in that same tab, but tabbrowser code in _getDragTargetTab treats |
|
54 // drops on the outer edges of a tab differently (loading a new tab |
|
55 // instead). The events created by synthesizeDrop have all of their |
|
56 // coordinates set to 0 (screenX/screenY), so they're treated as drops |
|
57 // on the outer edge of the tab, thus they open new tabs. |
|
58 ChromeUtils.synthesizeDrop(newTab, newTab, [[{type: "text/plain", data: text}]], "link", window); |
|
59 }); |
|
60 } |
|
61 |
|
62 // Begin and end with valid drops to make sure we wait for all drops before |
|
63 // ending the test |
|
64 drop("mochi.test/first", true); |
|
65 drop("javascript:'bad'"); |
|
66 drop("jAvascript:'bad'"); |
|
67 drop("search this", true); |
|
68 drop("mochi.test/second", true); |
|
69 drop("data:text/html,bad"); |
|
70 drop("mochi.test/third", true); |
|
71 } |