|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <head> |
|
4 <meta charset="utf-8"> |
|
5 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> |
|
6 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
7 <script type="application/javascript" src="head.js"></script> |
|
8 </head> |
|
9 <body> |
|
10 <pre id="test"> |
|
11 <script type="application/javascript;version=1.8"> |
|
12 createHTML({ |
|
13 bug: "857765", |
|
14 title: "Throw in PeerConnection callbacks" |
|
15 }); |
|
16 |
|
17 let error_count = 0; |
|
18 let oldOnError = window.onerror; |
|
19 window.onerror = function (errorMsg, url, lineNumber) { |
|
20 if (errorMsg.indexOf("Expected") == -1) { |
|
21 getFail()(errorMsg); |
|
22 } |
|
23 error_count += 1; |
|
24 info("onerror " + error_count + ": " + errorMsg); |
|
25 if (error_count == 7) { |
|
26 finish(); |
|
27 } |
|
28 throw new Error("window.onerror may throw"); |
|
29 return false; |
|
30 } |
|
31 |
|
32 let pc0, pc1, pc2; |
|
33 |
|
34 runTest(function () { |
|
35 error_count = 0; |
|
36 |
|
37 // Test failure callbacks (limited to 1 for now) |
|
38 pc0 = new mozRTCPeerConnection(); |
|
39 pc0.createOffer(getFail(), function(err) { |
|
40 pc1 = new mozRTCPeerConnection(); |
|
41 pc2 = new mozRTCPeerConnection(); |
|
42 |
|
43 // Test success callbacks (happy path) |
|
44 navigator.mozGetUserMedia({video:true, fake: true}, function(video1) { |
|
45 pc1.addStream(video1); |
|
46 pc1.createOffer(function(offer) { |
|
47 pc1.setLocalDescription(offer, function() { |
|
48 pc2.setRemoteDescription(offer, function() { |
|
49 pc2.createAnswer(function(answer) { |
|
50 pc2.setLocalDescription(answer, function() { |
|
51 pc1.setRemoteDescription(answer, function() { |
|
52 throw new Error("Expected"); |
|
53 }, getFail()); |
|
54 throw new Error("Expected"); |
|
55 }, getFail()); |
|
56 throw new Error("Expected"); |
|
57 }, getFail()); |
|
58 throw new Error("Expected"); |
|
59 }, getFail()); |
|
60 throw new Error("Expected"); |
|
61 }, getFail()); |
|
62 throw new Error("Expected"); |
|
63 }, getFail()); |
|
64 }, getFail()); |
|
65 throw new Error("Expected"); |
|
66 }); |
|
67 }); |
|
68 |
|
69 function finish() { |
|
70 window.onerror = oldOnError; |
|
71 is(error_count, 7, "Seven expected errors verified."); |
|
72 SimpleTest.finish(); |
|
73 } |
|
74 |
|
75 function getFail() { |
|
76 return function (err) { |
|
77 window.onerror = oldOnError; |
|
78 generateErrorCallback()(err); |
|
79 }; |
|
80 } |
|
81 </script> |
|
82 </pre> |
|
83 </body> |
|
84 </html> |