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

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

Issue 456213002: Cast channel: Add cast.channel.getLogs extension API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 years, 4 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 "chrome/browser/extensions/extension_apitest.h" 8 #include "chrome/browser/extensions/extension_apitest.h"
9 #include "chrome/browser/extensions/extension_function_test_utils.h" 9 #include "chrome/browser/extensions/extension_function_test_utils.h"
10 #include "chrome/browser/extensions/extension_service.h" 10 #include "chrome/browser/extensions/extension_service.h"
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 net::IPAddressNumber ip_number; 106 net::IPAddressNumber ip_number;
107 net::ParseIPLiteralToNumber("192.168.1.1", &ip_number); 107 net::ParseIPLiteralToNumber("192.168.1.1", &ip_number);
108 net::IPEndPoint ip_endpoint(ip_number, 8009); 108 net::IPEndPoint ip_endpoint(ip_number, 8009);
109 mock_cast_socket_ = new MockCastSocket( 109 mock_cast_socket_ = new MockCastSocket(
110 api, ip_endpoint, &capturing_net_log_, api->GetLogger()); 110 api, ip_endpoint, &capturing_net_log_, api->GetLogger());
111 // Transfers ownership of the socket. 111 // Transfers ownership of the socket.
112 api->SetSocketForTest( 112 api->SetSocketForTest(
113 make_scoped_ptr<CastSocket>(mock_cast_socket_).Pass()); 113 make_scoped_ptr<CastSocket>(mock_cast_socket_).Pass());
114 } 114 }
115 115
116 void SetUpOpenSendClose() {
117 SetUpMockCastSocket();
118 EXPECT_CALL(*mock_cast_socket_, error_state())
119 .WillRepeatedly(Return(cast_channel::CHANNEL_ERROR_NONE));
120 {
121 InSequence sequence;
122 EXPECT_CALL(*mock_cast_socket_, Connect(_))
123 .WillOnce(InvokeCompletionCallback<0>(net::OK));
124 EXPECT_CALL(*mock_cast_socket_, ready_state())
125 .WillOnce(Return(cast_channel::READY_STATE_OPEN));
126 EXPECT_CALL(*mock_cast_socket_, SendMessage(A<const MessageInfo&>(), _))
127 .WillOnce(InvokeCompletionCallback<1>(net::OK));
128 EXPECT_CALL(*mock_cast_socket_, ready_state())
129 .WillOnce(Return(cast_channel::READY_STATE_OPEN));
130 EXPECT_CALL(*mock_cast_socket_, Close(_))
131 .WillOnce(InvokeCompletionCallback<0>(net::OK));
132 EXPECT_CALL(*mock_cast_socket_, ready_state())
133 .WillOnce(Return(cast_channel::READY_STATE_CLOSED));
134 }
135 }
136
116 extensions::CastChannelAPI* GetApi() { 137 extensions::CastChannelAPI* GetApi() {
117 return extensions::CastChannelAPI::Get(profile()); 138 return extensions::CastChannelAPI::Get(profile());
118 } 139 }
119 140
120 void CallOnError(extensions::CastChannelAPI* api) { 141 void CallOnError(extensions::CastChannelAPI* api) {
121 cast_channel::LastErrors last_errors; 142 cast_channel::LastErrors last_errors;
122 last_errors.challenge_reply_error_type = 143 last_errors.challenge_reply_error_type =
123 cast_channel::proto::CHALLENGE_REPLY_ERROR_NSS_CERT_PARSING_FAILED; 144 cast_channel::proto::CHALLENGE_REPLY_ERROR_NSS_CERT_PARSING_FAILED;
124 last_errors.nss_error_code = -8164; 145 last_errors.nss_error_code = -8164;
125 api->OnError(mock_cast_socket_, 146 api->OnError(mock_cast_socket_,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 // TODO(munjal): Win Dbg has a workaround that makes RunExtensionSubtest 188 // TODO(munjal): Win Dbg has a workaround that makes RunExtensionSubtest
168 // always return true without actually running the test. Remove when fixed. 189 // always return true without actually running the test. Remove when fixed.
169 #if defined(OS_WIN) && !defined(NDEBUG) 190 #if defined(OS_WIN) && !defined(NDEBUG)
170 #define MAYBE_TestOpenSendClose DISABLED_TestOpenSendClose 191 #define MAYBE_TestOpenSendClose DISABLED_TestOpenSendClose
171 #else 192 #else
172 #define MAYBE_TestOpenSendClose TestOpenSendClose 193 #define MAYBE_TestOpenSendClose TestOpenSendClose
173 #endif 194 #endif
174 // Test loading extension, opening a channel with ConnectInfo, adding a 195 // Test loading extension, opening a channel with ConnectInfo, adding a
175 // listener, writing, reading, and closing. 196 // listener, writing, reading, and closing.
176 IN_PROC_BROWSER_TEST_F(CastChannelAPITest, MAYBE_TestOpenSendClose) { 197 IN_PROC_BROWSER_TEST_F(CastChannelAPITest, MAYBE_TestOpenSendClose) {
177 SetUpMockCastSocket(); 198 SetUpOpenSendClose();
178 EXPECT_CALL(*mock_cast_socket_, error_state())
179 .WillRepeatedly(Return(cast_channel::CHANNEL_ERROR_NONE));
180
181 {
182 InSequence dummy;
183 EXPECT_CALL(*mock_cast_socket_, Connect(_))
184 .WillOnce(InvokeCompletionCallback<0>(net::OK));
185 EXPECT_CALL(*mock_cast_socket_, ready_state())
186 .WillOnce(Return(cast_channel::READY_STATE_OPEN));
187 EXPECT_CALL(*mock_cast_socket_, SendMessage(A<const MessageInfo&>(), _))
188 .WillOnce(InvokeCompletionCallback<1>(net::OK));
189 EXPECT_CALL(*mock_cast_socket_, ready_state())
190 .WillOnce(Return(cast_channel::READY_STATE_OPEN));
191 EXPECT_CALL(*mock_cast_socket_, Close(_))
192 .WillOnce(InvokeCompletionCallback<0>(net::OK));
193 EXPECT_CALL(*mock_cast_socket_, ready_state())
194 .WillOnce(Return(cast_channel::READY_STATE_CLOSED));
195 }
196 199
197 EXPECT_TRUE(RunExtensionSubtest("cast_channel/api", 200 EXPECT_TRUE(RunExtensionSubtest("cast_channel/api",
198 "test_open_send_close.html")); 201 "test_open_send_close.html"));
199 } 202 }
200 203
201 // TODO(munjal): Win Dbg has a workaround that makes RunExtensionSubtest 204 // TODO(munjal): Win Dbg has a workaround that makes RunExtensionSubtest
202 // always return true without actually running the test. Remove when fixed. 205 // always return true without actually running the test. Remove when fixed.
203 #if defined(OS_WIN) && !defined(NDEBUG) 206 #if defined(OS_WIN) && !defined(NDEBUG)
204 #define MAYBE_TestOpenSendCloseWithUrl DISABLED_TestOpenSendCloseWithUrl 207 #define MAYBE_TestOpenSendCloseWithUrl DISABLED_TestOpenSendCloseWithUrl
205 #else 208 #else
206 #define MAYBE_TestOpenSendCloseWithUrl TestOpenSendCloseWithUrl 209 #define MAYBE_TestOpenSendCloseWithUrl TestOpenSendCloseWithUrl
207 #endif 210 #endif
208 // Test loading extension, opening a channel with a URL, adding a listener, 211 // Test loading extension, opening a channel with a URL, adding a listener,
209 // writing, reading, and closing. 212 // writing, reading, and closing.
210 IN_PROC_BROWSER_TEST_F(CastChannelAPITest, MAYBE_TestOpenSendCloseWithUrl) { 213 IN_PROC_BROWSER_TEST_F(CastChannelAPITest, MAYBE_TestOpenSendCloseWithUrl) {
211 SetUpMockCastSocket(); 214 SetUpOpenSendClose();
212 EXPECT_CALL(*mock_cast_socket_, error_state())
213 .WillRepeatedly(Return(cast_channel::CHANNEL_ERROR_NONE));
214
215 {
216 InSequence dummy;
217 EXPECT_CALL(*mock_cast_socket_, Connect(_))
218 .WillOnce(InvokeCompletionCallback<0>(net::OK));
219 EXPECT_CALL(*mock_cast_socket_, ready_state())
220 .WillOnce(Return(cast_channel::READY_STATE_OPEN));
221 EXPECT_CALL(*mock_cast_socket_, SendMessage(A<const MessageInfo&>(), _))
222 .WillOnce(InvokeCompletionCallback<1>(net::OK));
223 EXPECT_CALL(*mock_cast_socket_, ready_state())
224 .WillOnce(Return(cast_channel::READY_STATE_OPEN));
225 EXPECT_CALL(*mock_cast_socket_, Close(_))
226 .WillOnce(InvokeCompletionCallback<0>(net::OK));
227 EXPECT_CALL(*mock_cast_socket_, ready_state())
228 .WillOnce(Return(cast_channel::READY_STATE_CLOSED));
229 }
230 215
231 EXPECT_TRUE(RunExtensionSubtest("cast_channel/api", 216 EXPECT_TRUE(RunExtensionSubtest("cast_channel/api",
232 "test_open_send_close_url.html")); 217 "test_open_send_close_url.html"));
233 } 218 }
234 219
235 // TODO(munjal): Win Dbg has a workaround that makes RunExtensionSubtest 220 // TODO(munjal): Win Dbg has a workaround that makes RunExtensionSubtest
236 // always return true without actually running the test. Remove when fixed. 221 // always return true without actually running the test. Remove when fixed.
237 #if defined(OS_WIN) && !defined(NDEBUG) 222 #if defined(OS_WIN) && !defined(NDEBUG)
238 #define MAYBE_TestOpenReceiveClose DISABLED_TestOpenReceiveClose 223 #define MAYBE_TestOpenReceiveClose DISABLED_TestOpenReceiveClose
239 #else 224 #else
240 #define MAYBE_TestOpenReceiveClose TestOpenReceiveClose 225 #define MAYBE_TestOpenReceiveClose TestOpenReceiveClose
241 #endif 226 #endif
242 // Test loading extension, opening a channel, adding a listener, 227 // Test loading extension, opening a channel, adding a listener,
243 // writing, reading, and closing. 228 // writing, reading, and closing.
244 IN_PROC_BROWSER_TEST_F(CastChannelAPITest, MAYBE_TestOpenReceiveClose) { 229 IN_PROC_BROWSER_TEST_F(CastChannelAPITest, MAYBE_TestOpenReceiveClose) {
245 SetUpMockCastSocket(); 230 SetUpMockCastSocket();
246 EXPECT_CALL(*mock_cast_socket_, error_state()) 231 EXPECT_CALL(*mock_cast_socket_, error_state())
247 .WillRepeatedly(Return(cast_channel::CHANNEL_ERROR_NONE)); 232 .WillRepeatedly(Return(cast_channel::CHANNEL_ERROR_NONE));
248 233
249 { 234 {
250 InSequence dummy; 235 InSequence sequence;
251 EXPECT_CALL(*mock_cast_socket_, Connect(_)) 236 EXPECT_CALL(*mock_cast_socket_, Connect(_))
252 .WillOnce(InvokeCompletionCallback<0>(net::OK)); 237 .WillOnce(InvokeCompletionCallback<0>(net::OK));
253 EXPECT_CALL(*mock_cast_socket_, ready_state()) 238 EXPECT_CALL(*mock_cast_socket_, ready_state())
254 .Times(3) 239 .Times(3)
255 .WillRepeatedly(Return(cast_channel::READY_STATE_OPEN)); 240 .WillRepeatedly(Return(cast_channel::READY_STATE_OPEN));
256 EXPECT_CALL(*mock_cast_socket_, Close(_)) 241 EXPECT_CALL(*mock_cast_socket_, Close(_))
257 .WillOnce(InvokeCompletionCallback<0>(net::OK)); 242 .WillOnce(InvokeCompletionCallback<0>(net::OK));
258 EXPECT_CALL(*mock_cast_socket_, ready_state()) 243 EXPECT_CALL(*mock_cast_socket_, ready_state())
259 .WillOnce(Return(cast_channel::READY_STATE_CLOSED)); 244 .WillOnce(Return(cast_channel::READY_STATE_CLOSED));
260 } 245 }
261 246
262 EXPECT_TRUE(RunExtensionSubtest("cast_channel/api", 247 EXPECT_TRUE(RunExtensionSubtest("cast_channel/api",
263 "test_open_receive_close.html")); 248 "test_open_receive_close.html"));
264 249
265 ResultCatcher catcher; 250 ResultCatcher catcher;
266 CallOnMessage("some-message"); 251 CallOnMessage("some-message");
267 CallOnMessage("some-message"); 252 CallOnMessage("some-message");
268 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 253 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
269 } 254 }
270 255
256 // TODO(imcheng): Win Dbg has a workaround that makes RunExtensionSubtest
257 // always return true without actually running the test. Remove when fixed.
258 #if defined(OS_WIN) && !defined(NDEBUG)
259 #define MAYBE_TestGetLogs DISABLED_TestGetLogs
260 #else
261 #define MAYBE_TestGetLogs TestGetLogs
262 #endif
263 // Test loading extension, execute a open-send-close sequence, then get logs.
264 IN_PROC_BROWSER_TEST_F(CastChannelAPITest, MAYBE_TestGetLogs) {
265 SetUpOpenSendClose();
266
267 EXPECT_TRUE(RunExtensionSubtest("cast_channel/api", "test_get_logs.html"));
268 }
269
271 // TODO(munjal): Win Dbg has a workaround that makes RunExtensionSubtest 270 // TODO(munjal): Win Dbg has a workaround that makes RunExtensionSubtest
272 // always return true without actually running the test. Remove when fixed. 271 // always return true without actually running the test. Remove when fixed.
273 // Flaky on mac: crbug.com/393969 272 // Flaky on mac: crbug.com/393969
274 #if (defined(OS_WIN) && !defined(NDEBUG)) || defined(OS_MACOSX) 273 #if (defined(OS_WIN) && !defined(NDEBUG)) || defined(OS_MACOSX)
275 #define MAYBE_TestOpenError DISABLED_TestOpenError 274 #define MAYBE_TestOpenError DISABLED_TestOpenError
276 #else 275 #else
277 #define MAYBE_TestOpenError TestOpenError 276 #define MAYBE_TestOpenError TestOpenError
278 #endif 277 #endif
279 // Test the case when socket open results in an error. 278 // Test the case when socket open results in an error.
280 IN_PROC_BROWSER_TEST_F(CastChannelAPITest, MAYBE_TestOpenError) { 279 IN_PROC_BROWSER_TEST_F(CastChannelAPITest, MAYBE_TestOpenError) {
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 cast_channel_send_function.get(), 389 cast_channel_send_function.get(),
391 "[{\"channelId\": 1, \"url\": \"cast://127.0.0.1:8009\", " 390 "[{\"channelId\": 1, \"url\": \"cast://127.0.0.1:8009\", "
392 "\"connectInfo\": " 391 "\"connectInfo\": "
393 "{\"ipAddress\": \"127.0.0.1\", \"port\": 8009, " 392 "{\"ipAddress\": \"127.0.0.1\", \"port\": 8009, "
394 "\"auth\": \"ssl\"}, \"readyState\": \"open\"}, " 393 "\"auth\": \"ssl\"}, \"readyState\": \"open\"}, "
395 "{\"namespace_\": \"foo\", \"sourceId\": \"src\", " 394 "{\"namespace_\": \"foo\", \"sourceId\": \"src\", "
396 "\"destinationId\": \"\", \"data\": \"data\"}]", 395 "\"destinationId\": \"\", \"data\": \"data\"}]",
397 browser()); 396 browser());
398 EXPECT_EQ(error, "message_info.destination_id is required"); 397 EXPECT_EQ(error, "message_info.destination_id is required");
399 } 398 }
OLDNEW
« no previous file with comments | « extensions/browser/api/cast_channel/cast_channel_api.cc ('k') | extensions/browser/api/cast_channel/logger.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698