| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/timer/mock_timer.h" | 9 #include "base/timer/mock_timer.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 } | 207 } |
| 208 | 208 |
| 209 extensions::CastChannelSendFunction* CreateSendFunction( | 209 extensions::CastChannelSendFunction* CreateSendFunction( |
| 210 scoped_refptr<Extension> extension) { | 210 scoped_refptr<Extension> extension) { |
| 211 extensions::CastChannelSendFunction* cast_channel_send_function = | 211 extensions::CastChannelSendFunction* cast_channel_send_function = |
| 212 new extensions::CastChannelSendFunction; | 212 new extensions::CastChannelSendFunction; |
| 213 cast_channel_send_function->set_extension(extension.get()); | 213 cast_channel_send_function->set_extension(extension.get()); |
| 214 return cast_channel_send_function; | 214 return cast_channel_send_function; |
| 215 } | 215 } |
| 216 | 216 |
| 217 extensions::CastChannelSetAuthorityKeysFunction* | |
| 218 CreateSetAuthorityKeysFunction(scoped_refptr<Extension> extension) { | |
| 219 extensions::CastChannelSetAuthorityKeysFunction* | |
| 220 cast_channel_set_authority_keys_function = | |
| 221 new extensions::CastChannelSetAuthorityKeysFunction; | |
| 222 cast_channel_set_authority_keys_function->set_extension(extension.get()); | |
| 223 return cast_channel_set_authority_keys_function; | |
| 224 } | |
| 225 | |
| 226 MockCastSocket* mock_cast_socket_; | 217 MockCastSocket* mock_cast_socket_; |
| 227 base::MockTimer* timeout_timer_; | 218 base::MockTimer* timeout_timer_; |
| 228 net::IPEndPoint ip_endpoint_; | 219 net::IPEndPoint ip_endpoint_; |
| 229 LastErrors last_errors_; | 220 LastErrors last_errors_; |
| 230 CastTransport::Delegate* message_delegate_; | 221 CastTransport::Delegate* message_delegate_; |
| 231 net::TestNetLog capturing_net_log_; | 222 net::TestNetLog capturing_net_log_; |
| 232 int channel_id_; | 223 int channel_id_; |
| 233 }; | 224 }; |
| 234 | 225 |
| 235 ACTION_P2(InvokeDelegateOnError, api_test, api) { | 226 ACTION_P2(InvokeDelegateOnError, api_test, api) { |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 | 322 |
| 332 EXPECT_TRUE(RunExtensionSubtest("cast_channel/api", | 323 EXPECT_TRUE(RunExtensionSubtest("cast_channel/api", |
| 333 "test_open_receive_close.html")); | 324 "test_open_receive_close.html")); |
| 334 | 325 |
| 335 extensions::ResultCatcher catcher; | 326 extensions::ResultCatcher catcher; |
| 336 CallOnMessage("some-message"); | 327 CallOnMessage("some-message"); |
| 337 CallOnMessage("some-message"); | 328 CallOnMessage("some-message"); |
| 338 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 329 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 339 } | 330 } |
| 340 | 331 |
| 341 // TODO(imcheng): Win Dbg has a workaround that makes RunExtensionSubtest | |
| 342 // always return true without actually running the test. Remove when fixed. | |
| 343 #if defined(OS_WIN) && !defined(NDEBUG) | |
| 344 #define MAYBE_TestGetLogs DISABLED_TestGetLogs | |
| 345 #else | |
| 346 #define MAYBE_TestGetLogs TestGetLogs | |
| 347 #endif | |
| 348 // Test loading extension, execute a open-send-close sequence, then get logs. | |
| 349 IN_PROC_BROWSER_TEST_F(CastChannelAPITest, MAYBE_TestGetLogs) { | |
| 350 SetUpOpenSendClose(); | |
| 351 | |
| 352 EXPECT_TRUE(RunExtensionSubtest("cast_channel/api", "test_get_logs.html")); | |
| 353 } | |
| 354 | |
| 355 // TODO(kmarshall): Win Dbg has a workaround that makes RunExtensionSubtest | 332 // TODO(kmarshall): Win Dbg has a workaround that makes RunExtensionSubtest |
| 356 // always return true without actually running the test. Remove when fixed. | 333 // always return true without actually running the test. Remove when fixed. |
| 357 #if defined(OS_WIN) && !defined(NDEBUG) | 334 #if defined(OS_WIN) && !defined(NDEBUG) |
| 358 #define MAYBE_TestOpenError DISABLED_TestOpenError | 335 #define MAYBE_TestOpenError DISABLED_TestOpenError |
| 359 #else | 336 #else |
| 360 #define MAYBE_TestOpenError TestOpenError | 337 #define MAYBE_TestOpenError TestOpenError |
| 361 #endif | 338 #endif |
| 362 // Test the case when socket open results in an error. | 339 // Test the case when socket open results in an error. |
| 363 IN_PROC_BROWSER_TEST_F(CastChannelAPITest, MAYBE_TestOpenError) { | 340 IN_PROC_BROWSER_TEST_F(CastChannelAPITest, MAYBE_TestOpenError) { |
| 364 SetUpMockCastSocket(); | 341 SetUpMockCastSocket(); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 "\"keepAlive\": true, " | 438 "\"keepAlive\": true, " |
| 462 "\"audioOnly\": false, " | 439 "\"audioOnly\": false, " |
| 463 "\"connectInfo\": " | 440 "\"connectInfo\": " |
| 464 "{\"ipAddress\": \"127.0.0.1\", \"port\": 8009, " | 441 "{\"ipAddress\": \"127.0.0.1\", \"port\": 8009, " |
| 465 "\"auth\": \"ssl_verified\"}, \"readyState\": \"open\"}, " | 442 "\"auth\": \"ssl_verified\"}, \"readyState\": \"open\"}, " |
| 466 "{\"namespace_\": \"foo\", \"sourceId\": \"src\", " | 443 "{\"namespace_\": \"foo\", \"sourceId\": \"src\", " |
| 467 "\"destinationId\": \"\", \"data\": \"data\"}]", | 444 "\"destinationId\": \"\", \"data\": \"data\"}]", |
| 468 browser()); | 445 browser()); |
| 469 EXPECT_EQ(error, "message_info.destination_id is required"); | 446 EXPECT_EQ(error, "message_info.destination_id is required"); |
| 470 } | 447 } |
| 471 | |
| 472 IN_PROC_BROWSER_TEST_F(CastChannelAPITest, TestSetAuthorityKeysInvalid) { | |
| 473 scoped_refptr<Extension> empty_extension( | |
| 474 extensions::test_util::CreateEmptyExtension()); | |
| 475 scoped_refptr<extensions::CastChannelSetAuthorityKeysFunction> | |
| 476 cast_channel_set_authority_keys_function; | |
| 477 // TODO(eroman): crbug.com/601171: Delete this test once the API has | |
| 478 // been removed. The API is deprecated and will trivially return | |
| 479 // success. So this is just testing that it succeeds for all inputs | |
| 480 // (even invalid ones). | |
| 481 cast_channel_set_authority_keys_function = | |
| 482 CreateSetAuthorityKeysFunction(empty_extension); | |
| 483 EXPECT_TRUE(utils::RunFunction(cast_channel_set_authority_keys_function.get(), | |
| 484 "[\"\", \"signature\"]", browser(), | |
| 485 utils::NONE)); | |
| 486 | |
| 487 cast_channel_set_authority_keys_function = | |
| 488 CreateSetAuthorityKeysFunction(empty_extension); | |
| 489 EXPECT_TRUE(utils::RunFunction(cast_channel_set_authority_keys_function.get(), | |
| 490 "[\"keys\", \"\"]", browser(), utils::NONE)); | |
| 491 | |
| 492 std::string keys = | |
| 493 "CrMCCiBSnZzWf+XraY5w3SbX2PEmWfHm5SNIv2pc9xbhP0EOcxKOAjCCAQoCggEBALwigL" | |
| 494 "2A9johADuudl41fz3DZFxVlIY0LwWHKM33aYwXs1CnuIL638dDLdZ+q6BvtxNygKRHFcEg" | |
| 495 "mVDN7BRiCVukmM3SQbY2Tv/oLjIwSoGoQqNsmzNuyrL1U2bgJ1OGGoUepzk/SneO+1RmZv" | |
| 496 "tYVMBeOcf1UAYL4IrUzuFqVR+LFwDmaaMn5gglaTwSnY0FLNYuojHetFJQ1iBJ3nGg+a0g" | |
| 497 "QBLx3SXr1ea4NvTWj3/KQ9zXEFvmP1GKhbPz//YDLcsjT5ytGOeTBYysUpr3TOmZer5ufk" | |
| 498 "0K48YcqZP6OqWRXRy9ZuvMYNyGdMrP+JIcmH1X+mFHnquAt+RIgCqSxRsCAwEAAQ=="; | |
| 499 std::string signature = | |
| 500 "chCUHZKkykcwU8HzU+hm027fUTBL0dqPMtrzppwExQwK9+" | |
| 501 "XlmCjJswfce2sUUfhR1OL1tyW4hWFwu4JnuQCJ+CvmSmAh2bzRpnuSKzBfgvIDjNOAGUs7" | |
| 502 "ADaNSSWPLxp+6ko++2Dn4S9HpOt8N1v6gMWqj3Ru5IqFSQPZSvGH2ois6uE50CFayPcjQE" | |
| 503 "OVZt41noQdFd15RmKTvocoCC5tHNlaikeQ52yi0IScOlad1B1lMhoplW3rWophQaqxMumr" | |
| 504 "OcHIZ+Y+p858x5f8Pny/kuqUClmFh9B/vF07NsUHwoSL9tA5t5jCY3L5iUc/v7o3oFcW/T" | |
| 505 "gojKkX2Kg7KQ86QA=="; | |
| 506 | |
| 507 cast_channel_set_authority_keys_function = | |
| 508 CreateSetAuthorityKeysFunction(empty_extension); | |
| 509 EXPECT_TRUE(utils::RunFunction(cast_channel_set_authority_keys_function.get(), | |
| 510 "[\"" + keys + "\", \"signature\"]", browser(), | |
| 511 utils::NONE)); | |
| 512 | |
| 513 cast_channel_set_authority_keys_function = | |
| 514 CreateSetAuthorityKeysFunction(empty_extension); | |
| 515 EXPECT_TRUE(utils::RunFunction(cast_channel_set_authority_keys_function.get(), | |
| 516 "[\"keys\", \"" + signature + "\"]", browser(), | |
| 517 utils::NONE)); | |
| 518 | |
| 519 cast_channel_set_authority_keys_function = | |
| 520 CreateSetAuthorityKeysFunction(empty_extension); | |
| 521 EXPECT_TRUE(utils::RunFunction(cast_channel_set_authority_keys_function.get(), | |
| 522 "[\"" + keys + "\", \"" + signature + "\"]", | |
| 523 browser(), utils::NONE)); | |
| 524 } | |
| 525 | |
| 526 IN_PROC_BROWSER_TEST_F(CastChannelAPITest, TestSetAuthorityKeysValid) { | |
| 527 scoped_refptr<Extension> empty_extension( | |
| 528 extensions::test_util::CreateEmptyExtension()); | |
| 529 scoped_refptr<extensions::CastChannelSetAuthorityKeysFunction> | |
| 530 cast_channel_set_authority_keys_function; | |
| 531 | |
| 532 cast_channel_set_authority_keys_function = | |
| 533 CreateSetAuthorityKeysFunction(empty_extension); | |
| 534 std::string keys = | |
| 535 "CrMCCiBSnZzWf+XraY5w3SbX2PEmWfHm5SNIv2pc9xbhP0EOcxKOAjCCAQoCggEBALwigL" | |
| 536 "2A9johADuudl41fz3DZFxVlIY0LwWHKM33aYwXs1CnuIL638dDLdZ+q6BvtxNygKRHFcEg" | |
| 537 "mVDN7BRiCVukmM3SQbY2Tv/oLjIwSoGoQqNsmzNuyrL1U2bgJ1OGGoUepzk/SneO+1RmZv" | |
| 538 "tYVMBeOcf1UAYL4IrUzuFqVR+LFwDmaaMn5gglaTwSnY0FLNYuojHetFJQ1iBJ3nGg+a0g" | |
| 539 "QBLx3SXr1ea4NvTWj3/KQ9zXEFvmP1GKhbPz//YDLcsjT5ytGOeTBYysUpr3TOmZer5ufk" | |
| 540 "0K48YcqZP6OqWRXRy9ZuvMYNyGdMrP+JIcmH1X+mFHnquAt+RIgCqSxRsCAwEAAQqzAgog" | |
| 541 "okjC6FTmVqVt6CMfHuF1b9vkB/n+1GUNYMxay2URxyASjgIwggEKAoIBAQCwDl4HOt+kX2" | |
| 542 "j3Icdk27Z27+6Lk/j2G4jhk7cX8BUeflJVdzwCjXtKbNO91sGccsizFc8RwfVGxNUgR/sw" | |
| 543 "9ORhDGjwXqs3jpvhvIHDcIp41oM0MpwZYuvknO3jZGxBHZzSi0hMI5CVs+dS6gVXzGCzuh" | |
| 544 "TkugA55EZVdM5ajnpnI9poCvrEhB60xaGianMfbsguL5qeqLEO/Yemj009SwXVNVp0TbyO" | |
| 545 "gkSW9LWVYE6l3yc9QVwHo7Q1WrOe8gUkys0xWg0mTNTT/VDhNOlMgVgwssd63YGJptQ6OI" | |
| 546 "QDtzSedz//eAdbmcGyHzVWbjo8DCXhV/aKfknAzIMRNeeRbS5lAgMBAAE="; | |
| 547 std::string signature = | |
| 548 "o83oku3jP+xjTysNBalqp/ZfJRPLt8R+IUhZMepbARFSRVizLoeFW5XyUwe6lQaC+PFFQH" | |
| 549 "SZeGZyeeGRpwCJ/lef0xh6SWJlVMWNTk5+z0U84GQdizJP/CTCeHpIwMobN+kyDajgOyfD" | |
| 550 "DLhktc6LHmSlFGG6J7B8W67oziS8ZFEdrcT9WSXFrjLVyURHjvidZD5iFtuImI6k9R9OoX" | |
| 551 "LR6SyAwpjdrL+vlHMk3Gol6KQ98YpF0ghHnN3/FFW4ibvIwjmRbp+tUV3h8TRcCOjlXVGp" | |
| 552 "bzPtNRRlTqfv7Rxm5YXkZMLmJJMZiTs5+o8FMRMTQZT4hRR3DQ+A/jofViyTGA=="; | |
| 553 | |
| 554 std::string args = "[\"" + keys + "\", \"" + signature + "\"]"; | |
| 555 EXPECT_TRUE(utils::RunFunction(cast_channel_set_authority_keys_function.get(), | |
| 556 args, browser(), utils::NONE)); | |
| 557 } | |
| 558 | |
| 559 // TODO(vadimgo): Win Dbg has a workaround that makes RunExtensionSubtest | |
| 560 // always return true without actually running the test. Remove when fixed. | |
| 561 #if defined(OS_WIN) && !defined(NDEBUG) | |
| 562 #define MAYBE_TestSetAuthorityKeys DISABLED_TestSetAuthorityKeys | |
| 563 #else | |
| 564 #define MAYBE_TestSetAuthorityKeys TestSetAuthorityKeys | |
| 565 #endif | |
| 566 // Test loading extension, opening a channel with ConnectInfo, adding a | |
| 567 // listener, writing, reading, and closing. | |
| 568 IN_PROC_BROWSER_TEST_F(CastChannelAPITest, MAYBE_TestSetAuthorityKeys) { | |
| 569 EXPECT_TRUE( | |
| 570 RunExtensionSubtest("cast_channel/api", "test_authority_keys.html")); | |
| 571 } | |
| OLD | NEW |