| 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 <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "ash/ash_switches.h" | 10 #include "ash/ash_switches.h" |
| 11 #include "ash/test/ash_test_base.h" | 11 #include "ash/test/ash_test_base.h" |
| 12 #include "base/containers/scoped_ptr_map.h" | |
| 13 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 14 #include "chromeos/dbus/power_manager/power_supply_properties.pb.h" | 13 #include "chromeos/dbus/power_manager/power_supply_properties.pb.h" |
| 15 #include "ui/message_center/fake_message_center.h" | 14 #include "ui/message_center/fake_message_center.h" |
| 16 | 15 |
| 17 using message_center::Notification; | 16 using message_center::Notification; |
| 18 using power_manager::PowerSupplyProperties; | 17 using power_manager::PowerSupplyProperties; |
| 19 | 18 |
| 20 namespace { | 19 namespace { |
| 21 | 20 |
| 22 class MockMessageCenter : public message_center::FakeMessageCenter { | 21 class MockMessageCenter : public message_center::FakeMessageCenter { |
| 23 public: | 22 public: |
| 24 MockMessageCenter() : add_count_(0), remove_count_(0) {} | 23 MockMessageCenter() : add_count_(0), remove_count_(0) {} |
| 25 ~MockMessageCenter() override {} | 24 ~MockMessageCenter() override {} |
| 26 | 25 |
| 27 int add_count() const { return add_count_; } | 26 int add_count() const { return add_count_; } |
| 28 int remove_count() const { return remove_count_; } | 27 int remove_count() const { return remove_count_; } |
| 29 | 28 |
| 30 // message_center::FakeMessageCenter overrides: | 29 // message_center::FakeMessageCenter overrides: |
| 31 void AddNotification(scoped_ptr<Notification> notification) override { | 30 void AddNotification(scoped_ptr<Notification> notification) override { |
| 32 add_count_++; | 31 add_count_++; |
| 33 notifications_.insert(notification->id(), notification.Pass()); | 32 notifications_.insert( |
| 33 std::make_pair(notification->id(), std::move(notification))); |
| 34 } | 34 } |
| 35 void RemoveNotification(const std::string& id, bool by_user) override { | 35 void RemoveNotification(const std::string& id, bool by_user) override { |
| 36 Notification* notification = FindVisibleNotificationById(id); | 36 Notification* notification = FindVisibleNotificationById(id); |
| 37 if (notification && notification->delegate()) | 37 if (notification && notification->delegate()) |
| 38 notification->delegate()->Close(by_user); | 38 notification->delegate()->Close(by_user); |
| 39 remove_count_++; | 39 remove_count_++; |
| 40 notifications_.erase(id); | 40 notifications_.erase(id); |
| 41 } | 41 } |
| 42 | 42 |
| 43 Notification* FindVisibleNotificationById(const std::string& id) override { | 43 Notification* FindVisibleNotificationById(const std::string& id) override { |
| 44 auto it = notifications_.find(id); | 44 auto it = notifications_.find(id); |
| 45 return it == notifications_.end() ? NULL : it->second; | 45 return it == notifications_.end() ? NULL : it->second.get(); |
| 46 } | 46 } |
| 47 | 47 |
| 48 private: | 48 private: |
| 49 int add_count_; | 49 int add_count_; |
| 50 int remove_count_; | 50 int remove_count_; |
| 51 base::ScopedPtrMap<std::string, scoped_ptr<Notification>> notifications_; | 51 std::map<std::string, scoped_ptr<Notification>> notifications_; |
| 52 | 52 |
| 53 DISALLOW_COPY_AND_ASSIGN(MockMessageCenter); | 53 DISALLOW_COPY_AND_ASSIGN(MockMessageCenter); |
| 54 }; | 54 }; |
| 55 | 55 |
| 56 } // namespace | 56 } // namespace |
| 57 | 57 |
| 58 namespace ash { | 58 namespace ash { |
| 59 | 59 |
| 60 class TrayPowerTest : public test::AshTestBase { | 60 class TrayPowerTest : public test::AshTestBase { |
| 61 public: | 61 public: |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 power_manager::PowerSupplyProperties_ExternalPower_USB); | 310 power_manager::PowerSupplyProperties_ExternalPower_USB); |
| 311 safe_usb.set_battery_percent(TrayPower::kNoWarningPercentage - 0.1); | 311 safe_usb.set_battery_percent(TrayPower::kNoWarningPercentage - 0.1); |
| 312 { | 312 { |
| 313 SCOPED_TRACE("Notification removed for rounded percent above threshold"); | 313 SCOPED_TRACE("Notification removed for rounded percent above threshold"); |
| 314 UpdateNotificationState(safe_usb, TrayPower::NOTIFICATION_NONE, false, | 314 UpdateNotificationState(safe_usb, TrayPower::NOTIFICATION_NONE, false, |
| 315 true); | 315 true); |
| 316 } | 316 } |
| 317 } | 317 } |
| 318 | 318 |
| 319 } // namespace ash | 319 } // namespace ash |
| OLD | NEW |