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

Side by Side Diff: chrome/browser/extensions/api/cast_channel/cast_channel_api_unittest.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 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 "chrome/browser/extensions/api/cast_channel/cast_channel_api.h" 5 #include "chrome/browser/extensions/api/cast_channel/cast_channel_api.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "net/base/ip_endpoint.h" 8 #include "net/base/ip_endpoint.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "url/gurl.h" 10 #include "url/gurl.h"
11 11
12 namespace extensions { 12 namespace extensions {
imcheng 2014/07/15 21:26:41 nit: Can this file be reverted?
mark a. foltz 2014/07/16 21:43:26 Done.
13 namespace api {
14 namespace cast_channel {
15 13
16 // Tests URL parsing and validation. 14 // Tests URL parsing and validation.
17 TEST(CastChannelOpenFunctionTest, TestParseChannelUrl) { 15 TEST(CastChannelOpenFunctionTest, TestParseChannelUrl) {
18 typedef CastChannelOpenFunction ccof; 16 typedef CastChannelOpenFunction ccof;
19 ConnectInfo connect_info; 17 cast_channel::ConnectInfo connect_info;
20 18
21 EXPECT_TRUE(ccof::ParseChannelUrl(GURL("cast://192.0.0.1:8009"), 19 EXPECT_TRUE(ccof::ParseChannelUrl(GURL("cast://192.0.0.1:8009"),
22 &connect_info)); 20 &connect_info));
23 EXPECT_EQ(connect_info.ip_address, "192.0.0.1"); 21 EXPECT_EQ(connect_info.ip_address, "192.0.0.1");
24 EXPECT_EQ(connect_info.port, 8009); 22 EXPECT_EQ(connect_info.port, 8009);
25 EXPECT_EQ(connect_info.auth, CHANNEL_AUTH_TYPE_SSL); 23 EXPECT_EQ(connect_info.auth, cast_channel::CHANNEL_AUTH_TYPE_SSL);
26 24
27 EXPECT_TRUE(ccof::ParseChannelUrl(GURL("casts://192.0.0.1:12345"), 25 EXPECT_TRUE(ccof::ParseChannelUrl(GURL("casts://192.0.0.1:12345"),
28 &connect_info)); 26 &connect_info));
29 EXPECT_EQ(connect_info.ip_address, "192.0.0.1"); 27 EXPECT_EQ(connect_info.ip_address, "192.0.0.1");
30 EXPECT_EQ(connect_info.port, 12345); 28 EXPECT_EQ(connect_info.port, 12345);
31 EXPECT_EQ(connect_info.auth, CHANNEL_AUTH_TYPE_SSL_VERIFIED); 29 EXPECT_EQ(connect_info.auth, cast_channel::CHANNEL_AUTH_TYPE_SSL_VERIFIED);
32 30
33 EXPECT_FALSE(ccof::ParseChannelUrl(GURL("http://192.0.0.1:12345"), 31 EXPECT_FALSE(ccof::ParseChannelUrl(GURL("http://192.0.0.1:12345"),
34 &connect_info)); 32 &connect_info));
35 EXPECT_FALSE(ccof::ParseChannelUrl(GURL("cast:192.0.0.1:12345"), 33 EXPECT_FALSE(ccof::ParseChannelUrl(GURL("cast:192.0.0.1:12345"),
36 &connect_info)); 34 &connect_info));
37 EXPECT_FALSE(ccof::ParseChannelUrl(GURL("cast://:12345"), &connect_info)); 35 EXPECT_FALSE(ccof::ParseChannelUrl(GURL("cast://:12345"), &connect_info));
38 EXPECT_FALSE(ccof::ParseChannelUrl(GURL("cast://192.0.0.1:abcd"), 36 EXPECT_FALSE(ccof::ParseChannelUrl(GURL("cast://192.0.0.1:abcd"),
39 &connect_info)); 37 &connect_info));
40 EXPECT_FALSE(ccof::ParseChannelUrl(GURL(""), &connect_info)); 38 EXPECT_FALSE(ccof::ParseChannelUrl(GURL(""), &connect_info));
41 EXPECT_FALSE(ccof::ParseChannelUrl(GURL("foo"), &connect_info)); 39 EXPECT_FALSE(ccof::ParseChannelUrl(GURL("foo"), &connect_info));
42 EXPECT_FALSE(ccof::ParseChannelUrl(GURL("cast:"), &connect_info)); 40 EXPECT_FALSE(ccof::ParseChannelUrl(GURL("cast:"), &connect_info));
43 EXPECT_FALSE(ccof::ParseChannelUrl(GURL("cast::"), &connect_info)); 41 EXPECT_FALSE(ccof::ParseChannelUrl(GURL("cast::"), &connect_info));
44 EXPECT_FALSE(ccof::ParseChannelUrl(GURL("cast://192.0.0.1"), &connect_info)); 42 EXPECT_FALSE(ccof::ParseChannelUrl(GURL("cast://192.0.0.1"), &connect_info));
45 EXPECT_FALSE(ccof::ParseChannelUrl(GURL("cast://:"), &connect_info)); 43 EXPECT_FALSE(ccof::ParseChannelUrl(GURL("cast://:"), &connect_info));
46 EXPECT_FALSE(ccof::ParseChannelUrl(GURL("cast://192.0.0.1:"), &connect_info)); 44 EXPECT_FALSE(ccof::ParseChannelUrl(GURL("cast://192.0.0.1:"), &connect_info));
47 } 45 }
48 46
49 // Tests validation of ConnectInfo. 47 // Tests validation of ConnectInfo.
50 TEST(CastChannelOpenFunctionTest, TestParseConnectInfo) { 48 TEST(CastChannelOpenFunctionTest, TestParseConnectInfo) {
51 typedef CastChannelOpenFunction ccof; 49 typedef CastChannelOpenFunction ccof;
52 scoped_ptr<net::IPEndPoint> ip_endpoint; 50 scoped_ptr<net::IPEndPoint> ip_endpoint;
53 51
54 // Valid ConnectInfo 52 // Valid ConnectInfo
55 ConnectInfo connect_info; 53 cast_channel::ConnectInfo connect_info;
56 connect_info.ip_address = "192.0.0.1"; 54 connect_info.ip_address = "192.0.0.1";
57 connect_info.port = 8009; 55 connect_info.port = 8009;
58 connect_info.auth = CHANNEL_AUTH_TYPE_SSL; 56 connect_info.auth = cast_channel::CHANNEL_AUTH_TYPE_SSL;
59 57
60 ip_endpoint.reset(ccof::ParseConnectInfo(connect_info)); 58 ip_endpoint.reset(ccof::ParseConnectInfo(connect_info));
61 EXPECT_TRUE(ip_endpoint.get() != NULL); 59 EXPECT_TRUE(ip_endpoint.get() != NULL);
62 EXPECT_EQ(ip_endpoint->ToString(), "192.0.0.1:8009"); 60 EXPECT_EQ(ip_endpoint->ToString(), "192.0.0.1:8009");
63 61
64 // Invalid IP 62 // Invalid IP
65 ConnectInfo invalid_ip_connect_info; 63 cast_channel::ConnectInfo invalid_ip_connect_info;
66 invalid_ip_connect_info.ip_address = "blargh"; 64 invalid_ip_connect_info.ip_address = "blargh";
67 invalid_ip_connect_info.port = 8009; 65 invalid_ip_connect_info.port = 8009;
68 invalid_ip_connect_info.auth = CHANNEL_AUTH_TYPE_SSL; 66 invalid_ip_connect_info.auth = cast_channel::CHANNEL_AUTH_TYPE_SSL;
69 ip_endpoint.reset(ccof::ParseConnectInfo(invalid_ip_connect_info)); 67 ip_endpoint.reset(ccof::ParseConnectInfo(invalid_ip_connect_info));
70 EXPECT_TRUE(ip_endpoint.get() == NULL); 68 EXPECT_TRUE(ip_endpoint.get() == NULL);
71 69
72 // Invalid port 70 // Invalid port
73 ConnectInfo invalid_port_connect_info; 71 cast_channel::ConnectInfo invalid_port_connect_info;
74 invalid_port_connect_info.ip_address = "192.0.0.1"; 72 invalid_port_connect_info.ip_address = "192.0.0.1";
75 invalid_port_connect_info.port = -1; 73 invalid_port_connect_info.port = -1;
76 invalid_port_connect_info.auth = CHANNEL_AUTH_TYPE_SSL; 74 invalid_port_connect_info.auth = cast_channel::CHANNEL_AUTH_TYPE_SSL;
77 ip_endpoint.reset(ccof::ParseConnectInfo(invalid_port_connect_info)); 75 ip_endpoint.reset(ccof::ParseConnectInfo(invalid_port_connect_info));
78 EXPECT_TRUE(ip_endpoint.get() == NULL); 76 EXPECT_TRUE(ip_endpoint.get() == NULL);
79 77
80 // Invalid auth 78 // Invalid auth
81 ConnectInfo invalid_auth_connect_info; 79 cast_channel::ConnectInfo invalid_auth_connect_info;
82 invalid_auth_connect_info.ip_address = "192.0.0.1"; 80 invalid_auth_connect_info.ip_address = "192.0.0.1";
83 invalid_auth_connect_info.port = 8009; 81 invalid_auth_connect_info.port = 8009;
84 invalid_auth_connect_info.auth = CHANNEL_AUTH_TYPE_NONE; 82 invalid_auth_connect_info.auth = cast_channel::CHANNEL_AUTH_TYPE_NONE;
85 ip_endpoint.reset(ccof::ParseConnectInfo(invalid_auth_connect_info)); 83 ip_endpoint.reset(ccof::ParseConnectInfo(invalid_auth_connect_info));
86 EXPECT_TRUE(ip_endpoint.get() == NULL); 84 EXPECT_TRUE(ip_endpoint.get() == NULL);
87 } 85 }
88 86
89 } // namespace cast_channel
90 } // namespace api
91 } // namespace extensions 87 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698