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