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
3 // found in the LICENSE file.
6 #include "base/command_line.h"
7 #include "base/files/file_path.h"
8 #include "base/timer/mock_timer.h"
9 #include "chrome/browser/extensions/extension_apitest.h"
10 #include "chrome/browser/extensions/extension_function_test_utils.h"
11 #include "chrome/browser/extensions/extension_service.h"
12 #include "chrome/browser/ui/browser.h"
13 #include "content/public/browser/browser_thread.h"
14 #include "extensions/browser/api/cast_channel/cast_channel_api.h"
15 #include "extensions/browser/api/cast_channel/cast_socket.h"
16 #include "extensions/browser/api/cast_channel/logger.h"
17 #include "extensions/browser/api/cast_channel/test_util.h"
18 #include "extensions/common/api/cast_channel.h"
19 #include "extensions/common/api/cast_channel/cast_channel.pb.h"
20 #include "extensions/common/switches.h"
21 #include "extensions/common/test_util.h"
22 #include "extensions/test/extension_test_message_listener.h"
23 #include "extensions/test/result_catcher.h"
24 #include "net/base/capturing_net_log.h"
25 #include "net/base/completion_callback.h"
26 #include "net/base/net_errors.h"
27 #include "testing/gmock/include/gmock/gmock.h"
28 #include "testing/gmock_mutant.h"
30 // TODO(mfoltz): Mock out the ApiResourceManager to resolve threading issues
31 // (crbug.com/398242) and simulate unloading of the extension.
33 namespace cast_channel
= extensions::core_api::cast_channel
;
34 using cast_channel::CastMessage
;
35 using cast_channel::CastSocket
;
36 using cast_channel::CastTransport
;
37 using cast_channel::ChannelAuthType
;
38 using cast_channel::ChannelError
;
39 using cast_channel::CreateIPEndPointForTest
;
40 using cast_channel::ErrorInfo
;
41 using cast_channel::Logger
;
42 using cast_channel::MessageInfo
;
43 using cast_channel::MockCastSocket
;
44 using cast_channel::MockCastTransport
;
45 using cast_channel::ReadyState
;
46 using extensions::Extension
;
48 namespace utils
= extension_function_test_utils
;
52 using ::testing::DoAll
;
53 using ::testing::Invoke
;
54 using ::testing::InSequence
;
55 using ::testing::NotNull
;
56 using ::testing::Return
;
57 using ::testing::ReturnRef
;
58 using ::testing::ReturnPointee
;
59 using ::testing::SaveArg
;
63 const char kTestCastUrl
[] = "cast://192.168.1.1:8009";
65 static void FillCastMessage(const std::string
& message
,
66 CastMessage
* cast_message
) {
67 cast_message
->set_namespace_("foo");
68 cast_message
->set_source_id("src");
69 cast_message
->set_destination_id("dest");
70 cast_message
->set_payload_utf8(message
);
71 cast_message
->set_payload_type(CastMessage::STRING
);
74 ACTION_TEMPLATE(InvokeCompletionCallback
,
75 HAS_1_TEMPLATE_PARAMS(int, k
),
76 AND_1_VALUE_PARAMS(result
)) {
77 ::std::tr1::get
<k
>(args
).Run(result
);
80 ACTION_P2(InvokeDelegateOnError
, api_test
, api
) {
81 api_test
->CallOnError(api
);
86 class CastChannelAPITest
: public ExtensionApiTest
{
88 CastChannelAPITest() : ip_endpoint_(CreateIPEndPointForTest()) {}
90 void SetUpCommandLine(base::CommandLine
* command_line
) override
{
91 ExtensionApiTest::SetUpCommandLine(command_line
);
92 command_line
->AppendSwitchASCII(
93 extensions::switches::kWhitelistedExtensionID
,
94 cast_channel::kTestExtensionId
);
97 void SetUpMockCastSocket() {
98 extensions::CastChannelAPI
* api
= GetApi();
99 timeout_timer_
= new base::MockTimer(true, false);
100 api
->SetPingTimeoutTimerForTest(make_scoped_ptr(timeout_timer_
));
102 net::IPAddressNumber ip_number
;
103 net::ParseIPLiteralToNumber("192.168.1.1", &ip_number
);
104 net::IPEndPoint
ip_endpoint(ip_number
, 8009);
105 mock_cast_socket_
= new MockCastSocket
;
106 // Transfers ownership of the socket.
107 api
->SetSocketForTest(
108 make_scoped_ptr
<CastSocket
>(mock_cast_socket_
).Pass());
109 ON_CALL(*mock_cast_socket_
, set_id(_
))
110 .WillByDefault(SaveArg
<0>(&channel_id_
));
111 ON_CALL(*mock_cast_socket_
, id())
112 .WillByDefault(ReturnPointee(&channel_id_
));
113 ON_CALL(*mock_cast_socket_
, ip_endpoint())
114 .WillByDefault(ReturnRef(ip_endpoint_
));
115 ON_CALL(*mock_cast_socket_
, channel_auth())
116 .WillByDefault(Return(cast_channel::CHANNEL_AUTH_TYPE_SSL
));
117 ON_CALL(*mock_cast_socket_
, keep_alive()).WillByDefault(Return(false));
118 ON_CALL(*mock_cast_socket_
, cast_url()).WillByDefault(Return(kTestCastUrl
));
121 void SetUpOpenSendClose() {
122 SetUpMockCastSocket();
123 EXPECT_CALL(*mock_cast_socket_
, error_state())
124 .WillRepeatedly(Return(cast_channel::CHANNEL_ERROR_NONE
));
127 EXPECT_CALL(*mock_cast_socket_
, ConnectRawPtr(_
, _
))
129 InvokeCompletionCallback
<1>(cast_channel::CHANNEL_ERROR_NONE
));
130 EXPECT_CALL(*mock_cast_socket_
, ready_state())
131 .WillOnce(Return(cast_channel::READY_STATE_OPEN
));
132 EXPECT_CALL(*mock_cast_socket_
->mock_transport(),
133 SendMessage(A
<const CastMessage
&>(), _
))
134 .WillOnce(InvokeCompletionCallback
<1>(net::OK
));
135 EXPECT_CALL(*mock_cast_socket_
, ready_state())
136 .WillOnce(Return(cast_channel::READY_STATE_OPEN
));
137 EXPECT_CALL(*mock_cast_socket_
, Close(_
))
138 .WillOnce(InvokeCompletionCallback
<0>(net::OK
));
139 EXPECT_CALL(*mock_cast_socket_
, ready_state())
140 .WillOnce(Return(cast_channel::READY_STATE_CLOSED
));
144 void SetUpOpenPingTimeout() {
145 SetUpMockCastSocket();
146 EXPECT_CALL(*mock_cast_socket_
, error_state())
147 .WillRepeatedly(Return(cast_channel::CHANNEL_ERROR_NONE
));
148 EXPECT_CALL(*mock_cast_socket_
, keep_alive()).WillRepeatedly(Return(true));
151 EXPECT_CALL(*mock_cast_socket_
, ConnectRawPtr(_
, _
))
153 SaveArg
<0>(&message_delegate_
),
154 InvokeCompletionCallback
<1>(cast_channel::CHANNEL_ERROR_NONE
)));
155 EXPECT_CALL(*mock_cast_socket_
, ready_state())
156 .WillOnce(Return(cast_channel::READY_STATE_OPEN
))
157 .RetiresOnSaturation();
158 EXPECT_CALL(*mock_cast_socket_
, ready_state())
159 .WillOnce(Return(cast_channel::READY_STATE_CLOSED
));
163 extensions::CastChannelAPI
* GetApi() {
164 return extensions::CastChannelAPI::Get(profile());
167 void CallOnError(extensions::CastChannelAPI
* api
) {
168 cast_channel::LastErrors last_errors
;
169 last_errors
.challenge_reply_error_type
=
170 cast_channel::proto::CHALLENGE_REPLY_ERROR_CERT_PARSING_FAILED
;
171 last_errors
.nss_error_code
= -8164;
172 message_delegate_
->OnError(cast_channel::CHANNEL_ERROR_CONNECT_ERROR
,
177 void CallOnMessage(const std::string
& message
) {
178 content::BrowserThread::PostTask(
179 content::BrowserThread::IO
,
181 base::Bind(&CastChannelAPITest::DoCallOnMessage
, this,
182 GetApi(), mock_cast_socket_
, message
));
185 void DoCallOnMessage(extensions::CastChannelAPI
* api
,
186 MockCastSocket
* cast_socket
,
187 const std::string
& message
) {
188 CastMessage cast_message
;
189 FillCastMessage(message
, &cast_message
);
190 message_delegate_
->OnMessage(cast_message
);
193 // Starts the read delegate on the IO thread.
194 void StartDelegate() {
195 CHECK(message_delegate_
);
196 content::BrowserThread::PostTask(
197 content::BrowserThread::IO
, FROM_HERE
,
198 base::Bind(&cast_channel::CastTransport::Delegate::Start
,
199 base::Unretained(message_delegate_
)));
202 // Fires a timer on the IO thread.
204 content::BrowserThread::PostTask(
205 content::BrowserThread::IO
, FROM_HERE
,
206 base::Bind(&base::MockTimer::Fire
, base::Unretained(timeout_timer_
)));
209 extensions::CastChannelOpenFunction
* CreateOpenFunction(
210 scoped_refptr
<Extension
> extension
) {
211 extensions::CastChannelOpenFunction
* cast_channel_open_function
=
212 new extensions::CastChannelOpenFunction
;
213 cast_channel_open_function
->set_extension(extension
.get());
214 return cast_channel_open_function
;
217 extensions::CastChannelSendFunction
* CreateSendFunction(
218 scoped_refptr
<Extension
> extension
) {
219 extensions::CastChannelSendFunction
* cast_channel_send_function
=
220 new extensions::CastChannelSendFunction
;
221 cast_channel_send_function
->set_extension(extension
.get());
222 return cast_channel_send_function
;
225 extensions::CastChannelSetAuthorityKeysFunction
*
226 CreateSetAuthorityKeysFunction(scoped_refptr
<Extension
> extension
) {
227 extensions::CastChannelSetAuthorityKeysFunction
*
228 cast_channel_set_authority_keys_function
=
229 new extensions::CastChannelSetAuthorityKeysFunction
;
230 cast_channel_set_authority_keys_function
->set_extension(extension
.get());
231 return cast_channel_set_authority_keys_function
;
234 MockCastSocket
* mock_cast_socket_
;
235 base::MockTimer
* timeout_timer_
;
236 net::IPEndPoint ip_endpoint_
;
237 CastTransport::Delegate
* message_delegate_
;
238 net::CapturingNetLog capturing_net_log_
;
242 // TODO(kmarshall): Win Dbg has a workaround that makes RunExtensionSubtest
243 // always return true without actually running the test. Remove when fixed.
244 #if defined(OS_WIN) && !defined(NDEBUG)
245 #define MAYBE_TestOpenSendClose DISABLED_TestOpenSendClose
247 #define MAYBE_TestOpenSendClose TestOpenSendClose
249 // Test loading extension, opening a channel with ConnectInfo, adding a
250 // listener, writing, reading, and closing.
251 IN_PROC_BROWSER_TEST_F(CastChannelAPITest
, MAYBE_TestOpenSendClose
) {
252 SetUpOpenSendClose();
254 EXPECT_TRUE(RunExtensionSubtest("cast_channel/api",
255 "test_open_send_close.html"));
258 // TODO(kmarshall): Win Dbg has a workaround that makes RunExtensionSubtest
259 // always return true without actually running the test. Remove when fixed.
260 #if defined(OS_WIN) && !defined(NDEBUG)
261 #define MAYBE_TestPingTimeout DISABLED_TestPingTimeout
263 #define MAYBE_TestPingTimeout TestPingTimeout
265 // Verify that timeout events are propagated through the API layer.
266 // (SSL, non-verified).
267 IN_PROC_BROWSER_TEST_F(CastChannelAPITest
, MAYBE_TestPingTimeout
) {
268 SetUpOpenPingTimeout();
270 ExtensionTestMessageListener
channel_opened("channel_opened_ssl", false);
271 ExtensionTestMessageListener
timeout("timeout_ssl", false);
273 RunExtensionSubtest("cast_channel/api", "test_open_timeout.html"));
274 EXPECT_TRUE(channel_opened
.WaitUntilSatisfied());
277 EXPECT_TRUE(timeout
.WaitUntilSatisfied());
280 // TODO(kmarshall): Win Dbg has a workaround that makes RunExtensionSubtest
281 // always return true without actually running the test. Remove when fixed.
282 #if defined(OS_WIN) && !defined(NDEBUG)
283 #define MAYBE_TestPingTimeoutSslVerified DISABLED_TestPingTimeoutSslVerified
285 #define MAYBE_TestPingTimeoutSslVerified TestPingTimeoutSslVerified
287 // Verify that timeout events are propagated through the API layer.
289 IN_PROC_BROWSER_TEST_F(CastChannelAPITest
, MAYBE_TestPingTimeoutSslVerified
) {
290 SetUpOpenPingTimeout();
292 ExtensionTestMessageListener
channel_opened("channel_opened_ssl_verified",
294 ExtensionTestMessageListener
timeout("timeout_ssl_verified", false);
295 EXPECT_TRUE(RunExtensionSubtest("cast_channel/api",
296 "test_open_timeout_verified.html"));
297 EXPECT_TRUE(channel_opened
.WaitUntilSatisfied());
300 EXPECT_TRUE(timeout
.WaitUntilSatisfied());
303 // TODO(kmarshall): Win Dbg has a workaround that makes RunExtensionSubtest
304 // always return true without actually running the test. Remove when fixed.
305 #if defined(OS_WIN) && !defined(NDEBUG)
306 #define MAYBE_TestOpenSendCloseWithUrl DISABLED_TestOpenSendCloseWithUrl
308 #define MAYBE_TestOpenSendCloseWithUrl TestOpenSendCloseWithUrl
310 // Test loading extension, opening a channel with a URL, adding a listener,
311 // writing, reading, and closing.
312 IN_PROC_BROWSER_TEST_F(CastChannelAPITest
, MAYBE_TestOpenSendCloseWithUrl
) {
313 SetUpOpenSendClose();
315 EXPECT_TRUE(RunExtensionSubtest("cast_channel/api",
316 "test_open_send_close_url.html"));
319 // TODO(kmarshall): Win Dbg has a workaround that makes RunExtensionSubtest
320 // always return true without actually running the test. Remove when fixed.
321 #if defined(OS_WIN) && !defined(NDEBUG)
322 #define MAYBE_TestOpenReceiveClose DISABLED_TestOpenReceiveClose
324 #define MAYBE_TestOpenReceiveClose TestOpenReceiveClose
326 // Test loading extension, opening a channel, adding a listener,
327 // writing, reading, and closing.
328 IN_PROC_BROWSER_TEST_F(CastChannelAPITest
, MAYBE_TestOpenReceiveClose
) {
329 SetUpMockCastSocket();
330 EXPECT_CALL(*mock_cast_socket_
, error_state())
331 .WillRepeatedly(Return(cast_channel::CHANNEL_ERROR_NONE
));
335 EXPECT_CALL(*mock_cast_socket_
, ConnectRawPtr(NotNull(), _
))
337 SaveArg
<0>(&message_delegate_
),
338 InvokeCompletionCallback
<1>(cast_channel::CHANNEL_ERROR_NONE
)));
339 EXPECT_CALL(*mock_cast_socket_
, ready_state())
341 .WillRepeatedly(Return(cast_channel::READY_STATE_OPEN
));
342 EXPECT_CALL(*mock_cast_socket_
, Close(_
))
343 .WillOnce(InvokeCompletionCallback
<0>(net::OK
));
344 EXPECT_CALL(*mock_cast_socket_
, ready_state())
345 .WillOnce(Return(cast_channel::READY_STATE_CLOSED
));
348 EXPECT_TRUE(RunExtensionSubtest("cast_channel/api",
349 "test_open_receive_close.html"));
351 extensions::ResultCatcher catcher
;
352 CallOnMessage("some-message");
353 CallOnMessage("some-message");
354 EXPECT_TRUE(catcher
.GetNextResult()) << catcher
.message();
357 // TODO(imcheng): Win Dbg has a workaround that makes RunExtensionSubtest
358 // always return true without actually running the test. Remove when fixed.
359 #if defined(OS_WIN) && !defined(NDEBUG)
360 #define MAYBE_TestGetLogs DISABLED_TestGetLogs
362 #define MAYBE_TestGetLogs TestGetLogs
364 // Test loading extension, execute a open-send-close sequence, then get logs.
365 IN_PROC_BROWSER_TEST_F(CastChannelAPITest
, MAYBE_TestGetLogs
) {
366 SetUpOpenSendClose();
368 EXPECT_TRUE(RunExtensionSubtest("cast_channel/api", "test_get_logs.html"));
371 // TODO(kmarshall): Win Dbg has a workaround that makes RunExtensionSubtest
372 // always return true without actually running the test. Remove when fixed.
373 #if defined(OS_WIN) && !defined(NDEBUG)
374 #define MAYBE_TestOpenError DISABLED_TestOpenError
376 #define MAYBE_TestOpenError TestOpenError
378 // Test the case when socket open results in an error.
379 IN_PROC_BROWSER_TEST_F(CastChannelAPITest
, MAYBE_TestOpenError
) {
380 SetUpMockCastSocket();
382 EXPECT_CALL(*mock_cast_socket_
, ConnectRawPtr(NotNull(), _
))
383 .WillOnce(DoAll(SaveArg
<0>(&message_delegate_
),
384 InvokeDelegateOnError(this, GetApi()),
385 InvokeCompletionCallback
<1>(
386 cast_channel::CHANNEL_ERROR_CONNECT_ERROR
)));
387 EXPECT_CALL(*mock_cast_socket_
, error_state())
388 .WillRepeatedly(Return(cast_channel::CHANNEL_ERROR_CONNECT_ERROR
));
389 EXPECT_CALL(*mock_cast_socket_
, ready_state())
390 .WillRepeatedly(Return(cast_channel::READY_STATE_CLOSED
));
391 EXPECT_CALL(*mock_cast_socket_
, Close(_
))
392 .WillOnce(InvokeCompletionCallback
<0>(net::OK
));
394 EXPECT_TRUE(RunExtensionSubtest("cast_channel/api",
395 "test_open_error.html"));
398 IN_PROC_BROWSER_TEST_F(CastChannelAPITest
, TestOpenInvalidConnectInfo
) {
399 scoped_refptr
<Extension
> empty_extension
=
400 extensions::test_util::CreateEmptyExtension();
401 scoped_refptr
<extensions::CastChannelOpenFunction
> cast_channel_open_function
;
404 // TODO(mfoltz): Remove this test case when fixing crbug.com/331905
405 cast_channel_open_function
= CreateOpenFunction(empty_extension
);
406 std::string
error(utils::RunFunctionAndReturnError(
407 cast_channel_open_function
.get(), "[\"blargh\"]", browser()));
408 EXPECT_EQ(error
, "Invalid connect_info (invalid Cast URL blargh)");
411 // TODO(mfoltz): Remove this test case when fixing crbug.com/331905
412 cast_channel_open_function
= CreateOpenFunction(empty_extension
);
413 error
= utils::RunFunctionAndReturnError(
414 cast_channel_open_function
.get(),
416 EXPECT_EQ(error
, "Invalid connect_info (unknown type)");
418 // Invalid IP address
419 cast_channel_open_function
= CreateOpenFunction(empty_extension
);
420 error
= utils::RunFunctionAndReturnError(
421 cast_channel_open_function
.get(),
422 "[{\"ipAddress\": \"invalid_ip\", \"port\": 8009, \"auth\": \"ssl\"}]",
424 EXPECT_EQ(error
, "Invalid connect_info (invalid IP address)");
427 cast_channel_open_function
= CreateOpenFunction(empty_extension
);
428 error
= utils::RunFunctionAndReturnError(
429 cast_channel_open_function
.get(),
430 "[{\"ipAddress\": \"127.0.0.1\", \"port\": -200, \"auth\": \"ssl\"}]",
432 EXPECT_EQ(error
, "Invalid connect_info (invalid port)");
435 cast_channel_open_function
= CreateOpenFunction(empty_extension
);
436 error
= utils::RunFunctionAndReturnError(
437 cast_channel_open_function
.get(),
438 "[{\"ipAddress\": \"127.0.0.1\", \"port\": 8009}]",
440 EXPECT_EQ(error
, "connect_info.auth is required");
443 IN_PROC_BROWSER_TEST_F(CastChannelAPITest
, TestSendInvalidMessageInfo
) {
444 scoped_refptr
<Extension
> empty_extension(
445 extensions::test_util::CreateEmptyExtension());
446 scoped_refptr
<extensions::CastChannelSendFunction
> cast_channel_send_function
;
448 // Numbers are not supported
449 cast_channel_send_function
= CreateSendFunction(empty_extension
);
450 std::string
error(utils::RunFunctionAndReturnError(
451 cast_channel_send_function
.get(),
452 "[{\"channelId\": 1, \"url\": \"cast://127.0.0.1:8009\", "
453 "\"keepAlive\": true, "
455 "{\"ipAddress\": \"127.0.0.1\", \"port\": 8009, "
456 "\"auth\": \"ssl\"}, \"readyState\": \"open\"}, "
457 "{\"namespace_\": \"foo\", \"sourceId\": \"src\", "
458 "\"destinationId\": \"dest\", \"data\": 1235}]",
460 EXPECT_EQ(error
, "Invalid type of message_info.data");
462 // Missing namespace_
463 cast_channel_send_function
= CreateSendFunction(empty_extension
);
464 error
= utils::RunFunctionAndReturnError(
465 cast_channel_send_function
.get(),
466 "[{\"channelId\": 1, \"url\": \"cast://127.0.0.1:8009\", "
467 "\"keepAlive\": true, "
469 "{\"ipAddress\": \"127.0.0.1\", \"port\": 8009, "
470 "\"auth\": \"ssl\"}, \"readyState\": \"open\"}, "
471 "{\"namespace_\": \"\", \"sourceId\": \"src\", "
472 "\"destinationId\": \"dest\", \"data\": \"data\"}]",
474 EXPECT_EQ(error
, "message_info.namespace_ is required");
477 cast_channel_send_function
= CreateSendFunction(empty_extension
);
478 error
= utils::RunFunctionAndReturnError(
479 cast_channel_send_function
.get(),
480 "[{\"channelId\": 1, \"url\": \"cast://127.0.0.1:8009\", "
481 "\"keepAlive\": true, "
483 "{\"ipAddress\": \"127.0.0.1\", \"port\": 8009, "
484 "\"auth\": \"ssl\"}, \"readyState\": \"open\"}, "
485 "{\"namespace_\": \"foo\", \"sourceId\": \"\", "
486 "\"destinationId\": \"dest\", \"data\": \"data\"}]",
488 EXPECT_EQ(error
, "message_info.source_id is required");
490 // Missing destination_id
491 cast_channel_send_function
= CreateSendFunction(empty_extension
);
492 error
= utils::RunFunctionAndReturnError(
493 cast_channel_send_function
.get(),
494 "[{\"channelId\": 1, \"url\": \"cast://127.0.0.1:8009\", "
495 "\"keepAlive\": true, "
497 "{\"ipAddress\": \"127.0.0.1\", \"port\": 8009, "
498 "\"auth\": \"ssl\"}, \"readyState\": \"open\"}, "
499 "{\"namespace_\": \"foo\", \"sourceId\": \"src\", "
500 "\"destinationId\": \"\", \"data\": \"data\"}]",
502 EXPECT_EQ(error
, "message_info.destination_id is required");
505 IN_PROC_BROWSER_TEST_F(CastChannelAPITest
, TestSetAuthorityKeysInvalid
) {
506 scoped_refptr
<Extension
> empty_extension(
507 extensions::test_util::CreateEmptyExtension());
508 scoped_refptr
<extensions::CastChannelSetAuthorityKeysFunction
>
509 cast_channel_set_authority_keys_function
;
510 std::string errorResult
= "Unable to set authority keys.";
512 cast_channel_set_authority_keys_function
=
513 CreateSetAuthorityKeysFunction(empty_extension
);
514 std::string error
= utils::RunFunctionAndReturnError(
515 cast_channel_set_authority_keys_function
.get(),
516 "[\"\", \"signature\"]",
518 EXPECT_EQ(error
, errorResult
);
520 cast_channel_set_authority_keys_function
=
521 CreateSetAuthorityKeysFunction(empty_extension
);
522 error
= utils::RunFunctionAndReturnError(
523 cast_channel_set_authority_keys_function
.get(),
526 EXPECT_EQ(error
, errorResult
);
529 "CrMCCiBSnZzWf+XraY5w3SbX2PEmWfHm5SNIv2pc9xbhP0EOcxKOAjCCAQoCggEBALwigL"
530 "2A9johADuudl41fz3DZFxVlIY0LwWHKM33aYwXs1CnuIL638dDLdZ+q6BvtxNygKRHFcEg"
531 "mVDN7BRiCVukmM3SQbY2Tv/oLjIwSoGoQqNsmzNuyrL1U2bgJ1OGGoUepzk/SneO+1RmZv"
532 "tYVMBeOcf1UAYL4IrUzuFqVR+LFwDmaaMn5gglaTwSnY0FLNYuojHetFJQ1iBJ3nGg+a0g"
533 "QBLx3SXr1ea4NvTWj3/KQ9zXEFvmP1GKhbPz//YDLcsjT5ytGOeTBYysUpr3TOmZer5ufk"
534 "0K48YcqZP6OqWRXRy9ZuvMYNyGdMrP+JIcmH1X+mFHnquAt+RIgCqSxRsCAwEAAQ==";
535 std::string signature
=
536 "chCUHZKkykcwU8HzU+hm027fUTBL0dqPMtrzppwExQwK9+"
537 "XlmCjJswfce2sUUfhR1OL1tyW4hWFwu4JnuQCJ+CvmSmAh2bzRpnuSKzBfgvIDjNOAGUs7"
538 "ADaNSSWPLxp+6ko++2Dn4S9HpOt8N1v6gMWqj3Ru5IqFSQPZSvGH2ois6uE50CFayPcjQE"
539 "OVZt41noQdFd15RmKTvocoCC5tHNlaikeQ52yi0IScOlad1B1lMhoplW3rWophQaqxMumr"
540 "OcHIZ+Y+p858x5f8Pny/kuqUClmFh9B/vF07NsUHwoSL9tA5t5jCY3L5iUc/v7o3oFcW/T"
541 "gojKkX2Kg7KQ86QA==";
543 cast_channel_set_authority_keys_function
=
544 CreateSetAuthorityKeysFunction(empty_extension
);
545 error
= utils::RunFunctionAndReturnError(
546 cast_channel_set_authority_keys_function
.get(),
547 "[\"" + keys
+ "\", \"signature\"]",
549 EXPECT_EQ(error
, errorResult
);
551 cast_channel_set_authority_keys_function
=
552 CreateSetAuthorityKeysFunction(empty_extension
);
553 error
= utils::RunFunctionAndReturnError(
554 cast_channel_set_authority_keys_function
.get(),
555 "[\"keys\", \"" + signature
+ "\"]",
557 EXPECT_EQ(error
, errorResult
);
559 cast_channel_set_authority_keys_function
=
560 CreateSetAuthorityKeysFunction(empty_extension
);
561 error
= utils::RunFunctionAndReturnError(
562 cast_channel_set_authority_keys_function
.get(),
563 "[\"" + keys
+ "\", \"" + signature
+ "\"]",
565 EXPECT_EQ(error
, errorResult
);
568 IN_PROC_BROWSER_TEST_F(CastChannelAPITest
, TestSetAuthorityKeysValid
) {
569 scoped_refptr
<Extension
> empty_extension(
570 extensions::test_util::CreateEmptyExtension());
571 scoped_refptr
<extensions::CastChannelSetAuthorityKeysFunction
>
572 cast_channel_set_authority_keys_function
;
574 cast_channel_set_authority_keys_function
=
575 CreateSetAuthorityKeysFunction(empty_extension
);
577 "CrMCCiBSnZzWf+XraY5w3SbX2PEmWfHm5SNIv2pc9xbhP0EOcxKOAjCCAQoCggEBALwigL"
578 "2A9johADuudl41fz3DZFxVlIY0LwWHKM33aYwXs1CnuIL638dDLdZ+q6BvtxNygKRHFcEg"
579 "mVDN7BRiCVukmM3SQbY2Tv/oLjIwSoGoQqNsmzNuyrL1U2bgJ1OGGoUepzk/SneO+1RmZv"
580 "tYVMBeOcf1UAYL4IrUzuFqVR+LFwDmaaMn5gglaTwSnY0FLNYuojHetFJQ1iBJ3nGg+a0g"
581 "QBLx3SXr1ea4NvTWj3/KQ9zXEFvmP1GKhbPz//YDLcsjT5ytGOeTBYysUpr3TOmZer5ufk"
582 "0K48YcqZP6OqWRXRy9ZuvMYNyGdMrP+JIcmH1X+mFHnquAt+RIgCqSxRsCAwEAAQqzAgog"
583 "okjC6FTmVqVt6CMfHuF1b9vkB/n+1GUNYMxay2URxyASjgIwggEKAoIBAQCwDl4HOt+kX2"
584 "j3Icdk27Z27+6Lk/j2G4jhk7cX8BUeflJVdzwCjXtKbNO91sGccsizFc8RwfVGxNUgR/sw"
585 "9ORhDGjwXqs3jpvhvIHDcIp41oM0MpwZYuvknO3jZGxBHZzSi0hMI5CVs+dS6gVXzGCzuh"
586 "TkugA55EZVdM5ajnpnI9poCvrEhB60xaGianMfbsguL5qeqLEO/Yemj009SwXVNVp0TbyO"
587 "gkSW9LWVYE6l3yc9QVwHo7Q1WrOe8gUkys0xWg0mTNTT/VDhNOlMgVgwssd63YGJptQ6OI"
588 "QDtzSedz//eAdbmcGyHzVWbjo8DCXhV/aKfknAzIMRNeeRbS5lAgMBAAE=";
589 std::string signature
=
590 "o83oku3jP+xjTysNBalqp/ZfJRPLt8R+IUhZMepbARFSRVizLoeFW5XyUwe6lQaC+PFFQH"
591 "SZeGZyeeGRpwCJ/lef0xh6SWJlVMWNTk5+z0U84GQdizJP/CTCeHpIwMobN+kyDajgOyfD"
592 "DLhktc6LHmSlFGG6J7B8W67oziS8ZFEdrcT9WSXFrjLVyURHjvidZD5iFtuImI6k9R9OoX"
593 "LR6SyAwpjdrL+vlHMk3Gol6KQ98YpF0ghHnN3/FFW4ibvIwjmRbp+tUV3h8TRcCOjlXVGp"
594 "bzPtNRRlTqfv7Rxm5YXkZMLmJJMZiTs5+o8FMRMTQZT4hRR3DQ+A/jofViyTGA==";
596 std::string args
= "[\"" + keys
+ "\", \"" + signature
+ "\"]";
597 std::string error
= utils::RunFunctionAndReturnError(
598 cast_channel_set_authority_keys_function
.get(), args
, browser());
599 EXPECT_EQ(error
, std::string());
602 // TODO(vadimgo): Win Dbg has a workaround that makes RunExtensionSubtest
603 // always return true without actually running the test. Remove when fixed.
604 #if defined(OS_WIN) && !defined(NDEBUG)
605 #define MAYBE_TestSetAuthorityKeys DISABLED_TestSetAuthorityKeys
607 #define MAYBE_TestSetAuthorityKeys TestSetAuthorityKeys
609 // Test loading extension, opening a channel with ConnectInfo, adding a
610 // listener, writing, reading, and closing.
611 IN_PROC_BROWSER_TEST_F(CastChannelAPITest
, MAYBE_TestSetAuthorityKeys
) {
613 RunExtensionSubtest("cast_channel/api", "test_authority_keys.html"));