summaryrefslogtreecommitdiff
path: root/chromium/net/nqe/effective_connection_type_unittest.cc
blob: 1aa0f0450e34d1ca867647d0941a620153f9dfb7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "net/nqe/effective_connection_type.h"

#include <string>

#include "base/optional.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace net {

namespace {

// Tests that the effective connection type is converted correctly to a
// descriptive string name, and vice-versa.
TEST(EffectiveConnectionTypeTest, NameConnectionTypeConversion) {
  // Verify GetEffectiveConnectionTypeForName() returns an unset value when an
  // invalid effective connection type name is provided.
  EXPECT_FALSE(
      GetEffectiveConnectionTypeForName("InvalidEffectiveConnectionTypeName"));
  EXPECT_FALSE(GetEffectiveConnectionTypeForName(std::string()));

  for (size_t i = 0; i < EFFECTIVE_CONNECTION_TYPE_LAST; ++i) {
    const EffectiveConnectionType effective_connection_type =
        static_cast<EffectiveConnectionType>(i);
    std::string connection_type_name = std::string(
        GetNameForEffectiveConnectionType(effective_connection_type));
    EXPECT_FALSE(connection_type_name.empty());

    if (effective_connection_type != EFFECTIVE_CONNECTION_TYPE_SLOW_2G) {
      // For all effective connection types except Slow2G,
      // DeprecatedGetNameForEffectiveConnectionType should return the same
      // name as GetNameForEffectiveConnectionType.
      EXPECT_EQ(connection_type_name,
                DeprecatedGetNameForEffectiveConnectionType(
                    effective_connection_type));
    }

    EXPECT_EQ(effective_connection_type,
              GetEffectiveConnectionTypeForName(connection_type_name));
  }
}
// Tests that the Slow 2G effective connection type is converted correctly to a
// descriptive string name, and vice-versa.
TEST(EffectiveConnectionTypeTest, Slow2GTypeConversion) {
  // GetEffectiveConnectionTypeForName should return Slow2G as effective
  // connection type for both the deprecated and the current string
  // representation.
  base::Optional<EffectiveConnectionType> type =
      GetEffectiveConnectionTypeForName("Slow2G");
  EXPECT_EQ(EFFECTIVE_CONNECTION_TYPE_SLOW_2G, type.value());

  type = GetEffectiveConnectionTypeForName("Slow-2G");
  EXPECT_EQ(EFFECTIVE_CONNECTION_TYPE_SLOW_2G, type.value());

  EXPECT_EQ("Slow-2G", std::string(GetNameForEffectiveConnectionType(
                           EFFECTIVE_CONNECTION_TYPE_SLOW_2G)));
  EXPECT_EQ("Slow2G", std::string(DeprecatedGetNameForEffectiveConnectionType(
                          EFFECTIVE_CONNECTION_TYPE_SLOW_2G)));
}

}  // namespace

}  // namespace net