Follow-on fix for bug 457825. Use sheet principal for agent and user sheets. r=dbaron...
[wine-gecko.git] / netwerk / test / unit / test_bug396389.js
blob9e44437745e1044613e5593f122cc9b3e5e8ad29
1 const Cc = Components.classes;
2 const Ci = Components.interfaces;
4 function round_trip(uri) {
5   var objectOutStream = Cc["@mozilla.org/binaryoutputstream;1"].
6                        createInstance(Ci.nsIObjectOutputStream);
7   var pipe = Cc["@mozilla.org/pipe;1"].createInstance(Ci.nsIPipe);
8   pipe.init(false, false, 0, 0xffffffff, null);
9   objectOutStream.setOutputStream(pipe.outputStream);
10   objectOutStream.writeCompoundObject(uri, Ci.nsISupports, true);
11   objectOutStream.close();
13   var objectInStream = Cc["@mozilla.org/binaryinputstream;1"].
14                        createInstance(Ci.nsIObjectInputStream);
15   objectInStream.setInputStream(pipe.inputStream);
16   return objectInStream.readObject(true).QueryInterface(Ci.nsIURI);
19 var prefData =
20   [
21     {
22       name: "network.enableIDN",
23       newVal: true
24     },
25     {
26       name: "network.IDN_show_punycode",
27       newVal: false
28     },
29     {
30       name: "network.IDN.whitelist.ch",
31       newVal: true
32     }
33   ];
35 function run_test() {
36   var ios = Cc["@mozilla.org/network/io-service;1"].
37     getService(Ci.nsIIOService);
39   var uri1 = ios.newURI("file:///", null, null);
40   do_check_true(uri1 instanceof Ci.nsIFileURL);
42   var uri2 = uri1.clone();
43   do_check_true(uri2 instanceof Ci.nsIFileURL);
44   do_check_true(uri1.equals(uri2));
46   var uri3 = round_trip(uri1);
47   do_check_true(uri3 instanceof Ci.nsIFileURL);
48   do_check_true(uri1.equals(uri3));
50   // Make sure our prefs are set such that this test actually means something
51   var prefs = Cc["@mozilla.org/preferences-service;1"].
52               getService(Ci.nsIPrefBranch);
53   for each (var pref in prefData) {
54     try {
55       pref.oldVal = prefs.getBoolPref(pref.name);
56       pref.set = true;
57     } catch(e) {
58       pref.set = false;
59     }
60     prefs.setBoolPref(pref.name, pref.newVal);
61   }
62   
63   try {
64     // URI stolen from
65     // http://lists.w3.org/Archives/Public/public-iri/2004Mar/0012.html
66     var uri4 = ios.newURI("http://xn--jos-dma.example.net.ch/", null, null);
67     do_check_eq(uri4.asciiHost, "xn--jos-dma.example.net.ch");
68     do_check_eq(uri4.host, "jos\u00e9.example.net.ch");
69     
70     var uri5 = round_trip(uri4);
71     do_check_true(uri4.equals(uri5));
72     do_check_eq(uri4.host, uri5.host);
73     do_check_eq(uri4.asciiHost, uri5.asciiHost);
74   } finally {
75     for each (var pref in prefData) {
76       if (pref.set) {
77         prefs.setBoolPref(pref.name, pref.oldVal);
78       } else {
79         prefs.clearUserPref(pref.name);
80       }
81     }
82   }