Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(233)

Side by Side Diff: chrome/browser/extensions/api/cast_channel/cast_channel_apitest.cc

Issue 255443002: Implement argument validation for chrome.cast.channel.{open,send} (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove extraneous code Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 .WillRepeatedly(Return(cast_channel::READY_STATE_CLOSED)); 256 .WillRepeatedly(Return(cast_channel::READY_STATE_CLOSED));
252 EXPECT_CALL(*mock_cast_socket_, Close(_)); 257 EXPECT_CALL(*mock_cast_socket_, Close(_));
253 258
254 EXPECT_TRUE(RunExtensionSubtest("cast_channel/api", 259 EXPECT_TRUE(RunExtensionSubtest("cast_channel/api",
255 "test_open_error.html")); 260 "test_open_error.html"));
256 261
257 ResultCatcher catcher; 262 ResultCatcher catcher;
258 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 263 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
259 } 264 }
260 265
266 IN_PROC_BROWSER_TEST_F(CastChannelAPITest, TestOpenInvalidUrl) {
267 scoped_refptr<extensions::CastChannelOpenFunction> cast_channel_open_function(
268 new extensions::CastChannelOpenFunction);
269 scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension());
270 cast_channel_open_function->set_extension(empty_extension.get());
271
272 std::string error(utils::RunFunctionAndReturnError(
273 cast_channel_open_function.get(), "[\"blargh\"]", browser()));
274
275 EXPECT_EQ(error, "Invalid Cast URL blargh");
276 }
277
278 IN_PROC_BROWSER_TEST_F(CastChannelAPITest, TestOpenInvalidConnectInfo) {
279 scoped_refptr<extensions::CastChannelOpenFunction> cast_channel_open_function(
280 new extensions::CastChannelOpenFunction);
281 scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension());
282 cast_channel_open_function->set_extension(empty_extension.get());
283
284 // Invalid IP address.
285 std::string error(utils::RunFunctionAndReturnError(
286 cast_channel_open_function.get(),
287 "[{\"ipAddress\": \"invalid_ip\", \"port\": 8009, \"auth\": \"ssl\"}]",
288 browser()));
289
290 EXPECT_EQ(error, "Invalid connect_info");
291 }
292
293 IN_PROC_BROWSER_TEST_F(CastChannelAPITest, TestSendInvalidMessageInfo) {
294 scoped_refptr<extensions::CastChannelSendFunction> cast_channel_send_function(
295 new extensions::CastChannelSendFunction);
296 scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension());
297 cast_channel_send_function->set_extension(empty_extension.get());
298
299 // Invalid message data - numbers are not supported
300 std::string error(utils::RunFunctionAndReturnError(
301 cast_channel_send_function.get(),
302 "[{\"channelId\": 1, \"url\": \"cast://127.0.0.1:8009\", "
303 "\"connectInfo\": "
304 "{\"ipAddress\": \"127.0.0.1\", \"port\": 8009, "
305 "\"auth\": \"ssl\"}, \"readyState\": \"open\"}, "
306 "{\"namespace_\": \"foo\", \"sourceId\": \"src\", "
307 "\"destinationId\": \"bar\", \"data\": 1235}]",
308 browser()));
309
310 EXPECT_EQ(error, "Invalid type of message_info.data");
311 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698