Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <head> |
michael@0 | 4 | <title>Test bug 480619</title> |
michael@0 | 5 | <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 6 | <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" /> |
michael@0 | 7 | </head> |
michael@0 | 8 | <body> |
michael@0 | 9 | |
michael@0 | 10 | <script class="testbody" type="text/javascript"> |
michael@0 | 11 | |
michael@0 | 12 | const Cc = Components.classes; |
michael@0 | 13 | const Ci = Components.interfaces; |
michael@0 | 14 | |
michael@0 | 15 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 16 | |
michael@0 | 17 | var currentThread = Cc["@mozilla.org/thread-manager;1"]. |
michael@0 | 18 | getService(Ci.nsIThreadManager). |
michael@0 | 19 | currentThread; |
michael@0 | 20 | var socketTransportService = Cc["@mozilla.org/network/socket-transport-service;1"]. |
michael@0 | 21 | getService(Ci.nsISocketTransportService); |
michael@0 | 22 | |
michael@0 | 23 | var tearDown = false; |
michael@0 | 24 | |
michael@0 | 25 | var reader = { |
michael@0 | 26 | onInputStreamReady: function(stream) { |
michael@0 | 27 | try { |
michael@0 | 28 | stream.available(); |
michael@0 | 29 | SimpleTest.ok(false, "Stream should be in an error state"); |
michael@0 | 30 | } |
michael@0 | 31 | catch (e) { |
michael@0 | 32 | SimpleTest.is(e.result, Components.results.NS_ERROR_FAILURE, |
michael@0 | 33 | "The stream should be inside an error state"); |
michael@0 | 34 | SimpleTest.ok(tearDown, "The stream should be closed after a teardown of secure decoder ring"); |
michael@0 | 35 | } |
michael@0 | 36 | SimpleTest.finish(); |
michael@0 | 37 | } |
michael@0 | 38 | }; |
michael@0 | 39 | |
michael@0 | 40 | var sink = { |
michael@0 | 41 | onTransportStatus: function(transport, status, progress, progressmax) { |
michael@0 | 42 | if (status == Ci.nsISocketTransport.STATUS_CONNECTED_TO) { |
michael@0 | 43 | // Try to logout and tear down the secure decoder ring. |
michael@0 | 44 | // This should close and stream and notify the reader. |
michael@0 | 45 | // The test will time out if this fails. |
michael@0 | 46 | tearDown = true; |
michael@0 | 47 | Cc["@mozilla.org/security/sdr;1"]. |
michael@0 | 48 | getService(Ci.nsISecretDecoderRing). |
michael@0 | 49 | logoutAndTeardown(); |
michael@0 | 50 | } |
michael@0 | 51 | } |
michael@0 | 52 | }; |
michael@0 | 53 | |
michael@0 | 54 | var transport = socketTransportService.createTransport(["ssl"], 1, "127.0.0.1", 4443, null); |
michael@0 | 55 | |
michael@0 | 56 | transport.setEventSink(sink, currentThread); |
michael@0 | 57 | |
michael@0 | 58 | var inStream = transport.openInputStream(0, 0, 0) |
michael@0 | 59 | .QueryInterface(Ci.nsIAsyncInputStream); |
michael@0 | 60 | |
michael@0 | 61 | inStream.asyncWait(reader, Ci.nsIAsyncInputStream.WAIT_CLOSURE_ONLY, 0, currentThread); |
michael@0 | 62 | |
michael@0 | 63 | </script> |
michael@0 | 64 | </body> |
michael@0 | 65 | </html> |