| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/extensions/api/cast_channel/cast_socket.h" | 5 #include "extensions/browser/api/cast_channel/cast_socket.h" |
| 6 | 6 |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/sys_byteorder.h" | 10 #include "base/sys_byteorder.h" |
| 11 #include "chrome/browser/extensions/api/cast_channel/cast_channel.pb.h" | 11 #include "extensions/browser/api/cast_channel/cast_channel.pb.h" |
| 12 #include "chrome/browser/extensions/api/cast_channel/cast_message_util.h" | 12 #include "extensions/browser/api/cast_channel/cast_message_util.h" |
| 13 #include "net/base/address_list.h" | 13 #include "net/base/address_list.h" |
| 14 #include "net/base/capturing_net_log.h" | 14 #include "net/base/capturing_net_log.h" |
| 15 #include "net/base/net_errors.h" | 15 #include "net/base/net_errors.h" |
| 16 #include "net/base/net_util.h" | 16 #include "net/base/net_util.h" |
| 17 #include "net/socket/socket_test_util.h" | 17 #include "net/socket/socket_test_util.h" |
| 18 #include "net/socket/ssl_client_socket.h" | 18 #include "net/socket/ssl_client_socket.h" |
| 19 #include "net/socket/tcp_client_socket.h" | 19 #include "net/socket/tcp_client_socket.h" |
| 20 #include "net/ssl/ssl_info.h" | 20 #include "net/ssl/ssl_info.h" |
| 21 #include "testing/gmock/include/gmock/gmock.h" | 21 #include "testing/gmock/include/gmock/gmock.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 23 | 23 |
| 24 using ::testing::_; | 24 using ::testing::_; |
| 25 using ::testing::A; | 25 using ::testing::A; |
| 26 using ::testing::DoAll; | 26 using ::testing::DoAll; |
| 27 using ::testing::Return; | 27 using ::testing::Return; |
| 28 using ::testing::SaveArg; | 28 using ::testing::SaveArg; |
| 29 | 29 |
| 30 namespace { | 30 namespace { |
| 31 const char* kTestData[4] = { | 31 const char* kTestData[4] = { |
| 32 "Hello, World!", | 32 "Hello, World!", |
| 33 "Goodbye, World!", | 33 "Goodbye, World!", |
| 34 "Hello, Sky!", | 34 "Hello, Sky!", |
| 35 "Goodbye, Volcano!", | 35 "Goodbye, Volcano!", |
| 36 }; | 36 }; |
| 37 } // namespace | 37 } // namespace |
| 38 | 38 |
| 39 namespace extensions { | 39 namespace extensions { |
| 40 namespace api { | 40 namespace core_api { |
| 41 namespace cast_channel { | 41 namespace cast_channel { |
| 42 | 42 |
| 43 // Fills in |message| with a string message. | 43 // Fills in |message| with a string message. |
| 44 static void CreateStringMessage(const std::string& namespace_, | 44 static void CreateStringMessage(const std::string& namespace_, |
| 45 const std::string& source_id, | 45 const std::string& source_id, |
| 46 const std::string& destination_id, | 46 const std::string& destination_id, |
| 47 const std::string& data, | 47 const std::string& data, |
| 48 MessageInfo* message) { | 48 MessageInfo* message) { |
| 49 message->namespace_ = namespace_; | 49 message->namespace_ = namespace_; |
| 50 message->source_id = source_id; | 50 message->source_id = source_id; |
| (...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 768 EXPECT_CALL(handler_, OnWriteComplete(net::ERR_FAILED)); | 768 EXPECT_CALL(handler_, OnWriteComplete(net::ERR_FAILED)); |
| 769 size_t size = CastSocket::MessageHeader::max_message_size() + 1; | 769 size_t size = CastSocket::MessageHeader::max_message_size() + 1; |
| 770 test_messages_[0].data.reset( | 770 test_messages_[0].data.reset( |
| 771 new base::StringValue(std::string(size, 'a'))); | 771 new base::StringValue(std::string(size, 'a'))); |
| 772 socket_->SendMessage(test_messages_[0], | 772 socket_->SendMessage(test_messages_[0], |
| 773 base::Bind(&CompleteHandler::OnWriteComplete, | 773 base::Bind(&CompleteHandler::OnWriteComplete, |
| 774 base::Unretained(&handler_))); | 774 base::Unretained(&handler_))); |
| 775 | 775 |
| 776 EXPECT_EQ(cast_channel::READY_STATE_OPEN, socket_->ready_state()); | 776 EXPECT_EQ(cast_channel::READY_STATE_OPEN, socket_->ready_state()); |
| 777 EXPECT_EQ(cast_channel::CHANNEL_ERROR_NONE, socket_->error_state()); | 777 EXPECT_EQ(cast_channel::CHANNEL_ERROR_NONE, socket_->error_state()); |
| 778 | |
| 779 } | 778 } |
| 780 | 779 |
| 781 // Test write error - network error (sync) | 780 // Test write error - network error (sync) |
| 782 TEST_F(CastSocketTest, TestWriteNetworkErrorSync) { | 781 TEST_F(CastSocketTest, TestWriteNetworkErrorSync) { |
| 783 CreateCastSocket(); | 782 CreateCastSocket(); |
| 784 socket_->AddWriteResult(net::SYNCHRONOUS, net::ERR_FAILED); | 783 socket_->AddWriteResult(net::SYNCHRONOUS, net::ERR_FAILED); |
| 785 ConnectHelper(); | 784 ConnectHelper(); |
| 786 | 785 |
| 787 EXPECT_CALL(handler_, OnWriteComplete(net::ERR_FAILED)); | 786 EXPECT_CALL(handler_, OnWriteComplete(net::ERR_FAILED)); |
| 788 EXPECT_CALL(mock_delegate_, | 787 EXPECT_CALL(mock_delegate_, |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 991 OnError(socket_.get(), | 990 OnError(socket_.get(), |
| 992 cast_channel::CHANNEL_ERROR_INVALID_MESSAGE)); | 991 cast_channel::CHANNEL_ERROR_INVALID_MESSAGE)); |
| 993 ConnectHelper(); | 992 ConnectHelper(); |
| 994 | 993 |
| 995 EXPECT_EQ(cast_channel::READY_STATE_CLOSED, socket_->ready_state()); | 994 EXPECT_EQ(cast_channel::READY_STATE_CLOSED, socket_->ready_state()); |
| 996 EXPECT_EQ(cast_channel::CHANNEL_ERROR_INVALID_MESSAGE, | 995 EXPECT_EQ(cast_channel::CHANNEL_ERROR_INVALID_MESSAGE, |
| 997 socket_->error_state()); | 996 socket_->error_state()); |
| 998 } | 997 } |
| 999 | 998 |
| 1000 } // namespace cast_channel | 999 } // namespace cast_channel |
| 1001 } // namespace api | 1000 } // namespace core_api |
| 1002 } // namespace extensions | 1001 } // namespace extensions |
| OLD | NEW |