| 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 "chrome/browser/extensions/extension_apitest.h" | 8 #include "chrome/browser/extensions/extension_apitest.h" |
| 9 #include "chrome/browser/extensions/extension_function_test_utils.h" | 9 #include "chrome/browser/extensions/extension_function_test_utils.h" |
| 10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
| 11 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
| 12 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
| 13 #include "extensions/browser/api/cast_channel/cast_channel_api.h" | 13 #include "extensions/browser/api/cast_channel/cast_channel_api.h" |
| 14 #include "extensions/browser/api/cast_channel/cast_socket.h" | 14 #include "extensions/browser/api/cast_channel/cast_socket.h" |
| 15 #include "extensions/browser/api/cast_channel/logger.h" | 15 #include "extensions/browser/api/cast_channel/logger.h" |
| 16 #include "extensions/common/api/cast_channel.h" | 16 #include "extensions/common/api/cast_channel.h" |
| 17 #include "extensions/common/switches.h" | 17 #include "extensions/common/switches.h" |
| 18 #include "extensions/common/test_util.h" |
| 18 #include "extensions/test/result_catcher.h" | 19 #include "extensions/test/result_catcher.h" |
| 19 #include "net/base/capturing_net_log.h" | 20 #include "net/base/capturing_net_log.h" |
| 20 #include "net/base/completion_callback.h" | 21 #include "net/base/completion_callback.h" |
| 21 #include "net/base/net_errors.h" | 22 #include "net/base/net_errors.h" |
| 22 #include "testing/gmock/include/gmock/gmock.h" | 23 #include "testing/gmock/include/gmock/gmock.h" |
| 23 #include "testing/gmock_mutant.h" | 24 #include "testing/gmock_mutant.h" |
| 24 | 25 |
| 25 // TODO(mfoltz): Mock out the ApiResourceManager to resolve threading issues | 26 // TODO(mfoltz): Mock out the ApiResourceManager to resolve threading issues |
| 26 // (crbug.com/398242) and simulate unloading of the extension. | 27 // (crbug.com/398242) and simulate unloading of the extension. |
| 27 | 28 |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 EXPECT_CALL(*mock_cast_socket_, ready_state()) | 288 EXPECT_CALL(*mock_cast_socket_, ready_state()) |
| 288 .WillRepeatedly(Return(cast_channel::READY_STATE_CLOSED)); | 289 .WillRepeatedly(Return(cast_channel::READY_STATE_CLOSED)); |
| 289 EXPECT_CALL(*mock_cast_socket_, Close(_)) | 290 EXPECT_CALL(*mock_cast_socket_, Close(_)) |
| 290 .WillOnce(InvokeCompletionCallback<0>(net::OK)); | 291 .WillOnce(InvokeCompletionCallback<0>(net::OK)); |
| 291 | 292 |
| 292 EXPECT_TRUE(RunExtensionSubtest("cast_channel/api", | 293 EXPECT_TRUE(RunExtensionSubtest("cast_channel/api", |
| 293 "test_open_error.html")); | 294 "test_open_error.html")); |
| 294 } | 295 } |
| 295 | 296 |
| 296 IN_PROC_BROWSER_TEST_F(CastChannelAPITest, TestOpenInvalidConnectInfo) { | 297 IN_PROC_BROWSER_TEST_F(CastChannelAPITest, TestOpenInvalidConnectInfo) { |
| 297 scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension()); | 298 scoped_refptr<Extension> empty_extension = |
| 299 extensions::test_util::CreateEmptyExtension(); |
| 298 scoped_refptr<extensions::CastChannelOpenFunction> cast_channel_open_function; | 300 scoped_refptr<extensions::CastChannelOpenFunction> cast_channel_open_function; |
| 299 | 301 |
| 300 // Invalid URL | 302 // Invalid URL |
| 301 // TODO(mfoltz): Remove this test case when fixing crbug.com/331905 | 303 // TODO(mfoltz): Remove this test case when fixing crbug.com/331905 |
| 302 cast_channel_open_function = CreateOpenFunction(empty_extension); | 304 cast_channel_open_function = CreateOpenFunction(empty_extension); |
| 303 std::string error(utils::RunFunctionAndReturnError( | 305 std::string error(utils::RunFunctionAndReturnError( |
| 304 cast_channel_open_function.get(), "[\"blargh\"]", browser())); | 306 cast_channel_open_function.get(), "[\"blargh\"]", browser())); |
| 305 EXPECT_EQ(error, "Invalid connect_info (invalid Cast URL blargh)"); | 307 EXPECT_EQ(error, "Invalid connect_info (invalid Cast URL blargh)"); |
| 306 | 308 |
| 307 // Wrong type | 309 // Wrong type |
| (...skipping 23 matching lines...) Expand all Loading... |
| 331 // Auth not set | 333 // Auth not set |
| 332 cast_channel_open_function = CreateOpenFunction(empty_extension); | 334 cast_channel_open_function = CreateOpenFunction(empty_extension); |
| 333 error = utils::RunFunctionAndReturnError( | 335 error = utils::RunFunctionAndReturnError( |
| 334 cast_channel_open_function.get(), | 336 cast_channel_open_function.get(), |
| 335 "[{\"ipAddress\": \"127.0.0.1\", \"port\": 8009}]", | 337 "[{\"ipAddress\": \"127.0.0.1\", \"port\": 8009}]", |
| 336 browser()); | 338 browser()); |
| 337 EXPECT_EQ(error, "connect_info.auth is required"); | 339 EXPECT_EQ(error, "connect_info.auth is required"); |
| 338 } | 340 } |
| 339 | 341 |
| 340 IN_PROC_BROWSER_TEST_F(CastChannelAPITest, TestSendInvalidMessageInfo) { | 342 IN_PROC_BROWSER_TEST_F(CastChannelAPITest, TestSendInvalidMessageInfo) { |
| 341 scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension()); | 343 scoped_refptr<Extension> empty_extension( |
| 344 extensions::test_util::CreateEmptyExtension()); |
| 342 scoped_refptr<extensions::CastChannelSendFunction> cast_channel_send_function; | 345 scoped_refptr<extensions::CastChannelSendFunction> cast_channel_send_function; |
| 343 | 346 |
| 344 // Numbers are not supported | 347 // Numbers are not supported |
| 345 cast_channel_send_function = CreateSendFunction(empty_extension); | 348 cast_channel_send_function = CreateSendFunction(empty_extension); |
| 346 std::string error(utils::RunFunctionAndReturnError( | 349 std::string error(utils::RunFunctionAndReturnError( |
| 347 cast_channel_send_function.get(), | 350 cast_channel_send_function.get(), |
| 348 "[{\"channelId\": 1, \"url\": \"cast://127.0.0.1:8009\", " | 351 "[{\"channelId\": 1, \"url\": \"cast://127.0.0.1:8009\", " |
| 349 "\"connectInfo\": " | 352 "\"connectInfo\": " |
| 350 "{\"ipAddress\": \"127.0.0.1\", \"port\": 8009, " | 353 "{\"ipAddress\": \"127.0.0.1\", \"port\": 8009, " |
| 351 "\"auth\": \"ssl\"}, \"readyState\": \"open\"}, " | 354 "\"auth\": \"ssl\"}, \"readyState\": \"open\"}, " |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 cast_channel_send_function.get(), | 389 cast_channel_send_function.get(), |
| 387 "[{\"channelId\": 1, \"url\": \"cast://127.0.0.1:8009\", " | 390 "[{\"channelId\": 1, \"url\": \"cast://127.0.0.1:8009\", " |
| 388 "\"connectInfo\": " | 391 "\"connectInfo\": " |
| 389 "{\"ipAddress\": \"127.0.0.1\", \"port\": 8009, " | 392 "{\"ipAddress\": \"127.0.0.1\", \"port\": 8009, " |
| 390 "\"auth\": \"ssl\"}, \"readyState\": \"open\"}, " | 393 "\"auth\": \"ssl\"}, \"readyState\": \"open\"}, " |
| 391 "{\"namespace_\": \"foo\", \"sourceId\": \"src\", " | 394 "{\"namespace_\": \"foo\", \"sourceId\": \"src\", " |
| 392 "\"destinationId\": \"\", \"data\": \"data\"}]", | 395 "\"destinationId\": \"\", \"data\": \"data\"}]", |
| 393 browser()); | 396 browser()); |
| 394 EXPECT_EQ(error, "message_info.destination_id is required"); | 397 EXPECT_EQ(error, "message_info.destination_id is required"); |
| 395 } | 398 } |
| OLD | NEW |