1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/uriloader/exthandler/tests/mochitest/handlerApps.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,118 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +// handlerApp.xhtml grabs this for verification purposes via window.opener 1.9 +var testURI = "webcal://127.0.0.1/rheeeeet.html"; 1.10 + 1.11 +const Cc = SpecialPowers.Cc; 1.12 + 1.13 +function test() { 1.14 + 1.15 + const isOSXMtnLion = navigator.userAgent.indexOf("Mac OS X 10.8") != -1; 1.16 + const isOSXMavericks = navigator.userAgent.indexOf("Mac OS X 10.9") != -1; 1.17 + if (isOSXMtnLion || isOSXMavericks) { 1.18 + todo(false, "This test fails on OS X 10.8 and 10.9, see bug 786938"); 1.19 + SimpleTest.finish(); 1.20 + return; 1.21 + } 1.22 + 1.23 + // set up the web handler object 1.24 + var webHandler = Cc["@mozilla.org/uriloader/web-handler-app;1"]. 1.25 + createInstance(SpecialPowers.Ci.nsIWebHandlerApp); 1.26 + webHandler.name = "Test Web Handler App"; 1.27 + webHandler.uriTemplate = 1.28 + "http://mochi.test:8888/tests/uriloader/exthandler/tests/mochitest/" + 1.29 + "handlerApp.xhtml?uri=%s"; 1.30 + 1.31 + // set up the uri to test with 1.32 + var ioService = Cc["@mozilla.org/network/io-service;1"]. 1.33 + getService(SpecialPowers.Ci.nsIIOService); 1.34 + var uri = ioService.newURI(testURI, null, null); 1.35 + 1.36 + // create a window, and launch the handler in it 1.37 + var newWindow = window.open("", "handlerWindow", "height=300,width=300"); 1.38 + var windowContext = 1.39 + SpecialPowers.wrap(newWindow).QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor). 1.40 + getInterface(SpecialPowers.Ci.nsIWebNavigation). 1.41 + QueryInterface(SpecialPowers.Ci.nsIDocShell); 1.42 + 1.43 + webHandler.launchWithURI(uri, windowContext); 1.44 + 1.45 + // if we get this far without an exception, we've at least partly passed 1.46 + // (remaining check in handlerApp.xhtml) 1.47 + ok(true, "webHandler launchWithURI (existing window/tab) started"); 1.48 + 1.49 + // make the web browser launch in its own window/tab 1.50 + webHandler.launchWithURI(uri); 1.51 + 1.52 + // if we get this far without an exception, we've passed 1.53 + ok(true, "webHandler launchWithURI (new window/tab) test started"); 1.54 + 1.55 + // set up the local handler object 1.56 + var localHandler = Cc["@mozilla.org/uriloader/local-handler-app;1"]. 1.57 + createInstance(SpecialPowers.Ci.nsILocalHandlerApp); 1.58 + localHandler.name = "Test Local Handler App"; 1.59 + 1.60 + // get a local app that we know will be there and do something sane 1.61 + var osString = Cc["@mozilla.org/xre/app-info;1"]. 1.62 + getService(SpecialPowers.Ci.nsIXULRuntime).OS; 1.63 + 1.64 + var dirSvc = Cc["@mozilla.org/file/directory_service;1"]. 1.65 + getService(SpecialPowers.Ci.nsIDirectoryServiceProvider); 1.66 + if (osString == "WINNT") { 1.67 + var windowsDir = dirSvc.getFile("WinD", {}); 1.68 + var exe = windowsDir.clone().QueryInterface(SpecialPowers.Ci.nsILocalFile); 1.69 + exe.appendRelativePath("SYSTEM32\\HOSTNAME.EXE"); 1.70 + 1.71 + } else if (osString == "Darwin") { 1.72 + var localAppsDir = dirSvc.getFile("LocApp", {}); 1.73 + exe = localAppsDir.clone(); 1.74 + exe.append("iCal.app"); // lingers after the tests finish, but this seems 1.75 + // seems better than explicitly killing it, since 1.76 + // developers who run the tests locally may well 1.77 + // information in their running copy of iCal 1.78 + 1.79 + if (navigator.userAgent.match(/ SeaMonkey\//)) { 1.80 + // SeaMonkey tinderboxes don't like to have iCal lingering (and focused) 1.81 + // on next test suite run(s). 1.82 + todo(false, "On SeaMonkey, testing OS X as generic Unix. (Bug 749872)"); 1.83 + 1.84 + // assume a generic UNIX variant 1.85 + exe = Cc["@mozilla.org/file/local;1"]. 1.86 + createInstance(SpecialPowers.Ci.nsILocalFile); 1.87 + exe.initWithPath("/bin/echo"); 1.88 + } 1.89 + } else { 1.90 + // assume a generic UNIX variant 1.91 + exe = Cc["@mozilla.org/file/local;1"]. 1.92 + createInstance(SpecialPowers.Ci.nsILocalFile); 1.93 + exe.initWithPath("/bin/echo"); 1.94 + } 1.95 + 1.96 + localHandler.executable = exe; 1.97 + localHandler.launchWithURI(ioService.newURI(testURI, null, null)); 1.98 + 1.99 + // if we get this far without an exception, we've passed 1.100 + ok(true, "localHandler launchWithURI test"); 1.101 + 1.102 + // if we ever decide that killing iCal is the right thing to do, change 1.103 + // the if statement below from "NOTDarwin" to "Darwin" 1.104 + if (osString == "NOTDarwin") { 1.105 + 1.106 + var killall = Cc["@mozilla.org/file/local;1"]. 1.107 + createInstance(SpecialPowers.Ci.nsILocalFile); 1.108 + killall.initWithPath("/usr/bin/killall"); 1.109 + 1.110 + var process = Cc["@mozilla.org/process/util;1"]. 1.111 + createInstance(SpecialPowers.Ci.nsIProcess); 1.112 + process.init(killall); 1.113 + 1.114 + var args = ['iCal']; 1.115 + process.run(false, args, args.length); 1.116 + } 1.117 + 1.118 + SimpleTest.waitForExplicitFinish(); 1.119 +} 1.120 + 1.121 +test();