1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/uriloader/exthandler/tests/unit/test_punycodeURIs.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,127 @@ 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 +// Encoded test URI to work on all platforms/independent of file encoding 1.9 +const kTestURI = "http://\u65e5\u672c\u8a93.jp/"; 1.10 +const kExpectedURI = "http://xn--wgv71a309e.jp/"; 1.11 +const kOutputFile = "result.txt"; 1.12 + 1.13 +// Try several times in case the box we're running on is slow. 1.14 +const kMaxCheckExistAttempts = 30; // seconds 1.15 +var gCheckExistsAttempts = 0; 1.16 + 1.17 +const tempDir = do_get_tempdir(); 1.18 + 1.19 +function checkFile() { 1.20 + // This is where we expect the output 1.21 + var tempFile = tempDir.clone(); 1.22 + tempFile.append(kOutputFile); 1.23 + 1.24 + if (!tempFile.exists()) { 1.25 + if (gCheckExistsAttempts >= kMaxCheckExistAttempts) { 1.26 + do_throw("Expected File " + tempFile.path + " does not exist after " + 1.27 + kMaxCheckExistAttempts + " seconds"); 1.28 + } 1.29 + else { 1.30 + ++gCheckExistsAttempts; 1.31 + // Wait a bit longer then try again 1.32 + do_timeout(1000, checkFile); 1.33 + return; 1.34 + } 1.35 + } 1.36 + 1.37 + // Now read it 1.38 + var fstream = 1.39 + Components.classes["@mozilla.org/network/file-input-stream;1"] 1.40 + .createInstance(Components.interfaces.nsIFileInputStream); 1.41 + var sstream = 1.42 + Components.classes["@mozilla.org/scriptableinputstream;1"] 1.43 + .createInstance(Components.interfaces.nsIScriptableInputStream); 1.44 + fstream.init(tempFile, -1, 0, 0); 1.45 + sstream.init(fstream); 1.46 + 1.47 + // Read the first line only as that's the one we expect WriteArguments 1.48 + // to be writing the argument to. 1.49 + var data = sstream.read(4096); 1.50 + 1.51 + sstream.close(); 1.52 + fstream.close(); 1.53 + 1.54 + // Now remove the old file 1.55 + tempFile.remove(false); 1.56 + 1.57 + // This currently fails on Mac with an argument like -psn_0_nnnnnn 1.58 + // This seems to be to do with how the executable is called, but I couldn't 1.59 + // find a way around it. 1.60 + // Additionally the lack of OS detection in xpcshell tests sucks, so we'll 1.61 + // have to check for the argument mac gives us. 1.62 + if (data.substring(0, 7) != "-psn_0_") 1.63 + do_check_eq(data, kExpectedURI); 1.64 + 1.65 + do_test_finished(); 1.66 +} 1.67 + 1.68 +function run_test() { 1.69 + var isOSX = ("nsILocalFileMac" in Components.interfaces); 1.70 + if (isOSX) { 1.71 + dump("INFO | test_punycodeURIs.js | Skipping test on mac, bug 599475") 1.72 + return; 1.73 + } 1.74 + 1.75 + // set up the uri to test with 1.76 + var ioService = 1.77 + Components.classes["@mozilla.org/network/io-service;1"] 1.78 + .getService(Components.interfaces.nsIIOService); 1.79 + 1.80 + // set up the local handler object 1.81 + var localHandler = 1.82 + Components.classes["@mozilla.org/uriloader/local-handler-app;1"] 1.83 + .createInstance(Components.interfaces.nsILocalHandlerApp); 1.84 + localHandler.name = "Test Local Handler App"; 1.85 + 1.86 + // WriteArgument will just dump its arguments to a file for us. 1.87 + var processDir = do_get_cwd(); 1.88 + var exe = processDir.clone(); 1.89 + exe.append("WriteArgument"); 1.90 + 1.91 + if (!exe.exists()) { 1.92 + // Maybe we are on windows 1.93 + exe.leafName = "WriteArgument.exe"; 1.94 + if (!exe.exists()) 1.95 + do_throw("Could not locate the WriteArgument tests executable\n"); 1.96 + } 1.97 + 1.98 + var outFile = tempDir.clone(); 1.99 + outFile.append(kOutputFile); 1.100 + 1.101 + // Set an environment variable for WriteArgument to pick up 1.102 + var envSvc = 1.103 + Components.classes["@mozilla.org/process/environment;1"] 1.104 + .getService(Components.interfaces.nsIEnvironment); 1.105 + 1.106 + // The Write Argument file needs to know where its libraries are, so 1.107 + // just force the path variable 1.108 + // For mac 1.109 + var greDir = HandlerServiceTest._dirSvc.get("GreD", Components.interfaces.nsIFile); 1.110 + 1.111 + envSvc.set("DYLD_LIBRARY_PATH", greDir.path); 1.112 + // For Linux 1.113 + envSvc.set("LD_LIBRARY_PATH", greDir.path); 1.114 + //XXX: handle windows 1.115 + 1.116 + // Now tell it where we want the file. 1.117 + envSvc.set("WRITE_ARGUMENT_FILE", outFile.path); 1.118 + 1.119 + var uri = ioService.newURI(kTestURI, null, null); 1.120 + 1.121 + // Just check we've got these matching, if we haven't there's a problem 1.122 + // with ascii spec or our test case. 1.123 + do_check_eq(uri.asciiSpec, kExpectedURI); 1.124 + 1.125 + localHandler.executable = exe; 1.126 + localHandler.launchWithURI(uri); 1.127 + 1.128 + do_test_pending(); 1.129 + do_timeout(1000, checkFile); 1.130 +}