Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1431)

Side by Side Diff: extensions/browser/api/cast_channel/cast_channel_apitest.cc

Issue 2925053005: [cast_channel] Implement CastSocketService::OpenSocket() (Closed)
Patch Set: implement CastSocketService::OpenSocket() Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 91
92 void SetUpMockCastSocket() { 92 void SetUpMockCastSocket() {
93 extensions::CastChannelAPI* api = GetApi(); 93 extensions::CastChannelAPI* api = GetApi();
94 timeout_timer_ = new base::MockTimer(true, false); 94 timeout_timer_ = new base::MockTimer(true, false);
95 api->SetPingTimeoutTimerForTest(base::WrapUnique(timeout_timer_)); 95 api->SetPingTimeoutTimerForTest(base::WrapUnique(timeout_timer_));
96 96
97 net::IPEndPoint ip_endpoint(net::IPAddress(192, 168, 1, 1), 8009); 97 net::IPEndPoint ip_endpoint(net::IPAddress(192, 168, 1, 1), 8009);
98 mock_cast_socket_ = new MockCastSocket; 98 mock_cast_socket_ = new MockCastSocket;
99 // Transfers ownership of the socket. 99 // Transfers ownership of the socket.
100 api->SetSocketForTest(base::WrapUnique<CastSocket>(mock_cast_socket_)); 100 api->SetSocketForTest(base::WrapUnique<CastSocket>(mock_cast_socket_));
101 ON_CALL(*mock_cast_socket_, set_id(_)) 101 mock_cast_socket_->SetIPEndpoint(ip_endpoint_);
102 .WillByDefault(SaveArg<0>(&channel_id_)); 102 mock_cast_socket_->SetChannelAuth(ChannelAuthType::SSL_VERIFIED);
103 ON_CALL(*mock_cast_socket_, id()) 103 mock_cast_socket_->SetKeepAlive(false);
104 .WillByDefault(ReturnPointee(&channel_id_));
105 ON_CALL(*mock_cast_socket_, ip_endpoint())
106 .WillByDefault(ReturnRef(ip_endpoint_));
107 ON_CALL(*mock_cast_socket_, channel_auth())
108 .WillByDefault(Return(ChannelAuthType::SSL_VERIFIED));
109 ON_CALL(*mock_cast_socket_, keep_alive()).WillByDefault(Return(false));
110 } 104 }
111 105
112 void SetUpOpenSendClose() { 106 void SetUpOpenSendClose() {
113 SetUpMockCastSocket(); 107 SetUpMockCastSocket();
114 EXPECT_CALL(*mock_cast_socket_, error_state()) 108 mock_cast_socket_->SetErrorState(ChannelError::NONE);
115 .WillRepeatedly(Return(ChannelError::NONE));
116 { 109 {
117 InSequence sequence; 110 InSequence sequence;
118 EXPECT_CALL(*mock_cast_socket_, ConnectRawPtr(_, _)) 111 EXPECT_CALL(*mock_cast_socket_, ConnectRawPtr(_, _))
119 .WillOnce(InvokeCompletionCallback<1>(ChannelError::NONE)); 112 .WillOnce(InvokeCompletionCallback<1>(ChannelError::NONE));
120 EXPECT_CALL(*mock_cast_socket_, ready_state()) 113 EXPECT_CALL(*mock_cast_socket_, ready_state())
121 .WillOnce(Return(ReadyState::OPEN)); 114 .WillOnce(Return(ReadyState::OPEN));
122 EXPECT_CALL(*mock_cast_socket_->mock_transport(), 115 EXPECT_CALL(*mock_cast_socket_->mock_transport(),
123 SendMessage(A<const CastMessage&>(), _)) 116 SendMessage(A<const CastMessage&>(), _))
124 .WillOnce(InvokeCompletionCallback<1>(net::OK)); 117 .WillOnce(InvokeCompletionCallback<1>(net::OK));
125 EXPECT_CALL(*mock_cast_socket_, ready_state()) 118 EXPECT_CALL(*mock_cast_socket_, ready_state())
126 .WillOnce(Return(ReadyState::OPEN)); 119 .WillOnce(Return(ReadyState::OPEN));
127 EXPECT_CALL(*mock_cast_socket_, Close(_)) 120 EXPECT_CALL(*mock_cast_socket_, Close(_))
128 .WillOnce(InvokeCompletionCallback<0>(net::OK)); 121 .WillOnce(InvokeCompletionCallback<0>(net::OK));
129 EXPECT_CALL(*mock_cast_socket_, ready_state()) 122 EXPECT_CALL(*mock_cast_socket_, ready_state())
130 .WillOnce(Return(ReadyState::CLOSED)); 123 .WillOnce(Return(ReadyState::CLOSED));
131 } 124 }
132 } 125 }
133 126
134 void SetUpOpenPingTimeout() { 127 void SetUpOpenPingTimeout() {
135 SetUpMockCastSocket(); 128 SetUpMockCastSocket();
136 EXPECT_CALL(*mock_cast_socket_, error_state()) 129 mock_cast_socket_->SetErrorState(ChannelError::NONE);
137 .WillRepeatedly(Return(ChannelError::NONE)); 130 mock_cast_socket_->SetKeepAlive(true);
138 EXPECT_CALL(*mock_cast_socket_, keep_alive()).WillRepeatedly(Return(true));
139 { 131 {
140 InSequence sequence; 132 InSequence sequence;
141 EXPECT_CALL(*mock_cast_socket_, ConnectRawPtr(_, _)) 133 EXPECT_CALL(*mock_cast_socket_, ConnectRawPtr(_, _))
142 .WillOnce(DoAll(SaveArg<0>(&message_delegate_), 134 .WillOnce(DoAll(SaveArg<0>(&message_delegate_),
143 InvokeCompletionCallback<1>(ChannelError::NONE))); 135 InvokeCompletionCallback<1>(ChannelError::NONE)));
144 EXPECT_CALL(*mock_cast_socket_, ready_state()) 136 EXPECT_CALL(*mock_cast_socket_, ready_state())
145 .WillOnce(Return(ReadyState::OPEN)) 137 .WillOnce(Return(ReadyState::OPEN))
146 .RetiresOnSaturation(); 138 .RetiresOnSaturation();
147 EXPECT_CALL(*mock_cast_socket_, ready_state()) 139 EXPECT_CALL(*mock_cast_socket_, ready_state())
148 .WillOnce(Return(ReadyState::CLOSED)); 140 .WillOnce(Return(ReadyState::CLOSED));
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 // always return true without actually running the test. Remove when fixed. 282 // always return true without actually running the test. Remove when fixed.
291 #if defined(OS_WIN) && !defined(NDEBUG) 283 #if defined(OS_WIN) && !defined(NDEBUG)
292 #define MAYBE_TestOpenReceiveClose DISABLED_TestOpenReceiveClose 284 #define MAYBE_TestOpenReceiveClose DISABLED_TestOpenReceiveClose
293 #else 285 #else
294 #define MAYBE_TestOpenReceiveClose TestOpenReceiveClose 286 #define MAYBE_TestOpenReceiveClose TestOpenReceiveClose
295 #endif 287 #endif
296 // Test loading extension, opening a channel, adding a listener, 288 // Test loading extension, opening a channel, adding a listener,
297 // writing, reading, and closing. 289 // writing, reading, and closing.
298 IN_PROC_BROWSER_TEST_F(CastChannelAPITest, MAYBE_TestOpenReceiveClose) { 290 IN_PROC_BROWSER_TEST_F(CastChannelAPITest, MAYBE_TestOpenReceiveClose) {
299 SetUpMockCastSocket(); 291 SetUpMockCastSocket();
300 EXPECT_CALL(*mock_cast_socket_, error_state()) 292 mock_cast_socket_->SetErrorState(ChannelError::NONE);
301 .WillRepeatedly(Return(ChannelError::NONE));
302 293
303 { 294 {
304 InSequence sequence; 295 InSequence sequence;
305 EXPECT_CALL(*mock_cast_socket_, ConnectRawPtr(NotNull(), _)) 296 EXPECT_CALL(*mock_cast_socket_, ConnectRawPtr(NotNull(), _))
306 .WillOnce(DoAll(SaveArg<0>(&message_delegate_), 297 .WillOnce(DoAll(SaveArg<0>(&message_delegate_),
307 InvokeCompletionCallback<1>(ChannelError::NONE))); 298 InvokeCompletionCallback<1>(ChannelError::NONE)));
308 EXPECT_CALL(*mock_cast_socket_, ready_state()) 299 EXPECT_CALL(*mock_cast_socket_, ready_state())
309 .Times(3) 300 .Times(3)
310 .WillRepeatedly(Return(ReadyState::OPEN)); 301 .WillRepeatedly(Return(ReadyState::OPEN));
311 EXPECT_CALL(*mock_cast_socket_, Close(_)) 302 EXPECT_CALL(*mock_cast_socket_, Close(_))
(...skipping 19 matching lines...) Expand all
331 #define MAYBE_TestOpenError TestOpenError 322 #define MAYBE_TestOpenError TestOpenError
332 #endif 323 #endif
333 // Test the case when socket open results in an error. 324 // Test the case when socket open results in an error.
334 IN_PROC_BROWSER_TEST_F(CastChannelAPITest, MAYBE_TestOpenError) { 325 IN_PROC_BROWSER_TEST_F(CastChannelAPITest, MAYBE_TestOpenError) {
335 SetUpMockCastSocket(); 326 SetUpMockCastSocket();
336 327
337 EXPECT_CALL(*mock_cast_socket_, ConnectRawPtr(NotNull(), _)) 328 EXPECT_CALL(*mock_cast_socket_, ConnectRawPtr(NotNull(), _))
338 .WillOnce(DoAll( 329 .WillOnce(DoAll(
339 SaveArg<0>(&message_delegate_), InvokeDelegateOnError(this, GetApi()), 330 SaveArg<0>(&message_delegate_), InvokeDelegateOnError(this, GetApi()),
340 InvokeCompletionCallback<1>(ChannelError::CONNECT_ERROR))); 331 InvokeCompletionCallback<1>(ChannelError::CONNECT_ERROR)));
341 EXPECT_CALL(*mock_cast_socket_, error_state()) 332 mock_cast_socket_->SetErrorState(ChannelError::CONNECT_ERROR);
342 .WillRepeatedly(Return(ChannelError::CONNECT_ERROR));
343 EXPECT_CALL(*mock_cast_socket_, ready_state()) 333 EXPECT_CALL(*mock_cast_socket_, ready_state())
344 .WillRepeatedly(Return(ReadyState::CLOSED)); 334 .WillRepeatedly(Return(ReadyState::CLOSED));
345 EXPECT_CALL(*mock_cast_socket_, Close(_)) 335 EXPECT_CALL(*mock_cast_socket_, Close(_))
346 .WillOnce(InvokeCompletionCallback<0>(net::OK)); 336 .WillOnce(InvokeCompletionCallback<0>(net::OK));
347 337
348 EXPECT_TRUE(RunExtensionSubtest("cast_channel/api", 338 EXPECT_TRUE(RunExtensionSubtest("cast_channel/api",
349 "test_open_error.html")); 339 "test_open_error.html"));
350 } 340 }
351 341
352 IN_PROC_BROWSER_TEST_F(CastChannelAPITest, TestOpenInvalidConnectInfo) { 342 IN_PROC_BROWSER_TEST_F(CastChannelAPITest, TestOpenInvalidConnectInfo) {
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 "\"keepAlive\": true, " 421 "\"keepAlive\": true, "
432 "\"audioOnly\": false, " 422 "\"audioOnly\": false, "
433 "\"connectInfo\": " 423 "\"connectInfo\": "
434 "{\"ipAddress\": \"127.0.0.1\", \"port\": 8009, " 424 "{\"ipAddress\": \"127.0.0.1\", \"port\": 8009, "
435 "\"auth\": \"ssl_verified\"}, \"readyState\": \"open\"}, " 425 "\"auth\": \"ssl_verified\"}, \"readyState\": \"open\"}, "
436 "{\"namespace_\": \"foo\", \"sourceId\": \"src\", " 426 "{\"namespace_\": \"foo\", \"sourceId\": \"src\", "
437 "\"destinationId\": \"\", \"data\": \"data\"}]", 427 "\"destinationId\": \"\", \"data\": \"data\"}]",
438 browser()); 428 browser());
439 EXPECT_EQ(error, "message_info.destination_id is required"); 429 EXPECT_EQ(error, "message_info.destination_id is required");
440 } 430 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698