From 1dd29cc1eed0cb09de8fbc52414ee445338d44bf Mon Sep 17 00:00:00 2001 From: Masatoshi Kimura Date: Wed, 21 Oct 2015 15:23:00 -0400 Subject: [PATCH] Bug 1214981 - Disable output stream buffering. r=keeler --- .../ssl/tests/unit/test_weak_crypto.js | 43 +++++++++---------- security/manager/ssl/tests/unit/xpcshell.ini | 1 - 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/security/manager/ssl/tests/unit/test_weak_crypto.js b/security/manager/ssl/tests/unit/test_weak_crypto.js index d93fe7c6213..ab3bfaca18f 100644 --- a/security/manager/ssl/tests/unit/test_weak_crypto.js +++ b/security/manager/ssl/tests/unit/test_weak_crypto.js @@ -103,8 +103,6 @@ function storeCertOverride(port, cert) { } function startClient(port, expectedResult, options = {}) { - let SSL_ERROR_BASE = Ci.nsINSSErrorsService.NSS_SSL_ERROR_BASE; - let SSL_ERROR_BAD_CERT_ALERT = SSL_ERROR_BASE + 17; let transport = socketTransportService.createTransport(["ssl"], 1, "127.0.0.1", port, null); if (options.isPrivate) { @@ -113,8 +111,7 @@ function startClient(port, expectedResult, options = {}) { let input; let output; - let inputDeferred = Promise.defer(); - let outputDeferred = Promise.defer(); + let deferred = Promise.defer(); let handler = { @@ -125,46 +122,48 @@ function startClient(port, expectedResult, options = {}) { }, onInputStreamReady: function(input) { - let errorCode = Cr.NS_OK; try { let data = NetUtil.readInputStreamToString(input, input.available()); equal(data, "HELLO", "Echoed data received"); input.close(); output.close(); + deferred.resolve(); } catch (e) { - errorCode = e.result; - } - try { - equal(errorCode, expectedResult, - "Actual and expected connection result should match"); - inputDeferred.resolve(); - } catch (e) { - inputDeferred.reject(e); + deferred.reject(e); } }, onOutputStreamReady: function(output) { try { - output.write("HELLO", 5); + try { + output.write("HELLO", 5); + } catch (e) { + if (e.result == Cr.NS_BASE_STREAM_WOULD_BLOCK) { + output.asyncWait(handler, 0, 0, Services.tm.currentThread); + return; + } + equal(e.result, expectedResult, + "Actual and expected connection result should match"); + output.close(); + deferred.resolve(); + return; + } + equal(Cr.NS_OK, expectedResult, "Connection should succeed"); do_print("Output to server written"); - outputDeferred.resolve(); input = transport.openInputStream(0, 0, 0); input.asyncWait(handler, 0, 0, Services.tm.currentThread); } catch (e) { - let errorCode = -1 * (e.result & 0xFFFF); - if (errorCode == SSL_ERROR_BAD_CERT_ALERT) { - do_print("Server doesn't like client cert"); - } - outputDeferred.reject(e); + deferred.reject(e); } } }; transport.setEventSink(handler, Services.tm.currentThread); - output = transport.openOutputStream(0, 0, 0); + output = transport.openOutputStream(Ci.nsITransport.OPEN_UNBUFFERED, 0, 0); + output.QueryInterface(Ci.nsIAsyncOutputStream); - return Promise.all([inputDeferred.promise, outputDeferred.promise]); + return deferred.promise; } function run_test() { diff --git a/security/manager/ssl/tests/unit/xpcshell.ini b/security/manager/ssl/tests/unit/xpcshell.ini index 30b456e22f0..4b7d1d88383 100644 --- a/security/manager/ssl/tests/unit/xpcshell.ini +++ b/security/manager/ssl/tests/unit/xpcshell.ini @@ -152,4 +152,3 @@ skip-if = toolkit == 'android' || buildapp == 'b2g' [test_weak_crypto.js] firefox-appdir = browser -skip-if = toolkit == 'android'