This repository has been archived by the owner on Oct 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 110
/
test_punycodeURIs.js
144 lines (122 loc) · 5.42 KB
/
test_punycodeURIs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla code.
*
* The Initial Developer of the Original Code is
* Mozilla Messaging
* Portions created by the Initial Developer are Copyright (C) 2008
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Mark Banner <bugzilla@standard8.plus.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
// Encoded test URI to work on all platforms/independent of file encoding
const kTestURI = "http://\u65e5\u672c\u8a93.jp/";
const kExpectedURI = "http://xn--wgv71a309e.jp/";
const kOutputFile = "result.txt";
function checkFile() {
// This is where we expect the output
var tempFile = Components.classes["@mozilla.org/file/local;1"].
createInstance(Components.interfaces.nsILocalFile);
tempFile = HandlerServiceTest._dirSvc.get("CurProcD", Components.interfaces.nsIFile);
tempFile.append(kOutputFile);
if (!tempFile.exists())
do_throw("Expected File " + tempFile.path + " does not exist");
// Now read it
var fstream = Components.classes["@mozilla.org/network/file-input-stream;1"].
createInstance(Components.interfaces.nsIFileInputStream);
var sstream = Components.classes["@mozilla.org/scriptableinputstream;1"].
createInstance(Components.interfaces.nsIScriptableInputStream);
fstream.init(tempFile, -1, 0, 0);
sstream.init(fstream);
// Read the first line only as that's the one we expect WriteArguments
// to be writing the argument to.
var data = sstream.read(4096);
sstream.close();
fstream.close();
// Now remove the old file
tempFile.remove(false);
// This currently fails on Mac with an argument like -psn_0_nnnnnn
// This seems to be to do with how the executable is called, but I couldn't
// find a way around it.
// Additionally the lack of OS detection in xpcshell tests sucks, so we'll
// have to check for the argument mac gives us.
if (data.substring(0, 7) != "-psn_0_")
do_check_eq(data, kExpectedURI);
do_test_finished();
}
function run_test() {
// don't run the test on Mac OS 10.4 - see bug 447999
const httpHandler =
Components.classes["@mozilla.org/network/protocol;1?name=http"]
.getService(Components.interfaces.nsIHttpProtocolHandler);
const oscpu = httpHandler.oscpu;
if (oscpu.match(/Mac OS X 10.4/)) {
dump("This test is not run on Mac OS 10.4 because it fails for unknown " +
"reasons. See bug 447999.\n");
return;
}
// set up the uri to test with
var ioService = Components.classes["@mozilla.org/network/io-service;1"].
getService(Components.interfaces.nsIIOService);
// set up the local handler object
var localHandler =
Components.classes["@mozilla.org/uriloader/local-handler-app;1"].
createInstance(Components.interfaces.nsILocalHandlerApp);
localHandler.name = "Test Local Handler App";
// WriteArgument will just dump its arguments to a file for us.
var processDir = HandlerServiceTest._dirSvc.get("CurProcD", Components.interfaces.nsIFile);
var exe = processDir.clone();
exe.append("WriteArgument");
if (!exe.exists()) {
// Maybe we are on windows
exe.leafName = "WriteArgument.exe";
if (!exe.exists())
do_throw("Could not locate the WriteArgument tests executable\n");
}
var outFile = processDir.clone();
outFile.append(kOutputFile);
// Set an environment variable for WriteArgument to pick up
var envSvc = Components.classes["@mozilla.org/process/environment;1"].
getService(Components.interfaces.nsIEnvironment);
// The Write Argument file needs to know where its libraries are, so
// just force the path variable
// For mac
envSvc.set("DYLD_LIBRARY_PATH", processDir.path);
// For Linux/Windows
envSvc.set("LD_LIBRARY_PATH", processDir.path);
// Now tell it where we want the file.
envSvc.set("WRITE_ARGUMENT_FILE", outFile.path);
var uri = ioService.newURI(kTestURI, null, null);
// Just check we've got these matching, if we haven't there's a problem
// with ascii spec or our test case.
do_check_eq(uri.asciiSpec, kExpectedURI);
localHandler.executable = exe;
localHandler.launchWithURI(uri);
do_test_pending();
do_timeout(1000, "checkFile()");
}