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