| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/power_status_view.h" | 5 #include "ash/system/chromeos/power/power_status_view.h" |
| 6 | 6 |
| 7 #include "ash/system/chromeos/power/power_status.h" | 7 #include "ash/system/chromeos/power/power_status.h" |
| 8 #include "ash/test/ash_test_base.h" | 8 #include "ash/test/ash_test_base.h" |
| 9 #include "chromeos/dbus/power_manager/power_supply_properties.pb.h" | 9 #include "chromeos/dbus/power_manager/power_supply_properties.pb.h" |
| 10 #include "grit/ash_strings.h" | 10 #include "grit/ash_strings.h" |
| 11 #include "ui/base/l10n/l10n_util.h" | 11 #include "ui/base/l10n/l10n_util.h" |
| 12 #include "ui/base/l10n/time_format.h" | 12 #include "ui/base/l10n/time_format.h" |
| 13 #include "ui/views/controls/label.h" | 13 #include "ui/views/controls/label.h" |
| 14 | 14 |
| 15 using power_manager::PowerSupplyProperties; | 15 using power_manager::PowerSupplyProperties; |
| 16 | 16 |
| 17 namespace ash { | 17 namespace ash { |
| 18 | 18 |
| 19 class PowerStatusViewTest : public test::AshTestBase { | 19 class PowerStatusViewTest : public test::AshTestBase { |
| 20 public: | 20 public: |
| 21 PowerStatusViewTest() {} | 21 PowerStatusViewTest() {} |
| 22 virtual ~PowerStatusViewTest() {} | 22 virtual ~PowerStatusViewTest() {} |
| 23 | 23 |
| 24 // Overridden from testing::Test: | 24 // Overridden from testing::Test: |
| 25 virtual void SetUp() OVERRIDE { | 25 virtual void SetUp() override { |
| 26 test::AshTestBase::SetUp(); | 26 test::AshTestBase::SetUp(); |
| 27 view_.reset(new PowerStatusView(GetViewType(), false)); | 27 view_.reset(new PowerStatusView(GetViewType(), false)); |
| 28 } | 28 } |
| 29 | 29 |
| 30 virtual void TearDown() OVERRIDE { | 30 virtual void TearDown() override { |
| 31 view_.reset(); | 31 view_.reset(); |
| 32 test::AshTestBase::TearDown(); | 32 test::AshTestBase::TearDown(); |
| 33 } | 33 } |
| 34 | 34 |
| 35 protected: | 35 protected: |
| 36 virtual PowerStatusView::ViewType GetViewType() = 0; | 36 virtual PowerStatusView::ViewType GetViewType() = 0; |
| 37 PowerStatusView* view() { return view_.get(); } | 37 PowerStatusView* view() { return view_.get(); } |
| 38 | 38 |
| 39 void UpdatePowerStatus(const power_manager::PowerSupplyProperties& proto) { | 39 void UpdatePowerStatus(const power_manager::PowerSupplyProperties& proto) { |
| 40 PowerStatus::Get()->SetProtoForTesting(proto); | 40 PowerStatus::Get()->SetProtoForTesting(proto); |
| 41 view_->OnPowerStatusChanged(); | 41 view_->OnPowerStatusChanged(); |
| 42 } | 42 } |
| 43 | 43 |
| 44 private: | 44 private: |
| 45 scoped_ptr<PowerStatusView> view_; | 45 scoped_ptr<PowerStatusView> view_; |
| 46 | 46 |
| 47 DISALLOW_COPY_AND_ASSIGN(PowerStatusViewTest); | 47 DISALLOW_COPY_AND_ASSIGN(PowerStatusViewTest); |
| 48 }; | 48 }; |
| 49 | 49 |
| 50 class PowerStatusDefaultViewTest : public PowerStatusViewTest { | 50 class PowerStatusDefaultViewTest : public PowerStatusViewTest { |
| 51 public: | 51 public: |
| 52 PowerStatusDefaultViewTest() {} | 52 PowerStatusDefaultViewTest() {} |
| 53 virtual ~PowerStatusDefaultViewTest() {} | 53 virtual ~PowerStatusDefaultViewTest() {} |
| 54 | 54 |
| 55 protected: | 55 protected: |
| 56 virtual PowerStatusView::ViewType GetViewType() OVERRIDE { | 56 virtual PowerStatusView::ViewType GetViewType() override { |
| 57 return PowerStatusView::VIEW_DEFAULT; | 57 return PowerStatusView::VIEW_DEFAULT; |
| 58 } | 58 } |
| 59 | 59 |
| 60 bool IsPercentageVisible() { | 60 bool IsPercentageVisible() { |
| 61 return view()->percentage_label_->visible(); | 61 return view()->percentage_label_->visible(); |
| 62 } | 62 } |
| 63 | 63 |
| 64 bool IsTimeStatusVisible() { | 64 bool IsTimeStatusVisible() { |
| 65 return view()->time_status_label_->visible(); | 65 return view()->time_status_label_->visible(); |
| 66 } | 66 } |
| 67 | 67 |
| 68 base::string16 RemainingTimeInView() { | 68 base::string16 RemainingTimeInView() { |
| 69 return view()->time_status_label_->text(); | 69 return view()->time_status_label_->text(); |
| 70 } | 70 } |
| 71 | 71 |
| 72 private: | 72 private: |
| 73 DISALLOW_COPY_AND_ASSIGN(PowerStatusDefaultViewTest); | 73 DISALLOW_COPY_AND_ASSIGN(PowerStatusDefaultViewTest); |
| 74 }; | 74 }; |
| 75 | 75 |
| 76 class PowerStatusNotificationViewTest : public PowerStatusViewTest { | 76 class PowerStatusNotificationViewTest : public PowerStatusViewTest { |
| 77 public: | 77 public: |
| 78 PowerStatusNotificationViewTest() {} | 78 PowerStatusNotificationViewTest() {} |
| 79 virtual ~PowerStatusNotificationViewTest() {} | 79 virtual ~PowerStatusNotificationViewTest() {} |
| 80 | 80 |
| 81 protected: | 81 protected: |
| 82 virtual PowerStatusView::ViewType GetViewType() OVERRIDE { | 82 virtual PowerStatusView::ViewType GetViewType() override { |
| 83 return PowerStatusView::VIEW_NOTIFICATION; | 83 return PowerStatusView::VIEW_NOTIFICATION; |
| 84 } | 84 } |
| 85 | 85 |
| 86 base::string16 StatusInView() { | 86 base::string16 StatusInView() { |
| 87 return view()->status_label_->text(); | 87 return view()->status_label_->text(); |
| 88 } | 88 } |
| 89 | 89 |
| 90 base::string16 RemainingTimeInView() { | 90 base::string16 RemainingTimeInView() { |
| 91 return view()->time_label_->text(); | 91 return view()->time_label_->text(); |
| 92 } | 92 } |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 // Tricky -- connected to non-USB but still discharging. Not likely happening | 205 // Tricky -- connected to non-USB but still discharging. Not likely happening |
| 206 // on production though. | 206 // on production though. |
| 207 prop.set_external_power(PowerSupplyProperties::AC); | 207 prop.set_external_power(PowerSupplyProperties::AC); |
| 208 prop.set_battery_state(PowerSupplyProperties::DISCHARGING); | 208 prop.set_battery_state(PowerSupplyProperties::DISCHARGING); |
| 209 prop.set_battery_time_to_full_sec(120); | 209 prop.set_battery_time_to_full_sec(120); |
| 210 UpdatePowerStatus(prop); | 210 UpdatePowerStatus(prop); |
| 211 EXPECT_TRUE(RemainingTimeInView().empty()); | 211 EXPECT_TRUE(RemainingTimeInView().empty()); |
| 212 } | 212 } |
| 213 | 213 |
| 214 } // namespace ash | 214 } // namespace ash |
| OLD | NEW |