|
1 Cu.import("resource://testing-common/httpd.js"); |
|
2 |
|
3 const BUGID = "369787"; |
|
4 var server = null; |
|
5 var channel = null; |
|
6 |
|
7 function change_content_type() { |
|
8 var origType = channel.contentType; |
|
9 const newType = "x-foo/x-bar"; |
|
10 channel.contentType = newType; |
|
11 do_check_eq(channel.contentType, newType); |
|
12 channel.contentType = origType; |
|
13 do_check_eq(channel.contentType, origType); |
|
14 } |
|
15 |
|
16 function TestListener() { |
|
17 } |
|
18 TestListener.prototype.onStartRequest = function(request, context) { |
|
19 try { |
|
20 // request might be different from channel |
|
21 channel = request.QueryInterface(Components.interfaces.nsIChannel); |
|
22 |
|
23 change_content_type(); |
|
24 } catch (ex) { |
|
25 print(ex); |
|
26 throw ex; |
|
27 } |
|
28 } |
|
29 TestListener.prototype.onStopRequest = function(request, context, status) { |
|
30 try { |
|
31 change_content_type(); |
|
32 } catch (ex) { |
|
33 print(ex); |
|
34 // don't re-throw ex to avoid hanging the test |
|
35 } |
|
36 |
|
37 do_timeout(0, after_channel_closed); |
|
38 } |
|
39 |
|
40 function after_channel_closed() { |
|
41 try { |
|
42 change_content_type(); |
|
43 } finally { |
|
44 server.stop(do_test_finished); |
|
45 } |
|
46 } |
|
47 |
|
48 function run_test() { |
|
49 // start server |
|
50 server = new HttpServer(); |
|
51 |
|
52 server.registerPathHandler("/bug" + BUGID, bug369787); |
|
53 |
|
54 server.start(-1); |
|
55 |
|
56 // make request |
|
57 channel = |
|
58 Components.classes["@mozilla.org/network/io-service;1"]. |
|
59 getService(Components.interfaces.nsIIOService). |
|
60 newChannel("http://localhost:" + |
|
61 server.identity.primaryPort + "/bug" + BUGID, null, null); |
|
62 |
|
63 channel.QueryInterface(Components.interfaces.nsIHttpChannel); |
|
64 channel.asyncOpen(new TestListener(), null); |
|
65 |
|
66 do_test_pending(); |
|
67 } |
|
68 |
|
69 // PATH HANDLER FOR /bug369787 |
|
70 function bug369787(metadata, response) { |
|
71 /* do nothing */ |
|
72 } |