Upstream version 9.37.197.0
[platform/framework/web/crosswalk.git] / src / third_party / webrtc / test / w3c / peerconnection_conformance_test.html
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2
3 <!--
4 To quickly iterate when developing this test, use --use-fake-ui-for-media-stream
5 for Chrome and set the media.navigator.permission.disabled property to true in
6 Firefox. You must either have a webcam/mic available on the system or use for
7 instance --use-fake-device-for-media-stream for Chrome.
8 -->
9
10 <html>
11 <head>
12   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
13   <title>PeerConnection Connection Test</title>
14 </head>
15 <body>
16   <div id="log"></div>
17   <div>
18     <video id="local-view" autoplay="autoplay"></video>
19     <video id="remote-view" autoplay="autoplay"/>
20     </video>
21   </div>
22
23   <!-- These files are in place when executing on W3C. -->
24   <script src="/resources/testharness.js"></script>
25   <script src="/resources/testharnessreport.js"></script>
26   <script src="/common/vendor-prefix.js"
27           data-prefixed-objects=
28               '[{"ancestors":["navigator"], "name":"getUserMedia"},
29                 {"ancestors":["window"], "name":"RTCPeerConnection"},
30                 {"ancestors":["window"], "name":"RTCSessionDescription"},
31                 {"ancestors":["window"], "name":"RTCIceCandidate"}]'
32           data-prefixed-prototypes=
33                '[{"ancestors":["HTMLMediaElement"],"name":"srcObject"}]'>
34   </script>
35   <script type="text/javascript">
36   var test = async_test('Can set up a basic WebRTC call.', {timeout: 5000});
37
38   var gFirstConnection = null;
39   var gSecondConnection = null;
40
41   function getUserMediaOkCallback(localStream) {
42     gFirstConnection = new RTCPeerConnection(null, null);
43     gFirstConnection.onicecandidate = onIceCandidateToFirst;
44     gFirstConnection.addStream(localStream);
45     gFirstConnection.createOffer(onOfferCreated, failed('createOffer'));
46
47     var videoTag = document.getElementById('local-view');
48     videoTag.src = URL.createObjectURL(localStream);
49   };
50
51   var onOfferCreated = test.step_func(function(offer) {
52     gFirstConnection.setLocalDescription(offer);
53
54     // This would normally go across the application's signaling solution.
55     // In our case, the "signaling" is to call this function.
56     receiveCall(offer.sdp);
57   });
58
59   function receiveCall(offerSdp) {
60     gSecondConnection = new RTCPeerConnection(null, null);
61     gSecondConnection.onicecandidate = onIceCandidateToSecond;
62     gSecondConnection.onaddstream = onRemoteStream;
63
64     var parsedOffer = new RTCSessionDescription({ type: 'offer',
65                                                   sdp: offerSdp });
66     gSecondConnection.setRemoteDescription(parsedOffer);
67
68     gSecondConnection.createAnswer(onAnswerCreated,
69                                    failed('createAnswer'));
70   };
71
72   var onAnswerCreated = test.step_func(function(answer) {
73     gSecondConnection.setLocalDescription(answer);
74
75     // Similarly, this would go over the application's signaling solution.
76     handleAnswer(answer.sdp);
77   });
78
79   function handleAnswer(answerSdp) {
80     var parsedAnswer = new RTCSessionDescription({ type: 'answer',
81                                                    sdp: answerSdp });
82     gFirstConnection.setRemoteDescription(parsedAnswer);
83
84     // Call negotiated: done.
85     test.done();
86   };
87
88   // Note: the ice candidate handlers are special. We can not wrap them in test
89   // steps since that seems to cause some kind of starvation that prevents the
90   // call of being set up. Unfortunately we cannot report errors in here.
91   var onIceCandidateToFirst = function(event) {
92     // If event.candidate is null = no more candidates.
93     if (event.candidate) {
94       var candidate = new RTCIceCandidate(event.candidate);
95       gSecondConnection.addIceCandidate(candidate);
96     }
97   };
98
99   var onIceCandidateToSecond = function(event) {
100     if (event.candidate) {
101       var candidate = new RTCIceCandidate(event.candidate);
102       gFirstConnection.addIceCandidate(candidate);
103     }
104   };
105
106   var onRemoteStream = test.step_func(function(event) {
107     var videoTag = document.getElementById('remote-view');
108     videoTag.src = URL.createObjectURL(event.stream);
109   });
110
111   // Returns a suitable error callback.
112   function failed(function_name) {
113     return test.step_func(function() {
114       assert_unreached('WebRTC called error callback for ' + function_name);
115     });
116   }
117
118   // This function starts the test.
119   test.step(function() {
120     navigator.getUserMedia({ video: true, audio: true },
121         getUserMediaOkCallback,
122         failed('getUserMedia'));
123   });
124 </script>
125
126 </body>
127 </html>