Roll src/third_party/WebKit d10c917:a1123a1 (svn 198729:198730)
[chromium-blink-merge.git] / content / renderer / media / rtc_data_channel_handler_unittest.cc
blobe33dbbe8d60ccf1241fc2e3f8f36add106dbe526
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 didReceiveStringData(const blink::WebString& s) override {}
21 void didReceiveRawData(const char* data, size_t size) override {}
22 void didDetectError() override {}
24 ReadyState ready_state() const { return state_; }
26 private:
27 ReadyState state_;
30 class RtcDataChannelHandlerTest : public ::testing::Test {
31 public:
32 RtcDataChannelHandlerTest() {
33 signaling_thread_ = new base::TestSimpleTaskRunner();
36 void SetUp() override {
37 channel_ = new rtc::RefCountedObject<MockDataChannel>("test", &config);
40 void TearDown() override {
41 handler_.reset();
42 channel_ = nullptr;
43 signaling_thread_->ClearPendingTasks();
46 webrtc::DataChannelInit config;
47 scoped_refptr<base::TestSimpleTaskRunner> signaling_thread_;
48 scoped_refptr<MockDataChannel> channel_;
49 scoped_ptr<RtcDataChannelHandler> handler_;
52 // Add a client, change to the open state, and verify that the client has
53 // reached the open state.
54 TEST_F(RtcDataChannelHandlerTest, SetClient) {
55 handler_.reset(new RtcDataChannelHandler(signaling_thread_, channel_.get()));
56 MockDataChannelHandlerClient blink_channel;
57 handler_->setClient(&blink_channel);
58 channel_->changeState(webrtc::DataChannelInterface::kOpen);
59 signaling_thread_->RunPendingTasks();
60 EXPECT_EQ(MockDataChannelHandlerClient::ReadyStateOpen,
61 blink_channel.ready_state());
64 // Check that state() returns the expected default initial value.
65 TEST_F(RtcDataChannelHandlerTest, InitialState) {
66 handler_.reset(new RtcDataChannelHandler(signaling_thread_, channel_.get()));
67 EXPECT_EQ(MockDataChannelHandlerClient::ReadyStateConnecting,
68 handler_->state());
71 // Check that state() returns the expected value when the channel opens early.
72 TEST_F(RtcDataChannelHandlerTest, StateEarlyOpen) {
73 channel_->changeState(webrtc::DataChannelInterface::kOpen);
74 signaling_thread_->RunPendingTasks();
75 handler_.reset(new RtcDataChannelHandler(signaling_thread_, channel_.get()));
76 EXPECT_EQ(MockDataChannelHandlerClient::ReadyStateOpen,
77 handler_->state());
80 } // namespace content