Index: content/shell/renderer/test_runner/mock_webrtc_dtmf_sender_handler.cc |
diff --git a/content/shell/renderer/test_runner/mock_webrtc_dtmf_sender_handler.cc b/content/shell/renderer/test_runner/mock_webrtc_dtmf_sender_handler.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..ed7221a15741dbea84c137fda87466e449b78875 |
--- /dev/null |
+++ b/content/shell/renderer/test_runner/mock_webrtc_dtmf_sender_handler.cc |
@@ -0,0 +1,69 @@ |
+// Copyright 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "content/shell/renderer/test_runner/mock_webrtc_dtmf_sender_handler.h" |
+ |
+#include "base/logging.h" |
+#include "content/shell/renderer/test_runner/WebTestDelegate.h" |
+#include "third_party/WebKit/public/platform/WebMediaStreamSource.h" |
+#include "third_party/WebKit/public/platform/WebRTCDTMFSenderHandlerClient.h" |
+ |
+using namespace blink; |
+ |
+namespace content { |
+ |
+class DTMFSenderToneTask : public WebMethodTask<MockWebRTCDTMFSenderHandler> { |
+ public: |
+ DTMFSenderToneTask(MockWebRTCDTMFSenderHandler* object, |
+ WebRTCDTMFSenderHandlerClient* client) |
+ : WebMethodTask<MockWebRTCDTMFSenderHandler>(object), client_(client) {} |
+ |
+ virtual void runIfValid() OVERRIDE { |
+ WebString tones = m_object->currentToneBuffer(); |
+ m_object->ClearToneBuffer(); |
+ client_->didPlayTone(tones); |
+ } |
+ |
+ private: |
+ WebRTCDTMFSenderHandlerClient* client_; |
+}; |
+ |
+///////////////////// |
+ |
+MockWebRTCDTMFSenderHandler::MockWebRTCDTMFSenderHandler( |
+ const WebMediaStreamTrack& track, |
+ WebTestDelegate* delegate) |
+ : client_(0), track_(track), delegate_(delegate) { |
+} |
+ |
+void MockWebRTCDTMFSenderHandler::setClient( |
+ WebRTCDTMFSenderHandlerClient* client) { |
+ client_ = client; |
+} |
+ |
+WebString MockWebRTCDTMFSenderHandler::currentToneBuffer() { |
+ return tone_buffer_; |
+} |
+ |
+bool MockWebRTCDTMFSenderHandler::canInsertDTMF() { |
+ DCHECK(client_ && !track_.isNull()); |
+ return track_.source().type() == WebMediaStreamSource::TypeAudio && |
+ track_.isEnabled() && |
+ track_.source().readyState() == WebMediaStreamSource::ReadyStateLive; |
+} |
+ |
+bool MockWebRTCDTMFSenderHandler::insertDTMF(const WebString& tones, |
+ long duration, |
+ long inter_tone_gap) { |
+ DCHECK(client_); |
+ if (!canInsertDTMF()) |
+ return false; |
+ |
+ tone_buffer_ = tones; |
+ delegate_->postTask(new DTMFSenderToneTask(this, client_)); |
+ delegate_->postTask(new DTMFSenderToneTask(this, client_)); |
+ return true; |
+} |
+ |
+} // namespace content |