diff options
author | pbond <pbond@chromium.org> | 2015-08-18 06:44:27 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-08-18 13:45:10 +0000 |
commit | 4b90131c7279c62db8768a58c1c1068559b6da6c (patch) | |
tree | 8ae3cddf998044625a482754314b5159df028648 | |
parent | c8a6e0abd6532d280d646b37b1bd3a496d0c1e2d (diff) | |
download | chromium_src-4b90131c7279c62db8768a58c1c1068559b6da6c.zip chromium_src-4b90131c7279c62db8768a58c1c1068559b6da6c.tar.gz chromium_src-4b90131c7279c62db8768a58c1c1068559b6da6c.tar.bz2 |
Report network information for public sessions.
BUG=499810
Review URL: https://codereview.chromium.org/1290093002
Cr-Commit-Position: refs/heads/master@{#343905}
-rw-r--r-- | chrome/browser/chromeos/policy/device_status_collector.cc | 5 | ||||
-rw-r--r-- | chrome/browser/chromeos/policy/device_status_collector_browsertest.cc | 130 |
2 files changed, 75 insertions, 60 deletions
diff --git a/chrome/browser/chromeos/policy/device_status_collector.cc b/chrome/browser/chromeos/policy/device_status_collector.cc index e48b628..f857846 100644 --- a/chrome/browser/chromeos/policy/device_status_collector.cc +++ b/chrome/browser/chromeos/policy/device_status_collector.cc @@ -803,8 +803,9 @@ void DeviceStatusCollector::GetNetworkInterfaces( interface->set_device_path((*device)->path()); } - // Don't write any network state if we aren't in a kiosk session. - if (!GetAutoLaunchedKioskSessionInfo()) + // Don't write any network state if we aren't in a kiosk or public session. + if (!GetAutoLaunchedKioskSessionInfo() && + !user_manager::UserManager::Get()->IsLoggedInAsPublicAccount()) return; // Walk the various networks and store their state in the status report. diff --git a/chrome/browser/chromeos/policy/device_status_collector_browsertest.cc b/chrome/browser/chromeos/policy/device_status_collector_browsertest.cc index ff85be7..ec8f395 100644 --- a/chrome/browser/chromeos/policy/device_status_collector_browsertest.cc +++ b/chrome/browser/chromeos/policy/device_status_collector_browsertest.cc @@ -65,6 +65,7 @@ const int64 kMillisecondsPerDay = Time::kMicrosecondsPerDay / 1000; const char kKioskAccountId[] = "kiosk_user@localhost"; const char kKioskAppId[] = "kiosk_app_id"; const char kExternalMountPoint[] = "/a/b/c"; +const char kPublicAccountId[] = "public_user@localhost"; scoped_ptr<content::Geoposition> mock_position_to_return_next; @@ -1196,6 +1197,67 @@ class DeviceStatusCollectorNetworkInterfacesTest chromeos::NetworkHandler::Shutdown(); chromeos::DBusThreadManager::Shutdown(); } + + void VerifyNetworkReporting() { + int count = 0; + for (size_t i = 0; i < arraysize(kFakeDevices); ++i) { + const FakeDeviceData& dev = kFakeDevices[i]; + if (dev.expected_type == -1) + continue; + + // Find the corresponding entry in reporting data. + bool found_match = false; + google::protobuf::RepeatedPtrField<em::NetworkInterface>::const_iterator + iface; + for (iface = status_.network_interface().begin(); + iface != status_.network_interface().end(); ++iface) { + // Check whether type, field presence and field values match. + if (dev.expected_type == iface->type() && + iface->has_mac_address() == !!*dev.mac_address && + iface->has_meid() == !!*dev.meid && + iface->has_imei() == !!*dev.imei && + iface->mac_address() == dev.mac_address && + iface->meid() == dev.meid && iface->imei() == dev.imei && + iface->device_path() == dev.device_path) { + found_match = true; + break; + } + } + + EXPECT_TRUE(found_match) << "No matching interface for fake device " << i; + count++; + } + + EXPECT_EQ(count, status_.network_interface_size()); + + // Now make sure network state list is correct. + EXPECT_EQ(arraysize(kFakeNetworks), + static_cast<size_t>(status_.network_state_size())); + for (const FakeNetworkState& state : kFakeNetworks) { + bool found_match = false; + for (const em::NetworkState& proto_state : status_.network_state()) { + // Make sure every item has a matching entry in the proto. + bool should_have_signal_strength = state.expected_signal_strength != 0; + if (proto_state.has_device_path() == (strlen(state.device_path) > 0) && + proto_state.has_signal_strength() == should_have_signal_strength && + proto_state.signal_strength() == state.expected_signal_strength && + proto_state.connection_state() == state.expected_state) { + if (proto_state.has_ip_address()) + EXPECT_EQ(proto_state.ip_address(), state.address); + else + EXPECT_EQ(0U, strlen(state.address)); + if (proto_state.has_gateway()) + EXPECT_EQ(proto_state.gateway(), state.gateway); + else + EXPECT_EQ(0U, strlen(state.gateway)); + found_match = true; + break; + } + } + EXPECT_TRUE(found_match) << "No matching state for fake network " + << " (" << state.name << ")"; + } + } }; TEST_F(DeviceStatusCollectorNetworkInterfacesTest, NoNetworkStateIfNotKiosk) { @@ -1226,66 +1288,18 @@ TEST_F(DeviceStatusCollectorNetworkInterfacesTest, NetworkInterfaces) { settings_helper_.SetBoolean(chromeos::kReportDeviceNetworkInterfaces, true); GetStatus(); - int count = 0; - for (size_t i = 0; i < arraysize(kFakeDevices); ++i) { - const FakeDeviceData& dev = kFakeDevices[i]; - if (dev.expected_type == -1) - continue; - - // Find the corresponding entry in reporting data. - bool found_match = false; - google::protobuf::RepeatedPtrField<em::NetworkInterface>::const_iterator - iface; - for (iface = status_.network_interface().begin(); - iface != status_.network_interface().end(); - ++iface) { - // Check whether type, field presence and field values match. - if (dev.expected_type == iface->type() && - iface->has_mac_address() == !!*dev.mac_address && - iface->has_meid() == !!*dev.meid && - iface->has_imei() == !!*dev.imei && - iface->mac_address() == dev.mac_address && - iface->meid() == dev.meid && - iface->imei() == dev.imei && - iface->device_path() == dev.device_path) { - found_match = true; - break; - } - } + VerifyNetworkReporting(); +} - EXPECT_TRUE(found_match) << "No matching interface for fake device " << i; - count++; - } +TEST_F(DeviceStatusCollectorNetworkInterfacesTest, ReportIfPublicSession) { + // Report netowork state for public accounts. + user_manager_->CreatePublicAccountUser(kPublicAccountId); + EXPECT_CALL(*user_manager_, IsLoggedInAsPublicAccount()) + .WillRepeatedly(Return(true)); - EXPECT_EQ(count, status_.network_interface_size()); - - // Now make sure network state list is correct. - EXPECT_EQ(arraysize(kFakeNetworks), - static_cast<size_t>(status_.network_state_size())); - for (const FakeNetworkState& state : kFakeNetworks) { - bool found_match = false; - for (const em::NetworkState& proto_state : status_.network_state()) { - // Make sure every item has a matching entry in the proto. - bool should_have_signal_strength = state.expected_signal_strength != 0; - if (proto_state.has_device_path() == (strlen(state.device_path) > 0) && - proto_state.has_signal_strength() == should_have_signal_strength && - proto_state.signal_strength() == state.expected_signal_strength && - proto_state.connection_state() == state.expected_state) { - if (proto_state.has_ip_address()) - EXPECT_EQ(proto_state.ip_address(), state.address); - else - EXPECT_EQ(0U, strlen(state.address)); - if (proto_state.has_gateway()) - EXPECT_EQ(proto_state.gateway(), state.gateway); - else - EXPECT_EQ(0U, strlen(state.gateway)); - found_match = true; - break; - } - } - EXPECT_TRUE(found_match) << "No matching state for fake network " - << " (" << state.name << ")"; - } + settings_helper_.SetBoolean(chromeos::kReportDeviceNetworkInterfaces, true); + GetStatus(); + VerifyNetworkReporting(); } } // namespace policy |