browser/base/content/test/general/browser_homeDrop.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial