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 "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
8 #include "ash/test/ash_test_base.h" | 8 #include "ash/test/ash_test_base.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "chromeos/dbus/power_manager/power_supply_properties.pb.h" | 10 #include "chromeos/dbus/power_manager/power_supply_properties.pb.h" |
11 #include "ui/message_center/fake_message_center.h" | 11 #include "ui/message_center/fake_message_center.h" |
12 | 12 |
13 using message_center::Notification; | 13 using message_center::Notification; |
14 using power_manager::PowerSupplyProperties; | 14 using power_manager::PowerSupplyProperties; |
15 | 15 |
16 namespace { | 16 namespace { |
17 | 17 |
18 class MockMessageCenter : public message_center::FakeMessageCenter { | 18 class MockMessageCenter : public message_center::FakeMessageCenter { |
19 public: | 19 public: |
20 MockMessageCenter() : add_count_(0), remove_count_(0) {} | 20 MockMessageCenter() : add_count_(0), remove_count_(0) {} |
21 virtual ~MockMessageCenter() {} | 21 ~MockMessageCenter() override {} |
22 | 22 |
23 int add_count() const { return add_count_; } | 23 int add_count() const { return add_count_; } |
24 int remove_count() const { return remove_count_; } | 24 int remove_count() const { return remove_count_; } |
25 | 25 |
26 // message_center::FakeMessageCenter overrides: | 26 // message_center::FakeMessageCenter overrides: |
27 virtual void AddNotification(scoped_ptr<Notification> notification) override { | 27 void AddNotification(scoped_ptr<Notification> notification) override { |
28 add_count_++; | 28 add_count_++; |
29 } | 29 } |
30 virtual void RemoveNotification(const std::string& id, bool by_user) | 30 void RemoveNotification(const std::string& id, bool by_user) override { |
31 override { | |
32 remove_count_++; | 31 remove_count_++; |
33 } | 32 } |
34 | 33 |
35 private: | 34 private: |
36 int add_count_; | 35 int add_count_; |
37 int remove_count_; | 36 int remove_count_; |
38 | 37 |
39 DISALLOW_COPY_AND_ASSIGN(MockMessageCenter); | 38 DISALLOW_COPY_AND_ASSIGN(MockMessageCenter); |
40 }; | 39 }; |
41 | 40 |
42 } // namespace | 41 } // namespace |
43 | 42 |
44 namespace ash { | 43 namespace ash { |
45 | 44 |
46 class TrayPowerTest : public test::AshTestBase { | 45 class TrayPowerTest : public test::AshTestBase { |
47 public: | 46 public: |
48 TrayPowerTest() {} | 47 TrayPowerTest() {} |
49 virtual ~TrayPowerTest() {} | 48 ~TrayPowerTest() override {} |
50 | 49 |
51 MockMessageCenter* message_center() { return message_center_.get(); } | 50 MockMessageCenter* message_center() { return message_center_.get(); } |
52 TrayPower* tray_power() { return tray_power_.get(); } | 51 TrayPower* tray_power() { return tray_power_.get(); } |
53 | 52 |
54 // test::AshTestBase::SetUp() overrides: | 53 // test::AshTestBase::SetUp() overrides: |
55 virtual void SetUp() override { | 54 void SetUp() override { |
56 test::AshTestBase::SetUp(); | 55 test::AshTestBase::SetUp(); |
57 message_center_.reset(new MockMessageCenter()); | 56 message_center_.reset(new MockMessageCenter()); |
58 tray_power_.reset(new TrayPower(NULL, message_center_.get())); | 57 tray_power_.reset(new TrayPower(NULL, message_center_.get())); |
59 } | 58 } |
60 | 59 |
61 virtual void TearDown() override { | 60 void TearDown() override { |
62 tray_power_.reset(); | 61 tray_power_.reset(); |
63 message_center_.reset(); | 62 message_center_.reset(); |
64 test::AshTestBase::TearDown(); | 63 test::AshTestBase::TearDown(); |
65 } | 64 } |
66 | 65 |
67 TrayPower::NotificationState notification_state() const { | 66 TrayPower::NotificationState notification_state() const { |
68 return tray_power_->notification_state_; | 67 return tray_power_->notification_state_; |
69 } | 68 } |
70 | 69 |
71 bool MaybeShowUsbChargerNotification(const PowerSupplyProperties& proto) { | 70 bool MaybeShowUsbChargerNotification(const PowerSupplyProperties& proto) { |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 | 212 |
214 PowerSupplyProperties safe_usb = DefaultPowerSupplyProperties(); | 213 PowerSupplyProperties safe_usb = DefaultPowerSupplyProperties(); |
215 safe_usb.set_external_power( | 214 safe_usb.set_external_power( |
216 power_manager::PowerSupplyProperties_ExternalPower_USB); | 215 power_manager::PowerSupplyProperties_ExternalPower_USB); |
217 safe_usb.set_battery_percent(TrayPower::kNoWarningPercentage - 0.1); | 216 safe_usb.set_battery_percent(TrayPower::kNoWarningPercentage - 0.1); |
218 EXPECT_FALSE(UpdateNotificationState(safe_usb)); | 217 EXPECT_FALSE(UpdateNotificationState(safe_usb)); |
219 EXPECT_EQ(TrayPower::NOTIFICATION_NONE, notification_state()); | 218 EXPECT_EQ(TrayPower::NOTIFICATION_NONE, notification_state()); |
220 } | 219 } |
221 | 220 |
222 } // namespace ash | 221 } // namespace ash |
OLD | NEW |