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

Side by Side Diff: chrome/browser/chromeos/policy/device_status_collector_browsertest.cc

Issue 1062853005: Map signal_strength from percentage to dBm per spec (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Really fixed comment Created 5 years, 8 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
« no previous file with comments | « chrome/browser/chromeos/policy/device_status_collector.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "chrome/browser/chromeos/policy/device_status_collector.h" 5 #include "chrome/browser/chromeos/policy/device_status_collector.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 967 matching lines...) Expand 10 before | Expand all | Expand 10 after
978 "", "", "", 978 "", "", "",
979 -1 }, 979 -1 },
980 }; 980 };
981 981
982 // Fake network state. 982 // Fake network state.
983 struct FakeNetworkState { 983 struct FakeNetworkState {
984 const char* name; 984 const char* name;
985 const char* device_path; 985 const char* device_path;
986 const char* type; 986 const char* type;
987 int signal_strength; 987 int signal_strength;
988 int expected_signal_strength;
988 const char* connection_status; 989 const char* connection_status;
989 int expected_state; 990 int expected_state;
990 const char* address; 991 const char* address;
991 const char* gateway; 992 const char* gateway;
992 }; 993 };
993 994
994 // List of fake networks - primarily used to make sure that signal strength 995 // List of fake networks - primarily used to make sure that signal strength
995 // and connection state are properly populated in status reports. Note that 996 // and connection state are properly populated in status reports. Note that
996 // by convention shill will not report a signal strength of 0 for a visible 997 // by convention shill will not report a signal strength of 0 for a visible
997 // network, so we use 1 below. 998 // network, so we use 1 below.
998 static const FakeNetworkState kFakeNetworks[] = { 999 static const FakeNetworkState kFakeNetworks[] = {
999 { "offline", "/device/wifi", shill::kTypeWifi, 35, 1000 { "offline", "/device/wifi", shill::kTypeWifi, 35, -85,
1000 shill::kStateOffline, em::NetworkState::OFFLINE, "", "" }, 1001 shill::kStateOffline, em::NetworkState::OFFLINE, "", "" },
1001 { "ethernet", "/device/ethernet", shill::kTypeEthernet, 0, 1002 { "ethernet", "/device/ethernet", shill::kTypeEthernet, 0, 0,
1002 shill::kStateOnline, em::NetworkState::ONLINE, 1003 shill::kStateOnline, em::NetworkState::ONLINE,
1003 "192.168.0.1", "8.8.8.8" }, 1004 "192.168.0.1", "8.8.8.8" },
1004 { "wifi", "/device/wifi", shill::kTypeWifi, 23, shill::kStatePortal, 1005 { "wifi", "/device/wifi", shill::kTypeWifi, 23, -97, shill::kStatePortal,
1005 em::NetworkState::PORTAL, "", "" }, 1006 em::NetworkState::PORTAL, "", "" },
1006 { "idle", "/device/cellular1", shill::kTypeCellular, 0, shill::kStateIdle, 1007 { "idle", "/device/cellular1", shill::kTypeCellular, 0, 0, shill::kStateIdle,
1007 em::NetworkState::IDLE, "", "" }, 1008 em::NetworkState::IDLE, "", "" },
1008 { "carrier", "/device/cellular1", shill::kTypeCellular, 0, 1009 { "carrier", "/device/cellular1", shill::kTypeCellular, 0, 0,
1009 shill::kStateCarrier, em::NetworkState::CARRIER, "", "" }, 1010 shill::kStateCarrier, em::NetworkState::CARRIER, "", "" },
1010 { "association", "/device/cellular1", shill::kTypeCellular, 0, 1011 { "association", "/device/cellular1", shill::kTypeCellular, 0, 0,
1011 shill::kStateAssociation, em::NetworkState::ASSOCIATION, "", "" }, 1012 shill::kStateAssociation, em::NetworkState::ASSOCIATION, "", "" },
1012 { "config", "/device/cellular1", shill::kTypeCellular, 0, 1013 { "config", "/device/cellular1", shill::kTypeCellular, 0, 0,
1013 shill::kStateConfiguration, em::NetworkState::CONFIGURATION, "", "" }, 1014 shill::kStateConfiguration, em::NetworkState::CONFIGURATION, "", "" },
1014 { "ready", "/device/cellular1", shill::kTypeCellular, 0, shill::kStateReady, 1015 // Set signal strength for this network to -20, but expected strength to 0
1015 em::NetworkState::READY, "", "" }, 1016 // to test that we only report signal_strength for wifi connections.
1016 { "disconnect", "/device/wifi", shill::kTypeWifi, 1, 1017 { "ready", "/device/cellular1", shill::kTypeCellular, -20, 0,
1018 shill::kStateReady, em::NetworkState::READY, "", "" },
1019 { "disconnect", "/device/wifi", shill::kTypeWifi, 1, -119,
1017 shill::kStateDisconnect, em::NetworkState::DISCONNECT, "", "" }, 1020 shill::kStateDisconnect, em::NetworkState::DISCONNECT, "", "" },
1018 { "failure", "/device/wifi", shill::kTypeWifi, 1, shill::kStateFailure, 1021 { "failure", "/device/wifi", shill::kTypeWifi, 1, -119, shill::kStateFailure,
1019 em::NetworkState::FAILURE, "", "" }, 1022 em::NetworkState::FAILURE, "", "" },
1020 { "activation-failure", "/device/cellular1", shill::kTypeCellular, 0, 1023 { "activation-failure", "/device/cellular1", shill::kTypeCellular, 0, 0,
1021 shill::kStateActivationFailure, em::NetworkState::ACTIVATION_FAILURE, 1024 shill::kStateActivationFailure, em::NetworkState::ACTIVATION_FAILURE,
1022 "", "" }, 1025 "", "" },
1023 { "unknown", "", shill::kTypeWifi, 1, "unknown", em::NetworkState::UNKNOWN, 1026 { "unknown", "", shill::kTypeWifi, 1, -119, "unknown",
1024 "", "" }, 1027 em::NetworkState::UNKNOWN, "", "" },
1025 }; 1028 };
1026 1029
1027 static const FakeNetworkState kUnconfiguredNetwork = { 1030 static const FakeNetworkState kUnconfiguredNetwork = {
1028 "unconfigured", "/device/unconfigured", shill::kTypeWifi, 35, 1031 "unconfigured", "/device/unconfigured", shill::kTypeWifi, 35, -85,
1029 shill::kStateOffline, em::NetworkState::OFFLINE, "", "" 1032 shill::kStateOffline, em::NetworkState::OFFLINE, "", ""
1030 }; 1033 };
1031 1034
1032 class DeviceStatusCollectorNetworkInterfacesTest 1035 class DeviceStatusCollectorNetworkInterfacesTest
1033 : public DeviceStatusCollectorTest { 1036 : public DeviceStatusCollectorTest {
1034 protected: 1037 protected:
1035 void SetUp() override { 1038 void SetUp() override {
1036 chromeos::DBusThreadManager::Initialize(); 1039 chromeos::DBusThreadManager::Initialize();
1037 chromeos::NetworkHandler::Initialize(); 1040 chromeos::NetworkHandler::Initialize();
1038 chromeos::ShillDeviceClient::TestInterface* test_device_client = 1041 chromeos::ShillDeviceClient::TestInterface* test_device_client =
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1122 base::StringValue(kUnconfiguredNetwork.device_path)); 1125 base::StringValue(kUnconfiguredNetwork.device_path));
1123 1126
1124 // Flush out pending state updates. 1127 // Flush out pending state updates.
1125 base::RunLoop().RunUntilIdle(); 1128 base::RunLoop().RunUntilIdle();
1126 1129
1127 chromeos::NetworkStateHandler::NetworkStateList state_list; 1130 chromeos::NetworkStateHandler::NetworkStateList state_list;
1128 chromeos::NetworkStateHandler* network_state_handler = 1131 chromeos::NetworkStateHandler* network_state_handler =
1129 chromeos::NetworkHandler::Get()->network_state_handler(); 1132 chromeos::NetworkHandler::Get()->network_state_handler();
1130 network_state_handler->GetNetworkListByType( 1133 network_state_handler->GetNetworkListByType(
1131 chromeos::NetworkTypePattern::Default(), 1134 chromeos::NetworkTypePattern::Default(),
1132 true, // configured_only 1135 true, // configured_only
1133 false, // visible_only, 1136 false, // visible_only,
1134 0, // no limit to number of results 1137 0, // no limit to number of results
1135 &state_list); 1138 &state_list);
1136 ASSERT_EQ(arraysize(kFakeNetworks), state_list.size()); 1139 ASSERT_EQ(arraysize(kFakeNetworks), state_list.size());
1137 } 1140 }
1138 1141
1139 void TearDown() override { 1142 void TearDown() override {
1140 chromeos::NetworkHandler::Shutdown(); 1143 chromeos::NetworkHandler::Shutdown();
1141 chromeos::DBusThreadManager::Shutdown(); 1144 chromeos::DBusThreadManager::Shutdown();
1142 } 1145 }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1203 1206
1204 EXPECT_EQ(count, status_.network_interface_size()); 1207 EXPECT_EQ(count, status_.network_interface_size());
1205 1208
1206 // Now make sure network state list is correct. 1209 // Now make sure network state list is correct.
1207 EXPECT_EQ(arraysize(kFakeNetworks), 1210 EXPECT_EQ(arraysize(kFakeNetworks),
1208 static_cast<size_t>(status_.network_state_size())); 1211 static_cast<size_t>(status_.network_state_size()));
1209 for (const FakeNetworkState& state : kFakeNetworks) { 1212 for (const FakeNetworkState& state : kFakeNetworks) {
1210 bool found_match = false; 1213 bool found_match = false;
1211 for (const em::NetworkState& proto_state : status_.network_state()) { 1214 for (const em::NetworkState& proto_state : status_.network_state()) {
1212 // Make sure every item has a matching entry in the proto. 1215 // Make sure every item has a matching entry in the proto.
1216 bool should_have_signal_strength = state.expected_signal_strength != 0;
1213 if (proto_state.has_device_path() == (strlen(state.device_path) > 0) && 1217 if (proto_state.has_device_path() == (strlen(state.device_path) > 0) &&
1214 proto_state.signal_strength() == state.signal_strength && 1218 proto_state.has_signal_strength() == should_have_signal_strength &&
1219 proto_state.signal_strength() == state.expected_signal_strength &&
1215 proto_state.connection_state() == state.expected_state) { 1220 proto_state.connection_state() == state.expected_state) {
1216 if (proto_state.has_ip_address()) 1221 if (proto_state.has_ip_address())
1217 EXPECT_EQ(proto_state.ip_address(), state.address); 1222 EXPECT_EQ(proto_state.ip_address(), state.address);
1218 else 1223 else
1219 EXPECT_EQ(0U, strlen(state.address)); 1224 EXPECT_EQ(0U, strlen(state.address));
1220 if (proto_state.has_gateway()) 1225 if (proto_state.has_gateway())
1221 EXPECT_EQ(proto_state.gateway(), state.gateway); 1226 EXPECT_EQ(proto_state.gateway(), state.gateway);
1222 else 1227 else
1223 EXPECT_EQ(0U, strlen(state.gateway)); 1228 EXPECT_EQ(0U, strlen(state.gateway));
1224 found_match = true; 1229 found_match = true;
1225 break; 1230 break;
1226 } 1231 }
1227 } 1232 }
1228 EXPECT_TRUE(found_match) << "No matching state for fake network " 1233 EXPECT_TRUE(found_match) << "No matching state for fake network "
1229 << " (" << state.name << ")"; 1234 << " (" << state.name << ")";
1230 } 1235 }
1231 } 1236 }
1232 1237
1233 } // namespace policy 1238 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/policy/device_status_collector.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698