| 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/timer/mock_timer.h" | 9 #include "base/timer/mock_timer.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 CastChannelAPITest() : ip_endpoint_(CreateIPEndPointForTest()) {} | 83 CastChannelAPITest() : ip_endpoint_(CreateIPEndPointForTest()) {} |
| 84 | 84 |
| 85 void SetUpCommandLine(base::CommandLine* command_line) override { | 85 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 86 ExtensionApiTest::SetUpCommandLine(command_line); | 86 ExtensionApiTest::SetUpCommandLine(command_line); |
| 87 command_line->AppendSwitchASCII( | 87 command_line->AppendSwitchASCII( |
| 88 extensions::switches::kWhitelistedExtensionID, kTestExtensionId); | 88 extensions::switches::kWhitelistedExtensionID, kTestExtensionId); |
| 89 } | 89 } |
| 90 | 90 |
| 91 void SetUpMockCastSocket() { | 91 void SetUpMockCastSocket() { |
| 92 extensions::CastChannelAPI* api = GetApi(); | 92 extensions::CastChannelAPI* api = GetApi(); |
| 93 timeout_timer_ = new base::MockTimer(true, false); | |
| 94 api->SetPingTimeoutTimerForTest(base::WrapUnique(timeout_timer_)); | |
| 95 | 93 |
| 96 net::IPEndPoint ip_endpoint(net::IPAddress(192, 168, 1, 1), 8009); | 94 net::IPEndPoint ip_endpoint(net::IPAddress(192, 168, 1, 1), 8009); |
| 97 mock_cast_socket_ = new MockCastSocket; | 95 mock_cast_socket_ = new MockCastSocket; |
| 98 // Transfers ownership of the socket. | 96 // Transfers ownership of the socket. |
| 99 api->SetSocketForTest(base::WrapUnique<CastSocket>(mock_cast_socket_)); | 97 api->SetSocketForTest(base::WrapUnique<CastSocket>(mock_cast_socket_)); |
| 100 ON_CALL(*mock_cast_socket_, set_id(_)) | 98 ON_CALL(*mock_cast_socket_, set_id(_)) |
| 101 .WillByDefault(SaveArg<0>(&channel_id_)); | 99 .WillByDefault(SaveArg<0>(&channel_id_)); |
| 102 ON_CALL(*mock_cast_socket_, id()) | 100 ON_CALL(*mock_cast_socket_, id()) |
| 103 .WillByDefault(ReturnPointee(&channel_id_)); | 101 .WillByDefault(ReturnPointee(&channel_id_)); |
| 104 ON_CALL(*mock_cast_socket_, ip_endpoint()) | 102 ON_CALL(*mock_cast_socket_, ip_endpoint()) |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 content::BrowserThread::PostTask( | 178 content::BrowserThread::PostTask( |
| 181 content::BrowserThread::IO, FROM_HERE, | 179 content::BrowserThread::IO, FROM_HERE, |
| 182 base::Bind(&CastTransport::Delegate::Start, | 180 base::Bind(&CastTransport::Delegate::Start, |
| 183 base::Unretained(message_delegate_))); | 181 base::Unretained(message_delegate_))); |
| 184 } | 182 } |
| 185 | 183 |
| 186 // Fires a timer on the IO thread. | 184 // Fires a timer on the IO thread. |
| 187 void FireTimeout() { | 185 void FireTimeout() { |
| 188 content::BrowserThread::PostTask( | 186 content::BrowserThread::PostTask( |
| 189 content::BrowserThread::IO, FROM_HERE, | 187 content::BrowserThread::IO, FROM_HERE, |
| 190 base::Bind(&base::MockTimer::Fire, base::Unretained(timeout_timer_))); | 188 base::Bind(&CastTransport::Delegate::OnError, |
| 189 base::Unretained(message_delegate_), |
| 190 cast_channel::ChannelError::PING_TIMEOUT)); |
| 191 } | 191 } |
| 192 | 192 |
| 193 extensions::CastChannelOpenFunction* CreateOpenFunction( | 193 extensions::CastChannelOpenFunction* CreateOpenFunction( |
| 194 scoped_refptr<Extension> extension) { | 194 scoped_refptr<Extension> extension) { |
| 195 extensions::CastChannelOpenFunction* cast_channel_open_function = | 195 extensions::CastChannelOpenFunction* cast_channel_open_function = |
| 196 new extensions::CastChannelOpenFunction; | 196 new extensions::CastChannelOpenFunction; |
| 197 cast_channel_open_function->set_extension(extension.get()); | 197 cast_channel_open_function->set_extension(extension.get()); |
| 198 return cast_channel_open_function; | 198 return cast_channel_open_function; |
| 199 } | 199 } |
| 200 | 200 |
| 201 extensions::CastChannelSendFunction* CreateSendFunction( | 201 extensions::CastChannelSendFunction* CreateSendFunction( |
| 202 scoped_refptr<Extension> extension) { | 202 scoped_refptr<Extension> extension) { |
| 203 extensions::CastChannelSendFunction* cast_channel_send_function = | 203 extensions::CastChannelSendFunction* cast_channel_send_function = |
| 204 new extensions::CastChannelSendFunction; | 204 new extensions::CastChannelSendFunction; |
| 205 cast_channel_send_function->set_extension(extension.get()); | 205 cast_channel_send_function->set_extension(extension.get()); |
| 206 return cast_channel_send_function; | 206 return cast_channel_send_function; |
| 207 } | 207 } |
| 208 | 208 |
| 209 MockCastSocket* mock_cast_socket_; | 209 MockCastSocket* mock_cast_socket_; |
| 210 base::MockTimer* timeout_timer_; | |
| 211 net::IPEndPoint ip_endpoint_; | 210 net::IPEndPoint ip_endpoint_; |
| 212 LastError last_error_; | 211 LastError last_error_; |
| 213 CastTransport::Delegate* message_delegate_; | 212 CastTransport::Delegate* message_delegate_; |
| 214 net::TestNetLog capturing_net_log_; | 213 net::TestNetLog capturing_net_log_; |
| 215 int channel_id_; | 214 int channel_id_; |
| 216 }; | 215 }; |
| 217 | 216 |
| 218 ACTION_P2(InvokeDelegateOnError, api_test, api) { | 217 ACTION_P2(InvokeDelegateOnError, api_test, api) { |
| 219 content::BrowserThread::PostTask( | 218 content::BrowserThread::PostTask( |
| 220 content::BrowserThread::IO, FROM_HERE, | 219 content::BrowserThread::IO, FROM_HERE, |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 "\"keepAlive\": true, " | 427 "\"keepAlive\": true, " |
| 429 "\"audioOnly\": false, " | 428 "\"audioOnly\": false, " |
| 430 "\"connectInfo\": " | 429 "\"connectInfo\": " |
| 431 "{\"ipAddress\": \"127.0.0.1\", \"port\": 8009, " | 430 "{\"ipAddress\": \"127.0.0.1\", \"port\": 8009, " |
| 432 "\"auth\": \"ssl_verified\"}, \"readyState\": \"open\"}, " | 431 "\"auth\": \"ssl_verified\"}, \"readyState\": \"open\"}, " |
| 433 "{\"namespace_\": \"foo\", \"sourceId\": \"src\", " | 432 "{\"namespace_\": \"foo\", \"sourceId\": \"src\", " |
| 434 "\"destinationId\": \"\", \"data\": \"data\"}]", | 433 "\"destinationId\": \"\", \"data\": \"data\"}]", |
| 435 browser()); | 434 browser()); |
| 436 EXPECT_EQ(error, "message_info.destination_id is required"); | 435 EXPECT_EQ(error, "message_info.destination_id is required"); |
| 437 } | 436 } |
| OLD | NEW |