Finish refactoring of DomCodeToUsLayoutKeyboardCode().
[chromium-blink-merge.git] / extensions / browser / api / cast_channel / cast_channel_apitest.cc
blob63e31f0d3185f80ed059e2e1585858cea80427f7
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.
5 #include "base/bind.h"
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;
51 using ::testing::_;
52 using ::testing::A;
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;
62 namespace {
64 static void FillCastMessage(const std::string& message,
65 CastMessage* cast_message) {
66 cast_message->set_namespace_("foo");
67 cast_message->set_source_id("src");
68 cast_message->set_destination_id("dest");
69 cast_message->set_payload_utf8(message);
70 cast_message->set_payload_type(CastMessage::STRING);
73 ACTION_TEMPLATE(InvokeCompletionCallback,
74 HAS_1_TEMPLATE_PARAMS(int, k),
75 AND_1_VALUE_PARAMS(result)) {
76 ::std::tr1::get<k>(args).Run(result);
79 } // namespace
81 class CastChannelAPITest : public ExtensionApiTest {
82 public:
83 CastChannelAPITest() : ip_endpoint_(CreateIPEndPointForTest()) {}
85 void SetUpCommandLine(base::CommandLine* command_line) override {
86 ExtensionApiTest::SetUpCommandLine(command_line);
87 command_line->AppendSwitchASCII(
88 extensions::switches::kWhitelistedExtensionID,
89 cast_channel::kTestExtensionId);
92 void SetUpMockCastSocket() {
93 extensions::CastChannelAPI* api = GetApi();
94 timeout_timer_ = new base::MockTimer(true, false);
95 api->SetPingTimeoutTimerForTest(make_scoped_ptr(timeout_timer_));
97 net::IPAddressNumber ip_number;
98 net::ParseIPLiteralToNumber("192.168.1.1", &ip_number);
99 net::IPEndPoint ip_endpoint(ip_number, 8009);
100 mock_cast_socket_ = new MockCastSocket;
101 // Transfers ownership of the socket.
102 api->SetSocketForTest(
103 make_scoped_ptr<CastSocket>(mock_cast_socket_).Pass());
104 ON_CALL(*mock_cast_socket_, set_id(_))
105 .WillByDefault(SaveArg<0>(&channel_id_));
106 ON_CALL(*mock_cast_socket_, id())
107 .WillByDefault(ReturnPointee(&channel_id_));
108 ON_CALL(*mock_cast_socket_, ip_endpoint())
109 .WillByDefault(ReturnRef(ip_endpoint_));
110 ON_CALL(*mock_cast_socket_, channel_auth())
111 .WillByDefault(Return(cast_channel::CHANNEL_AUTH_TYPE_SSL));
112 ON_CALL(*mock_cast_socket_, keep_alive()).WillByDefault(Return(false));
115 void SetUpOpenSendClose() {
116 SetUpMockCastSocket();
117 EXPECT_CALL(*mock_cast_socket_, error_state())
118 .WillRepeatedly(Return(cast_channel::CHANNEL_ERROR_NONE));
120 InSequence sequence;
121 EXPECT_CALL(*mock_cast_socket_, ConnectRawPtr(_, _))
122 .WillOnce(
123 InvokeCompletionCallback<1>(cast_channel::CHANNEL_ERROR_NONE));
124 EXPECT_CALL(*mock_cast_socket_, ready_state())
125 .WillOnce(Return(cast_channel::READY_STATE_OPEN));
126 EXPECT_CALL(*mock_cast_socket_->mock_transport(),
127 SendMessage(A<const CastMessage&>(), _))
128 .WillOnce(InvokeCompletionCallback<1>(net::OK));
129 EXPECT_CALL(*mock_cast_socket_, ready_state())
130 .WillOnce(Return(cast_channel::READY_STATE_OPEN));
131 EXPECT_CALL(*mock_cast_socket_, Close(_))
132 .WillOnce(InvokeCompletionCallback<0>(net::OK));
133 EXPECT_CALL(*mock_cast_socket_, ready_state())
134 .WillOnce(Return(cast_channel::READY_STATE_CLOSED));
138 void SetUpOpenPingTimeout() {
139 SetUpMockCastSocket();
140 EXPECT_CALL(*mock_cast_socket_, error_state())
141 .WillRepeatedly(Return(cast_channel::CHANNEL_ERROR_NONE));
142 EXPECT_CALL(*mock_cast_socket_, keep_alive()).WillRepeatedly(Return(true));
144 InSequence sequence;
145 EXPECT_CALL(*mock_cast_socket_, ConnectRawPtr(_, _))
146 .WillOnce(DoAll(
147 SaveArg<0>(&message_delegate_),
148 InvokeCompletionCallback<1>(cast_channel::CHANNEL_ERROR_NONE)));
149 EXPECT_CALL(*mock_cast_socket_, ready_state())
150 .WillOnce(Return(cast_channel::READY_STATE_OPEN))
151 .RetiresOnSaturation();
152 EXPECT_CALL(*mock_cast_socket_, ready_state())
153 .WillOnce(Return(cast_channel::READY_STATE_CLOSED));
157 extensions::CastChannelAPI* GetApi() {
158 return extensions::CastChannelAPI::Get(profile());
161 // Logs some bogus error details and calls the OnError handler.
162 void DoCallOnError(extensions::CastChannelAPI* api) {
163 api->GetLogger()->LogSocketEventWithRv(mock_cast_socket_->id(),
164 cast_channel::proto::SOCKET_WRITE,
165 net::ERR_FAILED);
166 message_delegate_->OnError(cast_channel::CHANNEL_ERROR_CONNECT_ERROR);
169 protected:
170 void CallOnMessage(const std::string& message) {
171 content::BrowserThread::PostTask(
172 content::BrowserThread::IO,
173 FROM_HERE,
174 base::Bind(&CastChannelAPITest::DoCallOnMessage, this,
175 GetApi(), mock_cast_socket_, message));
178 void DoCallOnMessage(extensions::CastChannelAPI* api,
179 MockCastSocket* cast_socket,
180 const std::string& message) {
181 CastMessage cast_message;
182 FillCastMessage(message, &cast_message);
183 message_delegate_->OnMessage(cast_message);
186 // Starts the read delegate on the IO thread.
187 void StartDelegate() {
188 CHECK(message_delegate_);
189 content::BrowserThread::PostTask(
190 content::BrowserThread::IO, FROM_HERE,
191 base::Bind(&cast_channel::CastTransport::Delegate::Start,
192 base::Unretained(message_delegate_)));
195 // Fires a timer on the IO thread.
196 void FireTimeout() {
197 content::BrowserThread::PostTask(
198 content::BrowserThread::IO, FROM_HERE,
199 base::Bind(&base::MockTimer::Fire, base::Unretained(timeout_timer_)));
202 extensions::CastChannelOpenFunction* CreateOpenFunction(
203 scoped_refptr<Extension> extension) {
204 extensions::CastChannelOpenFunction* cast_channel_open_function =
205 new extensions::CastChannelOpenFunction;
206 cast_channel_open_function->set_extension(extension.get());
207 return cast_channel_open_function;
210 extensions::CastChannelSendFunction* CreateSendFunction(
211 scoped_refptr<Extension> extension) {
212 extensions::CastChannelSendFunction* cast_channel_send_function =
213 new extensions::CastChannelSendFunction;
214 cast_channel_send_function->set_extension(extension.get());
215 return cast_channel_send_function;
218 extensions::CastChannelSetAuthorityKeysFunction*
219 CreateSetAuthorityKeysFunction(scoped_refptr<Extension> extension) {
220 extensions::CastChannelSetAuthorityKeysFunction*
221 cast_channel_set_authority_keys_function =
222 new extensions::CastChannelSetAuthorityKeysFunction;
223 cast_channel_set_authority_keys_function->set_extension(extension.get());
224 return cast_channel_set_authority_keys_function;
227 MockCastSocket* mock_cast_socket_;
228 base::MockTimer* timeout_timer_;
229 net::IPEndPoint ip_endpoint_;
230 LastErrors last_errors_;
231 CastTransport::Delegate* message_delegate_;
232 net::TestNetLog capturing_net_log_;
233 int channel_id_;
236 ACTION_P2(InvokeDelegateOnError, api_test, api) {
237 content::BrowserThread::PostTask(
238 content::BrowserThread::IO, FROM_HERE,
239 base::Bind(&CastChannelAPITest::DoCallOnError, base::Unretained(api_test),
240 base::Unretained(api)));
243 // TODO(kmarshall): Win Dbg has a workaround that makes RunExtensionSubtest
244 // always return true without actually running the test. Remove when fixed.
245 #if defined(OS_WIN) && !defined(NDEBUG)
246 #define MAYBE_TestOpenSendClose DISABLED_TestOpenSendClose
247 #else
248 #define MAYBE_TestOpenSendClose TestOpenSendClose
249 #endif
250 // Test loading extension, opening a channel with ConnectInfo, adding a
251 // listener, writing, reading, and closing.
252 IN_PROC_BROWSER_TEST_F(CastChannelAPITest, MAYBE_TestOpenSendClose) {
253 SetUpOpenSendClose();
255 EXPECT_TRUE(RunExtensionSubtest("cast_channel/api",
256 "test_open_send_close.html"));
259 // TODO(kmarshall): Win Dbg has a workaround that makes RunExtensionSubtest
260 // always return true without actually running the test. Remove when fixed.
261 #if defined(OS_WIN) && !defined(NDEBUG)
262 #define MAYBE_TestPingTimeout DISABLED_TestPingTimeout
263 #else
264 #define MAYBE_TestPingTimeout TestPingTimeout
265 #endif
266 // Verify that timeout events are propagated through the API layer.
267 // (SSL, non-verified).
268 IN_PROC_BROWSER_TEST_F(CastChannelAPITest, MAYBE_TestPingTimeout) {
269 SetUpOpenPingTimeout();
271 ExtensionTestMessageListener channel_opened("channel_opened_ssl", false);
272 ExtensionTestMessageListener timeout("timeout_ssl", false);
273 EXPECT_TRUE(
274 RunExtensionSubtest("cast_channel/api", "test_open_timeout.html"));
275 EXPECT_TRUE(channel_opened.WaitUntilSatisfied());
276 StartDelegate();
277 FireTimeout();
278 EXPECT_TRUE(timeout.WaitUntilSatisfied());
281 // TODO(kmarshall): Win Dbg has a workaround that makes RunExtensionSubtest
282 // always return true without actually running the test. Remove when fixed.
283 #if defined(OS_WIN) && !defined(NDEBUG)
284 #define MAYBE_TestPingTimeoutSslVerified DISABLED_TestPingTimeoutSslVerified
285 #else
286 #define MAYBE_TestPingTimeoutSslVerified TestPingTimeoutSslVerified
287 #endif
288 // Verify that timeout events are propagated through the API layer.
289 // (SSL, verified).
290 IN_PROC_BROWSER_TEST_F(CastChannelAPITest, MAYBE_TestPingTimeoutSslVerified) {
291 SetUpOpenPingTimeout();
293 ExtensionTestMessageListener channel_opened("channel_opened_ssl_verified",
294 false);
295 ExtensionTestMessageListener timeout("timeout_ssl_verified", false);
296 EXPECT_TRUE(RunExtensionSubtest("cast_channel/api",
297 "test_open_timeout_verified.html"));
298 EXPECT_TRUE(channel_opened.WaitUntilSatisfied());
299 StartDelegate();
300 FireTimeout();
301 EXPECT_TRUE(timeout.WaitUntilSatisfied());
304 // TODO(kmarshall): Win Dbg has a workaround that makes RunExtensionSubtest
305 // always return true without actually running the test. Remove when fixed.
306 #if defined(OS_WIN) && !defined(NDEBUG)
307 #define MAYBE_TestOpenReceiveClose DISABLED_TestOpenReceiveClose
308 #else
309 #define MAYBE_TestOpenReceiveClose TestOpenReceiveClose
310 #endif
311 // Test loading extension, opening a channel, adding a listener,
312 // writing, reading, and closing.
313 IN_PROC_BROWSER_TEST_F(CastChannelAPITest, MAYBE_TestOpenReceiveClose) {
314 SetUpMockCastSocket();
315 EXPECT_CALL(*mock_cast_socket_, error_state())
316 .WillRepeatedly(Return(cast_channel::CHANNEL_ERROR_NONE));
319 InSequence sequence;
320 EXPECT_CALL(*mock_cast_socket_, ConnectRawPtr(NotNull(), _))
321 .WillOnce(DoAll(
322 SaveArg<0>(&message_delegate_),
323 InvokeCompletionCallback<1>(cast_channel::CHANNEL_ERROR_NONE)));
324 EXPECT_CALL(*mock_cast_socket_, ready_state())
325 .Times(3)
326 .WillRepeatedly(Return(cast_channel::READY_STATE_OPEN));
327 EXPECT_CALL(*mock_cast_socket_, Close(_))
328 .WillOnce(InvokeCompletionCallback<0>(net::OK));
329 EXPECT_CALL(*mock_cast_socket_, ready_state())
330 .WillOnce(Return(cast_channel::READY_STATE_CLOSED));
333 EXPECT_TRUE(RunExtensionSubtest("cast_channel/api",
334 "test_open_receive_close.html"));
336 extensions::ResultCatcher catcher;
337 CallOnMessage("some-message");
338 CallOnMessage("some-message");
339 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
342 // TODO(imcheng): Win Dbg has a workaround that makes RunExtensionSubtest
343 // always return true without actually running the test. Remove when fixed.
344 #if defined(OS_WIN) && !defined(NDEBUG)
345 #define MAYBE_TestGetLogs DISABLED_TestGetLogs
346 #else
347 #define MAYBE_TestGetLogs TestGetLogs
348 #endif
349 // Test loading extension, execute a open-send-close sequence, then get logs.
350 IN_PROC_BROWSER_TEST_F(CastChannelAPITest, MAYBE_TestGetLogs) {
351 SetUpOpenSendClose();
353 EXPECT_TRUE(RunExtensionSubtest("cast_channel/api", "test_get_logs.html"));
356 // TODO(kmarshall): Win Dbg has a workaround that makes RunExtensionSubtest
357 // always return true without actually running the test. Remove when fixed.
358 #if defined(OS_WIN) && !defined(NDEBUG)
359 #define MAYBE_TestOpenError DISABLED_TestOpenError
360 #else
361 #define MAYBE_TestOpenError TestOpenError
362 #endif
363 // Test the case when socket open results in an error.
364 IN_PROC_BROWSER_TEST_F(CastChannelAPITest, MAYBE_TestOpenError) {
365 SetUpMockCastSocket();
367 EXPECT_CALL(*mock_cast_socket_, ConnectRawPtr(NotNull(), _))
368 .WillOnce(DoAll(SaveArg<0>(&message_delegate_),
369 InvokeDelegateOnError(this, GetApi()),
370 InvokeCompletionCallback<1>(
371 cast_channel::CHANNEL_ERROR_CONNECT_ERROR)));
372 EXPECT_CALL(*mock_cast_socket_, error_state())
373 .WillRepeatedly(Return(cast_channel::CHANNEL_ERROR_CONNECT_ERROR));
374 EXPECT_CALL(*mock_cast_socket_, ready_state())
375 .WillRepeatedly(Return(cast_channel::READY_STATE_CLOSED));
376 EXPECT_CALL(*mock_cast_socket_, Close(_))
377 .WillOnce(InvokeCompletionCallback<0>(net::OK));
379 EXPECT_TRUE(RunExtensionSubtest("cast_channel/api",
380 "test_open_error.html"));
383 IN_PROC_BROWSER_TEST_F(CastChannelAPITest, TestOpenInvalidConnectInfo) {
384 scoped_refptr<Extension> empty_extension =
385 extensions::test_util::CreateEmptyExtension();
386 scoped_refptr<extensions::CastChannelOpenFunction> cast_channel_open_function;
388 // Invalid IP address
389 cast_channel_open_function = CreateOpenFunction(empty_extension);
390 std::string error = utils::RunFunctionAndReturnError(
391 cast_channel_open_function.get(),
392 "[{\"ipAddress\": \"invalid_ip\", \"port\": 8009, \"auth\": \"ssl\"}]",
393 browser());
394 EXPECT_EQ(error, "Invalid connect_info (invalid IP address)");
396 // Invalid port
397 cast_channel_open_function = CreateOpenFunction(empty_extension);
398 error = utils::RunFunctionAndReturnError(
399 cast_channel_open_function.get(),
400 "[{\"ipAddress\": \"127.0.0.1\", \"port\": -200, \"auth\": \"ssl\"}]",
401 browser());
402 EXPECT_EQ(error, "Invalid connect_info (invalid port)");
405 IN_PROC_BROWSER_TEST_F(CastChannelAPITest, TestSendInvalidMessageInfo) {
406 scoped_refptr<Extension> empty_extension(
407 extensions::test_util::CreateEmptyExtension());
408 scoped_refptr<extensions::CastChannelSendFunction> cast_channel_send_function;
410 // Numbers are not supported
411 cast_channel_send_function = CreateSendFunction(empty_extension);
412 std::string error(utils::RunFunctionAndReturnError(
413 cast_channel_send_function.get(),
414 "[{\"channelId\": 1, "
415 "\"keepAlive\": true, "
416 "\"connectInfo\": "
417 "{\"ipAddress\": \"127.0.0.1\", \"port\": 8009, "
418 "\"auth\": \"ssl\"}, \"readyState\": \"open\"}, "
419 "{\"namespace_\": \"foo\", \"sourceId\": \"src\", "
420 "\"destinationId\": \"dest\", \"data\": 1235}]",
421 browser()));
422 EXPECT_EQ(error, "Invalid type of message_info.data");
424 // Missing namespace_
425 cast_channel_send_function = CreateSendFunction(empty_extension);
426 error = utils::RunFunctionAndReturnError(
427 cast_channel_send_function.get(),
428 "[{\"channelId\": 1, "
429 "\"keepAlive\": true, "
430 "\"connectInfo\": "
431 "{\"ipAddress\": \"127.0.0.1\", \"port\": 8009, "
432 "\"auth\": \"ssl\"}, \"readyState\": \"open\"}, "
433 "{\"namespace_\": \"\", \"sourceId\": \"src\", "
434 "\"destinationId\": \"dest\", \"data\": \"data\"}]",
435 browser());
436 EXPECT_EQ(error, "message_info.namespace_ is required");
438 // Missing source_id
439 cast_channel_send_function = CreateSendFunction(empty_extension);
440 error = utils::RunFunctionAndReturnError(
441 cast_channel_send_function.get(),
442 "[{\"channelId\": 1, "
443 "\"keepAlive\": true, "
444 "\"connectInfo\": "
445 "{\"ipAddress\": \"127.0.0.1\", \"port\": 8009, "
446 "\"auth\": \"ssl\"}, \"readyState\": \"open\"}, "
447 "{\"namespace_\": \"foo\", \"sourceId\": \"\", "
448 "\"destinationId\": \"dest\", \"data\": \"data\"}]",
449 browser());
450 EXPECT_EQ(error, "message_info.source_id is required");
452 // Missing destination_id
453 cast_channel_send_function = CreateSendFunction(empty_extension);
454 error = utils::RunFunctionAndReturnError(
455 cast_channel_send_function.get(),
456 "[{\"channelId\": 1, "
457 "\"keepAlive\": true, "
458 "\"connectInfo\": "
459 "{\"ipAddress\": \"127.0.0.1\", \"port\": 8009, "
460 "\"auth\": \"ssl\"}, \"readyState\": \"open\"}, "
461 "{\"namespace_\": \"foo\", \"sourceId\": \"src\", "
462 "\"destinationId\": \"\", \"data\": \"data\"}]",
463 browser());
464 EXPECT_EQ(error, "message_info.destination_id is required");
467 IN_PROC_BROWSER_TEST_F(CastChannelAPITest, TestSetAuthorityKeysInvalid) {
468 scoped_refptr<Extension> empty_extension(
469 extensions::test_util::CreateEmptyExtension());
470 scoped_refptr<extensions::CastChannelSetAuthorityKeysFunction>
471 cast_channel_set_authority_keys_function;
472 std::string errorResult = "Unable to set authority keys.";
474 cast_channel_set_authority_keys_function =
475 CreateSetAuthorityKeysFunction(empty_extension);
476 std::string error = utils::RunFunctionAndReturnError(
477 cast_channel_set_authority_keys_function.get(),
478 "[\"\", \"signature\"]",
479 browser());
480 EXPECT_EQ(error, errorResult);
482 cast_channel_set_authority_keys_function =
483 CreateSetAuthorityKeysFunction(empty_extension);
484 error = utils::RunFunctionAndReturnError(
485 cast_channel_set_authority_keys_function.get(),
486 "[\"keys\", \"\"]",
487 browser());
488 EXPECT_EQ(error, errorResult);
490 std::string keys =
491 "CrMCCiBSnZzWf+XraY5w3SbX2PEmWfHm5SNIv2pc9xbhP0EOcxKOAjCCAQoCggEBALwigL"
492 "2A9johADuudl41fz3DZFxVlIY0LwWHKM33aYwXs1CnuIL638dDLdZ+q6BvtxNygKRHFcEg"
493 "mVDN7BRiCVukmM3SQbY2Tv/oLjIwSoGoQqNsmzNuyrL1U2bgJ1OGGoUepzk/SneO+1RmZv"
494 "tYVMBeOcf1UAYL4IrUzuFqVR+LFwDmaaMn5gglaTwSnY0FLNYuojHetFJQ1iBJ3nGg+a0g"
495 "QBLx3SXr1ea4NvTWj3/KQ9zXEFvmP1GKhbPz//YDLcsjT5ytGOeTBYysUpr3TOmZer5ufk"
496 "0K48YcqZP6OqWRXRy9ZuvMYNyGdMrP+JIcmH1X+mFHnquAt+RIgCqSxRsCAwEAAQ==";
497 std::string signature =
498 "chCUHZKkykcwU8HzU+hm027fUTBL0dqPMtrzppwExQwK9+"
499 "XlmCjJswfce2sUUfhR1OL1tyW4hWFwu4JnuQCJ+CvmSmAh2bzRpnuSKzBfgvIDjNOAGUs7"
500 "ADaNSSWPLxp+6ko++2Dn4S9HpOt8N1v6gMWqj3Ru5IqFSQPZSvGH2ois6uE50CFayPcjQE"
501 "OVZt41noQdFd15RmKTvocoCC5tHNlaikeQ52yi0IScOlad1B1lMhoplW3rWophQaqxMumr"
502 "OcHIZ+Y+p858x5f8Pny/kuqUClmFh9B/vF07NsUHwoSL9tA5t5jCY3L5iUc/v7o3oFcW/T"
503 "gojKkX2Kg7KQ86QA==";
505 cast_channel_set_authority_keys_function =
506 CreateSetAuthorityKeysFunction(empty_extension);
507 error = utils::RunFunctionAndReturnError(
508 cast_channel_set_authority_keys_function.get(),
509 "[\"" + keys + "\", \"signature\"]",
510 browser());
511 EXPECT_EQ(error, errorResult);
513 cast_channel_set_authority_keys_function =
514 CreateSetAuthorityKeysFunction(empty_extension);
515 error = utils::RunFunctionAndReturnError(
516 cast_channel_set_authority_keys_function.get(),
517 "[\"keys\", \"" + signature + "\"]",
518 browser());
519 EXPECT_EQ(error, errorResult);
521 cast_channel_set_authority_keys_function =
522 CreateSetAuthorityKeysFunction(empty_extension);
523 error = utils::RunFunctionAndReturnError(
524 cast_channel_set_authority_keys_function.get(),
525 "[\"" + keys + "\", \"" + signature + "\"]",
526 browser());
527 EXPECT_EQ(error, errorResult);
530 IN_PROC_BROWSER_TEST_F(CastChannelAPITest, TestSetAuthorityKeysValid) {
531 scoped_refptr<Extension> empty_extension(
532 extensions::test_util::CreateEmptyExtension());
533 scoped_refptr<extensions::CastChannelSetAuthorityKeysFunction>
534 cast_channel_set_authority_keys_function;
536 cast_channel_set_authority_keys_function =
537 CreateSetAuthorityKeysFunction(empty_extension);
538 std::string keys =
539 "CrMCCiBSnZzWf+XraY5w3SbX2PEmWfHm5SNIv2pc9xbhP0EOcxKOAjCCAQoCggEBALwigL"
540 "2A9johADuudl41fz3DZFxVlIY0LwWHKM33aYwXs1CnuIL638dDLdZ+q6BvtxNygKRHFcEg"
541 "mVDN7BRiCVukmM3SQbY2Tv/oLjIwSoGoQqNsmzNuyrL1U2bgJ1OGGoUepzk/SneO+1RmZv"
542 "tYVMBeOcf1UAYL4IrUzuFqVR+LFwDmaaMn5gglaTwSnY0FLNYuojHetFJQ1iBJ3nGg+a0g"
543 "QBLx3SXr1ea4NvTWj3/KQ9zXEFvmP1GKhbPz//YDLcsjT5ytGOeTBYysUpr3TOmZer5ufk"
544 "0K48YcqZP6OqWRXRy9ZuvMYNyGdMrP+JIcmH1X+mFHnquAt+RIgCqSxRsCAwEAAQqzAgog"
545 "okjC6FTmVqVt6CMfHuF1b9vkB/n+1GUNYMxay2URxyASjgIwggEKAoIBAQCwDl4HOt+kX2"
546 "j3Icdk27Z27+6Lk/j2G4jhk7cX8BUeflJVdzwCjXtKbNO91sGccsizFc8RwfVGxNUgR/sw"
547 "9ORhDGjwXqs3jpvhvIHDcIp41oM0MpwZYuvknO3jZGxBHZzSi0hMI5CVs+dS6gVXzGCzuh"
548 "TkugA55EZVdM5ajnpnI9poCvrEhB60xaGianMfbsguL5qeqLEO/Yemj009SwXVNVp0TbyO"
549 "gkSW9LWVYE6l3yc9QVwHo7Q1WrOe8gUkys0xWg0mTNTT/VDhNOlMgVgwssd63YGJptQ6OI"
550 "QDtzSedz//eAdbmcGyHzVWbjo8DCXhV/aKfknAzIMRNeeRbS5lAgMBAAE=";
551 std::string signature =
552 "o83oku3jP+xjTysNBalqp/ZfJRPLt8R+IUhZMepbARFSRVizLoeFW5XyUwe6lQaC+PFFQH"
553 "SZeGZyeeGRpwCJ/lef0xh6SWJlVMWNTk5+z0U84GQdizJP/CTCeHpIwMobN+kyDajgOyfD"
554 "DLhktc6LHmSlFGG6J7B8W67oziS8ZFEdrcT9WSXFrjLVyURHjvidZD5iFtuImI6k9R9OoX"
555 "LR6SyAwpjdrL+vlHMk3Gol6KQ98YpF0ghHnN3/FFW4ibvIwjmRbp+tUV3h8TRcCOjlXVGp"
556 "bzPtNRRlTqfv7Rxm5YXkZMLmJJMZiTs5+o8FMRMTQZT4hRR3DQ+A/jofViyTGA==";
558 std::string args = "[\"" + keys + "\", \"" + signature + "\"]";
559 std::string error = utils::RunFunctionAndReturnError(
560 cast_channel_set_authority_keys_function.get(), args, browser());
561 EXPECT_EQ(error, std::string());
564 // TODO(vadimgo): Win Dbg has a workaround that makes RunExtensionSubtest
565 // always return true without actually running the test. Remove when fixed.
566 #if defined(OS_WIN) && !defined(NDEBUG)
567 #define MAYBE_TestSetAuthorityKeys DISABLED_TestSetAuthorityKeys
568 #else
569 #define MAYBE_TestSetAuthorityKeys TestSetAuthorityKeys
570 #endif
571 // Test loading extension, opening a channel with ConnectInfo, adding a
572 // listener, writing, reading, and closing.
573 IN_PROC_BROWSER_TEST_F(CastChannelAPITest, MAYBE_TestSetAuthorityKeys) {
574 EXPECT_TRUE(
575 RunExtensionSubtest("cast_channel/api", "test_authority_keys.html"));