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

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

Issue 2734653002: chromeos: Move files in //ash/common to //ash (Closed)
Patch Set: fix a11y tests, fix docs Created 3 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ash/common/system/chromeos/power/power_status_view.h"
6
7 #include "ash/common/system/chromeos/power/power_status.h"
8 #include "ash/strings/grit/ash_strings.h"
9 #include "ash/test/ash_test_base.h"
10 #include "chromeos/dbus/power_manager/power_supply_properties.pb.h"
11 #include "ui/base/l10n/l10n_util.h"
12 #include "ui/base/l10n/time_format.h"
13 #include "ui/gfx/image/image_skia.h"
14 #include "ui/views/controls/image_view.h"
15 #include "ui/views/controls/label.h"
16
17 using power_manager::PowerSupplyProperties;
18
19 namespace ash {
20
21 class PowerStatusViewTest : public test::AshTestBase {
22 public:
23 PowerStatusViewTest() {}
24 ~PowerStatusViewTest() override {}
25
26 // Overridden from testing::Test:
27 void SetUp() override {
28 test::AshTestBase::SetUp();
29 view_.reset(new PowerStatusView(false));
30 }
31
32 void TearDown() override {
33 view_.reset();
34 test::AshTestBase::TearDown();
35 }
36
37 protected:
38 void UpdatePowerStatus(const power_manager::PowerSupplyProperties& proto) {
39 PowerStatus::Get()->SetProtoForTesting(proto);
40 view_->OnPowerStatusChanged();
41 }
42
43 bool IsPercentageVisible() const {
44 return view_->percentage_label_->visible();
45 }
46
47 bool IsTimeStatusVisible() const {
48 return view_->time_status_label_->visible();
49 }
50
51 base::string16 RemainingTimeInView() const {
52 return view_->time_status_label_->text();
53 }
54
55 gfx::ImageSkia GetBatteryImage() const { return view_->icon_->GetImage(); }
56
57 private:
58 std::unique_ptr<PowerStatusView> view_;
59
60 DISALLOW_COPY_AND_ASSIGN(PowerStatusViewTest);
61 };
62
63 TEST_F(PowerStatusViewTest, Basic) {
64 EXPECT_FALSE(IsPercentageVisible());
65 EXPECT_TRUE(IsTimeStatusVisible());
66
67 // Disconnect the power.
68 PowerSupplyProperties prop;
69 prop.set_external_power(PowerSupplyProperties::DISCONNECTED);
70 prop.set_battery_state(PowerSupplyProperties::DISCHARGING);
71 prop.set_battery_percent(99.0);
72 prop.set_battery_time_to_empty_sec(120);
73 prop.set_is_calculating_battery_time(true);
74 UpdatePowerStatus(prop);
75
76 EXPECT_TRUE(IsPercentageVisible());
77 EXPECT_TRUE(IsTimeStatusVisible());
78 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_BATTERY_CALCULATING),
79 RemainingTimeInView());
80
81 prop.set_is_calculating_battery_time(false);
82 UpdatePowerStatus(prop);
83 EXPECT_NE(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_BATTERY_CALCULATING),
84 RemainingTimeInView());
85 EXPECT_NE(l10n_util::GetStringUTF16(
86 IDS_ASH_STATUS_TRAY_BATTERY_CHARGING_UNRELIABLE),
87 RemainingTimeInView());
88
89 prop.set_external_power(PowerSupplyProperties::AC);
90 prop.set_battery_state(PowerSupplyProperties::CHARGING);
91 prop.set_battery_time_to_full_sec(120);
92 UpdatePowerStatus(prop);
93 EXPECT_TRUE(IsPercentageVisible());
94 EXPECT_TRUE(IsTimeStatusVisible());
95 EXPECT_NE(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_BATTERY_CALCULATING),
96 RemainingTimeInView());
97 EXPECT_NE(l10n_util::GetStringUTF16(
98 IDS_ASH_STATUS_TRAY_BATTERY_CHARGING_UNRELIABLE),
99 RemainingTimeInView());
100
101 prop.set_external_power(PowerSupplyProperties::USB);
102 UpdatePowerStatus(prop);
103 EXPECT_TRUE(IsPercentageVisible());
104 EXPECT_TRUE(IsTimeStatusVisible());
105 EXPECT_EQ(l10n_util::GetStringUTF16(
106 IDS_ASH_STATUS_TRAY_BATTERY_CHARGING_UNRELIABLE),
107 RemainingTimeInView());
108
109 // Tricky -- connected to non-USB but still discharging. Not likely happening
110 // on production though.
111 prop.set_external_power(PowerSupplyProperties::AC);
112 prop.set_battery_state(PowerSupplyProperties::DISCHARGING);
113 prop.set_battery_time_to_full_sec(120);
114 UpdatePowerStatus(prop);
115 EXPECT_TRUE(IsPercentageVisible());
116 EXPECT_FALSE(IsTimeStatusVisible());
117 }
118
119 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/system/chromeos/power/power_status_view.cc ('k') | ash/common/system/chromeos/power/tray_power.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698