| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "chromecast/base/system_time_change_notifier.h" | 5 #include "chromecast/base/system_time_change_notifier.h" |
| 6 | 6 |
| 7 #include <memory> |
| 8 |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/location.h" | 10 #include "base/location.h" |
| 9 #include "base/macros.h" | 11 #include "base/macros.h" |
| 10 #include "base/memory/scoped_ptr.h" | |
| 11 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 12 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 13 #include "base/sequenced_task_runner.h" | 14 #include "base/sequenced_task_runner.h" |
| 14 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 17 |
| 17 namespace chromecast { | 18 namespace chromecast { |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 notifier_->Finalize(); | 80 notifier_->Finalize(); |
| 80 } | 81 } |
| 81 | 82 |
| 82 // Runs pending tasks. It doesn't run tasks schedule after this call. | 83 // Runs pending tasks. It doesn't run tasks schedule after this call. |
| 83 void RunPendingTasks() { | 84 void RunPendingTasks() { |
| 84 base::RunLoop run_loop; | 85 base::RunLoop run_loop; |
| 85 base::MessageLoop::current()->PostTask(FROM_HERE, run_loop.QuitClosure()); | 86 base::MessageLoop::current()->PostTask(FROM_HERE, run_loop.QuitClosure()); |
| 86 run_loop.Run(); | 87 run_loop.Run(); |
| 87 } | 88 } |
| 88 | 89 |
| 89 scoped_ptr<base::MessageLoop> message_loop_; | 90 std::unique_ptr<base::MessageLoop> message_loop_; |
| 90 scoped_ptr<SystemTimeChangeNotifierPeriodicMonitor> notifier_; | 91 std::unique_ptr<SystemTimeChangeNotifierPeriodicMonitor> notifier_; |
| 91 scoped_ptr<TimeChangeObserver> observer_; | 92 std::unique_ptr<TimeChangeObserver> observer_; |
| 92 }; | 93 }; |
| 93 | 94 |
| 94 TEST_F(SystemTimeChangeNotifierTest, NotChanged) { | 95 TEST_F(SystemTimeChangeNotifierTest, NotChanged) { |
| 95 EXPECT_EQ(0, observer_->num_time_changed()); | 96 EXPECT_EQ(0, observer_->num_time_changed()); |
| 96 | 97 |
| 97 // Not changed. | 98 // Not changed. |
| 98 RunPendingTasks(); | 99 RunPendingTasks(); |
| 99 EXPECT_EQ(0, observer_->num_time_changed()); | 100 EXPECT_EQ(0, observer_->num_time_changed()); |
| 100 } | 101 } |
| 101 | 102 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 RunPendingTasks(); | 204 RunPendingTasks(); |
| 204 EXPECT_EQ(0, observer_->num_time_changed()); | 205 EXPECT_EQ(0, observer_->num_time_changed()); |
| 205 | 206 |
| 206 // Time change detected. Expected = now - 20 + 1, actual = now - 20. | 207 // Time change detected. Expected = now - 20 + 1, actual = now - 20. |
| 207 notifier_->set_fake_now_for_testing(now - base::TimeDelta::FromSeconds(20)); | 208 notifier_->set_fake_now_for_testing(now - base::TimeDelta::FromSeconds(20)); |
| 208 RunPendingTasks(); | 209 RunPendingTasks(); |
| 209 EXPECT_EQ(0, observer_->num_time_changed()); | 210 EXPECT_EQ(0, observer_->num_time_changed()); |
| 210 } | 211 } |
| 211 | 212 |
| 212 } // namespace chromecast | 213 } // namespace chromecast |
| OLD | NEW |