Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> | 1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> |
| 2 <html> | 2 <html> |
| 3 <head> | 3 <head> |
| 4 <script src="../../resources/js-test.js"></script> | 4 <script src="../../resources/testharness.js"></script> |
| 5 <!-- TODO(guidou): Convert test to testharness.js. crbug.com/614963 --> | 5 <script src="../../resources/testharnessreport.js"></script> |
| 6 </head> | 6 </head> |
| 7 <body> | 7 <body> |
| 8 <script> | 8 <script> |
| 9 description("Tests the RTCPeerConnection Ice functionality."); | |
| 10 | |
| 11 var pc = null; | 9 var pc = null; |
| 12 var iceCandidate = null; | 10 var iceCandidate = null; |
| 11 var calledCallbacks = []; | |
| 13 | 12 |
| 14 function onIceChange2() | 13 function onIceChange2() |
| 15 { | 14 { |
| 16 if (pc.iceConnectionState === "closed") { | 15 if (pc.iceConnectionState === "closed") { |
| 17 testPassed("iceConnectionState is closed."); | 16 calledCallbacks.push("iceConnectionState closed"); |
| 18 finishJSTest(); | 17 assert_array_equals(calledCallbacks, [ |
| 18 'iceConnectionState complete', | |
| 19 'expectedTypeError', | |
| 20 'expectedTypeError', | |
| 21 'expectedTypeError', | |
| 22 'expectedTypeError', | |
| 23 'success1', | |
| 24 'success2', | |
| 25 'success3', | |
| 26 'success4', | |
| 27 'iceConnectionState closed' | |
| 28 ]); | |
| 29 testRTC.done(); | |
|
qyearsley
2016/08/26 00:49:38
To make this more explicitly refer to the global v
jeffcarp
2016/08/26 01:26:40
I like that.
| |
| 19 } | 30 } |
| 20 } | 31 } |
| 21 | 32 |
| 22 function addIceCandidateSuccess1() | 33 function addIceCandidateSuccess1() |
| 23 { | 34 { |
| 24 testPassed("addIceCandidateSuccess1 was called."); | 35 calledCallbacks.push('success1'); |
| 25 shouldNotThrow('pc.addIceCandidate({candidate: "candidate", sdpMid: 0}, addI ceCandidateSuccess2, unexpectedCallback);'); | 36 pc.addIceCandidate({candidate: "candidate", sdpMid: 0}, addIceCandidateSucce ss2, unexpectedCallback); |
| 26 } | 37 } |
| 27 | 38 |
| 28 function addIceCandidateSuccess2() | 39 function addIceCandidateSuccess2() |
| 29 { | 40 { |
| 30 testPassed("addIceCandidateSuccess2 was called."); | 41 calledCallbacks.push('success2'); |
| 31 shouldNotThrow('pc.addIceCandidate({candidate: "candidate", sdpMLineIndex: 0 }, addIceCandidateSuccess3, unexpectedCallback);'); | 42 pc.addIceCandidate({candidate: "candidate", sdpMLineIndex: 0}, addIceCandida teSuccess3, unexpectedCallback); |
| 32 } | 43 } |
| 33 | 44 |
| 34 function addIceCandidateSuccess3() | 45 function addIceCandidateSuccess3() |
| 35 { | 46 { |
| 36 testPassed("addIceCandidateSuccess3 was called."); | 47 calledCallbacks.push('success3'); |
| 37 shouldNotThrow('pc.addIceCandidate({candidate: "candidate", sdpMid: 0, sdpML ineIndex: 0}, addIceCandidateSuccess4, unexpectedCallback);'); | 48 pc.addIceCandidate({candidate: "candidate", sdpMid: 0, sdpMLineIndex: 0}, ad dIceCandidateSuccess4, unexpectedCallback); |
| 38 } | 49 } |
| 39 | 50 |
| 40 function addIceCandidateSuccess4() | 51 function addIceCandidateSuccess4() |
| 41 { | 52 { |
| 42 testPassed("addIceCandidateSuccess4 was called."); | 53 calledCallbacks.push('success4'); |
| 43 pc.oniceconnectionstatechange = onIceChange2; | 54 pc.oniceconnectionstatechange = onIceChange2; |
| 44 pc.close(); | 55 pc.close(); |
| 45 } | 56 } |
| 46 | 57 |
| 47 function unexpectedCallback() | 58 function unexpectedCallback() |
| 48 { | 59 { |
| 49 testFailed("unexpectedCallback was called."); | 60 calledCallbacks.push('unexpected'); |
| 50 finishJSTest(); | |
| 51 } | 61 } |
| 52 | 62 |
| 53 function expectedTypeError(error) | 63 function expectedTypeError(error) |
| 54 { | 64 { |
| 55 window.error = error; | 65 window.error = error; |
|
qyearsley
2016/08/26 00:49:38
Looks like we may be able to remove window.error;
jeffcarp
2016/08/26 01:26:40
It's not used elsewhere, so it looks like we can,
| |
| 56 shouldBe('error.name', '"TypeError"'); | 66 assert_equals(error.name, 'TypeError'); |
| 57 testPassed("expectedTypeError was called."); | 67 calledCallbacks.push('expectedTypeError'); |
| 58 } | 68 } |
| 59 | 69 |
| 60 function onIceChange1() | 70 function onIceChange1() |
| 61 { | 71 { |
| 62 if (pc.iceConnectionState === "completed") { | 72 if (pc.iceConnectionState === "completed") { |
| 63 testPassed("iceConnectionState is completed"); | 73 calledCallbacks.push('iceConnectionState complete'); |
| 64 iceCandidate = new RTCIceCandidate({candidate:"nano nano"}); | 74 iceCandidate = new RTCIceCandidate({candidate: "nano nano"}); |
| 65 shouldNotThrow('pc.addIceCandidate(null, unexpectedCallback, unexpectedC allback).catch(expectedTypeError);'); | 75 pc.addIceCandidate(null, unexpectedCallback, unexpectedCallback).catch(e xpectedTypeError); |
| 66 shouldNotThrow('pc.addIceCandidate({candidate: "candidate"}, unexpectedC allback, unexpectedCallback).catch(expectedTypeError);'); | 76 pc.addIceCandidate({candidate: "candidate"}, unexpectedCallback, unexpec tedCallback).catch(expectedTypeError); |
| 67 shouldNotThrow('pc.addIceCandidate(iceCandidate, null, unexpectedCallbac k).catch(expectedTypeError);'); | 77 pc.addIceCandidate(iceCandidate, null, unexpectedCallback).catch(expecte dTypeError); |
| 68 shouldNotThrow('pc.addIceCandidate(iceCandidate, unexpectedCallback, nul l).catch(expectedTypeError);'); | 78 pc.addIceCandidate(iceCandidate, unexpectedCallback, null).catch(expecte dTypeError); |
| 69 shouldNotThrow('pc.addIceCandidate(iceCandidate, addIceCandidateSuccess1 , unexpectedCallback);'); | 79 pc.addIceCandidate(iceCandidate, addIceCandidateSuccess1, unexpectedCall back); |
| 70 } | 80 } |
| 71 } | 81 } |
| 72 | 82 |
| 73 function testExecutionOrderClosedConnection() | 83 function testExecutionOrderClosedConnection() |
| 74 { | 84 { |
| 75 var localPeerConnection = new webkitRTCPeerConnection(null, null); | 85 var localPeerConnection = new webkitRTCPeerConnection(null, null); |
| 76 localPeerConnection.close(); | 86 localPeerConnection.close(); |
| 77 var counter = 0; | 87 var counter = 0; |
| 78 window.events = []; | 88 window.events = []; |
| 79 Promise.resolve().then(_ => events[counter++] = 1); | 89 Promise.resolve().then(_ => events[counter++] = 1); |
| 80 var iceCandidate = new RTCIceCandidate({candidate:"nano nano"}); | 90 var iceCandidate = new RTCIceCandidate({candidate:"nano nano"}); |
| 81 localPeerConnection.addIceCandidate(iceCandidate, unexpectedCallback, error => { | 91 localPeerConnection.addIceCandidate(iceCandidate, unexpectedCallback, error => { |
| 82 window.error = error; | 92 window.error = error; |
| 83 shouldBe('error.name', '"InvalidStateError"'); | 93 assert_equals(error.name, 'InvalidStateError'); |
| 84 shouldBe('error.toString()', '"InvalidStateError: The RTCPeerConnection\ 's signalingState is \'closed\'."'); | 94 assert_equals(error.toString(), 'InvalidStateError: The RTCPeerConnectio n\'s signalingState is \'closed\'.'); |
| 85 events[counter++] = 2; | 95 events[counter++] = 2; |
| 86 }); | 96 }); |
| 87 Promise.resolve().then(_ => { | 97 Promise.resolve().then(_ => { |
| 88 events[counter++] = 3; | 98 events[counter++] = 3; |
| 89 shouldBe('events', '[1,2,3]'); | 99 assert_array_equals(events, [1, 2, 3]); |
| 90 }); | 100 }); |
| 91 } | 101 } |
| 92 | 102 |
| 93 shouldNotThrow('testExecutionOrderClosedConnection()'); | 103 window.testRTC = async_test("Tests the RTCPeerConnection Ice functionality."); |
|
qyearsley
2016/08/26 00:49:38
For consistency, it seems like we should declare a
jeffcarp
2016/08/26 01:26:40
I'll check if there's a convention in other tests
| |
| 94 shouldNotThrow('pc = new webkitRTCPeerConnection(null, null);'); | 104 |
| 105 testExecutionOrderClosedConnection(); | |
| 106 pc = new webkitRTCPeerConnection(null, null); | |
| 95 pc.oniceconnectionstatechange = onIceChange1; | 107 pc.oniceconnectionstatechange = onIceChange1; |
| 96 | |
| 97 window.jsTestIsAsync = true; | |
| 98 window.successfullyParsed = true; | |
| 99 </script> | 108 </script> |
| 100 </body> | 109 </body> |
| 101 </html> | 110 </html> |
| OLD | NEW |