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/cast_test_util.h"
17 #include "extensions/browser/api/cast_channel/logger.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/completion_callback.h"
25 #include "net/base/net_errors.h"
26 #include "net/log/test_net_log.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::LastErrors
;
42 using cast_channel::Logger
;
43 using cast_channel::MessageInfo
;
44 using cast_channel::MockCastSocket
;
45 using cast_channel::MockCastTransport
;
46 using cast_channel::ReadyState
;
47 using extensions::Extension
;
49 namespace utils
= extension_function_test_utils
;
53 using ::testing::DoAll
;
54 using ::testing::Invoke
;
55 using ::testing::InSequence
;
56 using ::testing::NotNull
;
57 using ::testing::Return
;
58 using ::testing::ReturnRef
;
59 using ::testing::ReturnPointee
;
60 using ::testing::SaveArg
;
64 const char kTestCastUrl
[] = "cast://192.168.1.1:8009";
66 static void FillCastMessage(const std::string
& message
,
67 CastMessage
* cast_message
) {
68 cast_message
->set_namespace_("foo");
69 cast_message
->set_source_id("src");
70 cast_message
->set_destination_id("dest");
71 cast_message
->set_payload_utf8(message
);
72 cast_message
->set_payload_type(CastMessage::STRING
);
75 ACTION_TEMPLATE(InvokeCompletionCallback
,
76 HAS_1_TEMPLATE_PARAMS(int, k
),
77 AND_1_VALUE_PARAMS(result
)) {
78 ::std::tr1::get
<k
>(args
).Run(result
);
83 class CastChannelAPITest
: public ExtensionApiTest
{
85 CastChannelAPITest() : ip_endpoint_(CreateIPEndPointForTest()) {}
87 void SetUpCommandLine(base::CommandLine
* command_line
) override
{
88 ExtensionApiTest::SetUpCommandLine(command_line
);
89 command_line
->AppendSwitchASCII(
90 extensions::switches::kWhitelistedExtensionID
,
91 cast_channel::kTestExtensionId
);
94 void SetUpMockCastSocket() {
95 extensions::CastChannelAPI
* api
= GetApi();
96 timeout_timer_
= new base::MockTimer(true, false);
97 api
->SetPingTimeoutTimerForTest(make_scoped_ptr(timeout_timer_
));
99 net::IPAddressNumber ip_number
;
100 net::ParseIPLiteralToNumber("192.168.1.1", &ip_number
);
101 net::IPEndPoint
ip_endpoint(ip_number
, 8009);
102 mock_cast_socket_
= new MockCastSocket
;
103 // Transfers ownership of the socket.
104 api
->SetSocketForTest(
105 make_scoped_ptr
<CastSocket
>(mock_cast_socket_
).Pass());
106 ON_CALL(*mock_cast_socket_
, set_id(_
))
107 .WillByDefault(SaveArg
<0>(&channel_id_
));
108 ON_CALL(*mock_cast_socket_
, id())
109 .WillByDefault(ReturnPointee(&channel_id_
));
110 ON_CALL(*mock_cast_socket_
, ip_endpoint())
111 .WillByDefault(ReturnRef(ip_endpoint_
));
112 ON_CALL(*mock_cast_socket_
, channel_auth())
113 .WillByDefault(Return(cast_channel::CHANNEL_AUTH_TYPE_SSL
));
114 ON_CALL(*mock_cast_socket_
, keep_alive()).WillByDefault(Return(false));
115 ON_CALL(*mock_cast_socket_
, cast_url()).WillByDefault(Return(kTestCastUrl
));
118 void SetUpOpenSendClose() {
119 SetUpMockCastSocket();
120 EXPECT_CALL(*mock_cast_socket_
, error_state())
121 .WillRepeatedly(Return(cast_channel::CHANNEL_ERROR_NONE
));
124 EXPECT_CALL(*mock_cast_socket_
, ConnectRawPtr(_
, _
))
126 InvokeCompletionCallback
<1>(cast_channel::CHANNEL_ERROR_NONE
));
127 EXPECT_CALL(*mock_cast_socket_
, ready_state())
128 .WillOnce(Return(cast_channel::READY_STATE_OPEN
));
129 EXPECT_CALL(*mock_cast_socket_
->mock_transport(),
130 SendMessage(A
<const CastMessage
&>(), _
))
131 .WillOnce(InvokeCompletionCallback
<1>(net::OK
));
132 EXPECT_CALL(*mock_cast_socket_
, ready_state())
133 .WillOnce(Return(cast_channel::READY_STATE_OPEN
));
134 EXPECT_CALL(*mock_cast_socket_
, Close(_
))
135 .WillOnce(InvokeCompletionCallback
<0>(net::OK
));
136 EXPECT_CALL(*mock_cast_socket_
, ready_state())
137 .WillOnce(Return(cast_channel::READY_STATE_CLOSED
));
141 void SetUpOpenPingTimeout() {
142 SetUpMockCastSocket();
143 EXPECT_CALL(*mock_cast_socket_
, error_state())
144 .WillRepeatedly(Return(cast_channel::CHANNEL_ERROR_NONE
));
145 EXPECT_CALL(*mock_cast_socket_
, keep_alive()).WillRepeatedly(Return(true));
148 EXPECT_CALL(*mock_cast_socket_
, ConnectRawPtr(_
, _
))
150 SaveArg
<0>(&message_delegate_
),
151 InvokeCompletionCallback
<1>(cast_channel::CHANNEL_ERROR_NONE
)));
152 EXPECT_CALL(*mock_cast_socket_
, ready_state())
153 .WillOnce(Return(cast_channel::READY_STATE_OPEN
))
154 .RetiresOnSaturation();
155 EXPECT_CALL(*mock_cast_socket_
, ready_state())
156 .WillOnce(Return(cast_channel::READY_STATE_CLOSED
));
160 extensions::CastChannelAPI
* GetApi() {
161 return extensions::CastChannelAPI::Get(profile());
164 // Logs some bogus error details and calls the OnError handler.
165 void DoCallOnError(extensions::CastChannelAPI
* api
) {
166 api
->GetLogger()->LogSocketEventWithRv(mock_cast_socket_
->id(),
167 cast_channel::proto::SOCKET_WRITE
,
169 message_delegate_
->OnError(cast_channel::CHANNEL_ERROR_CONNECT_ERROR
);
173 void CallOnMessage(const std::string
& message
) {
174 content::BrowserThread::PostTask(
175 content::BrowserThread::IO
,
177 base::Bind(&CastChannelAPITest::DoCallOnMessage
, this,
178 GetApi(), mock_cast_socket_
, message
));
181 void DoCallOnMessage(extensions::CastChannelAPI
* api
,
182 MockCastSocket
* cast_socket
,
183 const std::string
& message
) {
184 CastMessage cast_message
;
185 FillCastMessage(message
, &cast_message
);
186 message_delegate_
->OnMessage(cast_message
);
189 // Starts the read delegate on the IO thread.
190 void StartDelegate() {
191 CHECK(message_delegate_
);
192 content::BrowserThread::PostTask(
193 content::BrowserThread::IO
, FROM_HERE
,
194 base::Bind(&cast_channel::CastTransport::Delegate::Start
,
195 base::Unretained(message_delegate_
)));
198 // Fires a timer on the IO thread.
200 content::BrowserThread::PostTask(
201 content::BrowserThread::IO
, FROM_HERE
,
202 base::Bind(&base::MockTimer::Fire
, base::Unretained(timeout_timer_
)));
205 extensions::CastChannelOpenFunction
* CreateOpenFunction(
206 scoped_refptr
<Extension
> extension
) {
207 extensions::CastChannelOpenFunction
* cast_channel_open_function
=
208 new extensions::CastChannelOpenFunction
;
209 cast_channel_open_function
->set_extension(extension
.get());
210 return cast_channel_open_function
;
213 extensions::CastChannelSendFunction
* CreateSendFunction(
214 scoped_refptr
<Extension
> extension
) {
215 extensions::CastChannelSendFunction
* cast_channel_send_function
=
216 new extensions::CastChannelSendFunction
;
217 cast_channel_send_function
->set_extension(extension
.get());
218 return cast_channel_send_function
;
221 extensions::CastChannelSetAuthorityKeysFunction
*
222 CreateSetAuthorityKeysFunction(scoped_refptr
<Extension
> extension
) {
223 extensions::CastChannelSetAuthorityKeysFunction
*
224 cast_channel_set_authority_keys_function
=
225 new extensions::CastChannelSetAuthorityKeysFunction
;
226 cast_channel_set_authority_keys_function
->set_extension(extension
.get());
227 return cast_channel_set_authority_keys_function
;
230 MockCastSocket
* mock_cast_socket_
;
231 base::MockTimer
* timeout_timer_
;
232 net::IPEndPoint ip_endpoint_
;
233 LastErrors last_errors_
;
234 CastTransport::Delegate
* message_delegate_
;
235 net::TestNetLog capturing_net_log_
;
239 ACTION_P2(InvokeDelegateOnError
, api_test
, api
) {
240 content::BrowserThread::PostTask(
241 content::BrowserThread::IO
, FROM_HERE
,
242 base::Bind(&CastChannelAPITest::DoCallOnError
, base::Unretained(api_test
),
243 base::Unretained(api
)));
246 // TODO(kmarshall): Win Dbg has a workaround that makes RunExtensionSubtest
247 // always return true without actually running the test. Remove when fixed.
248 #if defined(OS_WIN) && !defined(NDEBUG)
249 #define MAYBE_TestOpenSendClose DISABLED_TestOpenSendClose
251 #define MAYBE_TestOpenSendClose TestOpenSendClose
253 // Test loading extension, opening a channel with ConnectInfo, adding a
254 // listener, writing, reading, and closing.
255 IN_PROC_BROWSER_TEST_F(CastChannelAPITest
, MAYBE_TestOpenSendClose
) {
256 SetUpOpenSendClose();
258 EXPECT_TRUE(RunExtensionSubtest("cast_channel/api",
259 "test_open_send_close.html"));
262 // TODO(kmarshall): Win Dbg has a workaround that makes RunExtensionSubtest
263 // always return true without actually running the test. Remove when fixed.
264 #if defined(OS_WIN) && !defined(NDEBUG)
265 #define MAYBE_TestPingTimeout DISABLED_TestPingTimeout
267 #define MAYBE_TestPingTimeout TestPingTimeout
269 // Verify that timeout events are propagated through the API layer.
270 // (SSL, non-verified).
271 IN_PROC_BROWSER_TEST_F(CastChannelAPITest
, MAYBE_TestPingTimeout
) {
272 SetUpOpenPingTimeout();
274 ExtensionTestMessageListener
channel_opened("channel_opened_ssl", false);
275 ExtensionTestMessageListener
timeout("timeout_ssl", false);
277 RunExtensionSubtest("cast_channel/api", "test_open_timeout.html"));
278 EXPECT_TRUE(channel_opened
.WaitUntilSatisfied());
281 EXPECT_TRUE(timeout
.WaitUntilSatisfied());
284 // TODO(kmarshall): Win Dbg has a workaround that makes RunExtensionSubtest
285 // always return true without actually running the test. Remove when fixed.
286 #if defined(OS_WIN) && !defined(NDEBUG)
287 #define MAYBE_TestPingTimeoutSslVerified DISABLED_TestPingTimeoutSslVerified
289 #define MAYBE_TestPingTimeoutSslVerified TestPingTimeoutSslVerified
291 // Verify that timeout events are propagated through the API layer.
293 IN_PROC_BROWSER_TEST_F(CastChannelAPITest
, MAYBE_TestPingTimeoutSslVerified
) {
294 SetUpOpenPingTimeout();
296 ExtensionTestMessageListener
channel_opened("channel_opened_ssl_verified",
298 ExtensionTestMessageListener
timeout("timeout_ssl_verified", false);
299 EXPECT_TRUE(RunExtensionSubtest("cast_channel/api",
300 "test_open_timeout_verified.html"));
301 EXPECT_TRUE(channel_opened
.WaitUntilSatisfied());
304 EXPECT_TRUE(timeout
.WaitUntilSatisfied());
307 // TODO(kmarshall): Win Dbg has a workaround that makes RunExtensionSubtest
308 // always return true without actually running the test. Remove when fixed.
309 #if defined(OS_WIN) && !defined(NDEBUG)
310 #define MAYBE_TestOpenSendCloseWithUrl DISABLED_TestOpenSendCloseWithUrl
312 #define MAYBE_TestOpenSendCloseWithUrl TestOpenSendCloseWithUrl
314 // Test loading extension, opening a channel with a URL, adding a listener,
315 // writing, reading, and closing.
316 IN_PROC_BROWSER_TEST_F(CastChannelAPITest
, MAYBE_TestOpenSendCloseWithUrl
) {
317 SetUpOpenSendClose();
319 EXPECT_TRUE(RunExtensionSubtest("cast_channel/api",
320 "test_open_send_close_url.html"));
323 // TODO(kmarshall): 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_TestOpenReceiveClose DISABLED_TestOpenReceiveClose
328 #define MAYBE_TestOpenReceiveClose TestOpenReceiveClose
330 // Test loading extension, opening a channel, adding a listener,
331 // writing, reading, and closing.
332 IN_PROC_BROWSER_TEST_F(CastChannelAPITest
, MAYBE_TestOpenReceiveClose
) {
333 SetUpMockCastSocket();
334 EXPECT_CALL(*mock_cast_socket_
, error_state())
335 .WillRepeatedly(Return(cast_channel::CHANNEL_ERROR_NONE
));
339 EXPECT_CALL(*mock_cast_socket_
, ConnectRawPtr(NotNull(), _
))
341 SaveArg
<0>(&message_delegate_
),
342 InvokeCompletionCallback
<1>(cast_channel::CHANNEL_ERROR_NONE
)));
343 EXPECT_CALL(*mock_cast_socket_
, ready_state())
345 .WillRepeatedly(Return(cast_channel::READY_STATE_OPEN
));
346 EXPECT_CALL(*mock_cast_socket_
, Close(_
))
347 .WillOnce(InvokeCompletionCallback
<0>(net::OK
));
348 EXPECT_CALL(*mock_cast_socket_
, ready_state())
349 .WillOnce(Return(cast_channel::READY_STATE_CLOSED
));
352 EXPECT_TRUE(RunExtensionSubtest("cast_channel/api",
353 "test_open_receive_close.html"));
355 extensions::ResultCatcher catcher
;
356 CallOnMessage("some-message");
357 CallOnMessage("some-message");
358 EXPECT_TRUE(catcher
.GetNextResult()) << catcher
.message();
361 // TODO(imcheng): Win Dbg has a workaround that makes RunExtensionSubtest
362 // always return true without actually running the test. Remove when fixed.
363 #if defined(OS_WIN) && !defined(NDEBUG)
364 #define MAYBE_TestGetLogs DISABLED_TestGetLogs
366 #define MAYBE_TestGetLogs TestGetLogs
368 // Test loading extension, execute a open-send-close sequence, then get logs.
369 IN_PROC_BROWSER_TEST_F(CastChannelAPITest
, MAYBE_TestGetLogs
) {
370 SetUpOpenSendClose();
372 EXPECT_TRUE(RunExtensionSubtest("cast_channel/api", "test_get_logs.html"));
375 // TODO(kmarshall): Win Dbg has a workaround that makes RunExtensionSubtest
376 // always return true without actually running the test. Remove when fixed.
377 #if defined(OS_WIN) && !defined(NDEBUG)
378 #define MAYBE_TestOpenError DISABLED_TestOpenError
380 #define MAYBE_TestOpenError TestOpenError
382 // Test the case when socket open results in an error.
383 IN_PROC_BROWSER_TEST_F(CastChannelAPITest
, MAYBE_TestOpenError
) {
384 SetUpMockCastSocket();
386 EXPECT_CALL(*mock_cast_socket_
, ConnectRawPtr(NotNull(), _
))
387 .WillOnce(DoAll(SaveArg
<0>(&message_delegate_
),
388 InvokeDelegateOnError(this, GetApi()),
389 InvokeCompletionCallback
<1>(
390 cast_channel::CHANNEL_ERROR_CONNECT_ERROR
)));
391 EXPECT_CALL(*mock_cast_socket_
, error_state())
392 .WillRepeatedly(Return(cast_channel::CHANNEL_ERROR_CONNECT_ERROR
));
393 EXPECT_CALL(*mock_cast_socket_
, ready_state())
394 .WillRepeatedly(Return(cast_channel::READY_STATE_CLOSED
));
395 EXPECT_CALL(*mock_cast_socket_
, Close(_
))
396 .WillOnce(InvokeCompletionCallback
<0>(net::OK
));
398 EXPECT_TRUE(RunExtensionSubtest("cast_channel/api",
399 "test_open_error.html"));
402 IN_PROC_BROWSER_TEST_F(CastChannelAPITest
, TestOpenInvalidConnectInfo
) {
403 scoped_refptr
<Extension
> empty_extension
=
404 extensions::test_util::CreateEmptyExtension();
405 scoped_refptr
<extensions::CastChannelOpenFunction
> cast_channel_open_function
;
408 // TODO(mfoltz): Remove this test case when fixing crbug.com/331905
409 cast_channel_open_function
= CreateOpenFunction(empty_extension
);
410 std::string
error(utils::RunFunctionAndReturnError(
411 cast_channel_open_function
.get(), "[\"blargh\"]", browser()));
412 EXPECT_EQ(error
, "Invalid connect_info (invalid Cast URL blargh)");
415 // TODO(mfoltz): Remove this test case when fixing crbug.com/331905
416 cast_channel_open_function
= CreateOpenFunction(empty_extension
);
417 error
= utils::RunFunctionAndReturnError(
418 cast_channel_open_function
.get(),
420 EXPECT_EQ(error
, "Invalid connect_info (unknown type)");
422 // Invalid IP address
423 cast_channel_open_function
= CreateOpenFunction(empty_extension
);
424 error
= utils::RunFunctionAndReturnError(
425 cast_channel_open_function
.get(),
426 "[{\"ipAddress\": \"invalid_ip\", \"port\": 8009, \"auth\": \"ssl\"}]",
428 EXPECT_EQ(error
, "Invalid connect_info (invalid IP address)");
431 cast_channel_open_function
= CreateOpenFunction(empty_extension
);
432 error
= utils::RunFunctionAndReturnError(
433 cast_channel_open_function
.get(),
434 "[{\"ipAddress\": \"127.0.0.1\", \"port\": -200, \"auth\": \"ssl\"}]",
436 EXPECT_EQ(error
, "Invalid connect_info (invalid port)");
439 cast_channel_open_function
= CreateOpenFunction(empty_extension
);
440 error
= utils::RunFunctionAndReturnError(
441 cast_channel_open_function
.get(),
442 "[{\"ipAddress\": \"127.0.0.1\", \"port\": 8009}]",
444 EXPECT_EQ(error
, "connect_info.auth is required");
447 IN_PROC_BROWSER_TEST_F(CastChannelAPITest
, TestSendInvalidMessageInfo
) {
448 scoped_refptr
<Extension
> empty_extension(
449 extensions::test_util::CreateEmptyExtension());
450 scoped_refptr
<extensions::CastChannelSendFunction
> cast_channel_send_function
;
452 // Numbers are not supported
453 cast_channel_send_function
= CreateSendFunction(empty_extension
);
454 std::string
error(utils::RunFunctionAndReturnError(
455 cast_channel_send_function
.get(),
456 "[{\"channelId\": 1, \"url\": \"cast://127.0.0.1:8009\", "
457 "\"keepAlive\": true, "
459 "{\"ipAddress\": \"127.0.0.1\", \"port\": 8009, "
460 "\"auth\": \"ssl\"}, \"readyState\": \"open\"}, "
461 "{\"namespace_\": \"foo\", \"sourceId\": \"src\", "
462 "\"destinationId\": \"dest\", \"data\": 1235}]",
464 EXPECT_EQ(error
, "Invalid type of message_info.data");
466 // Missing namespace_
467 cast_channel_send_function
= CreateSendFunction(empty_extension
);
468 error
= utils::RunFunctionAndReturnError(
469 cast_channel_send_function
.get(),
470 "[{\"channelId\": 1, \"url\": \"cast://127.0.0.1:8009\", "
471 "\"keepAlive\": true, "
473 "{\"ipAddress\": \"127.0.0.1\", \"port\": 8009, "
474 "\"auth\": \"ssl\"}, \"readyState\": \"open\"}, "
475 "{\"namespace_\": \"\", \"sourceId\": \"src\", "
476 "\"destinationId\": \"dest\", \"data\": \"data\"}]",
478 EXPECT_EQ(error
, "message_info.namespace_ is required");
481 cast_channel_send_function
= CreateSendFunction(empty_extension
);
482 error
= utils::RunFunctionAndReturnError(
483 cast_channel_send_function
.get(),
484 "[{\"channelId\": 1, \"url\": \"cast://127.0.0.1:8009\", "
485 "\"keepAlive\": true, "
487 "{\"ipAddress\": \"127.0.0.1\", \"port\": 8009, "
488 "\"auth\": \"ssl\"}, \"readyState\": \"open\"}, "
489 "{\"namespace_\": \"foo\", \"sourceId\": \"\", "
490 "\"destinationId\": \"dest\", \"data\": \"data\"}]",
492 EXPECT_EQ(error
, "message_info.source_id is required");
494 // Missing destination_id
495 cast_channel_send_function
= CreateSendFunction(empty_extension
);
496 error
= utils::RunFunctionAndReturnError(
497 cast_channel_send_function
.get(),
498 "[{\"channelId\": 1, \"url\": \"cast://127.0.0.1:8009\", "
499 "\"keepAlive\": true, "
501 "{\"ipAddress\": \"127.0.0.1\", \"port\": 8009, "
502 "\"auth\": \"ssl\"}, \"readyState\": \"open\"}, "
503 "{\"namespace_\": \"foo\", \"sourceId\": \"src\", "
504 "\"destinationId\": \"\", \"data\": \"data\"}]",
506 EXPECT_EQ(error
, "message_info.destination_id is required");
509 IN_PROC_BROWSER_TEST_F(CastChannelAPITest
, TestSetAuthorityKeysInvalid
) {
510 scoped_refptr
<Extension
> empty_extension(
511 extensions::test_util::CreateEmptyExtension());
512 scoped_refptr
<extensions::CastChannelSetAuthorityKeysFunction
>
513 cast_channel_set_authority_keys_function
;
514 std::string errorResult
= "Unable to set authority keys.";
516 cast_channel_set_authority_keys_function
=
517 CreateSetAuthorityKeysFunction(empty_extension
);
518 std::string error
= utils::RunFunctionAndReturnError(
519 cast_channel_set_authority_keys_function
.get(),
520 "[\"\", \"signature\"]",
522 EXPECT_EQ(error
, errorResult
);
524 cast_channel_set_authority_keys_function
=
525 CreateSetAuthorityKeysFunction(empty_extension
);
526 error
= utils::RunFunctionAndReturnError(
527 cast_channel_set_authority_keys_function
.get(),
530 EXPECT_EQ(error
, errorResult
);
533 "CrMCCiBSnZzWf+XraY5w3SbX2PEmWfHm5SNIv2pc9xbhP0EOcxKOAjCCAQoCggEBALwigL"
534 "2A9johADuudl41fz3DZFxVlIY0LwWHKM33aYwXs1CnuIL638dDLdZ+q6BvtxNygKRHFcEg"
535 "mVDN7BRiCVukmM3SQbY2Tv/oLjIwSoGoQqNsmzNuyrL1U2bgJ1OGGoUepzk/SneO+1RmZv"
536 "tYVMBeOcf1UAYL4IrUzuFqVR+LFwDmaaMn5gglaTwSnY0FLNYuojHetFJQ1iBJ3nGg+a0g"
537 "QBLx3SXr1ea4NvTWj3/KQ9zXEFvmP1GKhbPz//YDLcsjT5ytGOeTBYysUpr3TOmZer5ufk"
538 "0K48YcqZP6OqWRXRy9ZuvMYNyGdMrP+JIcmH1X+mFHnquAt+RIgCqSxRsCAwEAAQ==";
539 std::string signature
=
540 "chCUHZKkykcwU8HzU+hm027fUTBL0dqPMtrzppwExQwK9+"
541 "XlmCjJswfce2sUUfhR1OL1tyW4hWFwu4JnuQCJ+CvmSmAh2bzRpnuSKzBfgvIDjNOAGUs7"
542 "ADaNSSWPLxp+6ko++2Dn4S9HpOt8N1v6gMWqj3Ru5IqFSQPZSvGH2ois6uE50CFayPcjQE"
543 "OVZt41noQdFd15RmKTvocoCC5tHNlaikeQ52yi0IScOlad1B1lMhoplW3rWophQaqxMumr"
544 "OcHIZ+Y+p858x5f8Pny/kuqUClmFh9B/vF07NsUHwoSL9tA5t5jCY3L5iUc/v7o3oFcW/T"
545 "gojKkX2Kg7KQ86QA==";
547 cast_channel_set_authority_keys_function
=
548 CreateSetAuthorityKeysFunction(empty_extension
);
549 error
= utils::RunFunctionAndReturnError(
550 cast_channel_set_authority_keys_function
.get(),
551 "[\"" + keys
+ "\", \"signature\"]",
553 EXPECT_EQ(error
, errorResult
);
555 cast_channel_set_authority_keys_function
=
556 CreateSetAuthorityKeysFunction(empty_extension
);
557 error
= utils::RunFunctionAndReturnError(
558 cast_channel_set_authority_keys_function
.get(),
559 "[\"keys\", \"" + signature
+ "\"]",
561 EXPECT_EQ(error
, errorResult
);
563 cast_channel_set_authority_keys_function
=
564 CreateSetAuthorityKeysFunction(empty_extension
);
565 error
= utils::RunFunctionAndReturnError(
566 cast_channel_set_authority_keys_function
.get(),
567 "[\"" + keys
+ "\", \"" + signature
+ "\"]",
569 EXPECT_EQ(error
, errorResult
);
572 IN_PROC_BROWSER_TEST_F(CastChannelAPITest
, TestSetAuthorityKeysValid
) {
573 scoped_refptr
<Extension
> empty_extension(
574 extensions::test_util::CreateEmptyExtension());
575 scoped_refptr
<extensions::CastChannelSetAuthorityKeysFunction
>
576 cast_channel_set_authority_keys_function
;
578 cast_channel_set_authority_keys_function
=
579 CreateSetAuthorityKeysFunction(empty_extension
);
581 "CrMCCiBSnZzWf+XraY5w3SbX2PEmWfHm5SNIv2pc9xbhP0EOcxKOAjCCAQoCggEBALwigL"
582 "2A9johADuudl41fz3DZFxVlIY0LwWHKM33aYwXs1CnuIL638dDLdZ+q6BvtxNygKRHFcEg"
583 "mVDN7BRiCVukmM3SQbY2Tv/oLjIwSoGoQqNsmzNuyrL1U2bgJ1OGGoUepzk/SneO+1RmZv"
584 "tYVMBeOcf1UAYL4IrUzuFqVR+LFwDmaaMn5gglaTwSnY0FLNYuojHetFJQ1iBJ3nGg+a0g"
585 "QBLx3SXr1ea4NvTWj3/KQ9zXEFvmP1GKhbPz//YDLcsjT5ytGOeTBYysUpr3TOmZer5ufk"
586 "0K48YcqZP6OqWRXRy9ZuvMYNyGdMrP+JIcmH1X+mFHnquAt+RIgCqSxRsCAwEAAQqzAgog"
587 "okjC6FTmVqVt6CMfHuF1b9vkB/n+1GUNYMxay2URxyASjgIwggEKAoIBAQCwDl4HOt+kX2"
588 "j3Icdk27Z27+6Lk/j2G4jhk7cX8BUeflJVdzwCjXtKbNO91sGccsizFc8RwfVGxNUgR/sw"
589 "9ORhDGjwXqs3jpvhvIHDcIp41oM0MpwZYuvknO3jZGxBHZzSi0hMI5CVs+dS6gVXzGCzuh"
590 "TkugA55EZVdM5ajnpnI9poCvrEhB60xaGianMfbsguL5qeqLEO/Yemj009SwXVNVp0TbyO"
591 "gkSW9LWVYE6l3yc9QVwHo7Q1WrOe8gUkys0xWg0mTNTT/VDhNOlMgVgwssd63YGJptQ6OI"
592 "QDtzSedz//eAdbmcGyHzVWbjo8DCXhV/aKfknAzIMRNeeRbS5lAgMBAAE=";
593 std::string signature
=
594 "o83oku3jP+xjTysNBalqp/ZfJRPLt8R+IUhZMepbARFSRVizLoeFW5XyUwe6lQaC+PFFQH"
595 "SZeGZyeeGRpwCJ/lef0xh6SWJlVMWNTk5+z0U84GQdizJP/CTCeHpIwMobN+kyDajgOyfD"
596 "DLhktc6LHmSlFGG6J7B8W67oziS8ZFEdrcT9WSXFrjLVyURHjvidZD5iFtuImI6k9R9OoX"
597 "LR6SyAwpjdrL+vlHMk3Gol6KQ98YpF0ghHnN3/FFW4ibvIwjmRbp+tUV3h8TRcCOjlXVGp"
598 "bzPtNRRlTqfv7Rxm5YXkZMLmJJMZiTs5+o8FMRMTQZT4hRR3DQ+A/jofViyTGA==";
600 std::string args
= "[\"" + keys
+ "\", \"" + signature
+ "\"]";
601 std::string error
= utils::RunFunctionAndReturnError(
602 cast_channel_set_authority_keys_function
.get(), args
, browser());
603 EXPECT_EQ(error
, std::string());
606 // TODO(vadimgo): Win Dbg has a workaround that makes RunExtensionSubtest
607 // always return true without actually running the test. Remove when fixed.
608 #if defined(OS_WIN) && !defined(NDEBUG)
609 #define MAYBE_TestSetAuthorityKeys DISABLED_TestSetAuthorityKeys
611 #define MAYBE_TestSetAuthorityKeys TestSetAuthorityKeys
613 // Test loading extension, opening a channel with ConnectInfo, adding a
614 // listener, writing, reading, and closing.
615 IN_PROC_BROWSER_TEST_F(CastChannelAPITest
, MAYBE_TestSetAuthorityKeys
) {
617 RunExtensionSubtest("cast_channel/api", "test_authority_keys.html"));