michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: // handlerApp.xhtml grabs this for verification purposes via window.opener michael@0: var testURI = "webcal://127.0.0.1/rheeeeet.html"; michael@0: michael@0: const Cc = SpecialPowers.Cc; michael@0: michael@0: function test() { michael@0: michael@0: const isOSXMtnLion = navigator.userAgent.indexOf("Mac OS X 10.8") != -1; michael@0: const isOSXMavericks = navigator.userAgent.indexOf("Mac OS X 10.9") != -1; michael@0: if (isOSXMtnLion || isOSXMavericks) { michael@0: todo(false, "This test fails on OS X 10.8 and 10.9, see bug 786938"); michael@0: SimpleTest.finish(); michael@0: return; michael@0: } michael@0: michael@0: // set up the web handler object michael@0: var webHandler = Cc["@mozilla.org/uriloader/web-handler-app;1"]. michael@0: createInstance(SpecialPowers.Ci.nsIWebHandlerApp); michael@0: webHandler.name = "Test Web Handler App"; michael@0: webHandler.uriTemplate = michael@0: "http://mochi.test:8888/tests/uriloader/exthandler/tests/mochitest/" + michael@0: "handlerApp.xhtml?uri=%s"; michael@0: michael@0: // set up the uri to test with michael@0: var ioService = Cc["@mozilla.org/network/io-service;1"]. michael@0: getService(SpecialPowers.Ci.nsIIOService); michael@0: var uri = ioService.newURI(testURI, null, null); michael@0: michael@0: // create a window, and launch the handler in it michael@0: var newWindow = window.open("", "handlerWindow", "height=300,width=300"); michael@0: var windowContext = michael@0: SpecialPowers.wrap(newWindow).QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor). michael@0: getInterface(SpecialPowers.Ci.nsIWebNavigation). michael@0: QueryInterface(SpecialPowers.Ci.nsIDocShell); michael@0: michael@0: webHandler.launchWithURI(uri, windowContext); michael@0: michael@0: // if we get this far without an exception, we've at least partly passed michael@0: // (remaining check in handlerApp.xhtml) michael@0: ok(true, "webHandler launchWithURI (existing window/tab) started"); michael@0: michael@0: // make the web browser launch in its own window/tab michael@0: webHandler.launchWithURI(uri); michael@0: michael@0: // if we get this far without an exception, we've passed michael@0: ok(true, "webHandler launchWithURI (new window/tab) test started"); michael@0: michael@0: // set up the local handler object michael@0: var localHandler = Cc["@mozilla.org/uriloader/local-handler-app;1"]. michael@0: createInstance(SpecialPowers.Ci.nsILocalHandlerApp); michael@0: localHandler.name = "Test Local Handler App"; michael@0: michael@0: // get a local app that we know will be there and do something sane michael@0: var osString = Cc["@mozilla.org/xre/app-info;1"]. michael@0: getService(SpecialPowers.Ci.nsIXULRuntime).OS; michael@0: michael@0: var dirSvc = Cc["@mozilla.org/file/directory_service;1"]. michael@0: getService(SpecialPowers.Ci.nsIDirectoryServiceProvider); michael@0: if (osString == "WINNT") { michael@0: var windowsDir = dirSvc.getFile("WinD", {}); michael@0: var exe = windowsDir.clone().QueryInterface(SpecialPowers.Ci.nsILocalFile); michael@0: exe.appendRelativePath("SYSTEM32\\HOSTNAME.EXE"); michael@0: michael@0: } else if (osString == "Darwin") { michael@0: var localAppsDir = dirSvc.getFile("LocApp", {}); michael@0: exe = localAppsDir.clone(); michael@0: exe.append("iCal.app"); // lingers after the tests finish, but this seems michael@0: // seems better than explicitly killing it, since michael@0: // developers who run the tests locally may well michael@0: // information in their running copy of iCal michael@0: michael@0: if (navigator.userAgent.match(/ SeaMonkey\//)) { michael@0: // SeaMonkey tinderboxes don't like to have iCal lingering (and focused) michael@0: // on next test suite run(s). michael@0: todo(false, "On SeaMonkey, testing OS X as generic Unix. (Bug 749872)"); michael@0: michael@0: // assume a generic UNIX variant michael@0: exe = Cc["@mozilla.org/file/local;1"]. michael@0: createInstance(SpecialPowers.Ci.nsILocalFile); michael@0: exe.initWithPath("/bin/echo"); michael@0: } michael@0: } else { michael@0: // assume a generic UNIX variant michael@0: exe = Cc["@mozilla.org/file/local;1"]. michael@0: createInstance(SpecialPowers.Ci.nsILocalFile); michael@0: exe.initWithPath("/bin/echo"); michael@0: } michael@0: michael@0: localHandler.executable = exe; michael@0: localHandler.launchWithURI(ioService.newURI(testURI, null, null)); michael@0: michael@0: // if we get this far without an exception, we've passed michael@0: ok(true, "localHandler launchWithURI test"); michael@0: michael@0: // if we ever decide that killing iCal is the right thing to do, change michael@0: // the if statement below from "NOTDarwin" to "Darwin" michael@0: if (osString == "NOTDarwin") { michael@0: michael@0: var killall = Cc["@mozilla.org/file/local;1"]. michael@0: createInstance(SpecialPowers.Ci.nsILocalFile); michael@0: killall.initWithPath("/usr/bin/killall"); michael@0: michael@0: var process = Cc["@mozilla.org/process/util;1"]. michael@0: createInstance(SpecialPowers.Ci.nsIProcess); michael@0: process.init(killall); michael@0: michael@0: var args = ['iCal']; michael@0: process.run(false, args, args.length); michael@0: } michael@0: michael@0: SimpleTest.waitForExplicitFinish(); michael@0: } michael@0: michael@0: test();