| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/power/peripheral_battery_observer.h" | 5 #include "chrome/browser/chromeos/power/peripheral_battery_observer.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/chromeos/cros/cros_in_process_browser_test.h" | 10 #include "chrome/browser/chromeos/cros/cros_in_process_browser_test.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 observer_->PeripheralBatteryStatusReceived(kTestBatteryPath, | 75 observer_->PeripheralBatteryStatusReceived(kTestBatteryPath, |
| 76 kTestDeviceName, 50); | 76 kTestDeviceName, 50); |
| 77 EXPECT_EQ(observer_->batteries_.count(kTestBatteryAddress), 1u); | 77 EXPECT_EQ(observer_->batteries_.count(kTestBatteryAddress), 1u); |
| 78 | 78 |
| 79 const PeripheralBatteryObserver::BatteryInfo& info = | 79 const PeripheralBatteryObserver::BatteryInfo& info = |
| 80 observer_->batteries_[kTestBatteryAddress]; | 80 observer_->batteries_[kTestBatteryAddress]; |
| 81 | 81 |
| 82 EXPECT_EQ(info.name, kTestDeviceName); | 82 EXPECT_EQ(info.name, kTestDeviceName); |
| 83 EXPECT_EQ(info.level, 50); | 83 EXPECT_EQ(info.level, 50); |
| 84 EXPECT_EQ(info.last_notification_timestamp, base::TimeTicks()); | 84 EXPECT_EQ(info.last_notification_timestamp, base::TimeTicks()); |
| 85 EXPECT_FALSE(notification_manager->DoesIdExist(kTestBatteryAddress)); | 85 EXPECT_FALSE(notification_manager->FindById(kTestBatteryAddress) != NULL); |
| 86 | 86 |
| 87 // Level 5 at time 110, low-battery notification. | 87 // Level 5 at time 110, low-battery notification. |
| 88 clock.Advance(base::TimeDelta::FromSeconds(10)); | 88 clock.Advance(base::TimeDelta::FromSeconds(10)); |
| 89 observer_->PeripheralBatteryStatusReceived(kTestBatteryPath, | 89 observer_->PeripheralBatteryStatusReceived(kTestBatteryPath, |
| 90 kTestDeviceName, 5); | 90 kTestDeviceName, 5); |
| 91 EXPECT_EQ(info.level, 5); | 91 EXPECT_EQ(info.level, 5); |
| 92 EXPECT_EQ(info.last_notification_timestamp, clock.NowTicks()); | 92 EXPECT_EQ(info.last_notification_timestamp, clock.NowTicks()); |
| 93 EXPECT_TRUE(notification_manager->DoesIdExist(kTestBatteryAddress)); | 93 EXPECT_TRUE(notification_manager->FindById(kTestBatteryAddress) != NULL); |
| 94 | 94 |
| 95 // Level -1 at time 115, cancel previous notification | 95 // Level -1 at time 115, cancel previous notification |
| 96 clock.Advance(base::TimeDelta::FromSeconds(5)); | 96 clock.Advance(base::TimeDelta::FromSeconds(5)); |
| 97 observer_->PeripheralBatteryStatusReceived(kTestBatteryPath, | 97 observer_->PeripheralBatteryStatusReceived(kTestBatteryPath, |
| 98 kTestDeviceName, -1); | 98 kTestDeviceName, -1); |
| 99 EXPECT_EQ(info.level, 5); | 99 EXPECT_EQ(info.level, 5); |
| 100 EXPECT_EQ(info.last_notification_timestamp, | 100 EXPECT_EQ(info.last_notification_timestamp, |
| 101 clock.NowTicks() - base::TimeDelta::FromSeconds(5)); | 101 clock.NowTicks() - base::TimeDelta::FromSeconds(5)); |
| 102 EXPECT_FALSE(notification_manager->DoesIdExist(kTestBatteryAddress)); | 102 EXPECT_FALSE(notification_manager->FindById(kTestBatteryAddress) != NULL); |
| 103 | 103 |
| 104 // Level 50 at time 120, no low-battery notification. | 104 // Level 50 at time 120, no low-battery notification. |
| 105 clock.Advance(base::TimeDelta::FromSeconds(5)); | 105 clock.Advance(base::TimeDelta::FromSeconds(5)); |
| 106 observer_->PeripheralBatteryStatusReceived(kTestBatteryPath, | 106 observer_->PeripheralBatteryStatusReceived(kTestBatteryPath, |
| 107 kTestDeviceName, 50); | 107 kTestDeviceName, 50); |
| 108 EXPECT_EQ(info.level, 50); | 108 EXPECT_EQ(info.level, 50); |
| 109 EXPECT_EQ(info.last_notification_timestamp, | 109 EXPECT_EQ(info.last_notification_timestamp, |
| 110 clock.NowTicks() - base::TimeDelta::FromSeconds(10)); | 110 clock.NowTicks() - base::TimeDelta::FromSeconds(10)); |
| 111 EXPECT_FALSE(notification_manager->DoesIdExist(kTestBatteryAddress)); | 111 EXPECT_FALSE(notification_manager->FindById(kTestBatteryAddress) != NULL); |
| 112 | 112 |
| 113 // Level 5 at time 130, no low-battery notification (throttling). | 113 // Level 5 at time 130, no low-battery notification (throttling). |
| 114 clock.Advance(base::TimeDelta::FromSeconds(10)); | 114 clock.Advance(base::TimeDelta::FromSeconds(10)); |
| 115 observer_->PeripheralBatteryStatusReceived(kTestBatteryPath, | 115 observer_->PeripheralBatteryStatusReceived(kTestBatteryPath, |
| 116 kTestDeviceName, 5); | 116 kTestDeviceName, 5); |
| 117 EXPECT_EQ(info.level, 5); | 117 EXPECT_EQ(info.level, 5); |
| 118 EXPECT_EQ(info.last_notification_timestamp, | 118 EXPECT_EQ(info.last_notification_timestamp, |
| 119 clock.NowTicks() - base::TimeDelta::FromSeconds(20)); | 119 clock.NowTicks() - base::TimeDelta::FromSeconds(20)); |
| 120 EXPECT_FALSE(notification_manager->DoesIdExist(kTestBatteryAddress)); | 120 EXPECT_FALSE(notification_manager->FindById(kTestBatteryAddress) != NULL); |
| 121 } | 121 } |
| 122 | 122 |
| 123 IN_PROC_BROWSER_TEST_F(PeripheralBatteryObserverTest, InvalidBatteryInfo) { | 123 IN_PROC_BROWSER_TEST_F(PeripheralBatteryObserverTest, InvalidBatteryInfo) { |
| 124 observer_->PeripheralBatteryStatusReceived("invalid-path", kTestDeviceName, | 124 observer_->PeripheralBatteryStatusReceived("invalid-path", kTestDeviceName, |
| 125 10); | 125 10); |
| 126 EXPECT_TRUE(observer_->batteries_.empty()); | 126 EXPECT_TRUE(observer_->batteries_.empty()); |
| 127 | 127 |
| 128 observer_->PeripheralBatteryStatusReceived( | 128 observer_->PeripheralBatteryStatusReceived( |
| 129 "/sys/class/power_supply/hid-battery", kTestDeviceName, 10); | 129 "/sys/class/power_supply/hid-battery", kTestDeviceName, 10); |
| 130 EXPECT_TRUE(observer_->batteries_.empty()); | 130 EXPECT_TRUE(observer_->batteries_.empty()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 142 EXPECT_TRUE(observer_->batteries_.empty()); | 142 EXPECT_TRUE(observer_->batteries_.empty()); |
| 143 } | 143 } |
| 144 | 144 |
| 145 IN_PROC_BROWSER_TEST_F(PeripheralBatteryObserverTest, DeviceRemove) { | 145 IN_PROC_BROWSER_TEST_F(PeripheralBatteryObserverTest, DeviceRemove) { |
| 146 NotificationUIManager* notification_manager = | 146 NotificationUIManager* notification_manager = |
| 147 g_browser_process->notification_ui_manager(); | 147 g_browser_process->notification_ui_manager(); |
| 148 | 148 |
| 149 observer_->PeripheralBatteryStatusReceived(kTestBatteryPath, | 149 observer_->PeripheralBatteryStatusReceived(kTestBatteryPath, |
| 150 kTestDeviceName, 5); | 150 kTestDeviceName, 5); |
| 151 EXPECT_EQ(observer_->batteries_.count(kTestBatteryAddress), 1u); | 151 EXPECT_EQ(observer_->batteries_.count(kTestBatteryAddress), 1u); |
| 152 EXPECT_TRUE(notification_manager->DoesIdExist(kTestBatteryAddress)); | 152 EXPECT_TRUE(notification_manager->FindById(kTestBatteryAddress) != NULL); |
| 153 | 153 |
| 154 observer_->RemoveBattery(kTestBatteryAddress); | 154 observer_->RemoveBattery(kTestBatteryAddress); |
| 155 EXPECT_FALSE(notification_manager->DoesIdExist(kTestBatteryAddress)); | 155 EXPECT_FALSE(notification_manager->FindById(kTestBatteryAddress) != NULL); |
| 156 } | 156 } |
| 157 | 157 |
| 158 } // namespace chromeos | 158 } // namespace chromeos |
| OLD | NEW |