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