webapprt/test/chrome/browser_window-open-blank.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/webapprt/test/chrome/browser_window-open-blank.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,75 @@
     1.4 +Cu.import("resource://gre/modules/XPCOMUtils.jsm");
     1.5 +
     1.6 +let HandlerService = {
     1.7 +  classID: Components.ID("{b4ed9fab-fd39-435a-8e3e-edc3e689e72e}"),
     1.8 +
     1.9 +  QueryInterface: XPCOMUtils.generateQI([Ci.nsIFactory,
    1.10 +                                         Ci.nsIExternalProtocolService]),
    1.11 +
    1.12 +  createInstance: function(aOuter, aIID) {
    1.13 +    if (aOuter) {
    1.14 +      throw Cr.NS_ERROR_NO_AGGREGATION;
    1.15 +    }
    1.16 +
    1.17 +    return this.QueryInterface(aIID);
    1.18 +  },
    1.19 +
    1.20 +  init: function() {
    1.21 +    Components.manager.nsIComponentRegistrar.registerFactory(this.classID,
    1.22 +      "Test Protocol Handler Service",
    1.23 +      "@mozilla.org/uriloader/external-protocol-service;1",
    1.24 +      this);
    1.25 +  },
    1.26 +
    1.27 +  getProtocolHandlerInfo: function(aProtocolScheme) {
    1.28 +    let handlerInfoObj = {
    1.29 +      launchWithURI: function(aURI) {
    1.30 +        is(aURI.spec,
    1.31 +           "http://test/webapprtChrome/webapprt/test/chrome/sample.html",
    1.32 +           "The app tried to open the link in the default browser");
    1.33 +
    1.34 +        finish();
    1.35 +      }
    1.36 +    };
    1.37 +
    1.38 +    return handlerInfoObj;
    1.39 +  }
    1.40 +};
    1.41 +
    1.42 +HandlerService.init();
    1.43 +
    1.44 +function test() {
    1.45 +  waitForExplicitFinish();
    1.46 +
    1.47 +  let progressListener = {
    1.48 +    QueryInterface: XPCOMUtils.generateQI([Ci.nsIWebProgressListener,
    1.49 +                                           Ci.nsISupportsWeakReference]),
    1.50 +    onLocationChange: function(progress, request, location, flags) {
    1.51 +      ok(false, "Location changed");
    1.52 +      finish();
    1.53 +    }
    1.54 +  };
    1.55 +
    1.56 +  let winObserver = function(win, topic) {
    1.57 +    if (topic == "domwindowopened") {
    1.58 +      win.addEventListener("load", function onLoadWindow() {
    1.59 +        win.removeEventListener("load", onLoadWindow, false);
    1.60 +
    1.61 +        if (win.location == "chrome://webapprt/content/webapp.xul") {
    1.62 +          ok(false, "New app window opened");
    1.63 +          finish();
    1.64 +        }
    1.65 +      }, false);
    1.66 +    }
    1.67 +  }
    1.68 +
    1.69 +  loadWebapp("window-open-blank.webapp", undefined, function() {
    1.70 +    gAppBrowser.addProgressListener(progressListener,
    1.71 +                                    Ci.nsIWebProgress.NOTIFY_LOCATION);
    1.72 +  });
    1.73 +
    1.74 +  registerCleanupFunction(function() {
    1.75 +    Services.ww.unregisterNotification(winObserver);
    1.76 +    gAppBrowser.removeProgressListener(progressListener);
    1.77 +  });
    1.78 +}

mercurial