OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/chromeos/status/power_menu_button.h" | 5 #include "chrome/browser/chromeos/status/power_menu_button.h" |
6 | 6 |
7 #include "chrome/browser/chromeos/cros/cros_in_process_browser_test.h" | 7 #include "chrome/browser/chromeos/cros/cros_in_process_browser_test.h" |
8 #include "chrome/browser/chromeos/cros/mock_power_library.h" | 8 #include "chrome/browser/chromeos/cros/mock_power_library.h" |
9 #include "chrome/browser/chromeos/frame/browser_view.h" | 9 #include "chrome/browser/chromeos/frame/browser_view.h" |
10 #include "chrome/browser/chromeos/status/status_area_view.h" | 10 #include "chrome/browser/chromeos/status/status_area_view.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 } | 41 } |
42 | 42 |
43 int CallPowerChangedAndGetBatteryIndex(const PowerSupplyStatus& status) { | 43 int CallPowerChangedAndGetBatteryIndex(const PowerSupplyStatus& status) { |
44 PowerMenuButton* power = GetPowerMenuButton(); | 44 PowerMenuButton* power = GetPowerMenuButton(); |
45 power->PowerChanged(status); | 45 power->PowerChanged(status); |
46 return power->battery_index(); | 46 return power->battery_index(); |
47 } | 47 } |
48 }; | 48 }; |
49 | 49 |
50 IN_PROC_BROWSER_TEST_F(PowerMenuButtonTest, BatteryMissingTest) { | 50 IN_PROC_BROWSER_TEST_F(PowerMenuButtonTest, BatteryMissingTest) { |
51 PowerSupplyStatus status = {}; | 51 PowerSupplyStatus status; |
52 // No battery present. | 52 // No battery present. |
53 status.battery_is_present = false; | 53 status.battery_is_present = false; |
54 status.battery_percentage = 42.0; | 54 status.battery_percentage = 42.0; |
55 status.battery_is_full = false; | 55 status.battery_is_full = false; |
56 status.line_power_on = false; | 56 status.line_power_on = false; |
57 status.battery_seconds_to_empty = 42; | 57 status.battery_seconds_to_empty = 42; |
58 status.battery_seconds_to_full = 24; | 58 status.battery_seconds_to_full = 24; |
59 | 59 |
60 EXPECT_EQ(-1, CallPowerChangedAndGetBatteryIndex(status)); | 60 EXPECT_EQ(-1, CallPowerChangedAndGetBatteryIndex(status)); |
61 } | 61 } |
62 | 62 |
63 IN_PROC_BROWSER_TEST_F(PowerMenuButtonTest, BatteryChargedTest) { | 63 IN_PROC_BROWSER_TEST_F(PowerMenuButtonTest, BatteryChargedTest) { |
64 PowerSupplyStatus status = {}; | 64 PowerSupplyStatus status; |
65 // The battery is fully charged, and line power is plugged in. | 65 // The battery is fully charged, and line power is plugged in. |
66 status.battery_is_present = true; | 66 status.battery_is_present = true; |
67 status.battery_percentage = 42.0; | 67 status.battery_percentage = 42.0; |
68 status.battery_is_full = true; | 68 status.battery_is_full = true; |
69 status.line_power_on = true; | 69 status.line_power_on = true; |
70 status.battery_seconds_to_empty = 42; | 70 status.battery_seconds_to_empty = 42; |
71 status.battery_seconds_to_full = 24; | 71 status.battery_seconds_to_full = 24; |
72 | 72 |
73 EXPECT_EQ(kNumBatteryStates - 1, CallPowerChangedAndGetBatteryIndex(status)); | 73 EXPECT_EQ(kNumBatteryStates - 1, CallPowerChangedAndGetBatteryIndex(status)); |
74 } | 74 } |
75 | 75 |
76 IN_PROC_BROWSER_TEST_F(PowerMenuButtonTest, BatteryChargingTest) { | 76 IN_PROC_BROWSER_TEST_F(PowerMenuButtonTest, BatteryChargingTest) { |
77 PowerSupplyStatus status = {}; | 77 PowerSupplyStatus status; |
78 status.battery_is_present = true; | 78 status.battery_is_present = true; |
79 status.battery_is_full = false; | 79 status.battery_is_full = false; |
80 status.line_power_on = true; | 80 status.line_power_on = true; |
81 status.battery_seconds_to_empty = 42; | 81 status.battery_seconds_to_empty = 42; |
82 status.battery_seconds_to_full = 24; | 82 status.battery_seconds_to_full = 24; |
83 | 83 |
84 // Simulate various levels of charging. | 84 // Simulate various levels of charging. |
85 int index = 0; | 85 int index = 0; |
86 for (double percent = 5.0; percent < 100.0; percent += 5.0) { | 86 for (double percent = 5.0; percent < 100.0; percent += 5.0) { |
87 status.battery_percentage = percent; | 87 status.battery_percentage = percent; |
88 EXPECT_EQ(index, CallPowerChangedAndGetBatteryIndex(status)); | 88 EXPECT_EQ(index, CallPowerChangedAndGetBatteryIndex(status)); |
89 index++; | 89 index++; |
90 } | 90 } |
91 } | 91 } |
92 | 92 |
93 IN_PROC_BROWSER_TEST_F(PowerMenuButtonTest, BatteryDischargingTest) { | 93 IN_PROC_BROWSER_TEST_F(PowerMenuButtonTest, BatteryDischargingTest) { |
94 PowerSupplyStatus status = {}; | 94 PowerSupplyStatus status; |
95 status.battery_is_present = true; | 95 status.battery_is_present = true; |
96 status.battery_is_full = false; | 96 status.battery_is_full = false; |
97 status.line_power_on = false; | 97 status.line_power_on = false; |
98 status.battery_seconds_to_empty = 42; | 98 status.battery_seconds_to_empty = 42; |
99 status.battery_seconds_to_full = 24; | 99 status.battery_seconds_to_full = 24; |
100 | 100 |
101 // Simulate various levels of discharging. | 101 // Simulate various levels of discharging. |
102 int index = 0; | 102 int index = 0; |
103 for (float percent = 5.0; percent < 100.0; percent += 5.0) { | 103 for (float percent = 5.0; percent < 100.0; percent += 5.0) { |
104 status.battery_percentage = percent; | 104 status.battery_percentage = percent; |
105 EXPECT_EQ(index, CallPowerChangedAndGetBatteryIndex(status)); | 105 EXPECT_EQ(index, CallPowerChangedAndGetBatteryIndex(status)); |
106 index++; | 106 index++; |
107 } | 107 } |
108 } | 108 } |
109 | 109 |
110 } // namespace chromeos | 110 } // namespace chromeos |
OLD | NEW |