Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/api/cast_channel/cast_channel_api.h" | 8 #include "chrome/browser/extensions/api/cast_channel/cast_channel_api.h" |
| 9 #include "chrome/browser/extensions/api/cast_channel/cast_socket.h" | 9 #include "chrome/browser/extensions/api/cast_channel/cast_socket.h" |
| 10 #include "chrome/browser/extensions/extension_apitest.h" | 10 #include "chrome/browser/extensions/extension_apitest.h" |
| 11 #include "chrome/browser/extensions/extension_function_test_utils.h" | |
| 11 #include "chrome/browser/extensions/extension_service.h" | 12 #include "chrome/browser/extensions/extension_service.h" |
| 13 #include "chrome/browser/ui/browser.h" | |
| 12 #include "chrome/common/extensions/api/cast_channel.h" | 14 #include "chrome/common/extensions/api/cast_channel.h" |
| 13 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
| 14 #include "extensions/common/switches.h" | 16 #include "extensions/common/switches.h" |
| 15 #include "net/base/capturing_net_log.h" | 17 #include "net/base/capturing_net_log.h" |
| 16 #include "net/base/completion_callback.h" | 18 #include "net/base/completion_callback.h" |
| 17 #include "net/base/net_errors.h" | 19 #include "net/base/net_errors.h" |
| 18 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
| 19 #include "testing/gmock_mutant.h" | 21 #include "testing/gmock_mutant.h" |
| 20 | 22 |
| 21 namespace cast_channel = extensions::api::cast_channel; | 23 namespace cast_channel = extensions::api::cast_channel; |
| 22 using cast_channel::CastSocket; | 24 using cast_channel::CastSocket; |
| 23 using cast_channel::ChannelError; | 25 using cast_channel::ChannelError; |
| 24 using cast_channel::MessageInfo; | 26 using cast_channel::MessageInfo; |
| 25 using cast_channel::ReadyState; | 27 using cast_channel::ReadyState; |
| 28 using extensions::Extension; | |
| 29 | |
| 30 namespace utils = extension_function_test_utils; | |
| 26 | 31 |
| 27 using ::testing::_; | 32 using ::testing::_; |
| 28 using ::testing::A; | 33 using ::testing::A; |
| 29 using ::testing::DoAll; | 34 using ::testing::DoAll; |
| 30 using ::testing::Invoke; | 35 using ::testing::Invoke; |
| 31 using ::testing::InSequence; | 36 using ::testing::InSequence; |
| 32 using ::testing::Return; | 37 using ::testing::Return; |
| 33 | 38 |
| 34 namespace { | 39 namespace { |
| 35 | 40 |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 252 .WillRepeatedly(Return(cast_channel::READY_STATE_CLOSED)); | 257 .WillRepeatedly(Return(cast_channel::READY_STATE_CLOSED)); |
| 253 EXPECT_CALL(*mock_cast_socket_, Close(_)); | 258 EXPECT_CALL(*mock_cast_socket_, Close(_)); |
| 254 | 259 |
| 255 EXPECT_TRUE(RunExtensionSubtest("cast_channel/api", | 260 EXPECT_TRUE(RunExtensionSubtest("cast_channel/api", |
| 256 "test_open_error.html")); | 261 "test_open_error.html")); |
| 257 | 262 |
| 258 ResultCatcher catcher; | 263 ResultCatcher catcher; |
| 259 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 264 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 260 } | 265 } |
| 261 | 266 |
| 267 IN_PROC_BROWSER_TEST_F(CastChannelAPITest, TestOpenInvalidUrl) { | |
| 268 scoped_refptr<extensions::CastChannelOpenFunction> cast_channel_open_function( | |
| 269 new extensions::CastChannelOpenFunction); | |
| 270 scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension()); | |
| 271 cast_channel_open_function->set_extension(empty_extension.get()); | |
| 272 | |
| 273 std::string error(utils::RunFunctionAndReturnError( | |
| 274 cast_channel_open_function.get(), "[\"blargh\"]", browser())); | |
| 275 | |
| 276 EXPECT_EQ(error, "Invalid Cast URL blargh"); | |
| 277 } | |
| 278 | |
| 279 IN_PROC_BROWSER_TEST_F(CastChannelAPITest, TestOpenInvalidConnectInfo) { | |
| 280 scoped_refptr<extensions::CastChannelOpenFunction> cast_channel_open_function( | |
| 281 new extensions::CastChannelOpenFunction); | |
| 282 scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension()); | |
| 283 cast_channel_open_function->set_extension(empty_extension.get()); | |
| 284 | |
| 285 // Invalid IP address. | |
| 286 std::string error(utils::RunFunctionAndReturnError( | |
| 287 cast_channel_open_function.get(), | |
| 288 "[{\"ipAddress\": \"invalid_ip\", \"port\": 8009, \"auth\": \"ssl\"}]", | |
|
Wez
2014/07/16 22:42:33
This tests a valid ConnectInfo with invalid ipAddr
mark a. foltz
2014/07/17 19:26:51
Done.
| |
| 289 browser())); | |
| 290 | |
| 291 EXPECT_EQ(error, "Invalid connect_info"); | |
| 292 } | |
| 293 | |
| 294 IN_PROC_BROWSER_TEST_F(CastChannelAPITest, TestSendInvalidMessageInfo) { | |
| 295 scoped_refptr<extensions::CastChannelSendFunction> cast_channel_send_function( | |
| 296 new extensions::CastChannelSendFunction); | |
| 297 scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension()); | |
| 298 cast_channel_send_function->set_extension(empty_extension.get()); | |
| 299 | |
| 300 // Invalid message data - numbers are not supported | |
| 301 std::string error(utils::RunFunctionAndReturnError( | |
| 302 cast_channel_send_function.get(), | |
| 303 "[{\"channelId\": 1, \"url\": \"cast://127.0.0.1:8009\", " | |
| 304 "\"connectInfo\": " | |
| 305 "{\"ipAddress\": \"127.0.0.1\", \"port\": 8009, " | |
| 306 "\"auth\": \"ssl\"}, \"readyState\": \"open\"}, " | |
| 307 "{\"namespace_\": \"foo\", \"sourceId\": \"src\", " | |
| 308 "\"destinationId\": \"bar\", \"data\": 1235}]", | |
| 309 browser())); | |
| 310 | |
| 311 EXPECT_EQ(error, "Invalid type of message_info.data"); | |
| 312 } | |
| OLD | NEW |