Elim cr-checkbox
[chromium-blink-merge.git] / ash / system / chromeos / power / power_status_view_unittest.cc
blobdee352ae82f8067a1b7455134e79860fcd827408
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.
5 #include "ash/system/chromeos/power/power_status_view.h"
7 #include "ash/system/chromeos/power/power_status.h"
8 #include "ash/test/ash_test_base.h"
9 #include "chromeos/dbus/power_manager/power_supply_properties.pb.h"
10 #include "grit/ash_strings.h"
11 #include "ui/base/l10n/l10n_util.h"
12 #include "ui/base/l10n/time_format.h"
13 #include "ui/views/controls/label.h"
15 using power_manager::PowerSupplyProperties;
17 namespace ash {
19 class PowerStatusViewTest : public test::AshTestBase {
20 public:
21 PowerStatusViewTest() {}
22 ~PowerStatusViewTest() override {}
24 // Overridden from testing::Test:
25 void SetUp() override {
26 test::AshTestBase::SetUp();
27 view_.reset(new PowerStatusView(false));
30 void TearDown() override {
31 view_.reset();
32 test::AshTestBase::TearDown();
35 protected:
36 void UpdatePowerStatus(const power_manager::PowerSupplyProperties& proto) {
37 PowerStatus::Get()->SetProtoForTesting(proto);
38 view_->OnPowerStatusChanged();
41 bool IsPercentageVisible() const {
42 return view_->percentage_label_->visible();
45 bool IsTimeStatusVisible() const {
46 return view_->time_status_label_->visible();
49 base::string16 RemainingTimeInView() const {
50 return view_->time_status_label_->text();
53 private:
54 scoped_ptr<PowerStatusView> view_;
56 DISALLOW_COPY_AND_ASSIGN(PowerStatusViewTest);
59 TEST_F(PowerStatusViewTest, Basic) {
60 EXPECT_FALSE(IsPercentageVisible());
61 EXPECT_TRUE(IsTimeStatusVisible());
63 // Disconnect the power.
64 PowerSupplyProperties prop;
65 prop.set_external_power(PowerSupplyProperties::DISCONNECTED);
66 prop.set_battery_state(PowerSupplyProperties::DISCHARGING);
67 prop.set_battery_percent(99.0);
68 prop.set_battery_time_to_empty_sec(120);
69 prop.set_is_calculating_battery_time(true);
70 UpdatePowerStatus(prop);
72 EXPECT_TRUE(IsPercentageVisible());
73 EXPECT_TRUE(IsTimeStatusVisible());
74 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_BATTERY_CALCULATING),
75 RemainingTimeInView());
77 prop.set_is_calculating_battery_time(false);
78 UpdatePowerStatus(prop);
79 EXPECT_NE(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_BATTERY_CALCULATING),
80 RemainingTimeInView());
81 EXPECT_NE(
82 l10n_util::GetStringUTF16(
83 IDS_ASH_STATUS_TRAY_BATTERY_CHARGING_UNRELIABLE),
84 RemainingTimeInView());
86 prop.set_external_power(PowerSupplyProperties::AC);
87 prop.set_battery_state(PowerSupplyProperties::CHARGING);
88 prop.set_battery_time_to_full_sec(120);
89 UpdatePowerStatus(prop);
90 EXPECT_TRUE(IsPercentageVisible());
91 EXPECT_TRUE(IsTimeStatusVisible());
92 EXPECT_NE(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_BATTERY_CALCULATING),
93 RemainingTimeInView());
94 EXPECT_NE(
95 l10n_util::GetStringUTF16(
96 IDS_ASH_STATUS_TRAY_BATTERY_CHARGING_UNRELIABLE),
97 RemainingTimeInView());
99 prop.set_external_power(PowerSupplyProperties::USB);
100 UpdatePowerStatus(prop);
101 EXPECT_TRUE(IsPercentageVisible());
102 EXPECT_TRUE(IsTimeStatusVisible());
103 EXPECT_EQ(
104 l10n_util::GetStringUTF16(
105 IDS_ASH_STATUS_TRAY_BATTERY_CHARGING_UNRELIABLE),
106 RemainingTimeInView());
108 // Tricky -- connected to non-USB but still discharging. Not likely happening
109 // on production though.
110 prop.set_external_power(PowerSupplyProperties::AC);
111 prop.set_battery_state(PowerSupplyProperties::DISCHARGING);
112 prop.set_battery_time_to_full_sec(120);
113 UpdatePowerStatus(prop);
114 EXPECT_TRUE(IsPercentageVisible());
115 EXPECT_FALSE(IsTimeStatusVisible());
118 } // namespace ash