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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/base/content/test/general/browser_homeDrop.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,91 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +function test() {
     1.8 +  waitForExplicitFinish();
     1.9 +
    1.10 +  let str = Cc["@mozilla.org/supports-string;1"]
    1.11 +              .createInstance(Ci.nsISupportsString);
    1.12 +  str.data = "about:mozilla";
    1.13 +  Services.prefs.setComplexValue("browser.startup.homepage",
    1.14 +                                 Ci.nsISupportsString, str);
    1.15 +  registerCleanupFunction(() => {
    1.16 +    Services.prefs.clearUserPref("browser.startup.homepage");
    1.17 +  });
    1.18 +
    1.19 +  // Open a new tab, since starting a drag from the home button activates it and
    1.20 +  // we don't want to interfere with future tests by loading the home page.
    1.21 +  let newTab = gBrowser.selectedTab = gBrowser.addTab();
    1.22 +  registerCleanupFunction(function () {
    1.23 +    gBrowser.removeTab(newTab);
    1.24 +  });
    1.25 +
    1.26 +  let scriptLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
    1.27 +                     getService(Ci.mozIJSSubScriptLoader);
    1.28 +  let ChromeUtils = {};
    1.29 +  scriptLoader.loadSubScript("chrome://mochikit/content/tests/SimpleTest/ChromeUtils.js", ChromeUtils);
    1.30 +
    1.31 +  let homeButton = document.getElementById("home-button");
    1.32 +  ok(homeButton, "home button present");
    1.33 +
    1.34 +  let dialogListener = new WindowListener("chrome://global/content/commonDialog.xul", function (domwindow) {
    1.35 +    ok(true, "dialog appeared in response to home button drop");
    1.36 +    domwindow.document.documentElement.cancelDialog();
    1.37 +    Services.wm.removeListener(dialogListener);
    1.38 +
    1.39 +    // Now trigger the invalid URI test
    1.40 +    executeSoon(function () {
    1.41 +      let consoleListener = {
    1.42 +        observe: function (m) {
    1.43 +          if (m.message.contains("NS_ERROR_DOM_BAD_URI")) {
    1.44 +            ok(true, "drop was blocked");
    1.45 +            executeSoon(finish);
    1.46 +          }
    1.47 +        }
    1.48 +      }
    1.49 +      Services.console.registerListener(consoleListener);
    1.50 +      registerCleanupFunction(function () {
    1.51 +        Services.console.unregisterListener(consoleListener);
    1.52 +      });
    1.53 +
    1.54 +      executeSoon(function () {
    1.55 +        info("Attempting second drop, of a javascript: URI");
    1.56 +        // The drop handler throws an exception when dragging URIs that inherit
    1.57 +        // principal, e.g. javascript:
    1.58 +        expectUncaughtException();
    1.59 +        ChromeUtils.synthesizeDrop(homeButton, homeButton, [[{type: "text/plain", data: "javascript:8888"}]], "copy", window);
    1.60 +      });
    1.61 +    })
    1.62 +  });
    1.63 +
    1.64 +  Services.wm.addListener(dialogListener);
    1.65 +
    1.66 +  ChromeUtils.synthesizeDrop(homeButton, homeButton, [[{type: "text/plain", data: "http://mochi.test:8888/"}]], "copy", window);
    1.67 +}
    1.68 +
    1.69 +function WindowListener(aURL, aCallback) {
    1.70 +  this.callback = aCallback;
    1.71 +  this.url = aURL;
    1.72 +}
    1.73 +WindowListener.prototype = {
    1.74 +  onOpenWindow: function(aXULWindow) {
    1.75 +    var domwindow = aXULWindow.QueryInterface(Ci.nsIInterfaceRequestor)
    1.76 +                              .getInterface(Ci.nsIDOMWindow);
    1.77 +    var self = this;
    1.78 +    domwindow.addEventListener("load", function() {
    1.79 +      domwindow.removeEventListener("load", arguments.callee, false);
    1.80 +
    1.81 +      ok(true, "domwindow.document.location.href: " + domwindow.document.location.href);
    1.82 +      if (domwindow.document.location.href != self.url)
    1.83 +        return;
    1.84 +
    1.85 +      // Allow other window load listeners to execute before passing to callback
    1.86 +      executeSoon(function() {
    1.87 +        self.callback(domwindow);
    1.88 +      });
    1.89 +    }, false);
    1.90 +  },
    1.91 +  onCloseWindow: function(aXULWindow) {},
    1.92 +  onWindowTitleChange: function(aXULWindow, aNewTitle) {}
    1.93 +}
    1.94 +

mercurial