| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "extensions/browser/api/cast_channel/cast_socket.h" | 5 #include "components/cast_channel/cast_socket.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/location.h" | 12 #include "base/location.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
| 17 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
| 18 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
| 19 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
| 20 #include "base/sys_byteorder.h" | 20 #include "base/sys_byteorder.h" |
| 21 #include "base/threading/thread_task_runner_handle.h" | 21 #include "base/threading/thread_task_runner_handle.h" |
| 22 #include "base/timer/mock_timer.h" | 22 #include "base/timer/mock_timer.h" |
| 23 #include "extensions/browser/api/cast_channel/cast_auth_util.h" | 23 #include "components/cast_channel/cast_auth_util.h" |
| 24 #include "extensions/browser/api/cast_channel/cast_framer.h" | 24 #include "components/cast_channel/cast_framer.h" |
| 25 #include "extensions/browser/api/cast_channel/cast_message_util.h" | 25 #include "components/cast_channel/cast_message_util.h" |
| 26 #include "extensions/browser/api/cast_channel/cast_test_util.h" | 26 #include "components/cast_channel/cast_test_util.h" |
| 27 #include "extensions/browser/api/cast_channel/cast_transport.h" | 27 #include "components/cast_channel/cast_transport.h" |
| 28 #include "extensions/browser/api/cast_channel/logger.h" | 28 #include "components/cast_channel/logger.h" |
| 29 #include "extensions/common/api/cast_channel/cast_channel.pb.h" | 29 #include "components/cast_channel/proto/cast_channel.pb.h" |
| 30 #include "extensions/common/api/cast_channel/logging.pb.h" | 30 #include "components/cast_channel/proto/logging.pb.h" |
| 31 #include "net/base/address_list.h" | 31 #include "net/base/address_list.h" |
| 32 #include "net/base/net_errors.h" | 32 #include "net/base/net_errors.h" |
| 33 #include "net/log/test_net_log.h" | 33 #include "net/log/test_net_log.h" |
| 34 #include "net/socket/socket_test_util.h" | 34 #include "net/socket/socket_test_util.h" |
| 35 #include "net/socket/ssl_client_socket.h" | 35 #include "net/socket/ssl_client_socket.h" |
| 36 #include "net/socket/tcp_client_socket.h" | 36 #include "net/socket/tcp_client_socket.h" |
| 37 #include "net/ssl/ssl_info.h" | 37 #include "net/ssl/ssl_info.h" |
| 38 #include "net/test/cert_test_util.h" | 38 #include "net/test/cert_test_util.h" |
| 39 #include "net/test/test_data_directory.h" | 39 #include "net/test/test_data_directory.h" |
| 40 #include "testing/gmock/include/gmock/gmock.h" | 40 #include "testing/gmock/include/gmock/gmock.h" |
| 41 #include "testing/gtest/include/gtest/gtest.h" | 41 #include "testing/gtest/include/gtest/gtest.h" |
| 42 | 42 |
| 43 const int64_t kDistantTimeoutMillis = 100000; // 100 seconds (never hit). | 43 const int64_t kDistantTimeoutMillis = 100000; // 100 seconds (never hit). |
| 44 | 44 |
| 45 using ::cast_channel::ChannelError; | 45 using ::cast_channel::ChannelError; |
| 46 using ::cast_channel::ChannelAuthType; | 46 using ::cast_channel::ChannelAuthType; |
| 47 using ::cast_channel::ReadyState; | 47 using ::cast_channel::ReadyState; |
| 48 using ::testing::_; | 48 using ::testing::_; |
| 49 using ::testing::A; | 49 using ::testing::A; |
| 50 using ::testing::DoAll; | 50 using ::testing::DoAll; |
| 51 using ::testing::Invoke; | 51 using ::testing::Invoke; |
| 52 using ::testing::InvokeArgument; | 52 using ::testing::InvokeArgument; |
| 53 using ::testing::NotNull; | 53 using ::testing::NotNull; |
| 54 using ::testing::Return; | 54 using ::testing::Return; |
| 55 using ::testing::SaveArg; | 55 using ::testing::SaveArg; |
| 56 | 56 |
| 57 namespace extensions { | |
| 58 namespace api { | |
| 59 namespace cast_channel { | 57 namespace cast_channel { |
| 60 const char kAuthNamespace[] = "urn:x-cast:com.google.cast.tp.deviceauth"; | 58 const char kAuthNamespace[] = "urn:x-cast:com.google.cast.tp.deviceauth"; |
| 61 | 59 |
| 62 // Returns an auth challenge message inline. | 60 // Returns an auth challenge message inline. |
| 63 CastMessage CreateAuthChallenge() { | 61 CastMessage CreateAuthChallenge() { |
| 64 CastMessage output; | 62 CastMessage output; |
| 65 CreateAuthChallengeMessage(&output, AuthContext::Create()); | 63 CreateAuthChallengeMessage(&output, AuthContext::Create()); |
| 66 return output; | 64 return output; |
| 67 } | 65 } |
| 68 | 66 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 virtual bool SetKeepAlive(bool enable, int delay) { | 125 virtual bool SetKeepAlive(bool enable, int delay) { |
| 128 // Always return true in tests | 126 // Always return true in tests |
| 129 return true; | 127 return true; |
| 130 } | 128 } |
| 131 | 129 |
| 132 virtual bool SetNoDelay(bool no_delay) { | 130 virtual bool SetNoDelay(bool no_delay) { |
| 133 // Always return true in tests | 131 // Always return true in tests |
| 134 return true; | 132 return true; |
| 135 } | 133 } |
| 136 | 134 |
| 137 MOCK_METHOD3(Read, | 135 MOCK_METHOD3(Read, int(net::IOBuffer*, int, const net::CompletionCallback&)); |
| 138 int(net::IOBuffer*, int, const net::CompletionCallback&)); | 136 MOCK_METHOD3(Write, int(net::IOBuffer*, int, const net::CompletionCallback&)); |
| 139 MOCK_METHOD3(Write, | |
| 140 int(net::IOBuffer*, int, const net::CompletionCallback&)); | |
| 141 | 137 |
| 142 virtual void Disconnect() { | 138 virtual void Disconnect() { |
| 143 // Do nothing in tests | 139 // Do nothing in tests |
| 144 } | 140 } |
| 145 | 141 |
| 146 private: | 142 private: |
| 147 net::MockConnect connect_data_; | 143 net::MockConnect connect_data_; |
| 148 bool do_nothing_; | 144 bool do_nothing_; |
| 149 | 145 |
| 150 DISALLOW_COPY_AND_ASSIGN(MockTCPSocket); | 146 DISALLOW_COPY_AND_ASSIGN(MockTCPSocket); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 | 225 |
| 230 // Socket connection helpers. | 226 // Socket connection helpers. |
| 231 void SetupTcpConnect(net::IoMode mode, int result) { | 227 void SetupTcpConnect(net::IoMode mode, int result) { |
| 232 tcp_connect_data_.reset(new net::MockConnect(mode, result)); | 228 tcp_connect_data_.reset(new net::MockConnect(mode, result)); |
| 233 } | 229 } |
| 234 void SetupSslConnect(net::IoMode mode, int result) { | 230 void SetupSslConnect(net::IoMode mode, int result) { |
| 235 ssl_connect_data_.reset(new net::MockConnect(mode, result)); | 231 ssl_connect_data_.reset(new net::MockConnect(mode, result)); |
| 236 } | 232 } |
| 237 | 233 |
| 238 // Socket I/O helpers. | 234 // Socket I/O helpers. |
| 239 void AddWriteResult(const net::MockWrite& write) { | 235 void AddWriteResult(const net::MockWrite& write) { writes_.push_back(write); } |
| 240 writes_.push_back(write); | |
| 241 } | |
| 242 void AddWriteResult(net::IoMode mode, int result) { | 236 void AddWriteResult(net::IoMode mode, int result) { |
| 243 AddWriteResult(net::MockWrite(mode, result)); | 237 AddWriteResult(net::MockWrite(mode, result)); |
| 244 } | 238 } |
| 245 void AddWriteResultForData(net::IoMode mode, const std::string& msg) { | 239 void AddWriteResultForData(net::IoMode mode, const std::string& msg) { |
| 246 AddWriteResult(mode, msg.size()); | 240 AddWriteResult(mode, msg.size()); |
| 247 } | 241 } |
| 248 void AddReadResult(const net::MockRead& read) { | 242 void AddReadResult(const net::MockRead& read) { reads_.push_back(read); } |
| 249 reads_.push_back(read); | |
| 250 } | |
| 251 void AddReadResult(net::IoMode mode, int result) { | 243 void AddReadResult(net::IoMode mode, int result) { |
| 252 AddReadResult(net::MockRead(mode, result)); | 244 AddReadResult(net::MockRead(mode, result)); |
| 253 } | 245 } |
| 254 void AddReadResultForData(net::IoMode mode, const std::string& data) { | 246 void AddReadResultForData(net::IoMode mode, const std::string& data) { |
| 255 AddReadResult(net::MockRead(mode, data.c_str(), data.size())); | 247 AddReadResult(net::MockRead(mode, data.c_str(), data.size())); |
| 256 } | 248 } |
| 257 | 249 |
| 258 // Helpers for modifying other connection-related behaviors. | 250 // Helpers for modifying other connection-related behaviors. |
| 259 void SetupTcpConnectUnresponsive() { tcp_unresponsive_ = true; } | 251 void SetupTcpConnectUnresponsive() { tcp_unresponsive_ = true; } |
| 260 | 252 |
| 261 void SetExtractCertResult(bool value) { | 253 void SetExtractCertResult(bool value) { extract_cert_result_ = value; } |
| 262 extract_cert_result_ = value; | |
| 263 } | |
| 264 | 254 |
| 265 void SetVerifyChallengeResult(bool value) { | 255 void SetVerifyChallengeResult(bool value) { |
| 266 verify_challenge_result_ = value; | 256 verify_challenge_result_ = value; |
| 267 } | 257 } |
| 268 | 258 |
| 269 void TriggerTimeout() { | 259 void TriggerTimeout() { mock_timer_->Fire(); } |
| 270 mock_timer_->Fire(); | |
| 271 } | |
| 272 | 260 |
| 273 bool TestVerifyChannelPolicyNone() { | 261 bool TestVerifyChannelPolicyNone() { |
| 274 AuthResult authResult; | 262 AuthResult authResult; |
| 275 return VerifyChannelPolicy(authResult); | 263 return VerifyChannelPolicy(authResult); |
| 276 } | 264 } |
| 277 | 265 |
| 278 bool TestVerifyChannelPolicyAudioOnly() { | 266 bool TestVerifyChannelPolicyAudioOnly() { |
| 279 AuthResult authResult; | 267 AuthResult authResult; |
| 280 authResult.channel_policies |= AuthResult::POLICY_AUDIO_ONLY; | 268 authResult.channel_policies |= AuthResult::POLICY_AUDIO_ONLY; |
| 281 return VerifyChannelPolicy(authResult); | 269 return VerifyChannelPolicy(authResult); |
| (...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 783 socket_->transport()->SendMessage( | 771 socket_->transport()->SendMessage( |
| 784 test_message, base::Bind(&CompleteHandler::OnWriteComplete, | 772 test_message, base::Bind(&CompleteHandler::OnWriteComplete, |
| 785 base::Unretained(&handler_))); | 773 base::Unretained(&handler_))); |
| 786 RunPendingTasks(); | 774 RunPendingTasks(); |
| 787 | 775 |
| 788 EXPECT_EQ(ReadyState::OPEN, socket_->ready_state()); | 776 EXPECT_EQ(ReadyState::OPEN, socket_->ready_state()); |
| 789 EXPECT_EQ(ChannelError::NONE, socket_->error_state()); | 777 EXPECT_EQ(ChannelError::NONE, socket_->error_state()); |
| 790 } | 778 } |
| 791 | 779 |
| 792 } // namespace cast_channel | 780 } // namespace cast_channel |
| 793 } // namespace api | |
| 794 } // namespace extensions | |
| OLD | NEW |