uriloader/exthandler/tests/mochitest/handlerApps.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 // handlerApp.xhtml grabs this for verification purposes via window.opener
michael@0 6 var testURI = "webcal://127.0.0.1/rheeeeet.html";
michael@0 7
michael@0 8 const Cc = SpecialPowers.Cc;
michael@0 9
michael@0 10 function test() {
michael@0 11
michael@0 12 const isOSXMtnLion = navigator.userAgent.indexOf("Mac OS X 10.8") != -1;
michael@0 13 const isOSXMavericks = navigator.userAgent.indexOf("Mac OS X 10.9") != -1;
michael@0 14 if (isOSXMtnLion || isOSXMavericks) {
michael@0 15 todo(false, "This test fails on OS X 10.8 and 10.9, see bug 786938");
michael@0 16 SimpleTest.finish();
michael@0 17 return;
michael@0 18 }
michael@0 19
michael@0 20 // set up the web handler object
michael@0 21 var webHandler = Cc["@mozilla.org/uriloader/web-handler-app;1"].
michael@0 22 createInstance(SpecialPowers.Ci.nsIWebHandlerApp);
michael@0 23 webHandler.name = "Test Web Handler App";
michael@0 24 webHandler.uriTemplate =
michael@0 25 "http://mochi.test:8888/tests/uriloader/exthandler/tests/mochitest/" +
michael@0 26 "handlerApp.xhtml?uri=%s";
michael@0 27
michael@0 28 // set up the uri to test with
michael@0 29 var ioService = Cc["@mozilla.org/network/io-service;1"].
michael@0 30 getService(SpecialPowers.Ci.nsIIOService);
michael@0 31 var uri = ioService.newURI(testURI, null, null);
michael@0 32
michael@0 33 // create a window, and launch the handler in it
michael@0 34 var newWindow = window.open("", "handlerWindow", "height=300,width=300");
michael@0 35 var windowContext =
michael@0 36 SpecialPowers.wrap(newWindow).QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor).
michael@0 37 getInterface(SpecialPowers.Ci.nsIWebNavigation).
michael@0 38 QueryInterface(SpecialPowers.Ci.nsIDocShell);
michael@0 39
michael@0 40 webHandler.launchWithURI(uri, windowContext);
michael@0 41
michael@0 42 // if we get this far without an exception, we've at least partly passed
michael@0 43 // (remaining check in handlerApp.xhtml)
michael@0 44 ok(true, "webHandler launchWithURI (existing window/tab) started");
michael@0 45
michael@0 46 // make the web browser launch in its own window/tab
michael@0 47 webHandler.launchWithURI(uri);
michael@0 48
michael@0 49 // if we get this far without an exception, we've passed
michael@0 50 ok(true, "webHandler launchWithURI (new window/tab) test started");
michael@0 51
michael@0 52 // set up the local handler object
michael@0 53 var localHandler = Cc["@mozilla.org/uriloader/local-handler-app;1"].
michael@0 54 createInstance(SpecialPowers.Ci.nsILocalHandlerApp);
michael@0 55 localHandler.name = "Test Local Handler App";
michael@0 56
michael@0 57 // get a local app that we know will be there and do something sane
michael@0 58 var osString = Cc["@mozilla.org/xre/app-info;1"].
michael@0 59 getService(SpecialPowers.Ci.nsIXULRuntime).OS;
michael@0 60
michael@0 61 var dirSvc = Cc["@mozilla.org/file/directory_service;1"].
michael@0 62 getService(SpecialPowers.Ci.nsIDirectoryServiceProvider);
michael@0 63 if (osString == "WINNT") {
michael@0 64 var windowsDir = dirSvc.getFile("WinD", {});
michael@0 65 var exe = windowsDir.clone().QueryInterface(SpecialPowers.Ci.nsILocalFile);
michael@0 66 exe.appendRelativePath("SYSTEM32\\HOSTNAME.EXE");
michael@0 67
michael@0 68 } else if (osString == "Darwin") {
michael@0 69 var localAppsDir = dirSvc.getFile("LocApp", {});
michael@0 70 exe = localAppsDir.clone();
michael@0 71 exe.append("iCal.app"); // lingers after the tests finish, but this seems
michael@0 72 // seems better than explicitly killing it, since
michael@0 73 // developers who run the tests locally may well
michael@0 74 // information in their running copy of iCal
michael@0 75
michael@0 76 if (navigator.userAgent.match(/ SeaMonkey\//)) {
michael@0 77 // SeaMonkey tinderboxes don't like to have iCal lingering (and focused)
michael@0 78 // on next test suite run(s).
michael@0 79 todo(false, "On SeaMonkey, testing OS X as generic Unix. (Bug 749872)");
michael@0 80
michael@0 81 // assume a generic UNIX variant
michael@0 82 exe = Cc["@mozilla.org/file/local;1"].
michael@0 83 createInstance(SpecialPowers.Ci.nsILocalFile);
michael@0 84 exe.initWithPath("/bin/echo");
michael@0 85 }
michael@0 86 } else {
michael@0 87 // assume a generic UNIX variant
michael@0 88 exe = Cc["@mozilla.org/file/local;1"].
michael@0 89 createInstance(SpecialPowers.Ci.nsILocalFile);
michael@0 90 exe.initWithPath("/bin/echo");
michael@0 91 }
michael@0 92
michael@0 93 localHandler.executable = exe;
michael@0 94 localHandler.launchWithURI(ioService.newURI(testURI, null, null));
michael@0 95
michael@0 96 // if we get this far without an exception, we've passed
michael@0 97 ok(true, "localHandler launchWithURI test");
michael@0 98
michael@0 99 // if we ever decide that killing iCal is the right thing to do, change
michael@0 100 // the if statement below from "NOTDarwin" to "Darwin"
michael@0 101 if (osString == "NOTDarwin") {
michael@0 102
michael@0 103 var killall = Cc["@mozilla.org/file/local;1"].
michael@0 104 createInstance(SpecialPowers.Ci.nsILocalFile);
michael@0 105 killall.initWithPath("/usr/bin/killall");
michael@0 106
michael@0 107 var process = Cc["@mozilla.org/process/util;1"].
michael@0 108 createInstance(SpecialPowers.Ci.nsIProcess);
michael@0 109 process.init(killall);
michael@0 110
michael@0 111 var args = ['iCal'];
michael@0 112 process.run(false, args, args.length);
michael@0 113 }
michael@0 114
michael@0 115 SimpleTest.waitForExplicitFinish();
michael@0 116 }
michael@0 117
michael@0 118 test();

mercurial