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

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: Tweaked 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
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,
Thiemo Nagel 2015/04/16 15:16:33 I'm unsure what the expected behaviour for cellula
Andrew T Wilson (Slow) 2015/04/17 14:41:02 I've changed this to just not report for cellular
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 { "ready", "/device/cellular1", shill::kTypeCellular, 0, 0,
1015 em::NetworkState::READY, "", "" }, 1016 shill::kStateReady, em::NetworkState::READY, "", "" },
1016 { "disconnect", "/device/wifi", shill::kTypeWifi, 1, 1017 { "disconnect", "/device/wifi", shill::kTypeWifi, 1, -119,
1017 shill::kStateDisconnect, em::NetworkState::DISCONNECT, "", "" }, 1018 shill::kStateDisconnect, em::NetworkState::DISCONNECT, "", "" },
1018 { "failure", "/device/wifi", shill::kTypeWifi, 1, shill::kStateFailure, 1019 { "failure", "/device/wifi", shill::kTypeWifi, 1, -119, shill::kStateFailure,
1019 em::NetworkState::FAILURE, "", "" }, 1020 em::NetworkState::FAILURE, "", "" },
1020 { "activation-failure", "/device/cellular1", shill::kTypeCellular, 0, 1021 { "activation-failure", "/device/cellular1", shill::kTypeCellular, 0, 0,
1021 shill::kStateActivationFailure, em::NetworkState::ACTIVATION_FAILURE, 1022 shill::kStateActivationFailure, em::NetworkState::ACTIVATION_FAILURE,
1022 "", "" }, 1023 "", "" },
1023 { "unknown", "", shill::kTypeWifi, 1, "unknown", em::NetworkState::UNKNOWN, 1024 { "unknown", "", shill::kTypeWifi, 1, -119, "unknown",
1024 "", "" }, 1025 em::NetworkState::UNKNOWN, "", "" },
1025 }; 1026 };
1026 1027
1027 static const FakeNetworkState kUnconfiguredNetwork = { 1028 static const FakeNetworkState kUnconfiguredNetwork = {
1028 "unconfigured", "/device/unconfigured", shill::kTypeWifi, 35, 1029 "unconfigured", "/device/unconfigured", shill::kTypeWifi, 35, -85,
1029 shill::kStateOffline, em::NetworkState::OFFLINE, "", "" 1030 shill::kStateOffline, em::NetworkState::OFFLINE, "", ""
1030 }; 1031 };
1031 1032
1032 class DeviceStatusCollectorNetworkInterfacesTest 1033 class DeviceStatusCollectorNetworkInterfacesTest
1033 : public DeviceStatusCollectorTest { 1034 : public DeviceStatusCollectorTest {
1034 protected: 1035 protected:
1035 void SetUp() override { 1036 void SetUp() override {
1036 chromeos::DBusThreadManager::Initialize(); 1037 chromeos::DBusThreadManager::Initialize();
1037 chromeos::NetworkHandler::Initialize(); 1038 chromeos::NetworkHandler::Initialize();
1038 chromeos::ShillDeviceClient::TestInterface* test_device_client = 1039 chromeos::ShillDeviceClient::TestInterface* test_device_client =
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
1203 1204
1204 EXPECT_EQ(count, status_.network_interface_size()); 1205 EXPECT_EQ(count, status_.network_interface_size());
1205 1206
1206 // Now make sure network state list is correct. 1207 // Now make sure network state list is correct.
1207 EXPECT_EQ(arraysize(kFakeNetworks), 1208 EXPECT_EQ(arraysize(kFakeNetworks),
1208 static_cast<size_t>(status_.network_state_size())); 1209 static_cast<size_t>(status_.network_state_size()));
1209 for (const FakeNetworkState& state : kFakeNetworks) { 1210 for (const FakeNetworkState& state : kFakeNetworks) {
1210 bool found_match = false; 1211 bool found_match = false;
1211 for (const em::NetworkState& proto_state : status_.network_state()) { 1212 for (const em::NetworkState& proto_state : status_.network_state()) {
1212 // Make sure every item has a matching entry in the proto. 1213 // Make sure every item has a matching entry in the proto.
1214 bool should_have_signal_strength = state.expected_signal_strength != 0;
1213 if (proto_state.has_device_path() == (strlen(state.device_path) > 0) && 1215 if (proto_state.has_device_path() == (strlen(state.device_path) > 0) &&
1214 proto_state.signal_strength() == state.signal_strength && 1216 proto_state.has_signal_strength() == should_have_signal_strength &&
1217 proto_state.signal_strength() == state.expected_signal_strength &&
1215 proto_state.connection_state() == state.expected_state) { 1218 proto_state.connection_state() == state.expected_state) {
1216 if (proto_state.has_ip_address()) 1219 if (proto_state.has_ip_address())
1217 EXPECT_EQ(proto_state.ip_address(), state.address); 1220 EXPECT_EQ(proto_state.ip_address(), state.address);
1218 else 1221 else
1219 EXPECT_EQ(0U, strlen(state.address)); 1222 EXPECT_EQ(0U, strlen(state.address));
1220 if (proto_state.has_gateway()) 1223 if (proto_state.has_gateway())
1221 EXPECT_EQ(proto_state.gateway(), state.gateway); 1224 EXPECT_EQ(proto_state.gateway(), state.gateway);
1222 else 1225 else
1223 EXPECT_EQ(0U, strlen(state.gateway)); 1226 EXPECT_EQ(0U, strlen(state.gateway));
1224 found_match = true; 1227 found_match = true;
1225 break; 1228 break;
1226 } 1229 }
1227 } 1230 }
1228 EXPECT_TRUE(found_match) << "No matching state for fake network " 1231 EXPECT_TRUE(found_match) << "No matching state for fake network "
1229 << " (" << state.name << ")"; 1232 << " (" << state.name << ")";
1230 } 1233 }
1231 } 1234 }
1232 1235
1233 } // namespace policy 1236 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698