| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/browser/power_usage_monitor_impl.h" | 5 #include "content/browser/power_usage_monitor_impl.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "content/public/browser/notification_types.h" | 9 #include "content/public/browser/notification_types.h" |
| 10 #include "content/public/test/test_browser_thread_bundle.h" | 10 #include "content/public/test/test_browser_thread_bundle.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 int num_pending_histogram_reports_; | 58 int num_pending_histogram_reports_; |
| 59 int discharge_percent_per_hour_; | 59 int discharge_percent_per_hour_; |
| 60 base::Time now_; | 60 base::Time now_; |
| 61 }; | 61 }; |
| 62 | 62 |
| 63 class PowerUsageMonitorTest : public testing::Test { | 63 class PowerUsageMonitorTest : public testing::Test { |
| 64 protected: | 64 protected: |
| 65 void SetUp() override { | 65 void SetUp() override { |
| 66 monitor_.reset(new PowerUsageMonitor); | 66 monitor_.reset(new PowerUsageMonitor); |
| 67 // PowerUsageMonitor assumes ownership. | 67 // PowerUsageMonitor assumes ownership. |
| 68 scoped_ptr<SystemInterfaceForTest> test_interface( | 68 std::unique_ptr<SystemInterfaceForTest> test_interface( |
| 69 new SystemInterfaceForTest()); | 69 new SystemInterfaceForTest()); |
| 70 system_interface_ = test_interface.get(); | 70 system_interface_ = test_interface.get(); |
| 71 monitor_->SetSystemInterfaceForTest(std::move(test_interface)); | 71 monitor_->SetSystemInterfaceForTest(std::move(test_interface)); |
| 72 | 72 |
| 73 // Without live renderers, the monitor won't do anything. | 73 // Without live renderers, the monitor won't do anything. |
| 74 monitor_->OnRenderProcessNotification(NOTIFICATION_RENDERER_PROCESS_CREATED, | 74 monitor_->OnRenderProcessNotification(NOTIFICATION_RENDERER_PROCESS_CREATED, |
| 75 kDummyRenderProcessHostID); | 75 kDummyRenderProcessHostID); |
| 76 } | 76 } |
| 77 | 77 |
| 78 void UpdateBatteryStatus(bool charging, double battery_level) { | 78 void UpdateBatteryStatus(bool charging, double battery_level) { |
| 79 device::BatteryStatus battery_status; | 79 device::BatteryStatus battery_status; |
| 80 battery_status.charging = charging; | 80 battery_status.charging = charging; |
| 81 battery_status.level = battery_level; | 81 battery_status.level = battery_level; |
| 82 monitor_->OnBatteryStatusUpdate(battery_status); | 82 monitor_->OnBatteryStatusUpdate(battery_status); |
| 83 } | 83 } |
| 84 | 84 |
| 85 void KillTestRenderer() { | 85 void KillTestRenderer() { |
| 86 monitor_->OnRenderProcessNotification( | 86 monitor_->OnRenderProcessNotification( |
| 87 NOTIFICATION_RENDERER_PROCESS_CLOSED, kDummyRenderProcessHostID); | 87 NOTIFICATION_RENDERER_PROCESS_CLOSED, kDummyRenderProcessHostID); |
| 88 } | 88 } |
| 89 | 89 |
| 90 scoped_ptr<PowerUsageMonitor> monitor_; | 90 std::unique_ptr<PowerUsageMonitor> monitor_; |
| 91 SystemInterfaceForTest* system_interface_; | 91 SystemInterfaceForTest* system_interface_; |
| 92 TestBrowserThreadBundle thread_bundle_; | 92 TestBrowserThreadBundle thread_bundle_; |
| 93 }; | 93 }; |
| 94 | 94 |
| 95 TEST_F(PowerUsageMonitorTest, StartStopQuickly) { | 95 TEST_F(PowerUsageMonitorTest, StartStopQuickly) { |
| 96 // Going on battery power. | 96 // Going on battery power. |
| 97 UpdateBatteryStatus(false, 1.0); | 97 UpdateBatteryStatus(false, 1.0); |
| 98 int initial_num_histogram_reports = | 98 int initial_num_histogram_reports = |
| 99 system_interface_->num_pending_histogram_reports(); | 99 system_interface_->num_pending_histogram_reports(); |
| 100 ASSERT_GT(initial_num_histogram_reports, 0); | 100 ASSERT_GT(initial_num_histogram_reports, 0); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 ASSERT_EQ(0, system_interface_->num_pending_histogram_reports()); | 160 ASSERT_EQ(0, system_interface_->num_pending_histogram_reports()); |
| 161 | 161 |
| 162 // Wall power connected. | 162 // Wall power connected. |
| 163 system_interface_->AdvanceClockMinutes(31); | 163 system_interface_->AdvanceClockMinutes(31); |
| 164 UpdateBatteryStatus(true, 0); | 164 UpdateBatteryStatus(true, 0); |
| 165 ASSERT_EQ(0, system_interface_->num_pending_histogram_reports()); | 165 ASSERT_EQ(0, system_interface_->num_pending_histogram_reports()); |
| 166 ASSERT_EQ(0, system_interface_->discharge_percent_per_hour()); | 166 ASSERT_EQ(0, system_interface_->discharge_percent_per_hour()); |
| 167 } | 167 } |
| 168 | 168 |
| 169 } // namespace content | 169 } // namespace content |
| OLD | NEW |