Use unique image for lofi testing
[chromium-blink-merge.git] / components / test_runner / mock_webrtc_dtmf_sender_handler.cc
blob69aba6f8cbf33f273169f84a7db8d5b6370fcda0
1 // Copyright 2014 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.
5 #include "components/test_runner/mock_webrtc_dtmf_sender_handler.h"
7 #include "base/logging.h"
8 #include "components/test_runner/web_test_delegate.h"
9 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h"
10 #include "third_party/WebKit/public/platform/WebRTCDTMFSenderHandlerClient.h"
12 using namespace blink;
14 namespace test_runner {
16 class DTMFSenderToneTask : public WebMethodTask<MockWebRTCDTMFSenderHandler> {
17 public:
18 DTMFSenderToneTask(MockWebRTCDTMFSenderHandler* object,
19 WebRTCDTMFSenderHandlerClient* client)
20 : WebMethodTask<MockWebRTCDTMFSenderHandler>(object), client_(client) {}
22 void RunIfValid() override {
23 WebString tones = object_->currentToneBuffer();
24 object_->ClearToneBuffer();
25 client_->didPlayTone(tones);
28 private:
29 WebRTCDTMFSenderHandlerClient* client_;
32 /////////////////////
34 MockWebRTCDTMFSenderHandler::MockWebRTCDTMFSenderHandler(
35 const WebMediaStreamTrack& track,
36 WebTestDelegate* delegate)
37 : client_(0), track_(track), delegate_(delegate) {
40 void MockWebRTCDTMFSenderHandler::setClient(
41 WebRTCDTMFSenderHandlerClient* client) {
42 client_ = client;
45 WebString MockWebRTCDTMFSenderHandler::currentToneBuffer() {
46 return tone_buffer_;
49 bool MockWebRTCDTMFSenderHandler::canInsertDTMF() {
50 DCHECK(client_ && !track_.isNull());
51 return track_.source().type() == WebMediaStreamSource::TypeAudio &&
52 track_.isEnabled() &&
53 track_.source().readyState() == WebMediaStreamSource::ReadyStateLive;
56 bool MockWebRTCDTMFSenderHandler::insertDTMF(const WebString& tones,
57 long duration,
58 long inter_tone_gap) {
59 DCHECK(client_);
60 if (!canInsertDTMF())
61 return false;
63 tone_buffer_ = tones;
64 delegate_->PostTask(new DTMFSenderToneTask(this, client_));
65 delegate_->PostTask(new DTMFSenderToneTask(this, client_));
66 return true;
69 } // namespace test_runner