michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: // Encoded test URI to work on all platforms/independent of file encoding michael@0: const kTestURI = "http://\u65e5\u672c\u8a93.jp/"; michael@0: const kExpectedURI = "http://xn--wgv71a309e.jp/"; michael@0: const kOutputFile = "result.txt"; michael@0: michael@0: // Try several times in case the box we're running on is slow. michael@0: const kMaxCheckExistAttempts = 30; // seconds michael@0: var gCheckExistsAttempts = 0; michael@0: michael@0: const tempDir = do_get_tempdir(); michael@0: michael@0: function checkFile() { michael@0: // This is where we expect the output michael@0: var tempFile = tempDir.clone(); michael@0: tempFile.append(kOutputFile); michael@0: michael@0: if (!tempFile.exists()) { michael@0: if (gCheckExistsAttempts >= kMaxCheckExistAttempts) { michael@0: do_throw("Expected File " + tempFile.path + " does not exist after " + michael@0: kMaxCheckExistAttempts + " seconds"); michael@0: } michael@0: else { michael@0: ++gCheckExistsAttempts; michael@0: // Wait a bit longer then try again michael@0: do_timeout(1000, checkFile); michael@0: return; michael@0: } michael@0: } michael@0: michael@0: // Now read it michael@0: var fstream = michael@0: Components.classes["@mozilla.org/network/file-input-stream;1"] michael@0: .createInstance(Components.interfaces.nsIFileInputStream); michael@0: var sstream = michael@0: Components.classes["@mozilla.org/scriptableinputstream;1"] michael@0: .createInstance(Components.interfaces.nsIScriptableInputStream); michael@0: fstream.init(tempFile, -1, 0, 0); michael@0: sstream.init(fstream); michael@0: michael@0: // Read the first line only as that's the one we expect WriteArguments michael@0: // to be writing the argument to. michael@0: var data = sstream.read(4096); michael@0: michael@0: sstream.close(); michael@0: fstream.close(); michael@0: michael@0: // Now remove the old file michael@0: tempFile.remove(false); michael@0: michael@0: // This currently fails on Mac with an argument like -psn_0_nnnnnn michael@0: // This seems to be to do with how the executable is called, but I couldn't michael@0: // find a way around it. michael@0: // Additionally the lack of OS detection in xpcshell tests sucks, so we'll michael@0: // have to check for the argument mac gives us. michael@0: if (data.substring(0, 7) != "-psn_0_") michael@0: do_check_eq(data, kExpectedURI); michael@0: michael@0: do_test_finished(); michael@0: } michael@0: michael@0: function run_test() { michael@0: var isOSX = ("nsILocalFileMac" in Components.interfaces); michael@0: if (isOSX) { michael@0: dump("INFO | test_punycodeURIs.js | Skipping test on mac, bug 599475") michael@0: return; michael@0: } michael@0: michael@0: // set up the uri to test with michael@0: var ioService = michael@0: Components.classes["@mozilla.org/network/io-service;1"] michael@0: .getService(Components.interfaces.nsIIOService); michael@0: michael@0: // set up the local handler object michael@0: var localHandler = michael@0: Components.classes["@mozilla.org/uriloader/local-handler-app;1"] michael@0: .createInstance(Components.interfaces.nsILocalHandlerApp); michael@0: localHandler.name = "Test Local Handler App"; michael@0: michael@0: // WriteArgument will just dump its arguments to a file for us. michael@0: var processDir = do_get_cwd(); michael@0: var exe = processDir.clone(); michael@0: exe.append("WriteArgument"); michael@0: michael@0: if (!exe.exists()) { michael@0: // Maybe we are on windows michael@0: exe.leafName = "WriteArgument.exe"; michael@0: if (!exe.exists()) michael@0: do_throw("Could not locate the WriteArgument tests executable\n"); michael@0: } michael@0: michael@0: var outFile = tempDir.clone(); michael@0: outFile.append(kOutputFile); michael@0: michael@0: // Set an environment variable for WriteArgument to pick up michael@0: var envSvc = michael@0: Components.classes["@mozilla.org/process/environment;1"] michael@0: .getService(Components.interfaces.nsIEnvironment); michael@0: michael@0: // The Write Argument file needs to know where its libraries are, so michael@0: // just force the path variable michael@0: // For mac michael@0: var greDir = HandlerServiceTest._dirSvc.get("GreD", Components.interfaces.nsIFile); michael@0: michael@0: envSvc.set("DYLD_LIBRARY_PATH", greDir.path); michael@0: // For Linux michael@0: envSvc.set("LD_LIBRARY_PATH", greDir.path); michael@0: //XXX: handle windows michael@0: michael@0: // Now tell it where we want the file. michael@0: envSvc.set("WRITE_ARGUMENT_FILE", outFile.path); michael@0: michael@0: var uri = ioService.newURI(kTestURI, null, null); michael@0: michael@0: // Just check we've got these matching, if we haven't there's a problem michael@0: // with ascii spec or our test case. michael@0: do_check_eq(uri.asciiSpec, kExpectedURI); michael@0: michael@0: localHandler.executable = exe; michael@0: localHandler.launchWithURI(uri); michael@0: michael@0: do_test_pending(); michael@0: do_timeout(1000, checkFile); michael@0: }