Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* Any copyright is dedicated to the Public Domain.
2 * http://creativecommons.org/publicdomain/zero/1.0/ */
4 function test() {
5 waitForExplicitFinish();
7 let str = Cc["@mozilla.org/supports-string;1"]
8 .createInstance(Ci.nsISupportsString);
9 str.data = "about:mozilla";
10 Services.prefs.setComplexValue("browser.startup.homepage",
11 Ci.nsISupportsString, str);
12 registerCleanupFunction(() => {
13 Services.prefs.clearUserPref("browser.startup.homepage");
14 });
16 // Open a new tab, since starting a drag from the home button activates it and
17 // we don't want to interfere with future tests by loading the home page.
18 let newTab = gBrowser.selectedTab = gBrowser.addTab();
19 registerCleanupFunction(function () {
20 gBrowser.removeTab(newTab);
21 });
23 let scriptLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
24 getService(Ci.mozIJSSubScriptLoader);
25 let ChromeUtils = {};
26 scriptLoader.loadSubScript("chrome://mochikit/content/tests/SimpleTest/ChromeUtils.js", ChromeUtils);
28 let homeButton = document.getElementById("home-button");
29 ok(homeButton, "home button present");
31 let dialogListener = new WindowListener("chrome://global/content/commonDialog.xul", function (domwindow) {
32 ok(true, "dialog appeared in response to home button drop");
33 domwindow.document.documentElement.cancelDialog();
34 Services.wm.removeListener(dialogListener);
36 // Now trigger the invalid URI test
37 executeSoon(function () {
38 let consoleListener = {
39 observe: function (m) {
40 if (m.message.contains("NS_ERROR_DOM_BAD_URI")) {
41 ok(true, "drop was blocked");
42 executeSoon(finish);
43 }
44 }
45 }
46 Services.console.registerListener(consoleListener);
47 registerCleanupFunction(function () {
48 Services.console.unregisterListener(consoleListener);
49 });
51 executeSoon(function () {
52 info("Attempting second drop, of a javascript: URI");
53 // The drop handler throws an exception when dragging URIs that inherit
54 // principal, e.g. javascript:
55 expectUncaughtException();
56 ChromeUtils.synthesizeDrop(homeButton, homeButton, [[{type: "text/plain", data: "javascript:8888"}]], "copy", window);
57 });
58 })
59 });
61 Services.wm.addListener(dialogListener);
63 ChromeUtils.synthesizeDrop(homeButton, homeButton, [[{type: "text/plain", data: "http://mochi.test:8888/"}]], "copy", window);
64 }
66 function WindowListener(aURL, aCallback) {
67 this.callback = aCallback;
68 this.url = aURL;
69 }
70 WindowListener.prototype = {
71 onOpenWindow: function(aXULWindow) {
72 var domwindow = aXULWindow.QueryInterface(Ci.nsIInterfaceRequestor)
73 .getInterface(Ci.nsIDOMWindow);
74 var self = this;
75 domwindow.addEventListener("load", function() {
76 domwindow.removeEventListener("load", arguments.callee, false);
78 ok(true, "domwindow.document.location.href: " + domwindow.document.location.href);
79 if (domwindow.document.location.href != self.url)
80 return;
82 // Allow other window load listeners to execute before passing to callback
83 executeSoon(function() {
84 self.callback(domwindow);
85 });
86 }, false);
87 },
88 onCloseWindow: function(aXULWindow) {},
89 onWindowTitleChange: function(aXULWindow, aNewTitle) {}
90 }