Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / content / renderer / media / rtc_data_channel_handler_unittest.cc
blob70870950a8206c3af0c1845251edb5bff3a3479b
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 "base/memory/scoped_ptr.h"
6 #include "base/test/test_simple_task_runner.h"
7 #include "content/renderer/media/mock_data_channel_impl.h"
8 #include "content/renderer/media/rtc_data_channel_handler.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "third_party/WebKit/public/platform/WebRTCDataChannelHandlerClient.h"
12 namespace content {
14 class MockDataChannelHandlerClient :
15 public blink::WebRTCDataChannelHandlerClient {
16 public:
17 MockDataChannelHandlerClient() : state_(ReadyStateConnecting) {}
19 void didChangeReadyState(ReadyState state) override { state_ = state; }
20 void didDecreaseBufferedAmount(unsigned previous_amount) override {}
21 void didReceiveStringData(const blink::WebString& s) override {}
22 void didReceiveRawData(const char* data, size_t size) override {}
23 void didDetectError() override {}
25 ReadyState ready_state() const { return state_; }
27 private:
28 ReadyState state_;
31 class RtcDataChannelHandlerTest : public ::testing::Test {
32 public:
33 RtcDataChannelHandlerTest() {
34 signaling_thread_ = new base::TestSimpleTaskRunner();
37 void SetUp() override {
38 channel_ = new rtc::RefCountedObject<MockDataChannel>("test", &config);
41 void TearDown() override {
42 handler_.reset();
43 channel_ = nullptr;
44 signaling_thread_->ClearPendingTasks();
47 webrtc::DataChannelInit config;
48 scoped_refptr<base::TestSimpleTaskRunner> signaling_thread_;
49 scoped_refptr<MockDataChannel> channel_;
50 scoped_ptr<RtcDataChannelHandler> handler_;
53 // Add a client, change to the open state, and verify that the client has
54 // reached the open state.
55 TEST_F(RtcDataChannelHandlerTest, SetClient) {
56 handler_.reset(new RtcDataChannelHandler(signaling_thread_, channel_.get()));
57 MockDataChannelHandlerClient blink_channel;
58 handler_->setClient(&blink_channel);
59 channel_->changeState(webrtc::DataChannelInterface::kOpen);
60 signaling_thread_->RunPendingTasks();
61 EXPECT_EQ(MockDataChannelHandlerClient::ReadyStateOpen,
62 blink_channel.ready_state());
65 // Check that state() returns the expected default initial value.
66 TEST_F(RtcDataChannelHandlerTest, InitialState) {
67 handler_.reset(new RtcDataChannelHandler(signaling_thread_, channel_.get()));
68 EXPECT_EQ(MockDataChannelHandlerClient::ReadyStateConnecting,
69 handler_->state());
72 // Check that state() returns the expected value when the channel opens early.
73 TEST_F(RtcDataChannelHandlerTest, StateEarlyOpen) {
74 channel_->changeState(webrtc::DataChannelInterface::kOpen);
75 signaling_thread_->RunPendingTasks();
76 handler_.reset(new RtcDataChannelHandler(signaling_thread_, channel_.get()));
77 EXPECT_EQ(MockDataChannelHandlerClient::ReadyStateOpen,
78 handler_->state());
81 } // namespace content