|
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 // Encoded test URI to work on all platforms/independent of file encoding |
|
6 const kTestURI = "http://\u65e5\u672c\u8a93.jp/"; |
|
7 const kExpectedURI = "http://xn--wgv71a309e.jp/"; |
|
8 const kOutputFile = "result.txt"; |
|
9 |
|
10 // Try several times in case the box we're running on is slow. |
|
11 const kMaxCheckExistAttempts = 30; // seconds |
|
12 var gCheckExistsAttempts = 0; |
|
13 |
|
14 const tempDir = do_get_tempdir(); |
|
15 |
|
16 function checkFile() { |
|
17 // This is where we expect the output |
|
18 var tempFile = tempDir.clone(); |
|
19 tempFile.append(kOutputFile); |
|
20 |
|
21 if (!tempFile.exists()) { |
|
22 if (gCheckExistsAttempts >= kMaxCheckExistAttempts) { |
|
23 do_throw("Expected File " + tempFile.path + " does not exist after " + |
|
24 kMaxCheckExistAttempts + " seconds"); |
|
25 } |
|
26 else { |
|
27 ++gCheckExistsAttempts; |
|
28 // Wait a bit longer then try again |
|
29 do_timeout(1000, checkFile); |
|
30 return; |
|
31 } |
|
32 } |
|
33 |
|
34 // Now read it |
|
35 var fstream = |
|
36 Components.classes["@mozilla.org/network/file-input-stream;1"] |
|
37 .createInstance(Components.interfaces.nsIFileInputStream); |
|
38 var sstream = |
|
39 Components.classes["@mozilla.org/scriptableinputstream;1"] |
|
40 .createInstance(Components.interfaces.nsIScriptableInputStream); |
|
41 fstream.init(tempFile, -1, 0, 0); |
|
42 sstream.init(fstream); |
|
43 |
|
44 // Read the first line only as that's the one we expect WriteArguments |
|
45 // to be writing the argument to. |
|
46 var data = sstream.read(4096); |
|
47 |
|
48 sstream.close(); |
|
49 fstream.close(); |
|
50 |
|
51 // Now remove the old file |
|
52 tempFile.remove(false); |
|
53 |
|
54 // This currently fails on Mac with an argument like -psn_0_nnnnnn |
|
55 // This seems to be to do with how the executable is called, but I couldn't |
|
56 // find a way around it. |
|
57 // Additionally the lack of OS detection in xpcshell tests sucks, so we'll |
|
58 // have to check for the argument mac gives us. |
|
59 if (data.substring(0, 7) != "-psn_0_") |
|
60 do_check_eq(data, kExpectedURI); |
|
61 |
|
62 do_test_finished(); |
|
63 } |
|
64 |
|
65 function run_test() { |
|
66 var isOSX = ("nsILocalFileMac" in Components.interfaces); |
|
67 if (isOSX) { |
|
68 dump("INFO | test_punycodeURIs.js | Skipping test on mac, bug 599475") |
|
69 return; |
|
70 } |
|
71 |
|
72 // set up the uri to test with |
|
73 var ioService = |
|
74 Components.classes["@mozilla.org/network/io-service;1"] |
|
75 .getService(Components.interfaces.nsIIOService); |
|
76 |
|
77 // set up the local handler object |
|
78 var localHandler = |
|
79 Components.classes["@mozilla.org/uriloader/local-handler-app;1"] |
|
80 .createInstance(Components.interfaces.nsILocalHandlerApp); |
|
81 localHandler.name = "Test Local Handler App"; |
|
82 |
|
83 // WriteArgument will just dump its arguments to a file for us. |
|
84 var processDir = do_get_cwd(); |
|
85 var exe = processDir.clone(); |
|
86 exe.append("WriteArgument"); |
|
87 |
|
88 if (!exe.exists()) { |
|
89 // Maybe we are on windows |
|
90 exe.leafName = "WriteArgument.exe"; |
|
91 if (!exe.exists()) |
|
92 do_throw("Could not locate the WriteArgument tests executable\n"); |
|
93 } |
|
94 |
|
95 var outFile = tempDir.clone(); |
|
96 outFile.append(kOutputFile); |
|
97 |
|
98 // Set an environment variable for WriteArgument to pick up |
|
99 var envSvc = |
|
100 Components.classes["@mozilla.org/process/environment;1"] |
|
101 .getService(Components.interfaces.nsIEnvironment); |
|
102 |
|
103 // The Write Argument file needs to know where its libraries are, so |
|
104 // just force the path variable |
|
105 // For mac |
|
106 var greDir = HandlerServiceTest._dirSvc.get("GreD", Components.interfaces.nsIFile); |
|
107 |
|
108 envSvc.set("DYLD_LIBRARY_PATH", greDir.path); |
|
109 // For Linux |
|
110 envSvc.set("LD_LIBRARY_PATH", greDir.path); |
|
111 //XXX: handle windows |
|
112 |
|
113 // Now tell it where we want the file. |
|
114 envSvc.set("WRITE_ARGUMENT_FILE", outFile.path); |
|
115 |
|
116 var uri = ioService.newURI(kTestURI, null, null); |
|
117 |
|
118 // Just check we've got these matching, if we haven't there's a problem |
|
119 // with ascii spec or our test case. |
|
120 do_check_eq(uri.asciiSpec, kExpectedURI); |
|
121 |
|
122 localHandler.executable = exe; |
|
123 localHandler.launchWithURI(uri); |
|
124 |
|
125 do_test_pending(); |
|
126 do_timeout(1000, checkFile); |
|
127 } |