OLD | NEW |
| (Empty) |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "content/shell/renderer/test_runner/MockWebRTCDTMFSenderHandler.h" | |
6 | |
7 #include <assert.h> | |
8 | |
9 #include "content/shell/renderer/test_runner/WebTestDelegate.h" | |
10 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" | |
11 #include "third_party/WebKit/public/platform/WebRTCDTMFSenderHandlerClient.h" | |
12 | |
13 using namespace blink; | |
14 | |
15 namespace content { | |
16 | |
17 class DTMFSenderToneTask : public WebMethodTask<MockWebRTCDTMFSenderHandler> { | |
18 public: | |
19 DTMFSenderToneTask(MockWebRTCDTMFSenderHandler* object, WebRTCDTMFSenderHand
lerClient* client) | |
20 : WebMethodTask<MockWebRTCDTMFSenderHandler>(object) | |
21 , m_client(client) | |
22 { | |
23 } | |
24 | |
25 virtual void runIfValid() OVERRIDE | |
26 { | |
27 WebString tones = m_object->currentToneBuffer(); | |
28 m_object->clearToneBuffer(); | |
29 m_client->didPlayTone(tones); | |
30 } | |
31 | |
32 private: | |
33 WebRTCDTMFSenderHandlerClient* m_client; | |
34 }; | |
35 | |
36 ///////////////////// | |
37 | |
38 MockWebRTCDTMFSenderHandler::MockWebRTCDTMFSenderHandler(const WebMediaStreamTra
ck& track, WebTestDelegate* delegate) | |
39 : m_client(0) | |
40 , m_track(track) | |
41 , m_delegate(delegate) | |
42 { | |
43 } | |
44 | |
45 void MockWebRTCDTMFSenderHandler::setClient(WebRTCDTMFSenderHandlerClient* clien
t) | |
46 { | |
47 m_client = client; | |
48 } | |
49 | |
50 WebString MockWebRTCDTMFSenderHandler::currentToneBuffer() | |
51 { | |
52 return m_toneBuffer; | |
53 } | |
54 | |
55 bool MockWebRTCDTMFSenderHandler::canInsertDTMF() | |
56 { | |
57 assert(m_client && !m_track.isNull()); | |
58 return m_track.source().type() == WebMediaStreamSource::TypeAudio && m_track
.isEnabled() && m_track.source().readyState() == WebMediaStreamSource::ReadyStat
eLive; | |
59 } | |
60 | |
61 bool MockWebRTCDTMFSenderHandler::insertDTMF(const WebString& tones, long durati
on, long interToneGap) | |
62 { | |
63 assert(m_client); | |
64 if (!canInsertDTMF()) | |
65 return false; | |
66 | |
67 m_toneBuffer = tones; | |
68 m_delegate->postTask(new DTMFSenderToneTask(this, m_client)); | |
69 m_delegate->postTask(new DTMFSenderToneTask(this, m_client)); | |
70 return true; | |
71 } | |
72 | |
73 } // namespace content | |
OLD | NEW |