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 "chrome/browser/extensions/extension_apitest.h"
9 #include "chrome/browser/extensions/extension_function_test_utils.h"
10 #include "chrome/browser/extensions/extension_service.h"
11 #include "chrome/browser/ui/browser.h"
12 #include "content/public/browser/browser_thread.h"
13 #include "extensions/browser/api/cast_channel/cast_channel_api.h"
14 #include "extensions/browser/api/cast_channel/cast_socket.h"
15 #include "extensions/browser/api/cast_channel/logger.h"
16 #include "extensions/browser/api/cast_channel/test_util.h"
17 #include "extensions/common/api/cast_channel.h"
18 #include "extensions/common/api/cast_channel/cast_channel.pb.h"
19 #include "extensions/common/switches.h"
20 #include "extensions/common/test_util.h"
21 #include "extensions/test/result_catcher.h"
22 #include "net/base/capturing_net_log.h"
23 #include "net/base/completion_callback.h"
24 #include "net/base/net_errors.h"
25 #include "testing/gmock/include/gmock/gmock.h"
26 #include "testing/gmock_mutant.h"
28 // TODO(mfoltz): Mock out the ApiResourceManager to resolve threading issues
29 // (crbug.com/398242) and simulate unloading of the extension.
31 namespace cast_channel
= extensions::core_api::cast_channel
;
32 using cast_channel::CastMessage
;
33 using cast_channel::CastSocket
;
34 using cast_channel::CastTransport
;
35 using cast_channel::ChannelAuthType
;
36 using cast_channel::ChannelError
;
37 using cast_channel::CreateIPEndPointForTest
;
38 using cast_channel::ErrorInfo
;
39 using cast_channel::Logger
;
40 using cast_channel::MessageInfo
;
41 using cast_channel::MockCastTransport
;
42 using cast_channel::ReadyState
;
43 using extensions::Extension
;
45 namespace utils
= extension_function_test_utils
;
49 using ::testing::DoAll
;
50 using ::testing::Invoke
;
51 using ::testing::InSequence
;
52 using ::testing::NotNull
;
53 using ::testing::Return
;
54 using ::testing::ReturnRef
;
55 using ::testing::ReturnPointee
;
56 using ::testing::SaveArg
;
60 const char kTestExtensionId
[] = "ddchlicdkolnonkihahngkmmmjnjlkkf";
61 const char kTestCastUrl
[] = "cast://192.168.1.1:8009";
63 static void FillCastMessage(const std::string
& message
,
64 CastMessage
* cast_message
) {
65 cast_message
->set_namespace_("foo");
66 cast_message
->set_source_id("src");
67 cast_message
->set_destination_id("dest");
68 cast_message
->set_payload_utf8(message
);
69 cast_message
->set_payload_type(CastMessage::STRING
);
72 ACTION_TEMPLATE(InvokeCompletionCallback
,
73 HAS_1_TEMPLATE_PARAMS(int, k
),
74 AND_1_VALUE_PARAMS(result
)) {
75 ::std::tr1::get
<k
>(args
).Run(result
);
78 ACTION_P2(InvokeDelegateOnError
, api_test
, api
) {
79 api_test
->CallOnError(api
);
82 class MockCastSocket
: public CastSocket
{
85 : CastSocket(kTestExtensionId
), mock_transport_(new MockCastTransport
) {}
86 virtual ~MockCastSocket() {}
88 // Mockable version of Connect. Accepts a bare pointer to a mock object.
89 // (GMock won't compile with scoped_ptr method parameters.)
90 MOCK_METHOD2(ConnectWeakPtr
,
91 void(CastTransport::Delegate
* delegate
,
92 base::Callback
<void(ChannelError
)> callback
));
94 // Proxy for ConnectWeakPtr. Unpacks scoped_ptr into a GMock-friendly bare
96 virtual void Connect(scoped_ptr
<CastTransport::Delegate
> delegate
,
97 base::Callback
<void(ChannelError
)> callback
) override
{
98 delegate_
= delegate
.Pass();
99 ConnectWeakPtr(delegate_
.get(), callback
);
102 MOCK_METHOD1(Close
, void(const net::CompletionCallback
& callback
));
103 MOCK_CONST_METHOD0(ip_endpoint
, const net::IPEndPoint
&());
104 MOCK_CONST_METHOD0(id
, int());
105 MOCK_METHOD1(set_id
, void(int id
));
106 MOCK_CONST_METHOD0(channel_auth
, ChannelAuthType());
107 MOCK_CONST_METHOD0(cast_url
, std::string());
108 MOCK_CONST_METHOD0(ready_state
, ReadyState());
109 MOCK_CONST_METHOD0(error_state
, ChannelError());
110 MOCK_METHOD1(SetErrorState
, void(ChannelError error_state
));
112 CastTransport
* transport() const override
{ return mock_transport_
.get(); }
114 MockCastTransport
* mock_transport() const { return mock_transport_
.get(); }
117 scoped_ptr
<MockCastTransport
> mock_transport_
;
118 scoped_ptr
<CastTransport::Delegate
> delegate_
;
123 class CastChannelAPITest
: public ExtensionApiTest
{
125 CastChannelAPITest() : ip_endpoint_(CreateIPEndPointForTest()) {}
127 void SetUpCommandLine(CommandLine
* command_line
) override
{
128 ExtensionApiTest::SetUpCommandLine(command_line
);
129 command_line
->AppendSwitchASCII(
130 extensions::switches::kWhitelistedExtensionID
,
134 void SetUpMockCastSocket() {
135 extensions::CastChannelAPI
* api
= GetApi();
136 net::IPAddressNumber ip_number
;
137 net::ParseIPLiteralToNumber("192.168.1.1", &ip_number
);
138 net::IPEndPoint
ip_endpoint(ip_number
, 8009);
139 mock_cast_socket_
= new MockCastSocket
;
140 // Transfers ownership of the socket.
141 api
->SetSocketForTest(
142 make_scoped_ptr
<CastSocket
>(mock_cast_socket_
).Pass());
143 ON_CALL(*mock_cast_socket_
, set_id(_
))
144 .WillByDefault(SaveArg
<0>(&channel_id_
));
145 ON_CALL(*mock_cast_socket_
, id())
146 .WillByDefault(ReturnPointee(&channel_id_
));
147 ON_CALL(*mock_cast_socket_
, ip_endpoint())
148 .WillByDefault(ReturnRef(ip_endpoint_
));
149 ON_CALL(*mock_cast_socket_
, channel_auth())
150 .WillByDefault(Return(cast_channel::CHANNEL_AUTH_TYPE_SSL
));
151 ON_CALL(*mock_cast_socket_
, cast_url()).WillByDefault(Return(kTestCastUrl
));
154 void SetUpOpenSendClose() {
155 SetUpMockCastSocket();
156 EXPECT_CALL(*mock_cast_socket_
, error_state())
157 .WillRepeatedly(Return(cast_channel::CHANNEL_ERROR_NONE
));
160 EXPECT_CALL(*mock_cast_socket_
, ConnectWeakPtr(_
, _
))
162 InvokeCompletionCallback
<1>(cast_channel::CHANNEL_ERROR_NONE
));
163 EXPECT_CALL(*mock_cast_socket_
, ready_state())
164 .WillOnce(Return(cast_channel::READY_STATE_OPEN
));
165 EXPECT_CALL(*mock_cast_socket_
->mock_transport(),
166 SendMessage(A
<const CastMessage
&>(), _
))
167 .WillOnce(InvokeCompletionCallback
<1>(net::OK
));
168 EXPECT_CALL(*mock_cast_socket_
, ready_state())
169 .WillOnce(Return(cast_channel::READY_STATE_OPEN
));
170 EXPECT_CALL(*mock_cast_socket_
, Close(_
))
171 .WillOnce(InvokeCompletionCallback
<0>(net::OK
));
172 EXPECT_CALL(*mock_cast_socket_
, ready_state())
173 .WillOnce(Return(cast_channel::READY_STATE_CLOSED
));
177 extensions::CastChannelAPI
* GetApi() {
178 return extensions::CastChannelAPI::Get(profile());
181 void CallOnError(extensions::CastChannelAPI
* api
) {
182 cast_channel::LastErrors last_errors
;
183 last_errors
.challenge_reply_error_type
=
184 cast_channel::proto::CHALLENGE_REPLY_ERROR_CERT_PARSING_FAILED
;
185 last_errors
.nss_error_code
= -8164;
186 message_delegate_
->OnError(cast_channel::CHANNEL_ERROR_CONNECT_ERROR
,
191 void CallOnMessage(const std::string
& message
) {
192 content::BrowserThread::PostTask(
193 content::BrowserThread::IO
,
195 base::Bind(&CastChannelAPITest::DoCallOnMessage
, this,
196 GetApi(), mock_cast_socket_
, message
));
199 void DoCallOnMessage(extensions::CastChannelAPI
* api
,
200 MockCastSocket
* cast_socket
,
201 const std::string
& message
) {
202 CastMessage cast_message
;
203 FillCastMessage(message
, &cast_message
);
204 message_delegate_
->OnMessage(cast_message
);
207 extensions::CastChannelOpenFunction
* CreateOpenFunction(
208 scoped_refptr
<Extension
> extension
) {
209 extensions::CastChannelOpenFunction
* cast_channel_open_function
=
210 new extensions::CastChannelOpenFunction
;
211 cast_channel_open_function
->set_extension(extension
.get());
212 return cast_channel_open_function
;
215 extensions::CastChannelSendFunction
* CreateSendFunction(
216 scoped_refptr
<Extension
> extension
) {
217 extensions::CastChannelSendFunction
* cast_channel_send_function
=
218 new extensions::CastChannelSendFunction
;
219 cast_channel_send_function
->set_extension(extension
.get());
220 return cast_channel_send_function
;
223 extensions::CastChannelSetAuthorityKeysFunction
*
224 CreateSetAuthorityKeysFunction(scoped_refptr
<Extension
> extension
) {
225 extensions::CastChannelSetAuthorityKeysFunction
*
226 cast_channel_set_authority_keys_function
=
227 new extensions::CastChannelSetAuthorityKeysFunction
;
228 cast_channel_set_authority_keys_function
->set_extension(extension
.get());
229 return cast_channel_set_authority_keys_function
;
232 MockCastSocket
* mock_cast_socket_
;
233 net::IPEndPoint ip_endpoint_
;
234 CastTransport::Delegate
* message_delegate_
;
235 net::CapturingNetLog capturing_net_log_
;
239 // TODO(munjal): Win Dbg has a workaround that makes RunExtensionSubtest
240 // always return true without actually running the test. Remove when fixed.
241 #if defined(OS_WIN) && !defined(NDEBUG)
242 #define MAYBE_TestOpenSendClose DISABLED_TestOpenSendClose
244 #define MAYBE_TestOpenSendClose TestOpenSendClose
246 // Test loading extension, opening a channel with ConnectInfo, adding a
247 // listener, writing, reading, and closing.
248 IN_PROC_BROWSER_TEST_F(CastChannelAPITest
, MAYBE_TestOpenSendClose
) {
249 SetUpOpenSendClose();
251 EXPECT_TRUE(RunExtensionSubtest("cast_channel/api",
252 "test_open_send_close.html"));
255 // TODO(munjal): Win Dbg has a workaround that makes RunExtensionSubtest
256 // always return true without actually running the test. Remove when fixed.
257 #if defined(OS_WIN) && !defined(NDEBUG)
258 #define MAYBE_TestOpenSendCloseWithUrl DISABLED_TestOpenSendCloseWithUrl
260 #define MAYBE_TestOpenSendCloseWithUrl TestOpenSendCloseWithUrl
262 // Test loading extension, opening a channel with a URL, adding a listener,
263 // writing, reading, and closing.
264 IN_PROC_BROWSER_TEST_F(CastChannelAPITest
, MAYBE_TestOpenSendCloseWithUrl
) {
265 SetUpOpenSendClose();
267 EXPECT_TRUE(RunExtensionSubtest("cast_channel/api",
268 "test_open_send_close_url.html"));
271 // TODO(munjal): Win Dbg has a workaround that makes RunExtensionSubtest
272 // always return true without actually running the test. Remove when fixed.
273 #if defined(OS_WIN) && !defined(NDEBUG)
274 #define MAYBE_TestOpenReceiveClose DISABLED_TestOpenReceiveClose
276 #define MAYBE_TestOpenReceiveClose TestOpenReceiveClose
278 // Test loading extension, opening a channel, adding a listener,
279 // writing, reading, and closing.
280 IN_PROC_BROWSER_TEST_F(CastChannelAPITest
, MAYBE_TestOpenReceiveClose
) {
281 SetUpMockCastSocket();
282 EXPECT_CALL(*mock_cast_socket_
, error_state())
283 .WillRepeatedly(Return(cast_channel::CHANNEL_ERROR_NONE
));
287 EXPECT_CALL(*mock_cast_socket_
, ConnectWeakPtr(NotNull(), _
))
289 SaveArg
<0>(&message_delegate_
),
290 InvokeCompletionCallback
<1>(cast_channel::CHANNEL_ERROR_NONE
)));
291 EXPECT_CALL(*mock_cast_socket_
, ready_state())
293 .WillRepeatedly(Return(cast_channel::READY_STATE_OPEN
));
294 EXPECT_CALL(*mock_cast_socket_
, Close(_
))
295 .WillOnce(InvokeCompletionCallback
<0>(net::OK
));
296 EXPECT_CALL(*mock_cast_socket_
, ready_state())
297 .WillOnce(Return(cast_channel::READY_STATE_CLOSED
));
300 EXPECT_TRUE(RunExtensionSubtest("cast_channel/api",
301 "test_open_receive_close.html"));
303 extensions::ResultCatcher catcher
;
304 CallOnMessage("some-message");
305 CallOnMessage("some-message");
306 EXPECT_TRUE(catcher
.GetNextResult()) << catcher
.message();
309 // TODO(imcheng): Win Dbg has a workaround that makes RunExtensionSubtest
310 // always return true without actually running the test. Remove when fixed.
311 #if defined(OS_WIN) && !defined(NDEBUG)
312 #define MAYBE_TestGetLogs DISABLED_TestGetLogs
314 #define MAYBE_TestGetLogs TestGetLogs
316 // Test loading extension, execute a open-send-close sequence, then get logs.
317 IN_PROC_BROWSER_TEST_F(CastChannelAPITest
, MAYBE_TestGetLogs
) {
318 SetUpOpenSendClose();
320 EXPECT_TRUE(RunExtensionSubtest("cast_channel/api", "test_get_logs.html"));
323 // TODO(munjal): Win Dbg has a workaround that makes RunExtensionSubtest
324 // always return true without actually running the test. Remove when fixed.
325 #if defined(OS_WIN) && !defined(NDEBUG)
326 #define MAYBE_TestOpenError DISABLED_TestOpenError
328 #define MAYBE_TestOpenError TestOpenError
330 // Test the case when socket open results in an error.
331 IN_PROC_BROWSER_TEST_F(CastChannelAPITest
, MAYBE_TestOpenError
) {
332 SetUpMockCastSocket();
334 EXPECT_CALL(*mock_cast_socket_
, ConnectWeakPtr(NotNull(), _
))
335 .WillOnce(DoAll(SaveArg
<0>(&message_delegate_
),
336 InvokeDelegateOnError(this, GetApi()),
337 InvokeCompletionCallback
<1>(
338 cast_channel::CHANNEL_ERROR_CONNECT_ERROR
)));
339 EXPECT_CALL(*mock_cast_socket_
, error_state())
340 .WillRepeatedly(Return(cast_channel::CHANNEL_ERROR_CONNECT_ERROR
));
341 EXPECT_CALL(*mock_cast_socket_
, ready_state())
342 .WillRepeatedly(Return(cast_channel::READY_STATE_CLOSED
));
343 EXPECT_CALL(*mock_cast_socket_
, Close(_
))
344 .WillOnce(InvokeCompletionCallback
<0>(net::OK
));
346 EXPECT_TRUE(RunExtensionSubtest("cast_channel/api",
347 "test_open_error.html"));
350 IN_PROC_BROWSER_TEST_F(CastChannelAPITest
, TestOpenInvalidConnectInfo
) {
351 scoped_refptr
<Extension
> empty_extension
=
352 extensions::test_util::CreateEmptyExtension();
353 scoped_refptr
<extensions::CastChannelOpenFunction
> cast_channel_open_function
;
356 // TODO(mfoltz): Remove this test case when fixing crbug.com/331905
357 cast_channel_open_function
= CreateOpenFunction(empty_extension
);
358 std::string
error(utils::RunFunctionAndReturnError(
359 cast_channel_open_function
.get(), "[\"blargh\"]", browser()));
360 EXPECT_EQ(error
, "Invalid connect_info (invalid Cast URL blargh)");
363 // TODO(mfoltz): Remove this test case when fixing crbug.com/331905
364 cast_channel_open_function
= CreateOpenFunction(empty_extension
);
365 error
= utils::RunFunctionAndReturnError(
366 cast_channel_open_function
.get(),
368 EXPECT_EQ(error
, "Invalid connect_info (unknown type)");
370 // Invalid IP address
371 cast_channel_open_function
= CreateOpenFunction(empty_extension
);
372 error
= utils::RunFunctionAndReturnError(
373 cast_channel_open_function
.get(),
374 "[{\"ipAddress\": \"invalid_ip\", \"port\": 8009, \"auth\": \"ssl\"}]",
376 EXPECT_EQ(error
, "Invalid connect_info (invalid IP address)");
379 cast_channel_open_function
= CreateOpenFunction(empty_extension
);
380 error
= utils::RunFunctionAndReturnError(
381 cast_channel_open_function
.get(),
382 "[{\"ipAddress\": \"127.0.0.1\", \"port\": -200, \"auth\": \"ssl\"}]",
384 EXPECT_EQ(error
, "Invalid connect_info (invalid port)");
387 cast_channel_open_function
= CreateOpenFunction(empty_extension
);
388 error
= utils::RunFunctionAndReturnError(
389 cast_channel_open_function
.get(),
390 "[{\"ipAddress\": \"127.0.0.1\", \"port\": 8009}]",
392 EXPECT_EQ(error
, "connect_info.auth is required");
395 IN_PROC_BROWSER_TEST_F(CastChannelAPITest
, TestSendInvalidMessageInfo
) {
396 scoped_refptr
<Extension
> empty_extension(
397 extensions::test_util::CreateEmptyExtension());
398 scoped_refptr
<extensions::CastChannelSendFunction
> cast_channel_send_function
;
400 // Numbers are not supported
401 cast_channel_send_function
= CreateSendFunction(empty_extension
);
402 std::string
error(utils::RunFunctionAndReturnError(
403 cast_channel_send_function
.get(),
404 "[{\"channelId\": 1, \"url\": \"cast://127.0.0.1:8009\", "
406 "{\"ipAddress\": \"127.0.0.1\", \"port\": 8009, "
407 "\"auth\": \"ssl\"}, \"readyState\": \"open\"}, "
408 "{\"namespace_\": \"foo\", \"sourceId\": \"src\", "
409 "\"destinationId\": \"dest\", \"data\": 1235}]",
411 EXPECT_EQ(error
, "Invalid type of message_info.data");
413 // Missing namespace_
414 cast_channel_send_function
= CreateSendFunction(empty_extension
);
415 error
= utils::RunFunctionAndReturnError(
416 cast_channel_send_function
.get(),
417 "[{\"channelId\": 1, \"url\": \"cast://127.0.0.1:8009\", "
419 "{\"ipAddress\": \"127.0.0.1\", \"port\": 8009, "
420 "\"auth\": \"ssl\"}, \"readyState\": \"open\"}, "
421 "{\"namespace_\": \"\", \"sourceId\": \"src\", "
422 "\"destinationId\": \"dest\", \"data\": \"data\"}]",
424 EXPECT_EQ(error
, "message_info.namespace_ is required");
427 cast_channel_send_function
= CreateSendFunction(empty_extension
);
428 error
= utils::RunFunctionAndReturnError(
429 cast_channel_send_function
.get(),
430 "[{\"channelId\": 1, \"url\": \"cast://127.0.0.1:8009\", "
432 "{\"ipAddress\": \"127.0.0.1\", \"port\": 8009, "
433 "\"auth\": \"ssl\"}, \"readyState\": \"open\"}, "
434 "{\"namespace_\": \"foo\", \"sourceId\": \"\", "
435 "\"destinationId\": \"dest\", \"data\": \"data\"}]",
437 EXPECT_EQ(error
, "message_info.source_id is required");
439 // Missing destination_id
440 cast_channel_send_function
= CreateSendFunction(empty_extension
);
441 error
= utils::RunFunctionAndReturnError(
442 cast_channel_send_function
.get(),
443 "[{\"channelId\": 1, \"url\": \"cast://127.0.0.1:8009\", "
445 "{\"ipAddress\": \"127.0.0.1\", \"port\": 8009, "
446 "\"auth\": \"ssl\"}, \"readyState\": \"open\"}, "
447 "{\"namespace_\": \"foo\", \"sourceId\": \"src\", "
448 "\"destinationId\": \"\", \"data\": \"data\"}]",
450 EXPECT_EQ(error
, "message_info.destination_id is required");
453 IN_PROC_BROWSER_TEST_F(CastChannelAPITest
, TestSetAuthorityKeysInvalid
) {
454 scoped_refptr
<Extension
> empty_extension(
455 extensions::test_util::CreateEmptyExtension());
456 scoped_refptr
<extensions::CastChannelSetAuthorityKeysFunction
>
457 cast_channel_set_authority_keys_function
;
458 std::string errorResult
= "Unable to set authority keys.";
460 cast_channel_set_authority_keys_function
=
461 CreateSetAuthorityKeysFunction(empty_extension
);
462 std::string error
= utils::RunFunctionAndReturnError(
463 cast_channel_set_authority_keys_function
.get(),
464 "[\"\", \"signature\"]",
466 EXPECT_EQ(error
, errorResult
);
468 cast_channel_set_authority_keys_function
=
469 CreateSetAuthorityKeysFunction(empty_extension
);
470 error
= utils::RunFunctionAndReturnError(
471 cast_channel_set_authority_keys_function
.get(),
474 EXPECT_EQ(error
, errorResult
);
477 "CrMCCiBSnZzWf+XraY5w3SbX2PEmWfHm5SNIv2pc9xbhP0EOcxKOAjCCAQoCggEBALwigL"
478 "2A9johADuudl41fz3DZFxVlIY0LwWHKM33aYwXs1CnuIL638dDLdZ+q6BvtxNygKRHFcEg"
479 "mVDN7BRiCVukmM3SQbY2Tv/oLjIwSoGoQqNsmzNuyrL1U2bgJ1OGGoUepzk/SneO+1RmZv"
480 "tYVMBeOcf1UAYL4IrUzuFqVR+LFwDmaaMn5gglaTwSnY0FLNYuojHetFJQ1iBJ3nGg+a0g"
481 "QBLx3SXr1ea4NvTWj3/KQ9zXEFvmP1GKhbPz//YDLcsjT5ytGOeTBYysUpr3TOmZer5ufk"
482 "0K48YcqZP6OqWRXRy9ZuvMYNyGdMrP+JIcmH1X+mFHnquAt+RIgCqSxRsCAwEAAQ==";
483 std::string signature
=
484 "chCUHZKkykcwU8HzU+hm027fUTBL0dqPMtrzppwExQwK9+"
485 "XlmCjJswfce2sUUfhR1OL1tyW4hWFwu4JnuQCJ+CvmSmAh2bzRpnuSKzBfgvIDjNOAGUs7"
486 "ADaNSSWPLxp+6ko++2Dn4S9HpOt8N1v6gMWqj3Ru5IqFSQPZSvGH2ois6uE50CFayPcjQE"
487 "OVZt41noQdFd15RmKTvocoCC5tHNlaikeQ52yi0IScOlad1B1lMhoplW3rWophQaqxMumr"
488 "OcHIZ+Y+p858x5f8Pny/kuqUClmFh9B/vF07NsUHwoSL9tA5t5jCY3L5iUc/v7o3oFcW/T"
489 "gojKkX2Kg7KQ86QA==";
491 cast_channel_set_authority_keys_function
=
492 CreateSetAuthorityKeysFunction(empty_extension
);
493 error
= utils::RunFunctionAndReturnError(
494 cast_channel_set_authority_keys_function
.get(),
495 "[\"" + keys
+ "\", \"signature\"]",
497 EXPECT_EQ(error
, errorResult
);
499 cast_channel_set_authority_keys_function
=
500 CreateSetAuthorityKeysFunction(empty_extension
);
501 error
= utils::RunFunctionAndReturnError(
502 cast_channel_set_authority_keys_function
.get(),
503 "[\"keys\", \"" + signature
+ "\"]",
505 EXPECT_EQ(error
, errorResult
);
507 cast_channel_set_authority_keys_function
=
508 CreateSetAuthorityKeysFunction(empty_extension
);
509 error
= utils::RunFunctionAndReturnError(
510 cast_channel_set_authority_keys_function
.get(),
511 "[\"" + keys
+ "\", \"" + signature
+ "\"]",
513 EXPECT_EQ(error
, errorResult
);
516 IN_PROC_BROWSER_TEST_F(CastChannelAPITest
, TestSetAuthorityKeysValid
) {
517 scoped_refptr
<Extension
> empty_extension(
518 extensions::test_util::CreateEmptyExtension());
519 scoped_refptr
<extensions::CastChannelSetAuthorityKeysFunction
>
520 cast_channel_set_authority_keys_function
;
522 cast_channel_set_authority_keys_function
=
523 CreateSetAuthorityKeysFunction(empty_extension
);
525 "CrMCCiBSnZzWf+XraY5w3SbX2PEmWfHm5SNIv2pc9xbhP0EOcxKOAjCCAQoCggEBALwigL"
526 "2A9johADuudl41fz3DZFxVlIY0LwWHKM33aYwXs1CnuIL638dDLdZ+q6BvtxNygKRHFcEg"
527 "mVDN7BRiCVukmM3SQbY2Tv/oLjIwSoGoQqNsmzNuyrL1U2bgJ1OGGoUepzk/SneO+1RmZv"
528 "tYVMBeOcf1UAYL4IrUzuFqVR+LFwDmaaMn5gglaTwSnY0FLNYuojHetFJQ1iBJ3nGg+a0g"
529 "QBLx3SXr1ea4NvTWj3/KQ9zXEFvmP1GKhbPz//YDLcsjT5ytGOeTBYysUpr3TOmZer5ufk"
530 "0K48YcqZP6OqWRXRy9ZuvMYNyGdMrP+JIcmH1X+mFHnquAt+RIgCqSxRsCAwEAAQqzAgog"
531 "okjC6FTmVqVt6CMfHuF1b9vkB/n+1GUNYMxay2URxyASjgIwggEKAoIBAQCwDl4HOt+kX2"
532 "j3Icdk27Z27+6Lk/j2G4jhk7cX8BUeflJVdzwCjXtKbNO91sGccsizFc8RwfVGxNUgR/sw"
533 "9ORhDGjwXqs3jpvhvIHDcIp41oM0MpwZYuvknO3jZGxBHZzSi0hMI5CVs+dS6gVXzGCzuh"
534 "TkugA55EZVdM5ajnpnI9poCvrEhB60xaGianMfbsguL5qeqLEO/Yemj009SwXVNVp0TbyO"
535 "gkSW9LWVYE6l3yc9QVwHo7Q1WrOe8gUkys0xWg0mTNTT/VDhNOlMgVgwssd63YGJptQ6OI"
536 "QDtzSedz//eAdbmcGyHzVWbjo8DCXhV/aKfknAzIMRNeeRbS5lAgMBAAE=";
537 std::string signature
=
538 "o83oku3jP+xjTysNBalqp/ZfJRPLt8R+IUhZMepbARFSRVizLoeFW5XyUwe6lQaC+PFFQH"
539 "SZeGZyeeGRpwCJ/lef0xh6SWJlVMWNTk5+z0U84GQdizJP/CTCeHpIwMobN+kyDajgOyfD"
540 "DLhktc6LHmSlFGG6J7B8W67oziS8ZFEdrcT9WSXFrjLVyURHjvidZD5iFtuImI6k9R9OoX"
541 "LR6SyAwpjdrL+vlHMk3Gol6KQ98YpF0ghHnN3/FFW4ibvIwjmRbp+tUV3h8TRcCOjlXVGp"
542 "bzPtNRRlTqfv7Rxm5YXkZMLmJJMZiTs5+o8FMRMTQZT4hRR3DQ+A/jofViyTGA==";
544 std::string args
= "[\"" + keys
+ "\", \"" + signature
+ "\"]";
545 std::string error
= utils::RunFunctionAndReturnError(
546 cast_channel_set_authority_keys_function
.get(), args
, browser());
547 EXPECT_EQ(error
, std::string());
550 // TODO(vadimgo): Win Dbg has a workaround that makes RunExtensionSubtest
551 // always return true without actually running the test. Remove when fixed.
552 #if defined(OS_WIN) && !defined(NDEBUG)
553 #define MAYBE_TestSetAuthorityKeys DISABLED_TestSetAuthorityKeys
555 #define MAYBE_TestSetAuthorityKeys TestSetAuthorityKeys
557 // Test loading extension, opening a channel with ConnectInfo, adding a
558 // listener, writing, reading, and closing.
559 IN_PROC_BROWSER_TEST_F(CastChannelAPITest
, MAYBE_TestSetAuthorityKeys
) {
561 RunExtensionSubtest("cast_channel/api", "test_authority_keys.html"));