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 client_socket_factory_.reset(new net::MockClientSocketFactory()); |
| 30 |
| 31 gnubby_advertiser_ = new GnubbyAdvertiser(client_socket_factory_.get()); |
| 32 } |
| 33 |
| 34 void GnubbyAdvertiserTest::TearDown() { |
| 35 EXPECT_TRUE(gnubby_advertiser_->HasOneRef()); |
| 36 } |
| 37 |
| 38 TEST_F(GnubbyAdvertiserTest, ConnectFailed) { |
| 39 net::StaticSocketDataProvider socket_data(NULL, 0, NULL, 0); |
| 40 socket_data.set_connect_data( |
| 41 net::MockConnect(net::SYNCHRONOUS, net::ERR_FAILED)); |
| 42 |
| 43 client_socket_factory_->AddSocketDataProvider(&socket_data); |
| 44 |
| 45 gnubby_advertiser_->Advertise(80); |
| 46 } |
| 47 |
| 48 TEST_F(GnubbyAdvertiserTest, WriteFailed) { |
| 49 net::MockWrite write_fail(net::SYNCHRONOUS, net::ERR_FAILED); |
| 50 |
| 51 net::StaticSocketDataProvider socket_data(NULL, 0, &write_fail, 1); |
| 52 socket_data.set_connect_data(net::MockConnect(net::SYNCHRONOUS, net::OK)); |
| 53 |
| 54 client_socket_factory_->AddSocketDataProvider(&socket_data); |
| 55 |
| 56 gnubby_advertiser_->Advertise(80); |
| 57 } |
| 58 |
| 59 TEST_F(GnubbyAdvertiserTest, ReadFailed) { |
| 60 net::MockRead read_fail(net::SYNCHRONOUS, net::ERR_FAILED); |
| 61 net::MockWrite write(net::SYNCHRONOUS, net::OK); |
| 62 |
| 63 net::StaticSocketDataProvider socket_data(&read_fail, 1, &write, 1); |
| 64 socket_data.set_connect_data(net::MockConnect(net::SYNCHRONOUS, net::OK)); |
| 65 |
| 66 client_socket_factory_->AddSocketDataProvider(&socket_data); |
| 67 |
| 68 gnubby_advertiser_->Advertise(80); |
| 69 } |
| 70 |
| 71 } // namespace remoting |
OLD | NEW |