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 str = Cc["@mozilla.org/supports-string;1"] michael@0: .createInstance(Ci.nsISupportsString); michael@0: str.data = "about:mozilla"; michael@0: Services.prefs.setComplexValue("browser.startup.homepage", michael@0: Ci.nsISupportsString, str); michael@0: registerCleanupFunction(() => { michael@0: Services.prefs.clearUserPref("browser.startup.homepage"); michael@0: }); michael@0: michael@0: // Open a new tab, since starting a drag from the home button activates it and michael@0: // we don't want to interfere with future tests by loading the home page. 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 homeButton = document.getElementById("home-button"); michael@0: ok(homeButton, "home button present"); michael@0: michael@0: let dialogListener = new WindowListener("chrome://global/content/commonDialog.xul", function (domwindow) { michael@0: ok(true, "dialog appeared in response to home button drop"); michael@0: domwindow.document.documentElement.cancelDialog(); michael@0: Services.wm.removeListener(dialogListener); michael@0: michael@0: // Now trigger the invalid URI test michael@0: executeSoon(function () { michael@0: let consoleListener = { michael@0: observe: function (m) { michael@0: if (m.message.contains("NS_ERROR_DOM_BAD_URI")) { michael@0: ok(true, "drop was blocked"); michael@0: executeSoon(finish); michael@0: } michael@0: } michael@0: } michael@0: Services.console.registerListener(consoleListener); michael@0: registerCleanupFunction(function () { michael@0: Services.console.unregisterListener(consoleListener); michael@0: }); michael@0: michael@0: executeSoon(function () { michael@0: info("Attempting second drop, of a javascript: URI"); michael@0: // The drop handler throws an exception when dragging URIs that inherit michael@0: // principal, e.g. javascript: michael@0: expectUncaughtException(); michael@0: ChromeUtils.synthesizeDrop(homeButton, homeButton, [[{type: "text/plain", data: "javascript:8888"}]], "copy", window); michael@0: }); michael@0: }) michael@0: }); michael@0: michael@0: Services.wm.addListener(dialogListener); michael@0: michael@0: ChromeUtils.synthesizeDrop(homeButton, homeButton, [[{type: "text/plain", data: "http://mochi.test:8888/"}]], "copy", window); michael@0: } michael@0: michael@0: function WindowListener(aURL, aCallback) { michael@0: this.callback = aCallback; michael@0: this.url = aURL; michael@0: } michael@0: WindowListener.prototype = { michael@0: onOpenWindow: function(aXULWindow) { michael@0: var domwindow = aXULWindow.QueryInterface(Ci.nsIInterfaceRequestor) michael@0: .getInterface(Ci.nsIDOMWindow); michael@0: var self = this; michael@0: domwindow.addEventListener("load", function() { michael@0: domwindow.removeEventListener("load", arguments.callee, false); michael@0: michael@0: ok(true, "domwindow.document.location.href: " + domwindow.document.location.href); michael@0: if (domwindow.document.location.href != self.url) michael@0: return; michael@0: michael@0: // Allow other window load listeners to execute before passing to callback michael@0: executeSoon(function() { michael@0: self.callback(domwindow); michael@0: }); michael@0: }, false); michael@0: }, michael@0: onCloseWindow: function(aXULWindow) {}, michael@0: onWindowTitleChange: function(aXULWindow, aNewTitle) {} michael@0: } michael@0: