[safe-browsing] Database full hash matches like prefix match.
[chromium-blink-merge.git] / content / shell / renderer / test_runner / MockWebRTCDTMFSenderHandler.cpp
blob223c16d7df1b3c635f2d695e51992c18504141ca
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.
5 #include "content/shell/renderer/test_runner/MockWebRTCDTMFSenderHandler.h"
7 #include <assert.h>
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"
13 using namespace blink;
15 namespace WebTestRunner {
17 class DTMFSenderToneTask : public WebMethodTask<MockWebRTCDTMFSenderHandler> {
18 public:
19 DTMFSenderToneTask(MockWebRTCDTMFSenderHandler* object, WebRTCDTMFSenderHandlerClient* client)
20 : WebMethodTask<MockWebRTCDTMFSenderHandler>(object)
21 , m_client(client)
25 virtual void runIfValid() OVERRIDE
27 WebString tones = m_object->currentToneBuffer();
28 m_object->clearToneBuffer();
29 m_client->didPlayTone(tones);
32 private:
33 WebRTCDTMFSenderHandlerClient* m_client;
36 /////////////////////
38 MockWebRTCDTMFSenderHandler::MockWebRTCDTMFSenderHandler(const WebMediaStreamTrack& track, WebTestDelegate* delegate)
39 : m_client(0)
40 , m_track(track)
41 , m_delegate(delegate)
45 void MockWebRTCDTMFSenderHandler::setClient(WebRTCDTMFSenderHandlerClient* client)
47 m_client = client;
50 WebString MockWebRTCDTMFSenderHandler::currentToneBuffer()
52 return m_toneBuffer;
55 bool MockWebRTCDTMFSenderHandler::canInsertDTMF()
57 assert(m_client && !m_track.isNull());
58 return m_track.source().type() == WebMediaStreamSource::TypeAudio && m_track.isEnabled() && m_track.source().readyState() == WebMediaStreamSource::ReadyStateLive;
61 bool MockWebRTCDTMFSenderHandler::insertDTMF(const WebString& tones, long duration, long interToneGap)
63 assert(m_client);
64 if (!canInsertDTMF())
65 return false;
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;