| 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   virtual ~MockMessageCenter() {} | 
| 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   virtual 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   virtual void RemoveNotification(const std::string& id, bool by_user) | 
| 31       OVERRIDE { | 31       override { | 
| 32     remove_count_++; | 32     remove_count_++; | 
| 33   } | 33   } | 
| 34 | 34 | 
| 35  private: | 35  private: | 
| 36   int add_count_; | 36   int add_count_; | 
| 37   int remove_count_; | 37   int remove_count_; | 
| 38 | 38 | 
| 39   DISALLOW_COPY_AND_ASSIGN(MockMessageCenter); | 39   DISALLOW_COPY_AND_ASSIGN(MockMessageCenter); | 
| 40 }; | 40 }; | 
| 41 | 41 | 
| 42 }  // namespace | 42 }  // namespace | 
| 43 | 43 | 
| 44 namespace ash { | 44 namespace ash { | 
| 45 | 45 | 
| 46 class TrayPowerTest : public test::AshTestBase { | 46 class TrayPowerTest : public test::AshTestBase { | 
| 47  public: | 47  public: | 
| 48   TrayPowerTest() {} | 48   TrayPowerTest() {} | 
| 49   virtual ~TrayPowerTest() {} | 49   virtual ~TrayPowerTest() {} | 
| 50 | 50 | 
| 51   MockMessageCenter* message_center() { return message_center_.get(); } | 51   MockMessageCenter* message_center() { return message_center_.get(); } | 
| 52   TrayPower* tray_power() { return tray_power_.get(); } | 52   TrayPower* tray_power() { return tray_power_.get(); } | 
| 53 | 53 | 
| 54   // test::AshTestBase::SetUp() overrides: | 54   // test::AshTestBase::SetUp() overrides: | 
| 55   virtual void SetUp() OVERRIDE { | 55   virtual void SetUp() override { | 
| 56     test::AshTestBase::SetUp(); | 56     test::AshTestBase::SetUp(); | 
| 57     message_center_.reset(new MockMessageCenter()); | 57     message_center_.reset(new MockMessageCenter()); | 
| 58     tray_power_.reset(new TrayPower(NULL, message_center_.get())); | 58     tray_power_.reset(new TrayPower(NULL, message_center_.get())); | 
| 59   } | 59   } | 
| 60 | 60 | 
| 61   virtual void TearDown() OVERRIDE { | 61   virtual void TearDown() override { | 
| 62     tray_power_.reset(); | 62     tray_power_.reset(); | 
| 63     message_center_.reset(); | 63     message_center_.reset(); | 
| 64     test::AshTestBase::TearDown(); | 64     test::AshTestBase::TearDown(); | 
| 65   } | 65   } | 
| 66 | 66 | 
| 67   TrayPower::NotificationState notification_state() const { | 67   TrayPower::NotificationState notification_state() const { | 
| 68     return tray_power_->notification_state_; | 68     return tray_power_->notification_state_; | 
| 69   } | 69   } | 
| 70 | 70 | 
| 71   bool MaybeShowUsbChargerNotification(const PowerSupplyProperties& proto) { | 71   bool MaybeShowUsbChargerNotification(const PowerSupplyProperties& proto) { | 
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 225       PowerSupplyProperties_ExternalPower_ORIGINAL_SPRING_CHARGER); | 225       PowerSupplyProperties_ExternalPower_ORIGINAL_SPRING_CHARGER); | 
| 226   spring.set_battery_state( | 226   spring.set_battery_state( | 
| 227       power_manager::PowerSupplyProperties_BatteryState_FULL); | 227       power_manager::PowerSupplyProperties_BatteryState_FULL); | 
| 228   spring.set_battery_time_to_empty_sec(0); | 228   spring.set_battery_time_to_empty_sec(0); | 
| 229   spring.set_battery_time_to_full_sec(0); | 229   spring.set_battery_time_to_full_sec(0); | 
| 230   EXPECT_FALSE(UpdateNotificationState(spring)); | 230   EXPECT_FALSE(UpdateNotificationState(spring)); | 
| 231   EXPECT_EQ(TrayPower::NOTIFICATION_NONE, notification_state()); | 231   EXPECT_EQ(TrayPower::NOTIFICATION_NONE, notification_state()); | 
| 232 } | 232 } | 
| 233 | 233 | 
| 234 }  // namespace ash | 234 }  // namespace ash | 
| OLD | NEW | 
|---|