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

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

Issue 885853002: Disable network state reporting. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 PrefService* local_state, 86 PrefService* local_state,
87 chromeos::system::StatisticsProvider* provider, 87 chromeos::system::StatisticsProvider* provider,
88 const policy::DeviceStatusCollector::LocationUpdateRequester& 88 const policy::DeviceStatusCollector::LocationUpdateRequester&
89 location_update_requester, 89 location_update_requester,
90 const policy::DeviceStatusCollector::VolumeInfoFetcher& 90 const policy::DeviceStatusCollector::VolumeInfoFetcher&
91 volume_info_fetcher) 91 volume_info_fetcher)
92 : policy::DeviceStatusCollector( 92 : policy::DeviceStatusCollector(
93 local_state, 93 local_state,
94 provider, 94 provider,
95 location_update_requester, 95 location_update_requester,
96 volume_info_fetcher) { 96 volume_info_fetcher),
97 kiosk_mode_(false) {
97 // Set the baseline time to a fixed value (1 AM) to prevent test flakiness 98 // Set the baseline time to a fixed value (1 AM) to prevent test flakiness
98 // due to a single activity period spanning two days. 99 // due to a single activity period spanning two days.
99 SetBaselineTime(Time::Now().LocalMidnight() + TimeDelta::FromHours(1)); 100 SetBaselineTime(Time::Now().LocalMidnight() + TimeDelta::FromHours(1));
100 } 101 }
101 102
102 void Simulate(ui::IdleState* states, int len) { 103 void Simulate(ui::IdleState* states, int len) {
103 for (int i = 0; i < len; i++) 104 for (int i = 0; i < len; i++)
104 IdleStateCallback(states[i]); 105 IdleStateCallback(states[i]);
105 } 106 }
106 107
(...skipping 14 matching lines...) Expand all
121 void set_mock_cpu_usage(double total_cpu_usage, int num_processors) { 122 void set_mock_cpu_usage(double total_cpu_usage, int num_processors) {
122 std::vector<double> usage; 123 std::vector<double> usage;
123 for (int i = 0; i < num_processors; ++i) 124 for (int i = 0; i < num_processors; ++i)
124 usage.push_back(total_cpu_usage / num_processors); 125 usage.push_back(total_cpu_usage / num_processors);
125 126
126 mock_cpu_usage_ = usage; 127 mock_cpu_usage_ = usage;
127 128
128 RefreshSampleResourceUsage(); 129 RefreshSampleResourceUsage();
129 } 130 }
130 131
132 void set_kiosk_mode(bool is_kiosk) {
133 kiosk_mode_ = is_kiosk;
134 }
135
136 bool IsAutoLaunchedKioskSession() override {
137 return kiosk_mode_;
138 }
139
131 void RefreshSampleResourceUsage() { 140 void RefreshSampleResourceUsage() {
132 // Refresh our samples. Sample more than kMaxHardwareSamples times to 141 // Refresh our samples. Sample more than kMaxHardwareSamples times to
133 // make sure that the code correctly caps the number of cached samples. 142 // make sure that the code correctly caps the number of cached samples.
134 for (int i = 0; i < static_cast<int>(kMaxResourceUsageSamples + 1); ++i) 143 for (int i = 0; i < static_cast<int>(kMaxResourceUsageSamples + 1); ++i)
135 SampleResourceUsage(); 144 SampleResourceUsage();
136 } 145 }
137 146
138 protected: 147 protected:
139 void CheckIdleState() override { 148 void CheckIdleState() override {
140 // This should never be called in testing, as it results in a dbus call. 149 // This should never be called in testing, as it results in a dbus call.
(...skipping 13 matching lines...) Expand all
154 } 163 }
155 164
156 private: 165 private:
157 // Baseline time for the fake times returned from GetCurrentTime(). 166 // Baseline time for the fake times returned from GetCurrentTime().
158 Time baseline_time_; 167 Time baseline_time_;
159 168
160 // The number of simulated periods since the baseline time. 169 // The number of simulated periods since the baseline time.
161 int baseline_offset_periods_; 170 int baseline_offset_periods_;
162 171
163 std::vector<double> mock_cpu_usage_; 172 std::vector<double> mock_cpu_usage_;
173
174 bool kiosk_mode_;
164 }; 175 };
165 176
166 // Return the total number of active milliseconds contained in a device 177 // Return the total number of active milliseconds contained in a device
167 // status report. 178 // status report.
168 int64 GetActiveMilliseconds(em::DeviceStatusReportRequest& status) { 179 int64 GetActiveMilliseconds(em::DeviceStatusReportRequest& status) {
169 int64 active_milliseconds = 0; 180 int64 active_milliseconds = 0;
170 for (int i = 0; i < status.active_period_size(); i++) { 181 for (int i = 0; i < status.active_period_size(); i++) {
171 active_milliseconds += status.active_period(i).active_duration(); 182 active_milliseconds += status.active_period(i).active_duration();
172 } 183 }
173 return active_milliseconds; 184 return active_milliseconds;
(...skipping 844 matching lines...) Expand 10 before | Expand all | Expand 10 after
1018 &state_list); 1029 &state_list);
1019 ASSERT_EQ(arraysize(kFakeNetworks), state_list.size()); 1030 ASSERT_EQ(arraysize(kFakeNetworks), state_list.size());
1020 } 1031 }
1021 1032
1022 void TearDown() override { 1033 void TearDown() override {
1023 chromeos::NetworkHandler::Shutdown(); 1034 chromeos::NetworkHandler::Shutdown();
1024 chromeos::DBusThreadManager::Shutdown(); 1035 chromeos::DBusThreadManager::Shutdown();
1025 } 1036 }
1026 }; 1037 };
1027 1038
1039 TEST_F(DeviceStatusCollectorNetworkInterfacesTest, NoNetworkStateIfNotKiosk) {
1040 // If not in an active kiosk session, there should be network interfaces
1041 // reported, but no network state.
1042 GetStatus();
1043 EXPECT_LT(0, status_.network_interface_size());
1044 EXPECT_EQ(0, status_.network_state_size());
1045 }
1046
1028 TEST_F(DeviceStatusCollectorNetworkInterfacesTest, NetworkInterfaces) { 1047 TEST_F(DeviceStatusCollectorNetworkInterfacesTest, NetworkInterfaces) {
1048 // Mock that we are in kiosk mode so we report network state.
1049 status_collector_->set_kiosk_mode(true);
1050
1029 // Interfaces should be reported by default. 1051 // Interfaces should be reported by default.
1030 GetStatus(); 1052 GetStatus();
1031 EXPECT_LT(0, status_.network_interface_size()); 1053 EXPECT_LT(0, status_.network_interface_size());
1032 EXPECT_LT(0, status_.network_state_size()); 1054 EXPECT_LT(0, status_.network_state_size());
1033 1055
1034 // No interfaces should be reported if the policy is off. 1056 // No interfaces should be reported if the policy is off.
1035 cros_settings_->SetBoolean(chromeos::kReportDeviceNetworkInterfaces, false); 1057 cros_settings_->SetBoolean(chromeos::kReportDeviceNetworkInterfaces, false);
1036 GetStatus(); 1058 GetStatus();
1037 EXPECT_EQ(0, status_.network_interface_size()); 1059 EXPECT_EQ(0, status_.network_interface_size());
1038 EXPECT_EQ(0, status_.network_state_size()); 1060 EXPECT_EQ(0, status_.network_state_size());
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1095 found_match = true; 1117 found_match = true;
1096 break; 1118 break;
1097 } 1119 }
1098 } 1120 }
1099 EXPECT_TRUE(found_match) << "No matching state for fake network " 1121 EXPECT_TRUE(found_match) << "No matching state for fake network "
1100 << " (" << state.name << ")"; 1122 << " (" << state.name << ")";
1101 } 1123 }
1102 } 1124 }
1103 1125
1104 } // namespace policy 1126 } // 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