Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(181)

Side by Side Diff: ash/system/chromeos/power/power_status_view_unittest.cc

Issue 1014753003: Move low battery notification to Message Center. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/system/chromeos/power/power_status_view.cc ('k') | ash/system/chromeos/power/tray_power.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 ~PowerStatusViewTest() override {} 22 ~PowerStatusViewTest() override {}
23 23
24 // Overridden from testing::Test: 24 // Overridden from testing::Test:
25 void SetUp() override { 25 void SetUp() override {
26 test::AshTestBase::SetUp(); 26 test::AshTestBase::SetUp();
27 view_.reset(new PowerStatusView(GetViewType(), false)); 27 view_.reset(new PowerStatusView(false));
28 } 28 }
29 29
30 void TearDown() override { 30 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;
37 PowerStatusView* view() { return view_.get(); }
38
39 void UpdatePowerStatus(const power_manager::PowerSupplyProperties& proto) { 36 void UpdatePowerStatus(const power_manager::PowerSupplyProperties& proto) {
40 PowerStatus::Get()->SetProtoForTesting(proto); 37 PowerStatus::Get()->SetProtoForTesting(proto);
41 view_->OnPowerStatusChanged(); 38 view_->OnPowerStatusChanged();
42 } 39 }
43 40
41 bool IsPercentageVisible() const {
42 return view_->percentage_label_->visible();
43 }
44
45 bool IsTimeStatusVisible() const {
46 return view_->time_status_label_->visible();
47 }
48
49 base::string16 RemainingTimeInView() const {
50 return view_->time_status_label_->text();
51 }
52
44 private: 53 private:
45 scoped_ptr<PowerStatusView> view_; 54 scoped_ptr<PowerStatusView> view_;
46 55
47 DISALLOW_COPY_AND_ASSIGN(PowerStatusViewTest); 56 DISALLOW_COPY_AND_ASSIGN(PowerStatusViewTest);
48 }; 57 };
49 58
50 class PowerStatusDefaultViewTest : public PowerStatusViewTest { 59 TEST_F(PowerStatusViewTest, Basic) {
51 public:
52 PowerStatusDefaultViewTest() {}
53 ~PowerStatusDefaultViewTest() override {}
54
55 protected:
56 PowerStatusView::ViewType GetViewType() override {
57 return PowerStatusView::VIEW_DEFAULT;
58 }
59
60 bool IsPercentageVisible() {
61 return view()->percentage_label_->visible();
62 }
63
64 bool IsTimeStatusVisible() {
65 return view()->time_status_label_->visible();
66 }
67
68 base::string16 RemainingTimeInView() {
69 return view()->time_status_label_->text();
70 }
71
72 private:
73 DISALLOW_COPY_AND_ASSIGN(PowerStatusDefaultViewTest);
74 };
75
76 class PowerStatusNotificationViewTest : public PowerStatusViewTest {
77 public:
78 PowerStatusNotificationViewTest() {}
79 ~PowerStatusNotificationViewTest() override {}
80
81 protected:
82 PowerStatusView::ViewType GetViewType() override {
83 return PowerStatusView::VIEW_NOTIFICATION;
84 }
85
86 base::string16 StatusInView() {
87 return view()->status_label_->text();
88 }
89
90 base::string16 RemainingTimeInView() {
91 return view()->time_label_->text();
92 }
93
94 private:
95 DISALLOW_COPY_AND_ASSIGN(PowerStatusNotificationViewTest);
96 };
97
98 TEST_F(PowerStatusDefaultViewTest, Basic) {
99 EXPECT_FALSE(IsPercentageVisible()); 60 EXPECT_FALSE(IsPercentageVisible());
100 EXPECT_TRUE(IsTimeStatusVisible()); 61 EXPECT_TRUE(IsTimeStatusVisible());
101 62
102 // Disconnect the power. 63 // Disconnect the power.
103 PowerSupplyProperties prop; 64 PowerSupplyProperties prop;
104 prop.set_external_power(PowerSupplyProperties::DISCONNECTED); 65 prop.set_external_power(PowerSupplyProperties::DISCONNECTED);
105 prop.set_battery_state(PowerSupplyProperties::DISCHARGING); 66 prop.set_battery_state(PowerSupplyProperties::DISCHARGING);
106 prop.set_battery_percent(99.0); 67 prop.set_battery_percent(99.0);
107 prop.set_battery_time_to_empty_sec(120); 68 prop.set_battery_time_to_empty_sec(120);
108 prop.set_is_calculating_battery_time(true); 69 prop.set_is_calculating_battery_time(true);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 // Tricky -- connected to non-USB but still discharging. Not likely happening 108 // Tricky -- connected to non-USB but still discharging. Not likely happening
148 // on production though. 109 // on production though.
149 prop.set_external_power(PowerSupplyProperties::AC); 110 prop.set_external_power(PowerSupplyProperties::AC);
150 prop.set_battery_state(PowerSupplyProperties::DISCHARGING); 111 prop.set_battery_state(PowerSupplyProperties::DISCHARGING);
151 prop.set_battery_time_to_full_sec(120); 112 prop.set_battery_time_to_full_sec(120);
152 UpdatePowerStatus(prop); 113 UpdatePowerStatus(prop);
153 EXPECT_TRUE(IsPercentageVisible()); 114 EXPECT_TRUE(IsPercentageVisible());
154 EXPECT_FALSE(IsTimeStatusVisible()); 115 EXPECT_FALSE(IsTimeStatusVisible());
155 } 116 }
156 117
157 TEST_F(PowerStatusNotificationViewTest, Basic) {
158 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_BATTERY_FULL),
159 StatusInView());
160 EXPECT_TRUE(RemainingTimeInView().empty());
161
162 // Disconnect the power.
163 PowerSupplyProperties prop;
164 prop.set_external_power(PowerSupplyProperties::DISCONNECTED);
165 prop.set_battery_state(PowerSupplyProperties::DISCHARGING);
166 prop.set_battery_percent(99.0);
167 prop.set_battery_time_to_empty_sec(125);
168 prop.set_is_calculating_battery_time(true);
169 UpdatePowerStatus(prop);
170
171 EXPECT_NE(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_BATTERY_FULL),
172 StatusInView());
173 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_BATTERY_CALCULATING),
174 RemainingTimeInView());
175
176 prop.set_is_calculating_battery_time(false);
177 UpdatePowerStatus(prop);
178 // Low power warning has to be calculated by ui::TimeFormat, but ignore
179 // seconds.
180 EXPECT_EQ(ui::TimeFormat::Simple(ui::TimeFormat::FORMAT_REMAINING,
181 ui::TimeFormat::LENGTH_LONG,
182 base::TimeDelta::FromMinutes(2)),
183 RemainingTimeInView());
184
185 prop.set_external_power(PowerSupplyProperties::AC);
186 prop.set_battery_state(PowerSupplyProperties::CHARGING);
187 prop.set_battery_time_to_full_sec(120);
188 UpdatePowerStatus(prop);
189 EXPECT_NE(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_BATTERY_FULL),
190 StatusInView());
191 // Charging time is somehow using another format?
192 EXPECT_NE(ui::TimeFormat::Simple(ui::TimeFormat::FORMAT_REMAINING,
193 ui::TimeFormat::LENGTH_LONG,
194 base::TimeDelta::FromMinutes(2)),
195 RemainingTimeInView());
196
197 // Unreliable connection.
198 prop.set_external_power(PowerSupplyProperties::USB);
199 UpdatePowerStatus(prop);
200 EXPECT_EQ(
201 l10n_util::GetStringUTF16(
202 IDS_ASH_STATUS_TRAY_BATTERY_CHARGING_UNRELIABLE),
203 RemainingTimeInView());
204
205 // Tricky -- connected to non-USB but still discharging. Not likely happening
206 // on production though.
207 prop.set_external_power(PowerSupplyProperties::AC);
208 prop.set_battery_state(PowerSupplyProperties::DISCHARGING);
209 prop.set_battery_time_to_full_sec(120);
210 UpdatePowerStatus(prop);
211 EXPECT_TRUE(RemainingTimeInView().empty());
212 }
213
214 } // namespace ash 118 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/chromeos/power/power_status_view.cc ('k') | ash/system/chromeos/power/tray_power.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698