OLD | NEW |
---|---|
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/policy/device_status_collector.h" | 5 #include "chrome/browser/policy/device_status_collector.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/threading/sequenced_worker_pool.h" | 10 #include "base/threading/sequenced_worker_pool.h" |
11 #include "base/test/scoped_environment_variable.h" | |
11 #include "chrome/browser/chromeos/settings/cros_settings.h" | 12 #include "chrome/browser/chromeos/settings/cros_settings.h" |
12 #include "chrome/browser/chromeos/settings/cros_settings_names.h" | 13 #include "chrome/browser/chromeos/settings/cros_settings_names.h" |
13 #include "chrome/browser/chromeos/settings/cros_settings_provider.h" | 14 #include "chrome/browser/chromeos/settings/cros_settings_provider.h" |
14 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" | 15 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" |
15 #include "chrome/browser/chromeos/system/mock_statistics_provider.h" | 16 #include "chrome/browser/chromeos/system/mock_statistics_provider.h" |
16 #include "chrome/browser/chromeos/system/statistics_provider.h" | 17 #include "chrome/browser/chromeos/system/statistics_provider.h" |
17 #include "chrome/browser/policy/proto/device_management_backend.pb.h" | 18 #include "chrome/browser/policy/proto/device_management_backend.pb.h" |
18 #include "chrome/browser/prefs/pref_service.h" | 19 #include "chrome/browser/prefs/pref_service.h" |
19 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
20 #include "chrome/test/base/testing_pref_service.h" | 21 #include "chrome/test/base/testing_pref_service.h" |
21 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
22 #include "content/public/test/test_browser_thread.h" | 23 #include "content/public/test/test_browser_thread.h" |
23 #include "testing/gmock/include/gmock/gmock.h" | 24 #include "testing/gmock/include/gmock/gmock.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
25 | 26 |
26 using ::testing::_; | 27 using ::testing::_; |
27 using ::testing::DoAll; | 28 using ::testing::DoAll; |
28 using ::testing::NotNull; | 29 using ::testing::NotNull; |
29 using ::testing::Return; | 30 using ::testing::Return; |
30 using ::testing::SetArgPointee; | 31 using ::testing::SetArgPointee; |
31 using base::TimeDelta; | 32 using base::TimeDelta; |
32 using base::Time; | 33 using base::Time; |
33 | 34 |
34 namespace em = enterprise_management; | 35 namespace em = enterprise_management; |
35 | 36 |
36 namespace { | 37 namespace { |
37 | 38 |
38 const int64 kMillisecondsPerDay = Time::kMicrosecondsPerDay / 1000; | 39 const int64 kMillisecondsPerDay = Time::kMicrosecondsPerDay / 1000; |
39 | 40 |
41 const char kTimezoneEnvVariable[] = "TZ"; | |
42 const char kTestTimezone[] = "UTC"; | |
43 | |
40 scoped_ptr<content::Geoposition> mock_position_to_return_next; | 44 scoped_ptr<content::Geoposition> mock_position_to_return_next; |
41 | 45 |
46 Time TestBaselineTime() { | |
47 return Time::UnixEpoch() + TimeDelta::FromDays(42) + TimeDelta::FromHours(5); | |
jar (doing other things)
2012/11/16 20:29:23
Can you add a comment indicating how these numbers
Joao da Silva
2012/11/20 09:10:52
This has been removed. It was a misguided attempt
| |
48 } | |
49 | |
42 void SetMockPositionToReturnNext(const content::Geoposition &position) { | 50 void SetMockPositionToReturnNext(const content::Geoposition &position) { |
43 mock_position_to_return_next.reset(new content::Geoposition(position)); | 51 mock_position_to_return_next.reset(new content::Geoposition(position)); |
44 } | 52 } |
45 | 53 |
46 void MockPositionUpdateRequester( | 54 void MockPositionUpdateRequester( |
47 const content::GeolocationUpdateCallback& callback) { | 55 const content::GeolocationUpdateCallback& callback) { |
48 if (!mock_position_to_return_next.get()) | 56 if (!mock_position_to_return_next.get()) |
49 return; | 57 return; |
50 | 58 |
51 // If the fix is invalid, the DeviceStatusCollector will immediately request | 59 // If the fix is invalid, the DeviceStatusCollector will immediately request |
52 // another update when it receives the callback. This is desirable and safe in | 60 // another update when it receives the callback. This is desirable and safe in |
53 // real life where geolocation updates arrive asynchronously. In this testing | 61 // real life where geolocation updates arrive asynchronously. In this testing |
54 // harness, the callback is invoked synchronously upon request, leading to a | 62 // harness, the callback is invoked synchronously upon request, leading to a |
55 // request-callback loop. The loop is broken by returning the mock position | 63 // request-callback loop. The loop is broken by returning the mock position |
56 // only once. | 64 // only once. |
57 scoped_ptr<content::Geoposition> position( | 65 scoped_ptr<content::Geoposition> position( |
58 mock_position_to_return_next.release()); | 66 mock_position_to_return_next.release()); |
59 callback.Run(*position); | 67 callback.Run(*position); |
60 } | 68 } |
61 | 69 |
62 class TestingDeviceStatusCollector : public policy::DeviceStatusCollector { | 70 class TestingDeviceStatusCollector : public policy::DeviceStatusCollector { |
63 public: | 71 public: |
64 TestingDeviceStatusCollector( | 72 TestingDeviceStatusCollector( |
65 PrefService* local_state, | 73 PrefService* local_state, |
66 chromeos::system::StatisticsProvider* provider) | 74 chromeos::system::StatisticsProvider* provider) |
67 : policy::DeviceStatusCollector(local_state, | 75 : policy::DeviceStatusCollector(local_state, |
68 provider, | 76 provider, |
69 &MockPositionUpdateRequester) { | 77 &MockPositionUpdateRequester) { |
70 // Set the baseline time to a fixed value (1 AM) to prevent test flakiness | 78 // Set the baseline time to a fixed value to prevent test flakiness |
71 // due to a single activity period spanning two days. | 79 // due to a single activity period spanning two days. |
72 SetBaselineTime(Time::Now().LocalMidnight() + TimeDelta::FromHours(1)); | 80 SetBaselineTime(TestBaselineTime()); |
81 | |
82 // Initialize the collector after setting the baseline time. | |
83 Init(); | |
73 } | 84 } |
74 | 85 |
75 void Simulate(IdleState* states, int len) { | 86 void Simulate(IdleState* states, int len) { |
76 for (int i = 0; i < len; i++) | 87 for (int i = 0; i < len; i++) |
77 IdleStateCallback(states[i]); | 88 IdleStateCallback(states[i]); |
78 } | 89 } |
79 | 90 |
80 void set_max_stored_past_activity_days(unsigned int value) { | 91 void set_max_stored_past_activity_days(unsigned int value) { |
81 max_stored_past_activity_days_ = value; | 92 max_stored_past_activity_days_ = value; |
82 } | 93 } |
83 | 94 |
84 void set_max_stored_future_activity_days(unsigned int value) { | 95 void set_max_stored_future_activity_days(unsigned int value) { |
85 max_stored_future_activity_days_ = value; | 96 max_stored_future_activity_days_ = value; |
86 } | 97 } |
87 | 98 |
88 // Reset the baseline time. | 99 // Reset the baseline time. |
89 void SetBaselineTime(Time time) { | 100 void SetBaselineTime(Time time) { |
90 baseline_time_ = time; | 101 baseline_time_ = time; |
91 baseline_offset_periods_ = 0; | 102 baseline_offset_periods_ = 0; |
92 } | 103 } |
93 | 104 |
94 protected: | 105 protected: |
95 virtual void CheckIdleState() OVERRIDE { | 106 virtual void CheckIdleState() OVERRIDE { |
96 // This should never be called in testing, as it results in a dbus call. | 107 // This should never be called in testing, as it results in a dbus call. |
97 NOTREACHED(); | 108 ADD_FAILURE(); |
98 } | 109 } |
99 | 110 |
100 // Each time this is called, returns a time that is a fixed increment | 111 // Each time this is called, returns a time that is a fixed increment |
101 // later than the previous time. | 112 // later than the previous time. |
102 virtual Time GetCurrentTime() OVERRIDE { | 113 virtual Time GetCurrentTime() OVERRIDE { |
103 int poll_interval = policy::DeviceStatusCollector::kIdlePollIntervalSeconds; | 114 int poll_interval = policy::DeviceStatusCollector::kIdlePollIntervalSeconds; |
104 return baseline_time_ + | 115 return baseline_time_ + |
105 TimeDelta::FromSeconds(poll_interval * baseline_offset_periods_++); | 116 TimeDelta::FromSeconds(poll_interval * baseline_offset_periods_++); |
106 } | 117 } |
107 | 118 |
(...skipping 18 matching lines...) Expand all Loading... | |
126 } // namespace | 137 } // namespace |
127 | 138 |
128 namespace policy { | 139 namespace policy { |
129 | 140 |
130 class DeviceStatusCollectorTest : public testing::Test { | 141 class DeviceStatusCollectorTest : public testing::Test { |
131 public: | 142 public: |
132 DeviceStatusCollectorTest() | 143 DeviceStatusCollectorTest() |
133 : message_loop_(MessageLoop::TYPE_UI), | 144 : message_loop_(MessageLoop::TYPE_UI), |
134 ui_thread_(content::BrowserThread::UI, &message_loop_), | 145 ui_thread_(content::BrowserThread::UI, &message_loop_), |
135 file_thread_(content::BrowserThread::FILE, &message_loop_), | 146 file_thread_(content::BrowserThread::FILE, &message_loop_), |
136 io_thread_(content::BrowserThread::IO, &message_loop_) { | 147 io_thread_(content::BrowserThread::IO, &message_loop_), |
148 timezone_override_(kTimezoneEnvVariable, kTestTimezone) { | |
137 TestingDeviceStatusCollector::RegisterPrefs(&prefs_); | 149 TestingDeviceStatusCollector::RegisterPrefs(&prefs_); |
138 | 150 |
139 EXPECT_CALL(statistics_provider_, GetMachineStatistic(_, NotNull())) | 151 EXPECT_CALL(statistics_provider_, GetMachineStatistic(_, NotNull())) |
140 .WillRepeatedly(Return(false)); | 152 .WillRepeatedly(Return(false)); |
141 | 153 |
142 // Remove the real DeviceSettingsProvider and replace it with a stub. | 154 // Remove the real DeviceSettingsProvider and replace it with a stub. |
143 cros_settings_ = chromeos::CrosSettings::Get(); | 155 cros_settings_ = chromeos::CrosSettings::Get(); |
144 device_settings_provider_ = | 156 device_settings_provider_ = |
145 cros_settings_->GetProvider(chromeos::kReportDeviceVersionInfo); | 157 cros_settings_->GetProvider(chromeos::kReportDeviceVersionInfo); |
146 EXPECT_TRUE(device_settings_provider_ != NULL); | 158 EXPECT_TRUE(device_settings_provider_ != NULL); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
191 EXPECT_TRUE(location.has_timestamp()); | 203 EXPECT_TRUE(location.has_timestamp()); |
192 EXPECT_FALSE(location.has_altitude()); | 204 EXPECT_FALSE(location.has_altitude()); |
193 EXPECT_FALSE(location.has_altitude_accuracy()); | 205 EXPECT_FALSE(location.has_altitude_accuracy()); |
194 EXPECT_FALSE(location.has_heading()); | 206 EXPECT_FALSE(location.has_heading()); |
195 EXPECT_FALSE(location.has_speed()); | 207 EXPECT_FALSE(location.has_speed()); |
196 EXPECT_FALSE(location.has_error_message()); | 208 EXPECT_FALSE(location.has_error_message()); |
197 EXPECT_DOUBLE_EQ(4.3, location.latitude()); | 209 EXPECT_DOUBLE_EQ(4.3, location.latitude()); |
198 EXPECT_DOUBLE_EQ(-7.8, location.longitude()); | 210 EXPECT_DOUBLE_EQ(-7.8, location.longitude()); |
199 EXPECT_DOUBLE_EQ(3., location.accuracy()); | 211 EXPECT_DOUBLE_EQ(3., location.accuracy()); |
200 // Check that the timestamp is not older than ten minutes. | 212 // Check that the timestamp is not older than ten minutes. |
201 EXPECT_TRUE(Time::Now() - Time::FromDoubleT(location.timestamp() / 1000.) < | 213 Time timestamp = Time::FromDoubleT(location.timestamp() / 1000.0); |
202 TimeDelta::FromMinutes(10)); | 214 EXPECT_TRUE(TestBaselineTime() - timestamp < TimeDelta::FromMinutes(10)); |
203 } | 215 } |
204 | 216 |
205 void CheckThatALocationErrorIsReported() { | 217 void CheckThatALocationErrorIsReported() { |
206 GetStatus(); | 218 GetStatus(); |
207 EXPECT_TRUE(status_.has_device_location()); | 219 EXPECT_TRUE(status_.has_device_location()); |
208 em::DeviceLocation location = status_.device_location(); | 220 em::DeviceLocation location = status_.device_location(); |
209 EXPECT_TRUE(location.has_error_code()); | 221 EXPECT_TRUE(location.has_error_code()); |
210 EXPECT_EQ(em::DeviceLocation::ERROR_CODE_POSITION_UNAVAILABLE, | 222 EXPECT_EQ(em::DeviceLocation::ERROR_CODE_POSITION_UNAVAILABLE, |
211 location.error_code()); | 223 location.error_code()); |
212 } | 224 } |
213 | 225 |
214 protected: | 226 protected: |
215 // Convenience method. | 227 // Convenience method. |
216 int64 ActivePeriodMilliseconds() { | 228 int64 ActivePeriodMilliseconds() { |
217 return policy::DeviceStatusCollector::kIdlePollIntervalSeconds * 1000; | 229 return policy::DeviceStatusCollector::kIdlePollIntervalSeconds * 1000; |
218 } | 230 } |
219 | 231 |
220 MessageLoop message_loop_; | 232 MessageLoop message_loop_; |
221 content::TestBrowserThread ui_thread_; | 233 content::TestBrowserThread ui_thread_; |
222 content::TestBrowserThread file_thread_; | 234 content::TestBrowserThread file_thread_; |
223 content::TestBrowserThread io_thread_; | 235 content::TestBrowserThread io_thread_; |
224 | 236 |
237 base::ScopedEnvironmentVariable timezone_override_; | |
225 TestingPrefService prefs_; | 238 TestingPrefService prefs_; |
226 chromeos::system::MockStatisticsProvider statistics_provider_; | 239 chromeos::system::MockStatisticsProvider statistics_provider_; |
227 scoped_ptr<TestingDeviceStatusCollector> status_collector_; | 240 scoped_ptr<TestingDeviceStatusCollector> status_collector_; |
228 em::DeviceStatusReportRequest status_; | 241 em::DeviceStatusReportRequest status_; |
229 chromeos::CrosSettings* cros_settings_; | 242 chromeos::CrosSettings* cros_settings_; |
230 chromeos::CrosSettingsProvider* device_settings_provider_; | 243 chromeos::CrosSettingsProvider* device_settings_provider_; |
231 chromeos::StubCrosSettingsProvider stub_settings_provider_; | 244 chromeos::StubCrosSettingsProvider stub_settings_provider_; |
232 }; | 245 }; |
233 | 246 |
234 TEST_F(DeviceStatusCollectorTest, AllIdle) { | 247 TEST_F(DeviceStatusCollectorTest, AllIdle) { |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
331 IDLE_STATE_IDLE, | 344 IDLE_STATE_IDLE, |
332 IDLE_STATE_IDLE | 345 IDLE_STATE_IDLE |
333 }; | 346 }; |
334 cros_settings_->SetBoolean(chromeos::kReportDeviceActivityTimes, true); | 347 cros_settings_->SetBoolean(chromeos::kReportDeviceActivityTimes, true); |
335 status_collector_->Simulate(test_states, | 348 status_collector_->Simulate(test_states, |
336 sizeof(test_states) / sizeof(IdleState)); | 349 sizeof(test_states) / sizeof(IdleState)); |
337 GetStatus(); | 350 GetStatus(); |
338 EXPECT_EQ(3 * ActivePeriodMilliseconds(), GetActiveMilliseconds(status_)); | 351 EXPECT_EQ(3 * ActivePeriodMilliseconds(), GetActiveMilliseconds(status_)); |
339 } | 352 } |
340 | 353 |
341 // Fails after after WebKit roll [132375:132450] | 354 TEST_F(DeviceStatusCollectorTest, MaxStoredPeriods) { |
342 // http://crbug.com/157848 | |
343 TEST_F(DeviceStatusCollectorTest, DISABLED_MaxStoredPeriods) { | |
344 IdleState test_states[] = { | 355 IdleState test_states[] = { |
345 IDLE_STATE_ACTIVE, | 356 IDLE_STATE_ACTIVE, |
346 IDLE_STATE_IDLE | 357 IDLE_STATE_IDLE |
347 }; | 358 }; |
348 unsigned int max_days = 10; | 359 unsigned int max_days = 10; |
349 | 360 |
350 cros_settings_->SetBoolean(chromeos::kReportDeviceActivityTimes, true); | 361 cros_settings_->SetBoolean(chromeos::kReportDeviceActivityTimes, true); |
351 status_collector_->set_max_stored_past_activity_days(max_days - 1); | 362 status_collector_->set_max_stored_past_activity_days(max_days - 1); |
352 status_collector_->set_max_stored_future_activity_days(1); | 363 status_collector_->set_max_stored_future_activity_days(1); |
353 Time baseline = Time::Now().LocalMidnight(); | 364 Time baseline = TestBaselineTime(); |
354 | 365 |
355 // Simulate 12 active periods. | 366 // Simulate 12 active periods. |
356 for (int i = 0; i < static_cast<int>(max_days) + 2; i++) { | 367 for (int i = 0; i < static_cast<int>(max_days) + 2; i++) { |
357 status_collector_->Simulate(test_states, | 368 status_collector_->Simulate(test_states, |
358 sizeof(test_states) / sizeof(IdleState)); | 369 sizeof(test_states) / sizeof(IdleState)); |
359 // Advance the simulated clock by a day. | 370 // Advance the simulated clock by a day. |
360 baseline += TimeDelta::FromDays(1); | 371 baseline += TimeDelta::FromDays(1); |
361 status_collector_->SetBaselineTime(baseline); | 372 status_collector_->SetBaselineTime(baseline); |
362 } | 373 } |
363 | 374 |
(...skipping 12 matching lines...) Expand all Loading... | |
376 // Set the clock back so the previous simulated times are in the future. | 387 // Set the clock back so the previous simulated times are in the future. |
377 baseline -= TimeDelta::FromDays(20); | 388 baseline -= TimeDelta::FromDays(20); |
378 status_collector_->SetBaselineTime(baseline); | 389 status_collector_->SetBaselineTime(baseline); |
379 | 390 |
380 // Collect one more data point to trigger pruning. | 391 // Collect one more data point to trigger pruning. |
381 status_collector_->Simulate(test_states, 1); | 392 status_collector_->Simulate(test_states, 1); |
382 | 393 |
383 // Check that we don't exceed the max number of periods. | 394 // Check that we don't exceed the max number of periods. |
384 status_.clear_active_period(); | 395 status_.clear_active_period(); |
385 GetStatus(); | 396 GetStatus(); |
386 EXPECT_LT(status_.active_period_size(), static_cast<int>(max_days)); | 397 EXPECT_LE(status_.active_period_size(), static_cast<int>(max_days)); |
jar (doing other things)
2012/11/16 20:29:23
nit: It is strange that all but one use of |max_da
Joao da Silva
2012/11/20 09:10:52
The casts have been removed from the test. Why the
| |
387 } | 398 } |
388 | 399 |
389 TEST_F(DeviceStatusCollectorTest, ActivityTimesDisabledByDefault) { | 400 TEST_F(DeviceStatusCollectorTest, ActivityTimesDisabledByDefault) { |
390 // If the pref for collecting device activity times isn't explicitly turned | 401 // If the pref for collecting device activity times isn't explicitly turned |
391 // on, no data on activity times should be reported. | 402 // on, no data on activity times should be reported. |
392 | 403 |
393 IdleState test_states[] = { | 404 IdleState test_states[] = { |
394 IDLE_STATE_ACTIVE, | 405 IDLE_STATE_ACTIVE, |
395 IDLE_STATE_ACTIVE, | 406 IDLE_STATE_ACTIVE, |
396 IDLE_STATE_ACTIVE | 407 IDLE_STATE_ACTIVE |
397 }; | 408 }; |
398 status_collector_->Simulate(test_states, | 409 status_collector_->Simulate(test_states, |
399 sizeof(test_states) / sizeof(IdleState)); | 410 sizeof(test_states) / sizeof(IdleState)); |
400 GetStatus(); | 411 GetStatus(); |
401 EXPECT_EQ(0, status_.active_period_size()); | 412 EXPECT_EQ(0, status_.active_period_size()); |
402 EXPECT_EQ(0, GetActiveMilliseconds(status_)); | 413 EXPECT_EQ(0, GetActiveMilliseconds(status_)); |
403 } | 414 } |
404 | 415 |
405 TEST_F(DeviceStatusCollectorTest, ActivityCrossingMidnight) { | 416 TEST_F(DeviceStatusCollectorTest, ActivityCrossingMidnight) { |
406 IdleState test_states[] = { | 417 IdleState test_states[] = { |
407 IDLE_STATE_ACTIVE | 418 IDLE_STATE_ACTIVE |
408 }; | 419 }; |
409 cros_settings_->SetBoolean(chromeos::kReportDeviceActivityTimes, true); | 420 cros_settings_->SetBoolean(chromeos::kReportDeviceActivityTimes, true); |
410 | 421 |
411 // Set the baseline time to 10 seconds after midnight. | 422 // Set the baseline time to 10 seconds after midnight. |
412 status_collector_->SetBaselineTime( | 423 status_collector_->SetBaselineTime( |
413 Time::Now().LocalMidnight() + TimeDelta::FromSeconds(10)); | 424 TestBaselineTime().LocalMidnight() + TimeDelta::FromSeconds(10)); |
414 | 425 |
415 status_collector_->Simulate(test_states, 1); | 426 status_collector_->Simulate(test_states, 1); |
416 GetStatus(); | 427 GetStatus(); |
417 ASSERT_EQ(2, status_.active_period_size()); | 428 ASSERT_EQ(2, status_.active_period_size()); |
418 | 429 |
419 em::ActiveTimePeriod period0 = status_.active_period(0); | 430 em::ActiveTimePeriod period0 = status_.active_period(0); |
420 em::ActiveTimePeriod period1 = status_.active_period(1); | 431 em::ActiveTimePeriod period1 = status_.active_period(1); |
421 EXPECT_EQ(ActivePeriodMilliseconds() - 10000, period0.active_duration()); | 432 EXPECT_EQ(ActivePeriodMilliseconds() - 10000, period0.active_duration()); |
422 EXPECT_EQ(10000, period1.active_duration()); | 433 EXPECT_EQ(10000, period1.active_duration()); |
423 | 434 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
488 // don't have any reasonable values inside the unit test, so those | 499 // don't have any reasonable values inside the unit test, so those |
489 // aren't checked. | 500 // aren't checked. |
490 EXPECT_NE("", status_.browser_version()); | 501 EXPECT_NE("", status_.browser_version()); |
491 } | 502 } |
492 | 503 |
493 TEST_F(DeviceStatusCollectorTest, Location) { | 504 TEST_F(DeviceStatusCollectorTest, Location) { |
494 content::Geoposition valid_fix; | 505 content::Geoposition valid_fix; |
495 valid_fix.latitude = 4.3; | 506 valid_fix.latitude = 4.3; |
496 valid_fix.longitude = -7.8; | 507 valid_fix.longitude = -7.8; |
497 valid_fix.accuracy = 3.; | 508 valid_fix.accuracy = 3.; |
498 valid_fix.timestamp = Time::Now(); | 509 valid_fix.timestamp = TestBaselineTime() - TimeDelta::FromMinutes(5); |
499 | 510 |
500 content::Geoposition invalid_fix; | 511 content::Geoposition invalid_fix; |
501 invalid_fix.error_code = | 512 invalid_fix.error_code = |
502 content::Geoposition::ERROR_CODE_POSITION_UNAVAILABLE; | 513 content::Geoposition::ERROR_CODE_POSITION_UNAVAILABLE; |
503 invalid_fix.timestamp = Time::Now(); | 514 invalid_fix.timestamp = TestBaselineTime() - TimeDelta::FromMinutes(4); |
504 | 515 |
505 // Check that when device location reporting is disabled, no location is | 516 // Check that when device location reporting is disabled, no location is |
506 // reported. | 517 // reported. |
507 SetMockPositionToReturnNext(valid_fix); | 518 SetMockPositionToReturnNext(valid_fix); |
508 CheckThatNoLocationIsReported(); | 519 CheckThatNoLocationIsReported(); |
509 | 520 |
510 // Check that when device location reporting is enabled and a valid fix is | 521 // Check that when device location reporting is enabled and a valid fix is |
511 // available, the location is reported and is stored in local state. | 522 // available, the location is reported and is stored in local state. |
512 SetMockPositionToReturnNext(valid_fix); | 523 SetMockPositionToReturnNext(valid_fix); |
513 cros_settings_->SetBoolean(chromeos::kReportDeviceLocation, true); | 524 cros_settings_->SetBoolean(chromeos::kReportDeviceLocation, true); |
(...skipping 19 matching lines...) Expand all Loading... | |
533 // Check that after enabling location reporting again, an error is reported | 544 // Check that after enabling location reporting again, an error is reported |
534 // if no valid fix is available. | 545 // if no valid fix is available. |
535 SetMockPositionToReturnNext(invalid_fix); | 546 SetMockPositionToReturnNext(invalid_fix); |
536 cros_settings_->SetBoolean(chromeos::kReportDeviceLocation, true); | 547 cros_settings_->SetBoolean(chromeos::kReportDeviceLocation, true); |
537 // Allow the new pref to propagate to the status collector. | 548 // Allow the new pref to propagate to the status collector. |
538 message_loop_.RunAllPending(); | 549 message_loop_.RunAllPending(); |
539 CheckThatALocationErrorIsReported(); | 550 CheckThatALocationErrorIsReported(); |
540 } | 551 } |
541 | 552 |
542 } // namespace policy | 553 } // namespace policy |
OLD | NEW |