netwerk/test/unit/test_bug396389.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 function round_trip(uri) {
michael@0 2 var objectOutStream = Cc["@mozilla.org/binaryoutputstream;1"].
michael@0 3 createInstance(Ci.nsIObjectOutputStream);
michael@0 4 var pipe = Cc["@mozilla.org/pipe;1"].createInstance(Ci.nsIPipe);
michael@0 5 pipe.init(false, false, 0, 0xffffffff, null);
michael@0 6 objectOutStream.setOutputStream(pipe.outputStream);
michael@0 7 objectOutStream.writeCompoundObject(uri, Ci.nsISupports, true);
michael@0 8 objectOutStream.close();
michael@0 9
michael@0 10 var objectInStream = Cc["@mozilla.org/binaryinputstream;1"].
michael@0 11 createInstance(Ci.nsIObjectInputStream);
michael@0 12 objectInStream.setInputStream(pipe.inputStream);
michael@0 13 return objectInStream.readObject(true).QueryInterface(Ci.nsIURI);
michael@0 14 }
michael@0 15
michael@0 16 var prefData =
michael@0 17 [
michael@0 18 {
michael@0 19 name: "network.IDN_show_punycode",
michael@0 20 newVal: false
michael@0 21 },
michael@0 22 {
michael@0 23 name: "network.IDN.whitelist.ch",
michael@0 24 newVal: true
michael@0 25 }
michael@0 26 ];
michael@0 27
michael@0 28 function run_test() {
michael@0 29 var ios = Cc["@mozilla.org/network/io-service;1"].
michael@0 30 getService(Ci.nsIIOService);
michael@0 31
michael@0 32 var uri1 = ios.newURI("file:///", null, null);
michael@0 33 do_check_true(uri1 instanceof Ci.nsIFileURL);
michael@0 34
michael@0 35 var uri2 = uri1.clone();
michael@0 36 do_check_true(uri2 instanceof Ci.nsIFileURL);
michael@0 37 do_check_true(uri1.equals(uri2));
michael@0 38
michael@0 39 var uri3 = round_trip(uri1);
michael@0 40 do_check_true(uri3 instanceof Ci.nsIFileURL);
michael@0 41 do_check_true(uri1.equals(uri3));
michael@0 42
michael@0 43 // Make sure our prefs are set such that this test actually means something
michael@0 44 var prefs = Cc["@mozilla.org/preferences-service;1"].
michael@0 45 getService(Ci.nsIPrefBranch);
michael@0 46 for each (var pref in prefData) {
michael@0 47 try {
michael@0 48 pref.oldVal = prefs.getBoolPref(pref.name);
michael@0 49 } catch(e) {
michael@0 50 }
michael@0 51 prefs.setBoolPref(pref.name, pref.newVal);
michael@0 52 }
michael@0 53
michael@0 54 try {
michael@0 55 // URI stolen from
michael@0 56 // http://lists.w3.org/Archives/Public/public-iri/2004Mar/0012.html
michael@0 57 var uri4 = ios.newURI("http://xn--jos-dma.example.net.ch/", null, null);
michael@0 58 do_check_eq(uri4.asciiHost, "xn--jos-dma.example.net.ch");
michael@0 59 do_check_eq(uri4.host, "jos\u00e9.example.net.ch");
michael@0 60
michael@0 61 var uri5 = round_trip(uri4);
michael@0 62 do_check_true(uri4.equals(uri5));
michael@0 63 do_check_eq(uri4.host, uri5.host);
michael@0 64 do_check_eq(uri4.asciiHost, uri5.asciiHost);
michael@0 65 } finally {
michael@0 66 for each (var pref in prefData) {
michael@0 67 if (prefs.prefHasUserValue(pref.name))
michael@0 68 prefs.clearUserPref(pref.name);
michael@0 69 }
michael@0 70 }
michael@0 71 }

mercurial