test_loginNeeded.html (2300B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <script type="application/javascript">var scriptRelativePath = "../";</script> 5 <script type="application/javascript" src="../pc.js"></script> 6 </head> 7 <body> 8 <pre id="test"> 9 <script type="application/javascript"> 10 createHTML({ 11 title: 'RTCPeerConnection identity with login', 12 bug: '1153314' 13 }); 14 15 function waitForLoginDone() { 16 return new Promise(resolve => { 17 window.addEventListener('message', function listener(e) { 18 is(e.origin, 'https://example.com', 'got the right message origin'); 19 is(e.data, 'LOGINDONE', 'got the right message'); 20 window.removeEventListener('message', listener); 21 resolve(); 22 }); 23 }); 24 } 25 26 function checkLogin(t, name, onLoginNeeded) { 27 t.pcLocal.setIdentityProvider('example.com', 28 { protocol: 'idp.js#login:' + name }); 29 return t.pcLocal._pc.getIdentityAssertion() 30 .then(a => ok(false, 'should request login'), 31 e => { 32 is(e.name, 'IdpLoginError', 'name is IdpLoginError'); 33 is(t.pcLocal._pc.idpLoginUrl.split('#')[0], 34 'https://example.com/.well-known/idp-proxy/login.html', 35 'got the right login URL from the IdP'); 36 return t.pcLocal._pc.idpLoginUrl; 37 }) 38 .then(onLoginNeeded) 39 .then(waitForLoginDone) 40 .then(() => t.pcLocal._pc.getIdentityAssertion()) 41 .then(a => ok(a, 'got assertion')); 42 } 43 44 function theTest() { 45 var test = new PeerConnectionTest(); 46 test.setMediaConstraints([{audio: true}], [{audio: true}]); 47 test.chain.removeAfter('PC_REMOTE_CHECK_INITIAL_SIGNALINGSTATE'); 48 test.chain.append([ 49 function PC_LOCAL_IDENTITY_ASSERTION_WITH_IFRAME_LOGIN(t) { 50 return checkLogin(t, 'iframe', loginUrl => { 51 var iframe = document.createElement('iframe'); 52 iframe.setAttribute('src', loginUrl); 53 iframe.frameBorder = 0; 54 iframe.width = 400; 55 iframe.height = 60; 56 document.getElementById('display').appendChild(iframe); 57 }); 58 }, 59 function PC_LOCAL_IDENTITY_ASSERTION_WITH_WINDOW_LOGIN(t) { 60 return checkLogin(t, 'openwin', loginUrl => { 61 window.open(loginUrl, 'login', 'width=400,height=60'); 62 }); 63 } 64 ]); 65 return test.run(); 66 } 67 runNetworkTest(theTest); 68 69 </script> 70 </pre> 71 </body> 72 </html>