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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 } | 45 } |
46 | 46 |
47 int CallPowerChangedAndGetBatteryIndex() { | 47 int CallPowerChangedAndGetBatteryIndex() { |
48 PowerMenuButton* power = GetPowerMenuButton(); | 48 PowerMenuButton* power = GetPowerMenuButton(); |
49 power->PowerChanged(mock_power_library_); | 49 power->PowerChanged(mock_power_library_); |
50 return power->battery_index(); | 50 return power->battery_index(); |
51 } | 51 } |
52 }; | 52 }; |
53 | 53 |
54 IN_PROC_BROWSER_TEST_F(PowerMenuButtonTest, BatteryMissingTest) { | 54 IN_PROC_BROWSER_TEST_F(PowerMenuButtonTest, BatteryMissingTest) { |
55 EXPECT_CALL(*mock_power_library_, battery_is_present()) | 55 EXPECT_CALL(*mock_power_library_, IsBatteryPresent()) |
56 .WillOnce((Return(false))) // no battery | 56 .WillOnce((Return(false))) // no battery |
57 .RetiresOnSaturation(); | 57 .RetiresOnSaturation(); |
58 EXPECT_CALL(*mock_power_library_, battery_percentage()) | 58 EXPECT_CALL(*mock_power_library_, GetBatteryPercentage()) |
59 .WillOnce((Return(42.0))) | 59 .WillOnce((Return(42.0))) |
60 .RetiresOnSaturation(); | 60 .RetiresOnSaturation(); |
61 EXPECT_CALL(*mock_power_library_, battery_fully_charged()) | 61 EXPECT_CALL(*mock_power_library_, IsBatteryFullyCharged()) |
62 .WillOnce((Return(false))) | 62 .WillOnce((Return(false))) |
63 .RetiresOnSaturation(); | 63 .RetiresOnSaturation(); |
64 EXPECT_CALL(*mock_power_library_, line_power_on()) | 64 EXPECT_CALL(*mock_power_library_, IsLinePowerOn()) |
65 .WillOnce((Return(false))) | 65 .WillOnce((Return(false))) |
66 .RetiresOnSaturation(); | 66 .RetiresOnSaturation(); |
67 EXPECT_CALL(*mock_power_library_, battery_time_to_empty()) | 67 EXPECT_CALL(*mock_power_library_, GetBatteryTimeToEmpty()) |
68 .WillOnce((Return(base::TimeDelta::FromMinutes(42)))) | 68 .WillOnce((Return(base::TimeDelta::FromMinutes(42)))) |
69 .RetiresOnSaturation(); | 69 .RetiresOnSaturation(); |
70 EXPECT_CALL(*mock_power_library_, battery_time_to_full()) | 70 EXPECT_CALL(*mock_power_library_, GetBatteryTimeToFull()) |
71 .WillOnce((Return(base::TimeDelta::FromMinutes(24)))) | 71 .WillOnce((Return(base::TimeDelta::FromMinutes(24)))) |
72 .RetiresOnSaturation(); | 72 .RetiresOnSaturation(); |
73 EXPECT_EQ(-1, CallPowerChangedAndGetBatteryIndex()); | 73 EXPECT_EQ(-1, CallPowerChangedAndGetBatteryIndex()); |
74 } | 74 } |
75 | 75 |
76 IN_PROC_BROWSER_TEST_F(PowerMenuButtonTest, BatteryChargedTest) { | 76 IN_PROC_BROWSER_TEST_F(PowerMenuButtonTest, BatteryChargedTest) { |
77 EXPECT_CALL(*mock_power_library_, battery_is_present()) | 77 EXPECT_CALL(*mock_power_library_, IsBatteryPresent()) |
78 .WillOnce((Return(true))) | 78 .WillOnce((Return(true))) |
79 .RetiresOnSaturation(); | 79 .RetiresOnSaturation(); |
80 EXPECT_CALL(*mock_power_library_, battery_percentage()) | 80 EXPECT_CALL(*mock_power_library_, GetBatteryPercentage()) |
81 .WillOnce((Return(42.0))) | 81 .WillOnce((Return(42.0))) |
82 .RetiresOnSaturation(); | 82 .RetiresOnSaturation(); |
83 EXPECT_CALL(*mock_power_library_, battery_fully_charged()) | 83 EXPECT_CALL(*mock_power_library_, IsBatteryFullyCharged()) |
84 .WillOnce((Return(true))) // fully charged | 84 .WillOnce((Return(true))) // fully charged |
85 .RetiresOnSaturation(); | 85 .RetiresOnSaturation(); |
86 EXPECT_CALL(*mock_power_library_, line_power_on()) | 86 EXPECT_CALL(*mock_power_library_, IsLinePowerOn()) |
87 .WillOnce((Return(true))) // plugged in | 87 .WillOnce((Return(true))) // plugged in |
88 .RetiresOnSaturation(); | 88 .RetiresOnSaturation(); |
89 EXPECT_CALL(*mock_power_library_, battery_time_to_empty()) | 89 EXPECT_CALL(*mock_power_library_, GetBatteryTimeToEmpty()) |
90 .WillOnce((Return(base::TimeDelta::FromMinutes(42)))) | 90 .WillOnce((Return(base::TimeDelta::FromMinutes(42)))) |
91 .RetiresOnSaturation(); | 91 .RetiresOnSaturation(); |
92 EXPECT_CALL(*mock_power_library_, battery_time_to_full()) | 92 EXPECT_CALL(*mock_power_library_, GetBatteryTimeToFull()) |
93 .WillOnce((Return(base::TimeDelta::FromMinutes(0)))) | 93 .WillOnce((Return(base::TimeDelta::FromMinutes(0)))) |
94 .RetiresOnSaturation(); | 94 .RetiresOnSaturation(); |
95 EXPECT_EQ(kNumBatteryStates - 1, CallPowerChangedAndGetBatteryIndex()); | 95 EXPECT_EQ(kNumBatteryStates - 1, CallPowerChangedAndGetBatteryIndex()); |
96 } | 96 } |
97 | 97 |
98 IN_PROC_BROWSER_TEST_F(PowerMenuButtonTest, BatteryChargingTest) { | 98 IN_PROC_BROWSER_TEST_F(PowerMenuButtonTest, BatteryChargingTest) { |
99 const int NUM_TIMES = 19; | 99 const int NUM_TIMES = 19; |
100 EXPECT_CALL(*mock_power_library_, battery_is_present()) | 100 EXPECT_CALL(*mock_power_library_, IsBatteryPresent()) |
101 .Times(NUM_TIMES) | 101 .Times(NUM_TIMES) |
102 .WillRepeatedly((Return(true))) | 102 .WillRepeatedly((Return(true))) |
103 .RetiresOnSaturation(); | 103 .RetiresOnSaturation(); |
104 EXPECT_CALL(*mock_power_library_, battery_fully_charged()) | 104 EXPECT_CALL(*mock_power_library_, IsBatteryFullyCharged()) |
105 .Times(NUM_TIMES) | 105 .Times(NUM_TIMES) |
106 .WillRepeatedly((Return(false))) | 106 .WillRepeatedly((Return(false))) |
107 .RetiresOnSaturation(); | 107 .RetiresOnSaturation(); |
108 EXPECT_CALL(*mock_power_library_, line_power_on()) | 108 EXPECT_CALL(*mock_power_library_, IsLinePowerOn()) |
109 .Times(NUM_TIMES) | 109 .Times(NUM_TIMES) |
110 .WillRepeatedly((Return(true))) // plugged in | 110 .WillRepeatedly((Return(true))) // plugged in |
111 .RetiresOnSaturation(); | 111 .RetiresOnSaturation(); |
112 EXPECT_CALL(*mock_power_library_, battery_time_to_empty()) | 112 EXPECT_CALL(*mock_power_library_, GetBatteryTimeToEmpty()) |
113 .Times(NUM_TIMES) | 113 .Times(NUM_TIMES) |
114 .WillRepeatedly((Return(base::TimeDelta::FromMinutes(42)))) | 114 .WillRepeatedly((Return(base::TimeDelta::FromMinutes(42)))) |
115 .RetiresOnSaturation(); | 115 .RetiresOnSaturation(); |
116 EXPECT_CALL(*mock_power_library_, battery_time_to_full()) | 116 EXPECT_CALL(*mock_power_library_, GetBatteryTimeToFull()) |
117 .Times(NUM_TIMES) | 117 .Times(NUM_TIMES) |
118 .WillRepeatedly((Return(base::TimeDelta::FromMinutes(24)))) | 118 .WillRepeatedly((Return(base::TimeDelta::FromMinutes(24)))) |
119 .RetiresOnSaturation(); | 119 .RetiresOnSaturation(); |
120 | 120 |
121 int index = 0; | 121 int index = 0; |
122 for (float percent = 5.0; percent < 100.0; percent += 5.0) { | 122 for (float percent = 5.0; percent < 100.0; percent += 5.0) { |
123 EXPECT_CALL(*mock_power_library_, battery_percentage()) | 123 EXPECT_CALL(*mock_power_library_, GetBatteryPercentage()) |
124 .WillOnce((Return(percent))) | 124 .WillOnce((Return(percent))) |
125 .RetiresOnSaturation(); | 125 .RetiresOnSaturation(); |
126 EXPECT_EQ(index, CallPowerChangedAndGetBatteryIndex()); | 126 EXPECT_EQ(index, CallPowerChangedAndGetBatteryIndex()); |
127 index++; | 127 index++; |
128 } | 128 } |
129 } | 129 } |
130 | 130 |
131 IN_PROC_BROWSER_TEST_F(PowerMenuButtonTest, BatteryDischargingTest) { | 131 IN_PROC_BROWSER_TEST_F(PowerMenuButtonTest, BatteryDischargingTest) { |
132 const int NUM_TIMES = 19; | 132 const int NUM_TIMES = 19; |
133 EXPECT_CALL(*mock_power_library_, battery_is_present()) | 133 EXPECT_CALL(*mock_power_library_, IsBatteryPresent()) |
134 .Times(NUM_TIMES) | 134 .Times(NUM_TIMES) |
135 .WillRepeatedly((Return(true))) | 135 .WillRepeatedly((Return(true))) |
136 .RetiresOnSaturation(); | 136 .RetiresOnSaturation(); |
137 EXPECT_CALL(*mock_power_library_, battery_fully_charged()) | 137 EXPECT_CALL(*mock_power_library_, IsBatteryFullyCharged()) |
138 .Times(NUM_TIMES) | 138 .Times(NUM_TIMES) |
139 .WillRepeatedly((Return(false))) | 139 .WillRepeatedly((Return(false))) |
140 .RetiresOnSaturation(); | 140 .RetiresOnSaturation(); |
141 EXPECT_CALL(*mock_power_library_, line_power_on()) | 141 EXPECT_CALL(*mock_power_library_, IsLinePowerOn()) |
142 .Times(NUM_TIMES) | 142 .Times(NUM_TIMES) |
143 .WillRepeatedly((Return(false))) | 143 .WillRepeatedly((Return(false))) |
144 .RetiresOnSaturation(); | 144 .RetiresOnSaturation(); |
145 EXPECT_CALL(*mock_power_library_, battery_time_to_empty()) | 145 EXPECT_CALL(*mock_power_library_, GetBatteryTimeToEmpty()) |
146 .Times(NUM_TIMES) | 146 .Times(NUM_TIMES) |
147 .WillRepeatedly((Return(base::TimeDelta::FromMinutes(42)))) | 147 .WillRepeatedly((Return(base::TimeDelta::FromMinutes(42)))) |
148 .RetiresOnSaturation(); | 148 .RetiresOnSaturation(); |
149 EXPECT_CALL(*mock_power_library_, battery_time_to_full()) | 149 EXPECT_CALL(*mock_power_library_, GetBatteryTimeToFull()) |
150 .Times(NUM_TIMES) | 150 .Times(NUM_TIMES) |
151 .WillRepeatedly((Return(base::TimeDelta::FromMinutes(24)))) | 151 .WillRepeatedly((Return(base::TimeDelta::FromMinutes(24)))) |
152 .RetiresOnSaturation(); | 152 .RetiresOnSaturation(); |
153 | 153 |
154 int index = 0; | 154 int index = 0; |
155 for (float percent = 5.0; percent < 100.0; percent += 5.0) { | 155 for (float percent = 5.0; percent < 100.0; percent += 5.0) { |
156 EXPECT_CALL(*mock_power_library_, battery_percentage()) | 156 EXPECT_CALL(*mock_power_library_, GetBatteryPercentage()) |
157 .WillOnce((Return(percent))) | 157 .WillOnce((Return(percent))) |
158 .RetiresOnSaturation(); | 158 .RetiresOnSaturation(); |
159 EXPECT_EQ(index, CallPowerChangedAndGetBatteryIndex()); | 159 EXPECT_EQ(index, CallPowerChangedAndGetBatteryIndex()); |
160 index++; | 160 index++; |
161 } | 161 } |
162 } | 162 } |
163 | 163 |
164 } // namespace chromeos | 164 } // namespace chromeos |
OLD | NEW |