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 3// found in the LICENSE file. 4 5#include "extensions/browser/api/cast_channel/cast_channel_api.h" 6 7#include "base/memory/scoped_ptr.h" 8#include "net/base/ip_endpoint.h" 9#include "testing/gtest/include/gtest/gtest.h" 10#include "url/gurl.h" 11 12namespace extensions { 13namespace core_api { 14namespace cast_channel { 15 16// Tests URL parsing and validation. 17TEST(CastChannelOpenFunctionTest, TestParseChannelUrl) { 18 typedef CastChannelOpenFunction ccof; 19 ConnectInfo connect_info; 20 21 EXPECT_TRUE(ccof::ParseChannelUrl(GURL("cast://192.0.0.1:8009"), 22 &connect_info)); 23 EXPECT_EQ(connect_info.ip_address, "192.0.0.1"); 24 EXPECT_EQ(connect_info.port, 8009); 25 EXPECT_EQ(connect_info.auth, CHANNEL_AUTH_TYPE_SSL); 26 27 EXPECT_TRUE(ccof::ParseChannelUrl(GURL("casts://192.0.0.1:12345"), 28 &connect_info)); 29 EXPECT_EQ(connect_info.ip_address, "192.0.0.1"); 30 EXPECT_EQ(connect_info.port, 12345); 31 EXPECT_EQ(connect_info.auth, CHANNEL_AUTH_TYPE_SSL_VERIFIED); 32 33 EXPECT_FALSE(ccof::ParseChannelUrl(GURL("http://192.0.0.1:12345"), 34 &connect_info)); 35 EXPECT_FALSE(ccof::ParseChannelUrl(GURL("cast:192.0.0.1:12345"), 36 &connect_info)); 37 EXPECT_FALSE(ccof::ParseChannelUrl(GURL("cast://:12345"), &connect_info)); 38 EXPECT_FALSE(ccof::ParseChannelUrl(GURL("cast://192.0.0.1:abcd"), 39 &connect_info)); 40 EXPECT_FALSE(ccof::ParseChannelUrl(GURL(""), &connect_info)); 41 EXPECT_FALSE(ccof::ParseChannelUrl(GURL("foo"), &connect_info)); 42 EXPECT_FALSE(ccof::ParseChannelUrl(GURL("cast:"), &connect_info)); 43 EXPECT_FALSE(ccof::ParseChannelUrl(GURL("cast::"), &connect_info)); 44 EXPECT_FALSE(ccof::ParseChannelUrl(GURL("cast://192.0.0.1"), &connect_info)); 45 EXPECT_FALSE(ccof::ParseChannelUrl(GURL("cast://:"), &connect_info)); 46 EXPECT_FALSE(ccof::ParseChannelUrl(GURL("cast://192.0.0.1:"), &connect_info)); 47} 48 49// Tests parsing of ConnectInfo. 50TEST(CastChannelOpenFunctionTest, TestParseConnectInfo) { 51 typedef CastChannelOpenFunction ccof; 52 scoped_ptr<net::IPEndPoint> ip_endpoint; 53 54 // Valid ConnectInfo 55 ConnectInfo connect_info; 56 connect_info.ip_address = "192.0.0.1"; 57 connect_info.port = 8009; 58 connect_info.auth = CHANNEL_AUTH_TYPE_SSL; 59 60 ip_endpoint.reset(ccof::ParseConnectInfo(connect_info)); 61 EXPECT_TRUE(ip_endpoint.get() != NULL); 62 EXPECT_EQ(ip_endpoint->ToString(), "192.0.0.1:8009"); 63} 64 65} // namespace cast_channel 66} // namespace core_api 67} // namespace extensions 68