| 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> |
| 8 |
| 7 #include "content/public/browser/notification_types.h" | 9 #include "content/public/browser/notification_types.h" |
| 8 #include "content/public/test/test_browser_thread_bundle.h" | 10 #include "content/public/test/test_browser_thread_bundle.h" |
| 9 #include "device/battery/battery_monitor.mojom.h" | 11 #include "device/battery/battery_monitor.mojom.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 13 |
| 12 namespace content { | 14 namespace content { |
| 13 | 15 |
| 14 // Dummy ID to identify a phantom RenderProcessHost in tests. | 16 // Dummy ID to identify a phantom RenderProcessHost in tests. |
| 15 const int kDummyRenderProcessHostID = 1; | 17 const int kDummyRenderProcessHostID = 1; |
| 16 | 18 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 }; | 61 }; |
| 60 | 62 |
| 61 class PowerUsageMonitorTest : public testing::Test { | 63 class PowerUsageMonitorTest : public testing::Test { |
| 62 protected: | 64 protected: |
| 63 void SetUp() override { | 65 void SetUp() override { |
| 64 monitor_.reset(new PowerUsageMonitor); | 66 monitor_.reset(new PowerUsageMonitor); |
| 65 // PowerUsageMonitor assumes ownership. | 67 // PowerUsageMonitor assumes ownership. |
| 66 scoped_ptr<SystemInterfaceForTest> test_interface( | 68 scoped_ptr<SystemInterfaceForTest> test_interface( |
| 67 new SystemInterfaceForTest()); | 69 new SystemInterfaceForTest()); |
| 68 system_interface_ = test_interface.get(); | 70 system_interface_ = test_interface.get(); |
| 69 monitor_->SetSystemInterfaceForTest(test_interface.Pass()); | 71 monitor_->SetSystemInterfaceForTest(std::move(test_interface)); |
| 70 | 72 |
| 71 // Without live renderers, the monitor won't do anything. | 73 // Without live renderers, the monitor won't do anything. |
| 72 monitor_->OnRenderProcessNotification(NOTIFICATION_RENDERER_PROCESS_CREATED, | 74 monitor_->OnRenderProcessNotification(NOTIFICATION_RENDERER_PROCESS_CREATED, |
| 73 kDummyRenderProcessHostID); | 75 kDummyRenderProcessHostID); |
| 74 } | 76 } |
| 75 | 77 |
| 76 void UpdateBatteryStatus(bool charging, double battery_level) { | 78 void UpdateBatteryStatus(bool charging, double battery_level) { |
| 77 device::BatteryStatus battery_status; | 79 device::BatteryStatus battery_status; |
| 78 battery_status.charging = charging; | 80 battery_status.charging = charging; |
| 79 battery_status.level = battery_level; | 81 battery_status.level = battery_level; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 ASSERT_EQ(0, system_interface_->num_pending_histogram_reports()); | 160 ASSERT_EQ(0, system_interface_->num_pending_histogram_reports()); |
| 159 | 161 |
| 160 // Wall power connected. | 162 // Wall power connected. |
| 161 system_interface_->AdvanceClockMinutes(31); | 163 system_interface_->AdvanceClockMinutes(31); |
| 162 UpdateBatteryStatus(true, 0); | 164 UpdateBatteryStatus(true, 0); |
| 163 ASSERT_EQ(0, system_interface_->num_pending_histogram_reports()); | 165 ASSERT_EQ(0, system_interface_->num_pending_histogram_reports()); |
| 164 ASSERT_EQ(0, system_interface_->discharge_percent_per_hour()); | 166 ASSERT_EQ(0, system_interface_->discharge_percent_per_hour()); |
| 165 } | 167 } |
| 166 | 168 |
| 167 } // namespace content | 169 } // namespace content |
| OLD | NEW |