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

Side by Side Diff: chrome/browser/chromeos/cros/network_library_unittest.cc

Issue 10827283: This updates the StaticIP configuration UI to match new mocks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix unit test Created 8 years, 4 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 (c) 2012 The Chromium Authors. All rights reserved. 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 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 <cert.h> 5 #include <cert.h>
6 #include <pk11pub.h> 6 #include <pk11pub.h>
7 7
8 #include <vector> 8 #include <vector>
9 #include <string> 9 #include <string>
10 10
(...skipping 13 matching lines...) Expand all
24 #include "net/base/x509_certificate.h" 24 #include "net/base/x509_certificate.h"
25 #include "testing/gmock/include/gmock/gmock.h" 25 #include "testing/gmock/include/gmock/gmock.h"
26 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
27 27
28 using ::testing::Return; 28 using ::testing::Return;
29 29
30 namespace chromeos { 30 namespace chromeos {
31 31
32 namespace { 32 namespace {
33 33
34 int32 GetPrefixLength(std::string netmask) {
35 return NetworkIPConfig(std::string(), IPCONFIG_TYPE_UNKNOWN, std::string(),
36 netmask, std::string(), std::string()).GetPrefixLength();
37 }
38
39 // Have to do a stub here because MOCK can't handle closure arguments. 34 // Have to do a stub here because MOCK can't handle closure arguments.
40 class StubEnrollmentDelegate : public EnrollmentDelegate { 35 class StubEnrollmentDelegate : public EnrollmentDelegate {
41 public: 36 public:
42 explicit StubEnrollmentDelegate(OncNetworkParser* parser) 37 explicit StubEnrollmentDelegate(OncNetworkParser* parser)
43 : did_enroll(false), correct_args(false), parser_(parser) {} 38 : did_enroll(false), correct_args(false), parser_(parser) {}
44 39
45 void Enroll(const std::vector<std::string>& uri_list, 40 void Enroll(const std::vector<std::string>& uri_list,
46 const base::Closure& closure) { 41 const base::Closure& closure) {
47 std::vector<std::string> expected_uri_list; 42 std::vector<std::string> expected_uri_list;
48 expected_uri_list.push_back("http://youtu.be/dQw4w9WgXcQ"); 43 expected_uri_list.push_back("http://youtu.be/dQw4w9WgXcQ");
(...skipping 20 matching lines...) Expand all
69 void WifiNetworkConnectCallback(NetworkLibrary* cros, WifiNetwork* wifi) { 64 void WifiNetworkConnectCallback(NetworkLibrary* cros, WifiNetwork* wifi) {
70 cros->ConnectToWifiNetwork(wifi); 65 cros->ConnectToWifiNetwork(wifi);
71 } 66 }
72 67
73 void VirtualNetworkConnectCallback(NetworkLibrary* cros, VirtualNetwork* vpn) { 68 void VirtualNetworkConnectCallback(NetworkLibrary* cros, VirtualNetwork* vpn) {
74 cros->ConnectToVirtualNetwork(vpn); 69 cros->ConnectToVirtualNetwork(vpn);
75 } 70 }
76 71
77 } // namespace 72 } // namespace
78 73
79 TEST(NetworkLibraryTest, NetmaskToPrefixlen) {
80 // Valid netmasks
81 EXPECT_EQ(32, GetPrefixLength("255.255.255.255"));
82 EXPECT_EQ(31, GetPrefixLength("255.255.255.254"));
83 EXPECT_EQ(30, GetPrefixLength("255.255.255.252"));
84 EXPECT_EQ(29, GetPrefixLength("255.255.255.248"));
85 EXPECT_EQ(28, GetPrefixLength("255.255.255.240"));
86 EXPECT_EQ(27, GetPrefixLength("255.255.255.224"));
87 EXPECT_EQ(26, GetPrefixLength("255.255.255.192"));
88 EXPECT_EQ(25, GetPrefixLength("255.255.255.128"));
89 EXPECT_EQ(24, GetPrefixLength("255.255.255.0"));
90 EXPECT_EQ(23, GetPrefixLength("255.255.254.0"));
91 EXPECT_EQ(22, GetPrefixLength("255.255.252.0"));
92 EXPECT_EQ(21, GetPrefixLength("255.255.248.0"));
93 EXPECT_EQ(20, GetPrefixLength("255.255.240.0"));
94 EXPECT_EQ(19, GetPrefixLength("255.255.224.0"));
95 EXPECT_EQ(18, GetPrefixLength("255.255.192.0"));
96 EXPECT_EQ(17, GetPrefixLength("255.255.128.0"));
97 EXPECT_EQ(16, GetPrefixLength("255.255.0.0"));
98 EXPECT_EQ(15, GetPrefixLength("255.254.0.0"));
99 EXPECT_EQ(14, GetPrefixLength("255.252.0.0"));
100 EXPECT_EQ(13, GetPrefixLength("255.248.0.0"));
101 EXPECT_EQ(12, GetPrefixLength("255.240.0.0"));
102 EXPECT_EQ(11, GetPrefixLength("255.224.0.0"));
103 EXPECT_EQ(10, GetPrefixLength("255.192.0.0"));
104 EXPECT_EQ(9, GetPrefixLength("255.128.0.0"));
105 EXPECT_EQ(8, GetPrefixLength("255.0.0.0"));
106 EXPECT_EQ(7, GetPrefixLength("254.0.0.0"));
107 EXPECT_EQ(6, GetPrefixLength("252.0.0.0"));
108 EXPECT_EQ(5, GetPrefixLength("248.0.0.0"));
109 EXPECT_EQ(4, GetPrefixLength("240.0.0.0"));
110 EXPECT_EQ(3, GetPrefixLength("224.0.0.0"));
111 EXPECT_EQ(2, GetPrefixLength("192.0.0.0"));
112 EXPECT_EQ(1, GetPrefixLength("128.0.0.0"));
113 EXPECT_EQ(0, GetPrefixLength("0.0.0.0"));
114 // Invalid netmasks
115 EXPECT_EQ(-1, GetPrefixLength("255.255.255"));
116 EXPECT_EQ(-1, GetPrefixLength("255.255.255.255.255"));
117 EXPECT_EQ(-1, GetPrefixLength("255.255.255.255.0"));
118 EXPECT_EQ(-1, GetPrefixLength("255.255.255.256"));
119 EXPECT_EQ(-1, GetPrefixLength("255.255.255.1"));
120 EXPECT_EQ(-1, GetPrefixLength("255.255.240.255"));
121 EXPECT_EQ(-1, GetPrefixLength("255.0.0.255"));
122 EXPECT_EQ(-1, GetPrefixLength("255.255.255.FF"));
123 EXPECT_EQ(-1, GetPrefixLength("255,255,255,255"));
124 EXPECT_EQ(-1, GetPrefixLength("255 255 255 255"));
125 }
126
127 TEST(NetworkLibraryTest, DecodeNonAsciiSSID) { 74 TEST(NetworkLibraryTest, DecodeNonAsciiSSID) {
128 75
129 // Sets network name. 76 // Sets network name.
130 { 77 {
131 std::string wifi_setname = "SSID TEST"; 78 std::string wifi_setname = "SSID TEST";
132 std::string wifi_setname_result = "SSID TEST"; 79 std::string wifi_setname_result = "SSID TEST";
133 WifiNetwork* wifi = new WifiNetwork("fw"); 80 WifiNetwork* wifi = new WifiNetwork("fw");
134 wifi->SetName(wifi_setname); 81 wifi->SetName(wifi_setname);
135 EXPECT_EQ(wifi->name(), wifi_setname_result); 82 EXPECT_EQ(wifi->name(), wifi_setname_result);
136 delete wifi; 83 delete wifi;
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 371
425 // TODO(stevenjb): Test network profiles. 372 // TODO(stevenjb): Test network profiles.
426 373
427 // TODO(stevenjb): Test network devices. 374 // TODO(stevenjb): Test network devices.
428 375
429 // TODO(stevenjb): Test data plans. 376 // TODO(stevenjb): Test data plans.
430 377
431 // TODO(stevenjb): Test monitor network / device. 378 // TODO(stevenjb): Test monitor network / device.
432 379
433 } // namespace chromeos 380 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698