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