From 7f8f597ec4ea30f65bd3ae6473e975569b5500ae Mon Sep 17 00:00:00 2001 From: Martin Thomson Date: Tue, 27 Jan 2015 12:35:58 -0800 Subject: [PATCH] Bug 1119593 - Update identity tests, r=drno --HG-- extra : rebase_source : ef6aeb4bf9223837db2e2763204be40c5ff6a74e --- .../identity/test_getIdentityAssertion.html | 149 +++++++++--------- .../test_peerConnection_peerIdentity.html | 30 ++-- .../identity/test_setIdentityProvider.html | 81 ++++------ .../test_setIdentityProviderWithErrors.html | 78 ++++----- 4 files changed, 149 insertions(+), 189 deletions(-) diff --git a/dom/media/tests/mochitest/identity/test_getIdentityAssertion.html b/dom/media/tests/mochitest/identity/test_getIdentityAssertion.html index a51823bd4670..98464403b949 100644 --- a/dom/media/tests/mochitest/identity/test_getIdentityAssertion.html +++ b/dom/media/tests/mochitest/identity/test_getIdentityAssertion.html @@ -28,85 +28,80 @@ function theTest() { test.setMediaConstraints([{audio: true}], [{audio: true}]); test.chain.removeAfter('PC_REMOTE_CHECK_INITIAL_SIGNALINGSTATE'); test.chain.append([ - [ - "GET_IDENTITY_ASSERTION_FAILS_WITHOUT_PROVIDER", - function(test) { - test.pcLocal._pc.onidpassertionerror = function(e) { - ok(e, "getIdentityAssertion must fail without provider"); - test.next(); - }; - test.pcLocal._pc.getIdentityAssertion(); + function GET_IDENTITY_ASSERTION_FAILS_WITHOUT_PROVIDER(test) { + return new Promise(resolve => { + test.pcLocal._pc.onidpassertionerror = function(e) { + ok(e, "getIdentityAssertion must fail without provider"); + resolve(); + }; + test.pcLocal._pc.getIdentityAssertion(); + }); }, - ], - [ - "GET_IDENTITY_ASSERTION_FIRES_EVENTUALLY_AND_SUBSEQUENTLY", - function(test) { - var fired = 0; - test.setIdentityProvider(test.pcLocal, 'example.com', 'idp.html'); - test.pcLocal._pc.onidentityresult = function(e) { - fired++; - if (fired == 1) { - ok(true, "identityresult fired"); - checkIdentity(e.assertion, 'someone@example.com'); - } else if (fired == 2) { - ok(true, "identityresult fired 2x"); - checkIdentity(e.assertion, 'someone@example.com'); - test.next(); - } - }; - test.pcLocal._pc.onidpassertionerror = function(e) { - ok(false, "error event fired"); - test.next(); - }; - test.pcLocal._pc.getIdentityAssertion(); - test.pcLocal._pc.getIdentityAssertion(); + function GET_IDENTITY_ASSERTION_FIRES_EVENTUALLY_AND_SUBSEQUENTLY(test) { + return new Promise(resolve => { + var fired = 0; + test.setIdentityProvider(test.pcLocal, 'example.com', 'idp.html'); + test.pcLocal._pc.onidentityresult = function(e) { + fired++; + if (fired == 1) { + ok(true, "identityresult fired"); + checkIdentity(e.assertion, 'someone@example.com'); + } else if (fired == 2) { + ok(true, "identityresult fired 2x"); + checkIdentity(e.assertion, 'someone@example.com'); + resolve(); + } + }; + test.pcLocal._pc.onidpassertionerror = function(e) { + ok(false, "error event fired"); + resolve(); + }; + test.pcLocal._pc.getIdentityAssertion(); + test.pcLocal._pc.getIdentityAssertion(); + }); + }, + function GET_IDENTITY_ASSERTION_FAILS(test) { + return new Promise(resolve => { + test.setIdentityProvider(test.pcLocal, 'example.com', 'idp.html#error'); + test.pcLocal._pc.onidentityresult = function(e) { + ok(false, "Should not get an identity result"); + resolve(); + }; + test.pcLocal._pc.onidpassertionerror = function(err) { + ok(err, "Got error event from getIdentityAssertion"); + resolve(); + }; + test.pcLocal._pc.getIdentityAssertion(); + }); + }, + function GET_IDENTITY_ASSERTION_IDP_NOT_READY(test) { + return new Promise(resolve => { + test.setIdentityProvider(test.pcLocal, 'example.com', 'idp.html#error:ready'); + test.pcLocal._pc.onidentityresult = function(e) { + ok(false, "Should not get an identity result"); + resolve(); + }; + test.pcLocal._pc.onidpassertionerror = function(e) { + ok(e, "Got error callback from getIdentityAssertion"); + resolve(); + }; + test.pcLocal._pc.getIdentityAssertion(); + }); + }, + function GET_IDENTITY_ASSERTION_WITH_SPECIFIC_NAME(test) { + return new Promise(resolve => { + test.setIdentityProvider(test.pcLocal, 'example.com', 'idp.html', 'user@example.com'); + test.pcLocal._pc.onidentityresult = function(e) { + checkIdentity(e.assertion, 'user@example.com'); + resolve(); + }; + test.pcLocal._pc.onidpassertionerror = function(e) { + ok(false, "Got error callback from getIdentityAssertion"); + resolve(); + }; + test.pcLocal._pc.getIdentityAssertion(); + }); } - ], - [ - "GET_IDENTITY_ASSERTION_FAILS", - function(test) { - test.setIdentityProvider(test.pcLocal, 'example.com', 'idp.html#error'); - test.pcLocal._pc.onidentityresult = function(e) { - ok(false, "Should not get an identity result"); - test.next(); - }; - test.pcLocal._pc.onidpassertionerror = function(err) { - ok(err, "Got error event from getIdentityAssertion"); - test.next(); - }; - test.pcLocal._pc.getIdentityAssertion(); - } - ], - [ - "GET_IDENTITY_ASSERTION_IDP_NOT_READY", - function(test) { - test.setIdentityProvider(test.pcLocal, 'example.com', 'idp.html#error:ready'); - test.pcLocal._pc.onidentityresult = function(e) { - ok(false, "Should not get an identity result"); - test.next(); - }; - test.pcLocal._pc.onidpassertionerror = function(e) { - ok(e, "Got error callback from getIdentityAssertion"); - test.next(); - }; - test.pcLocal._pc.getIdentityAssertion(); - } - ], - [ - "GET_IDENTITY_ASSERTION_WITH_SPECIFIC_NAME", - function(test) { - test.setIdentityProvider(test.pcLocal, 'example.com', 'idp.html', 'user@example.com'); - test.pcLocal._pc.onidentityresult = function(e) { - checkIdentity(e.assertion, 'user@example.com'); - test.next(); - }; - test.pcLocal._pc.onidpassertionerror = function(e) { - ok(false, "Got error callback from getIdentityAssertion"); - test.next(); - }; - test.pcLocal._pc.getIdentityAssertion(); - } - ] ]); test.run(); } diff --git a/dom/media/tests/mochitest/identity/test_peerConnection_peerIdentity.html b/dom/media/tests/mochitest/identity/test_peerConnection_peerIdentity.html index f2eb201a5bb3..9ceb046cfc60 100644 --- a/dom/media/tests/mochitest/identity/test_peerConnection_peerIdentity.html +++ b/dom/media/tests/mochitest/identity/test_peerConnection_peerIdentity.html @@ -48,9 +48,8 @@ function theTest() { test.setIdentityProvider(test.pcLocal, 'test1.example.com', 'idp.html'); test.setIdentityProvider(test.pcRemote, 'test2.example.com', 'idp.html'); test.chain.append([ - [ - "PEER_IDENTITY_IS_SET_CORRECTLY", - function(test) { + + function PEER_IDENTITY_IS_SET_CORRECTLY(test) { // no need to wait to check identity in this case, // setRemoteDescription should wait for the IdP to complete function checkIdentity(pc, pfx, idp, name) { @@ -60,26 +59,15 @@ function theTest() { checkIdentity(test.pcLocal._pc, "local: ", "test2.example.com", "someone"); checkIdentity(test.pcRemote._pc, "remote: ", "test1.example.com", "someone"); - test.next(); - } - ], - [ - "REMOTE_STREAMS_ARE_RESTRICTED", - function(test) { - var remoteStream = test.pcLocal._pc.getRemoteStreams()[0]; - var oneDone = false; - function done() { - if (!oneDone) { - oneDone = true; - return; - } - test.next(); - } + }, - audioIsSilence(true, remoteStream, done); - videoIsBlack(true, remoteStream, done); + function REMOTE_STREAMS_ARE_RESTRICTED(test) { + var remoteStream = test.pcLocal._pc.getRemoteStreams()[0]; + return Promise.all([ + new Promise(done => audioIsSilence(true, remoteStream, done)), + new Promise(done => videoIsBlack(true, remoteStream, done)) + ]); } - ], ]); test.run(); } diff --git a/dom/media/tests/mochitest/identity/test_setIdentityProvider.html b/dom/media/tests/mochitest/identity/test_setIdentityProvider.html index 735bfc97de49..0ce21445c007 100644 --- a/dom/media/tests/mochitest/identity/test_setIdentityProvider.html +++ b/dom/media/tests/mochitest/identity/test_setIdentityProvider.html @@ -27,81 +27,66 @@ function theTest() { var remoteEvents = trapIdentityEvents(test.pcRemote._pc); test.chain.append([ - [ - "PEER_IDENTITY_IS_SET_CORRECTLY", - function(test) { + function PEER_IDENTITY_IS_SET_CORRECTLY(test) { var outstanding = 0; // we have to wait for the identity result in order to get the actual // identity information, since the call will complete before the identity // provider has a chance to finish verifying... that's OK, but it makes // testing more difficult - function checkOrSetupCheck(pc, pfx, idp, name) { + function checkOrSetupCheck(pc, prefix, idp, name) { function checkIdentity() { - ok(pc.peerIdentity, pfx + "peerIdentity is set"); - is(pc.peerIdentity.idp, idp, pfx + "IdP is correct"); - is(pc.peerIdentity.name, name + "@" + idp, pfx + "identity is correct"); + ok(pc.peerIdentity, prefix + "peerIdentity is set"); + is(pc.peerIdentity.idp, idp, prefix + "IdP is correct"); + is(pc.peerIdentity.name, name + "@" + idp, prefix + "identity is correct"); } if (pc.peerIdentity) { - info(pfx + "peerIdentity already set"); + info(prefix + "peerIdentity already set"); checkIdentity(); - } else { - ++outstanding; - info(pfx + "setting onpeeridentity handler"); - pc.onpeeridentity = function checkIdentityEvent(e) { - info(pfx + "checking peerIdentity"); - checkIdentity(); - --outstanding; - if (outstanding <= 0) { - test.next(); - } - }; + return Promise.resolve(); } + + return new Promise(resolve => { + info(prefix + "setting onpeeridentity handler"); + pc.onpeeridentity = e => { + checkIdentity(); + resolve(); + }; + }); } - checkOrSetupCheck(test.pcLocal._pc, "local: ", "test2.example.com", "someone"); - checkOrSetupCheck(test.pcRemote._pc, "remote: ", "test1.example.com", "someone"); - if (outstanding <= 0) { - test.next(); - } - } - ], - [ - "CHECK_IDENTITY_EVENTS", - function(test) { + return Promise.all([ + checkOrSetupCheck(test.pcLocal._pc, "local: ", "test2.example.com", "someone"), + checkOrSetupCheck(test.pcRemote._pc, "remote: ", "test1.example.com", "someone") + ]); + }, + + function CHECK_IDENTITY_EVENTS(test) { ok(!localEvents.idpassertionerror , "No assertion generation errors on local"); ok(!remoteEvents.idpassertionerror, "No assertion generation errors on remote"); ok(!localEvents.idpvalidationerror, "No assertion validation errors on local"); - ok( !remoteEvents.idpvalidationerror, "No assertion validation errors on remote"); + ok(!remoteEvents.idpvalidationerror, "No assertion validation errors on remote"); ok(localEvents.identityresult, "local acquired identity assertions"); ok(remoteEvents.identityresult, "remote acquired identity assertions"); ok(localEvents.peeridentity, "local got peer identity"); ok(remoteEvents.peeridentity, "remote got peer identity"); - test.next(); - } - ], - [ - "OFFERS_AND_ANSWERS_INCLUDE_IDENTITY", - function(test) { + }, + + function OFFERS_AND_ANSWERS_INCLUDE_IDENTITY(test) { ok(test.originalOffer.sdp.contains("a=identity"), "a=identity is in the offer SDP"); ok(test.originalAnswer.sdp.contains("a=identity"), "a=identity is in the answer SDP"); - test.next(); - } - ], - [ - "DESCRIPTIONS_CONTAIN_IDENTITY", - function(test) { + }, + + function DESCRIPTIONS_CONTAIN_IDENTITY(test) { ok(test.pcLocal.localDescription.sdp.contains("a=identity"), - "a=identity is in the local copy of the offer"); + "a=identity is in the local copy of the offer"); ok(test.pcRemote.localDescription.sdp.contains("a=identity"), - "a=identity is in the remote copy of the offer"); + "a=identity is in the remote copy of the offer"); ok(test.pcLocal.remoteDescription.sdp.contains("a=identity"), - "a=identity is in the local copy of the answer"); + "a=identity is in the local copy of the answer"); ok(test.pcRemote.remoteDescription.sdp.contains("a=identity"), - "a=identity is in the remote copy of the answer"); - test.next(); + "a=identity is in the remote copy of the answer"); } - ] ]); test.run(); } diff --git a/dom/media/tests/mochitest/identity/test_setIdentityProviderWithErrors.html b/dom/media/tests/mochitest/identity/test_setIdentityProviderWithErrors.html index 45b798ff5300..f9e7e7334cb4 100644 --- a/dom/media/tests/mochitest/identity/test_setIdentityProviderWithErrors.html +++ b/dom/media/tests/mochitest/identity/test_setIdentityProviderWithErrors.html @@ -28,53 +28,45 @@ runNetworkTest(function () { var remoteEvents = trapIdentityEvents(test.pcRemote._pc); test.chain.append([ - [ - 'CHECK_IDENTITY_EVENTS', - function(test) { - function checkEvents() { - ok(localEvents.idpassertionerror, 'local assertion generation should fail (idpassertionerror)'); - is(localEvents.idpassertionerror.idp, 'example.com', 'event IdP is correct'); - is(localEvents.idpassertionerror.protocol, 'idp.html#error', 'event IdP protocol is #error'); - ok(!remoteEvents.idpassertionerror, 'remote assertion generation should succeed (idpassertionerror)'); - ok(!localEvents.identityresult, 'local assertion generation should fail (identityresult)'); - ok(remoteEvents.identityresult, 'remote assertion generation should succeed (identityresult)'); + function CHECK_IDENTITY_EVENTS(test) { + function checkEvents() { + ok(localEvents.idpassertionerror, 'local assertion generation should fail (idpassertionerror)'); + is(localEvents.idpassertionerror.idp, 'example.com', 'event IdP is correct'); + is(localEvents.idpassertionerror.protocol, 'idp.html#error', 'event IdP protocol is #error'); + ok(!remoteEvents.idpassertionerror, 'remote assertion generation should succeed (idpassertionerror)'); + ok(!localEvents.identityresult, 'local assertion generation should fail (identityresult)'); + ok(remoteEvents.identityresult, 'remote assertion generation should succeed (identityresult)'); - ok(!localEvents.peeridentity, 'no peer identity event for local peer'); - ok(!remoteEvents.peeridentity, 'no peer identity event for remote peer'); - ok(localEvents.idpvalidationerror, 'local fails to validate'); - is(localEvents.idpvalidationerror.idp, 'example.com', 'event IdP is correct'); - is(localEvents.idpvalidationerror.protocol, 'idp.html#bad', 'event IdP protocol is #bad'); - ok(!remoteEvents.idpvalidationerror, 'remote doesn\'t even see an assertion'); + ok(!localEvents.peeridentity, 'no peer identity event for local peer'); + ok(!remoteEvents.peeridentity, 'no peer identity event for remote peer'); + ok(localEvents.idpvalidationerror, 'local fails to validate'); + is(localEvents.idpvalidationerror.idp, 'example.com', 'event IdP is correct'); + is(localEvents.idpvalidationerror.protocol, 'idp.html#bad', 'event IdP protocol is #bad'); + ok(!remoteEvents.idpvalidationerror, 'remote doesn\'t even see an assertion'); - test.next(); - } + } - // we actually have to wait on this because IdP validation happens asynchronously - if (localEvents.idpvalidationerror) { - checkEvents(); - } else { - // have to let the other event handler have a chance to record success - // before we run the checks that rely on that recording - test.pcLocal._pc.onidpvalidationerror = setTimeout.bind(window, checkEvents, 1); - } + // we actually have to wait on this because IdP validation happens asynchronously + if (localEvents.idpvalidationerror) { + checkEvents(); + return Promise.resolve(); } - ], - [ - 'PEER_IDENTITY_IS_EMPTY', - function(test) { - ok(!test.pcLocal._pc.peerIdentity, 'local peerIdentity is not set'); - ok(!test.pcRemote._pc.peerIdentity, 'remote peerIdentity is not set'); - test.next(); - } - ], - [ - 'ONLY_REMOTE_SDP_INCLUDES_IDENTITY_ASSERTION', - function(test) { - ok(!test.originalOffer.sdp.contains('a=identity'), 'a=identity not contained in the offer SDP'); - ok(test.originalAnswer.sdp.contains('a=identity'), 'a=identity is contained in the answer SDP'); - test.next(); - } - ] + // have to let the other event handler have a chance to record success + // before we run the checks that rely on that recording + return new Promise(resolve => { + test.pcLocal._pc.onidpvalidationerror = resolve; + }).then(checkEvents); + }, + + function PEER_IDENTITY_IS_EMPTY(test) { + ok(!test.pcLocal._pc.peerIdentity, 'local peerIdentity is not set'); + ok(!test.pcRemote._pc.peerIdentity, 'remote peerIdentity is not set'); + }, + + function ONLY_REMOTE_SDP_INCLUDES_IDENTITY_ASSERTION(test) { + ok(!test.originalOffer.sdp.contains('a=identity'), 'a=identity not contained in the offer SDP'); + ok(test.originalAnswer.sdp.contains('a=identity'), 'a=identity is contained in the answer SDP'); + } ]); test.run(); });