Home | History | Annotate | Download | only in communicator
      1 // Copyright (c) 2012 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 "jingle/notifier/communicator/connection_settings.h"
      6 
      7 #include "jingle/notifier/base/server_information.h"
      8 #include "testing/gtest/include/gtest/gtest.h"
      9 
     10 namespace notifier {
     11 
     12 namespace {
     13 
     14 class ConnectionSettingsTest : public ::testing::Test {
     15  protected:
     16   ConnectionSettingsTest() {
     17     servers_.push_back(
     18         ServerInformation(
     19             net::HostPortPair("supports_ssltcp.com", 100),
     20             SUPPORTS_SSLTCP));
     21     servers_.push_back(
     22         ServerInformation(
     23             net::HostPortPair("does_not_support_ssltcp.com", 200),
     24             DOES_NOT_SUPPORT_SSLTCP));
     25   }
     26 
     27   ServerList servers_;
     28 };
     29 
     30 // An empty server list should always map to an empty connection
     31 // settings list.
     32 TEST_F(ConnectionSettingsTest, Empty) {
     33   EXPECT_TRUE(MakeConnectionSettingsList(ServerList(), false).empty());
     34   EXPECT_TRUE(MakeConnectionSettingsList(ServerList(), true).empty());
     35 }
     36 
     37 // Make sure that servers that support SSLTCP get mapped to two
     38 // settings entries (with the SSLTCP one coming last) whereas those
     39 // that don't map to only one.
     40 TEST_F(ConnectionSettingsTest, Basic) {
     41   const ConnectionSettingsList settings_list =
     42       MakeConnectionSettingsList(servers_, false /* try_ssltcp_first */);
     43 
     44   ConnectionSettingsList expected_settings_list;
     45   expected_settings_list.push_back(
     46       ConnectionSettings(
     47           rtc::SocketAddress("supports_ssltcp.com", 100),
     48           DO_NOT_USE_SSLTCP,
     49           SUPPORTS_SSLTCP));
     50   expected_settings_list.push_back(
     51       ConnectionSettings(
     52           rtc::SocketAddress("supports_ssltcp.com", 443),
     53           USE_SSLTCP,
     54           SUPPORTS_SSLTCP));
     55   expected_settings_list.push_back(
     56       ConnectionSettings(
     57           rtc::SocketAddress("does_not_support_ssltcp.com", 200),
     58           DO_NOT_USE_SSLTCP,
     59           DOES_NOT_SUPPORT_SSLTCP));
     60 
     61   ASSERT_EQ(expected_settings_list.size(), settings_list.size());
     62   for (size_t i = 0; i < settings_list.size(); ++i) {
     63     EXPECT_TRUE(settings_list[i].Equals(expected_settings_list[i]));
     64   }
     65 }
     66 
     67 // Make sure that servers that support SSLTCP get mapped to two
     68 // settings entries (with the SSLTCP one coming first) when
     69 // try_ssltcp_first is set.
     70 TEST_F(ConnectionSettingsTest, TrySslTcpFirst) {
     71   const ConnectionSettingsList settings_list =
     72       MakeConnectionSettingsList(servers_, true /* try_ssltcp_first */);
     73 
     74   ConnectionSettingsList expected_settings_list;
     75   expected_settings_list.push_back(
     76       ConnectionSettings(
     77           rtc::SocketAddress("supports_ssltcp.com", 443),
     78           USE_SSLTCP,
     79           SUPPORTS_SSLTCP));
     80   expected_settings_list.push_back(
     81       ConnectionSettings(
     82           rtc::SocketAddress("supports_ssltcp.com", 100),
     83           DO_NOT_USE_SSLTCP,
     84           SUPPORTS_SSLTCP));
     85   expected_settings_list.push_back(
     86       ConnectionSettings(
     87           rtc::SocketAddress("does_not_support_ssltcp.com", 200),
     88           DO_NOT_USE_SSLTCP,
     89           DOES_NOT_SUPPORT_SSLTCP));
     90 
     91   ASSERT_EQ(expected_settings_list.size(), settings_list.size());
     92   for (size_t i = 0; i < settings_list.size(); ++i) {
     93     EXPECT_TRUE(settings_list[i].Equals(expected_settings_list[i]));
     94   }
     95 }
     96 
     97 }  // namespace
     98 
     99 }  // namespace notifier
    100