OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "base/test/test_simple_task_runner.h" |
| 6 #include "net/base/net_errors.h" |
| 7 #include "net/socket/socket_test_util.h" |
| 8 #include "remoting/host/gnubby_advertiser.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 |
| 11 namespace remoting { |
| 12 |
| 13 class GnubbyAdvertiserTest : public testing::Test { |
| 14 public: |
| 15 GnubbyAdvertiserTest() {} |
| 16 |
| 17 virtual void SetUp() OVERRIDE; |
| 18 virtual void TearDown() OVERRIDE; |
| 19 |
| 20 protected: |
| 21 // Returns mock sockets. |
| 22 scoped_ptr<net::MockClientSocketFactory> client_socket_factory_; |
| 23 |
| 24 // GnubbyAdvertiser instance under test. |
| 25 scoped_refptr<GnubbyAdvertiser> gnubby_advertiser_; |
| 26 }; |
| 27 |
| 28 void GnubbyAdvertiserTest::SetUp() { |
| 29 scoped_refptr<base::SingleThreadTaskRunner> task_runner = |
| 30 new base::TestSimpleTaskRunner(); |
| 31 |
| 32 client_socket_factory_.reset(new net::MockClientSocketFactory()); |
| 33 |
| 34 gnubby_advertiser_ = |
| 35 new GnubbyAdvertiser(task_runner, client_socket_factory_.get()); |
| 36 } |
| 37 |
| 38 void GnubbyAdvertiserTest::TearDown() { |
| 39 EXPECT_TRUE(gnubby_advertiser_->HasOneRef()); |
| 40 } |
| 41 |
| 42 TEST_F(GnubbyAdvertiserTest, ConnectFailed) { |
| 43 net::StaticSocketDataProvider socket_data(NULL, 0, NULL, 0); |
| 44 socket_data.set_connect_data( |
| 45 net::MockConnect(net::SYNCHRONOUS, net::ERR_FAILED)); |
| 46 |
| 47 client_socket_factory_->AddSocketDataProvider(&socket_data); |
| 48 |
| 49 gnubby_advertiser_->Advertise(80); |
| 50 } |
| 51 |
| 52 TEST_F(GnubbyAdvertiserTest, WriteFailed) { |
| 53 net::MockWrite write_fail(net::SYNCHRONOUS, net::ERR_FAILED); |
| 54 |
| 55 net::StaticSocketDataProvider socket_data(NULL, 0, &write_fail, 1); |
| 56 socket_data.set_connect_data(net::MockConnect(net::SYNCHRONOUS, net::OK)); |
| 57 |
| 58 client_socket_factory_->AddSocketDataProvider(&socket_data); |
| 59 |
| 60 gnubby_advertiser_->Advertise(80); |
| 61 } |
| 62 |
| 63 TEST_F(GnubbyAdvertiserTest, ReadFailed) { |
| 64 net::MockRead read_fail(net::SYNCHRONOUS, net::ERR_FAILED); |
| 65 net::MockWrite write(net::SYNCHRONOUS, net::OK); |
| 66 |
| 67 net::StaticSocketDataProvider socket_data(&read_fail, 1, &write, 1); |
| 68 socket_data.set_connect_data(net::MockConnect(net::SYNCHRONOUS, net::OK)); |
| 69 |
| 70 client_socket_factory_->AddSocketDataProvider(&socket_data); |
| 71 |
| 72 gnubby_advertiser_->Advertise(80); |
| 73 } |
| 74 |
| 75 } // namespace remoting |
OLD | NEW |