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 "ash/system/chromeos/power/tray_power.h" | 5 #include "ash/system/chromeos/power/tray_power.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
| 8 #include <memory> |
8 #include <string> | 9 #include <string> |
9 | 10 |
10 #include "ash/ash_switches.h" | 11 #include "ash/ash_switches.h" |
11 #include "ash/test/ash_test_base.h" | 12 #include "ash/test/ash_test_base.h" |
12 #include "base/memory/scoped_ptr.h" | |
13 #include "chromeos/dbus/power_manager/power_supply_properties.pb.h" | 13 #include "chromeos/dbus/power_manager/power_supply_properties.pb.h" |
14 #include "ui/message_center/fake_message_center.h" | 14 #include "ui/message_center/fake_message_center.h" |
15 | 15 |
16 using message_center::Notification; | 16 using message_center::Notification; |
17 using power_manager::PowerSupplyProperties; | 17 using power_manager::PowerSupplyProperties; |
18 | 18 |
19 namespace { | 19 namespace { |
20 | 20 |
21 class MockMessageCenter : public message_center::FakeMessageCenter { | 21 class MockMessageCenter : public message_center::FakeMessageCenter { |
22 public: | 22 public: |
23 MockMessageCenter() : add_count_(0), remove_count_(0), update_count_(0) {} | 23 MockMessageCenter() : add_count_(0), remove_count_(0), update_count_(0) {} |
24 ~MockMessageCenter() override {} | 24 ~MockMessageCenter() override {} |
25 | 25 |
26 int add_count() const { return add_count_; } | 26 int add_count() const { return add_count_; } |
27 int remove_count() const { return remove_count_; } | 27 int remove_count() const { return remove_count_; } |
28 int update_count() const { return update_count_; } | 28 int update_count() const { return update_count_; } |
29 | 29 |
30 // message_center::FakeMessageCenter overrides: | 30 // message_center::FakeMessageCenter overrides: |
31 void AddNotification(scoped_ptr<Notification> notification) override { | 31 void AddNotification(std::unique_ptr<Notification> notification) override { |
32 add_count_++; | 32 add_count_++; |
33 notifications_.insert( | 33 notifications_.insert( |
34 std::make_pair(notification->id(), std::move(notification))); | 34 std::make_pair(notification->id(), std::move(notification))); |
35 } | 35 } |
36 void RemoveNotification(const std::string& id, bool by_user) override { | 36 void RemoveNotification(const std::string& id, bool by_user) override { |
37 Notification* notification = FindVisibleNotificationById(id); | 37 Notification* notification = FindVisibleNotificationById(id); |
38 if (notification && notification->delegate()) | 38 if (notification && notification->delegate()) |
39 notification->delegate()->Close(by_user); | 39 notification->delegate()->Close(by_user); |
40 remove_count_++; | 40 remove_count_++; |
41 notifications_.erase(id); | 41 notifications_.erase(id); |
42 } | 42 } |
43 void UpdateNotification(const std::string& id, | 43 void UpdateNotification( |
44 scoped_ptr<Notification> new_notification) override { | 44 const std::string& id, |
| 45 std::unique_ptr<Notification> new_notification) override { |
45 update_count_++; | 46 update_count_++; |
46 Notification* notification = FindVisibleNotificationById(id); | 47 Notification* notification = FindVisibleNotificationById(id); |
47 if (notification) | 48 if (notification) |
48 notifications_.erase(id); | 49 notifications_.erase(id); |
49 notifications_.insert( | 50 notifications_.insert( |
50 std::make_pair(new_notification->id(), std::move(new_notification))); | 51 std::make_pair(new_notification->id(), std::move(new_notification))); |
51 } | 52 } |
52 | 53 |
53 Notification* FindVisibleNotificationById(const std::string& id) override { | 54 Notification* FindVisibleNotificationById(const std::string& id) override { |
54 auto it = notifications_.find(id); | 55 auto it = notifications_.find(id); |
55 return it == notifications_.end() ? NULL : it->second.get(); | 56 return it == notifications_.end() ? NULL : it->second.get(); |
56 } | 57 } |
57 | 58 |
58 private: | 59 private: |
59 int add_count_; | 60 int add_count_; |
60 int remove_count_; | 61 int remove_count_; |
61 int update_count_; | 62 int update_count_; |
62 std::map<std::string, scoped_ptr<Notification>> notifications_; | 63 std::map<std::string, std::unique_ptr<Notification>> notifications_; |
63 | 64 |
64 DISALLOW_COPY_AND_ASSIGN(MockMessageCenter); | 65 DISALLOW_COPY_AND_ASSIGN(MockMessageCenter); |
65 }; | 66 }; |
66 | 67 |
67 } // namespace | 68 } // namespace |
68 | 69 |
69 namespace ash { | 70 namespace ash { |
70 | 71 |
71 class TrayPowerTest : public test::AshTestBase { | 72 class TrayPowerTest : public test::AshTestBase { |
72 public: | 73 public: |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 proto.set_battery_state( | 130 proto.set_battery_state( |
130 power_manager::PowerSupplyProperties_BatteryState_DISCHARGING); | 131 power_manager::PowerSupplyProperties_BatteryState_DISCHARGING); |
131 proto.set_battery_percent(50.0); | 132 proto.set_battery_percent(50.0); |
132 proto.set_battery_time_to_empty_sec(3 * 60 * 60); | 133 proto.set_battery_time_to_empty_sec(3 * 60 * 60); |
133 proto.set_battery_time_to_full_sec(2 * 60 * 60); | 134 proto.set_battery_time_to_full_sec(2 * 60 * 60); |
134 proto.set_is_calculating_battery_time(false); | 135 proto.set_is_calculating_battery_time(false); |
135 return proto; | 136 return proto; |
136 } | 137 } |
137 | 138 |
138 private: | 139 private: |
139 scoped_ptr<MockMessageCenter> message_center_; | 140 std::unique_ptr<MockMessageCenter> message_center_; |
140 scoped_ptr<TrayPower> tray_power_; | 141 std::unique_ptr<TrayPower> tray_power_; |
141 | 142 |
142 DISALLOW_COPY_AND_ASSIGN(TrayPowerTest); | 143 DISALLOW_COPY_AND_ASSIGN(TrayPowerTest); |
143 }; | 144 }; |
144 | 145 |
145 TEST_F(TrayPowerTest, MaybeShowUsbChargerNotification) { | 146 TEST_F(TrayPowerTest, MaybeShowUsbChargerNotification) { |
146 PowerSupplyProperties discharging = DefaultPowerSupplyProperties(); | 147 PowerSupplyProperties discharging = DefaultPowerSupplyProperties(); |
147 EXPECT_FALSE(MaybeShowUsbChargerNotification(discharging)); | 148 EXPECT_FALSE(MaybeShowUsbChargerNotification(discharging)); |
148 EXPECT_EQ(0, message_center()->add_count()); | 149 EXPECT_EQ(0, message_center()->add_count()); |
149 EXPECT_EQ(0, message_center()->remove_count()); | 150 EXPECT_EQ(0, message_center()->remove_count()); |
150 | 151 |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 power_manager::PowerSupplyProperties_ExternalPower_USB); | 426 power_manager::PowerSupplyProperties_ExternalPower_USB); |
426 safe_usb.set_battery_percent(TrayPower::kNoWarningPercentage - 0.1); | 427 safe_usb.set_battery_percent(TrayPower::kNoWarningPercentage - 0.1); |
427 { | 428 { |
428 SCOPED_TRACE("Notification removed for rounded percent above threshold"); | 429 SCOPED_TRACE("Notification removed for rounded percent above threshold"); |
429 UpdateNotificationState(safe_usb, TrayPower::NOTIFICATION_NONE, false, | 430 UpdateNotificationState(safe_usb, TrayPower::NOTIFICATION_NONE, false, |
430 true); | 431 true); |
431 } | 432 } |
432 } | 433 } |
433 | 434 |
434 } // namespace ash | 435 } // namespace ash |
OLD | NEW |