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" |
11 #include "chrome/browser/extensions/extension_apitest.h" | 11 #include "chrome/browser/extensions/extension_apitest.h" |
12 #include "chrome/browser/extensions/extension_function_test_utils.h" | 12 #include "chrome/browser/extensions/extension_function_test_utils.h" |
13 #include "chrome/browser/extensions/extension_service.h" | 13 #include "chrome/browser/extensions/extension_service.h" |
14 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
15 #include "components/cast_channel/cast_socket.h" | 15 #include "components/cast_channel/cast_socket.h" |
16 #include "components/cast_channel/cast_socket_service.h" | 16 #include "components/cast_channel/cast_socket_service.h" |
17 #include "components/cast_channel/cast_socket_service_factory.h" | |
18 #include "components/cast_channel/cast_test_util.h" | 17 #include "components/cast_channel/cast_test_util.h" |
19 #include "components/cast_channel/logger.h" | 18 #include "components/cast_channel/logger.h" |
20 #include "components/cast_channel/proto/cast_channel.pb.h" | 19 #include "components/cast_channel/proto/cast_channel.pb.h" |
21 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
22 #include "extensions/browser/api/cast_channel/cast_channel_api.h" | 21 #include "extensions/browser/api/cast_channel/cast_channel_api.h" |
23 #include "extensions/common/api/cast_channel.h" | 22 #include "extensions/common/api/cast_channel.h" |
24 #include "extensions/common/switches.h" | 23 #include "extensions/common/switches.h" |
25 #include "extensions/common/test_util.h" | 24 #include "extensions/common/test_util.h" |
26 #include "extensions/test/extension_test_message_listener.h" | 25 #include "extensions/test/extension_test_message_listener.h" |
27 #include "extensions/test/result_catcher.h" | 26 #include "extensions/test/result_catcher.h" |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 .WillOnce(SaveArg<0>(&message_observer_)); | 137 .WillOnce(SaveArg<0>(&message_observer_)); |
139 EXPECT_CALL(*mock_cast_socket_, Connect(_)) | 138 EXPECT_CALL(*mock_cast_socket_, Connect(_)) |
140 .WillOnce(WithArgs<0>( | 139 .WillOnce(WithArgs<0>( |
141 Invoke([&](const CastSocket::OnOpenCallback& callback) { | 140 Invoke([&](const CastSocket::OnOpenCallback& callback) { |
142 callback.Run(mock_cast_socket_->id(), ChannelError::NONE); | 141 callback.Run(mock_cast_socket_->id(), ChannelError::NONE); |
143 }))); | 142 }))); |
144 EXPECT_CALL(*mock_cast_socket_, ready_state()) | 143 EXPECT_CALL(*mock_cast_socket_, ready_state()) |
145 .WillOnce(Return(ReadyState::OPEN)) | 144 .WillOnce(Return(ReadyState::OPEN)) |
146 .RetiresOnSaturation(); | 145 .RetiresOnSaturation(); |
147 EXPECT_CALL(*mock_cast_socket_, ready_state()) | 146 EXPECT_CALL(*mock_cast_socket_, ready_state()) |
148 .WillOnce(Return(ReadyState::CLOSED)); | 147 .Times(2) |
| 148 .WillRepeatedly(Return(ReadyState::CLOSED)); |
149 } | 149 } |
| 150 EXPECT_CALL(*mock_cast_socket_, Close(_)) |
| 151 .WillOnce(InvokeCompletionCallback<0>(net::OK)); |
150 } | 152 } |
151 | 153 |
152 extensions::CastChannelAPI* GetApi() { | 154 extensions::CastChannelAPI* GetApi() { |
153 return extensions::CastChannelAPI::Get(profile()); | 155 return extensions::CastChannelAPI::Get(profile()); |
154 } | 156 } |
155 | 157 |
156 cast_channel::CastSocketService* GetCastSocketService() { | 158 cast_channel::CastSocketService* GetCastSocketService() { |
157 return cast_channel::CastSocketServiceFactory::GetForBrowserContext( | 159 return cast_channel::CastSocketService::GetInstance(); |
158 profile()) | |
159 .get(); | |
160 } | 160 } |
161 | 161 |
162 // Logs some bogus error details and calls the OnError handler. | 162 // Logs some bogus error details and calls the OnError handler. |
163 void DoCallOnError(cast_channel::CastSocketService* cast_socket_service) { | 163 void DoCallOnError(cast_channel::CastSocketService* cast_socket_service) { |
164 cast_socket_service->GetLogger()->LogSocketEventWithRv( | 164 cast_socket_service->GetLogger()->LogSocketEventWithRv( |
165 mock_cast_socket_->id(), cast_channel::ChannelEvent::SOCKET_WRITE, | 165 mock_cast_socket_->id(), cast_channel::ChannelEvent::SOCKET_WRITE, |
166 net::ERR_FAILED); | 166 net::ERR_FAILED); |
167 message_observer_->OnError(*mock_cast_socket_, ChannelError::CONNECT_ERROR); | 167 message_observer_->OnError(*mock_cast_socket_, ChannelError::CONNECT_ERROR); |
168 } | 168 } |
169 | 169 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 LastError last_error_; | 217 LastError last_error_; |
218 CastSocket::Observer* message_observer_; | 218 CastSocket::Observer* message_observer_; |
219 net::TestNetLog capturing_net_log_; | 219 net::TestNetLog capturing_net_log_; |
220 int channel_id_; | 220 int channel_id_; |
221 }; | 221 }; |
222 | 222 |
223 ACTION_P2(InvokeObserverOnError, api_test, cast_socket_service) { | 223 ACTION_P2(InvokeObserverOnError, api_test, cast_socket_service) { |
224 content::BrowserThread::PostTask( | 224 content::BrowserThread::PostTask( |
225 content::BrowserThread::IO, FROM_HERE, | 225 content::BrowserThread::IO, FROM_HERE, |
226 base::Bind(&CastChannelAPITest::DoCallOnError, base::Unretained(api_test), | 226 base::Bind(&CastChannelAPITest::DoCallOnError, base::Unretained(api_test), |
227 base::RetainedRef(cast_socket_service))); | 227 base::Unretained(cast_socket_service))); |
228 } | 228 } |
229 | 229 |
230 // TODO(kmarshall): Win Dbg has a workaround that makes RunExtensionSubtest | 230 // TODO(kmarshall): Win Dbg has a workaround that makes RunExtensionSubtest |
231 // always return true without actually running the test. Remove when fixed. | 231 // always return true without actually running the test. Remove when fixed. |
232 #if defined(OS_WIN) && !defined(NDEBUG) | 232 #if defined(OS_WIN) && !defined(NDEBUG) |
233 #define MAYBE_TestOpenSendClose DISABLED_TestOpenSendClose | 233 #define MAYBE_TestOpenSendClose DISABLED_TestOpenSendClose |
234 #else | 234 #else |
235 #define MAYBE_TestOpenSendClose TestOpenSendClose | 235 #define MAYBE_TestOpenSendClose TestOpenSendClose |
236 #endif | 236 #endif |
237 // Test loading extension, opening a channel with ConnectInfo, adding a | 237 // Test loading extension, opening a channel with ConnectInfo, adding a |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 "\"keepAlive\": true, " | 437 "\"keepAlive\": true, " |
438 "\"audioOnly\": false, " | 438 "\"audioOnly\": false, " |
439 "\"connectInfo\": " | 439 "\"connectInfo\": " |
440 "{\"ipAddress\": \"127.0.0.1\", \"port\": 8009, " | 440 "{\"ipAddress\": \"127.0.0.1\", \"port\": 8009, " |
441 "\"auth\": \"ssl_verified\"}, \"readyState\": \"open\"}, " | 441 "\"auth\": \"ssl_verified\"}, \"readyState\": \"open\"}, " |
442 "{\"namespace_\": \"foo\", \"sourceId\": \"src\", " | 442 "{\"namespace_\": \"foo\", \"sourceId\": \"src\", " |
443 "\"destinationId\": \"\", \"data\": \"data\"}]", | 443 "\"destinationId\": \"\", \"data\": \"data\"}]", |
444 browser()); | 444 browser()); |
445 EXPECT_EQ(error, "message_info.destination_id is required"); | 445 EXPECT_EQ(error, "message_info.destination_id is required"); |
446 } | 446 } |
OLD | NEW |