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

Side by Side Diff: chrome/browser/chromeos/status/power_menu_button_browsertest.cc

Issue 7491083: Implemented nicer battery status (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review fix Created 9 years, 4 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 | Annotate | Revision Log
OLDNEW
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"
11 #include "chrome/browser/chromeos/view_ids.h" 11 #include "chrome/browser/chromeos/view_ids.h"
12 #include "chrome/browser/ui/browser.h" 12 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/browser_window.h" 13 #include "chrome/browser/ui/browser_window.h"
14 #include "grit/theme_resources.h" 14 #include "grit/theme_resources.h"
15 15
16 namespace {
17 const int kNumBatteryStates = 20;
18 }
16 namespace chromeos { 19 namespace chromeos {
17 using ::testing::AnyNumber; 20 using ::testing::AnyNumber;
18 using ::testing::InvokeWithoutArgs; 21 using ::testing::InvokeWithoutArgs;
19 using ::testing::Return; 22 using ::testing::Return;
20 using ::testing::ReturnRef; 23 using ::testing::ReturnRef;
21 using ::testing::_; 24 using ::testing::_;
22 25
23 class PowerMenuButtonTest : public CrosInProcessBrowserTest { 26 class PowerMenuButtonTest : public CrosInProcessBrowserTest {
24 protected: 27 protected:
25 MockPowerLibrary *mock_power_library_; 28 MockPowerLibrary *mock_power_library_;
26 29
27 PowerMenuButtonTest() : CrosInProcessBrowserTest(), 30 PowerMenuButtonTest() : CrosInProcessBrowserTest(),
28 mock_power_library_(NULL) { 31 mock_power_library_(NULL) {
29 } 32 }
30 33
31 virtual void SetUpInProcessBrowserTestFixture() { 34 virtual void SetUpInProcessBrowserTestFixture() {
32 cros_mock_->InitStatusAreaMocks(); 35 cros_mock_->InitStatusAreaMocks();
33 cros_mock_->SetStatusAreaMocksExpectations(); 36 cros_mock_->SetStatusAreaMocksExpectations();
34 mock_power_library_ = cros_mock_->mock_power_library(); 37 mock_power_library_ = cros_mock_->mock_power_library();
35 } 38 }
36 39
37 PowerMenuButton* GetPowerMenuButton() { 40 PowerMenuButton* GetPowerMenuButton() {
38 BrowserView* view = static_cast<BrowserView*>(browser()->window()); 41 BrowserView* view = static_cast<BrowserView*>(browser()->window());
39 PowerMenuButton* power = static_cast<StatusAreaView*>(view-> 42 PowerMenuButton* power = static_cast<StatusAreaView*>(view->
40 GetViewByID(VIEW_ID_STATUS_AREA))->power_view(); 43 GetViewByID(VIEW_ID_STATUS_AREA))->power_view();
41 return power; 44 return power;
42 } 45 }
43 46
44 int CallPowerChangedAndGetIconId() { 47 int CallPowerChangedAndGetBatteryIndex() {
45 PowerMenuButton* power = GetPowerMenuButton(); 48 PowerMenuButton* power = GetPowerMenuButton();
46 power->PowerChanged(mock_power_library_); 49 power->PowerChanged(mock_power_library_);
47 return power->icon_id(); 50 return power->battery_index();
48 } 51 }
49 }; 52 };
50 53
51 IN_PROC_BROWSER_TEST_F(PowerMenuButtonTest, BatteryMissingTest) { 54 IN_PROC_BROWSER_TEST_F(PowerMenuButtonTest, BatteryMissingTest) {
52 EXPECT_CALL(*mock_power_library_, battery_is_present()) 55 EXPECT_CALL(*mock_power_library_, battery_is_present())
53 .WillOnce((Return(false))) // no battery 56 .WillOnce((Return(false))) // no battery
54 .RetiresOnSaturation(); 57 .RetiresOnSaturation();
55 EXPECT_CALL(*mock_power_library_, battery_percentage()) 58 EXPECT_CALL(*mock_power_library_, battery_percentage())
56 .WillOnce((Return(42.0))) 59 .WillOnce((Return(42.0)))
57 .RetiresOnSaturation(); 60 .RetiresOnSaturation();
58 EXPECT_CALL(*mock_power_library_, battery_fully_charged()) 61 EXPECT_CALL(*mock_power_library_, battery_fully_charged())
59 .WillOnce((Return(false))) 62 .WillOnce((Return(false)))
60 .RetiresOnSaturation(); 63 .RetiresOnSaturation();
61 EXPECT_CALL(*mock_power_library_, line_power_on()) 64 EXPECT_CALL(*mock_power_library_, line_power_on())
62 .WillOnce((Return(false))) 65 .WillOnce((Return(false)))
63 .RetiresOnSaturation(); 66 .RetiresOnSaturation();
64 EXPECT_CALL(*mock_power_library_, battery_time_to_empty()) 67 EXPECT_CALL(*mock_power_library_, battery_time_to_empty())
65 .WillOnce((Return(base::TimeDelta::FromMinutes(42)))) 68 .WillOnce((Return(base::TimeDelta::FromMinutes(42))))
66 .RetiresOnSaturation(); 69 .RetiresOnSaturation();
67 EXPECT_CALL(*mock_power_library_, battery_time_to_full()) 70 EXPECT_CALL(*mock_power_library_, battery_time_to_full())
68 .WillOnce((Return(base::TimeDelta::FromMinutes(24)))) 71 .WillOnce((Return(base::TimeDelta::FromMinutes(24))))
69 .RetiresOnSaturation(); 72 .RetiresOnSaturation();
70 EXPECT_EQ(IDR_STATUSBAR_BATTERY_MISSING, CallPowerChangedAndGetIconId()); 73 EXPECT_EQ(-1, CallPowerChangedAndGetBatteryIndex());
71 } 74 }
72 75
73 IN_PROC_BROWSER_TEST_F(PowerMenuButtonTest, BatteryChargedTest) { 76 IN_PROC_BROWSER_TEST_F(PowerMenuButtonTest, BatteryChargedTest) {
74 EXPECT_CALL(*mock_power_library_, battery_is_present()) 77 EXPECT_CALL(*mock_power_library_, battery_is_present())
75 .WillOnce((Return(true))) 78 .WillOnce((Return(true)))
76 .RetiresOnSaturation(); 79 .RetiresOnSaturation();
77 EXPECT_CALL(*mock_power_library_, battery_percentage()) 80 EXPECT_CALL(*mock_power_library_, battery_percentage())
78 .WillOnce((Return(42.0))) 81 .WillOnce((Return(42.0)))
79 .RetiresOnSaturation(); 82 .RetiresOnSaturation();
80 EXPECT_CALL(*mock_power_library_, battery_fully_charged()) 83 EXPECT_CALL(*mock_power_library_, battery_fully_charged())
81 .WillOnce((Return(true))) // fully charged 84 .WillOnce((Return(true))) // fully charged
82 .RetiresOnSaturation(); 85 .RetiresOnSaturation();
83 EXPECT_CALL(*mock_power_library_, line_power_on()) 86 EXPECT_CALL(*mock_power_library_, line_power_on())
84 .WillOnce((Return(true))) // plugged in 87 .WillOnce((Return(true))) // plugged in
85 .RetiresOnSaturation(); 88 .RetiresOnSaturation();
86 EXPECT_CALL(*mock_power_library_, battery_time_to_empty()) 89 EXPECT_CALL(*mock_power_library_, battery_time_to_empty())
87 .WillOnce((Return(base::TimeDelta::FromMinutes(42)))) 90 .WillOnce((Return(base::TimeDelta::FromMinutes(42))))
88 .RetiresOnSaturation(); 91 .RetiresOnSaturation();
89 EXPECT_CALL(*mock_power_library_, battery_time_to_full()) 92 EXPECT_CALL(*mock_power_library_, battery_time_to_full())
90 .WillOnce((Return(base::TimeDelta::FromMinutes(0)))) 93 .WillOnce((Return(base::TimeDelta::FromMinutes(0))))
91 .RetiresOnSaturation(); 94 .RetiresOnSaturation();
92 EXPECT_EQ(IDR_STATUSBAR_BATTERY_CHARGED, CallPowerChangedAndGetIconId()); 95 EXPECT_EQ(kNumBatteryStates - 1, CallPowerChangedAndGetBatteryIndex());
93 } 96 }
94 97
95 IN_PROC_BROWSER_TEST_F(PowerMenuButtonTest, BatteryChargingTest) { 98 IN_PROC_BROWSER_TEST_F(PowerMenuButtonTest, BatteryChargingTest) {
96 const int NUM_TIMES = 19; 99 const int NUM_TIMES = 19;
97 EXPECT_CALL(*mock_power_library_, battery_is_present()) 100 EXPECT_CALL(*mock_power_library_, battery_is_present())
98 .Times(NUM_TIMES) 101 .Times(NUM_TIMES)
99 .WillRepeatedly((Return(true))) 102 .WillRepeatedly((Return(true)))
100 .RetiresOnSaturation(); 103 .RetiresOnSaturation();
101 EXPECT_CALL(*mock_power_library_, battery_fully_charged()) 104 EXPECT_CALL(*mock_power_library_, battery_fully_charged())
102 .Times(NUM_TIMES) 105 .Times(NUM_TIMES)
103 .WillRepeatedly((Return(false))) 106 .WillRepeatedly((Return(false)))
104 .RetiresOnSaturation(); 107 .RetiresOnSaturation();
105 EXPECT_CALL(*mock_power_library_, line_power_on()) 108 EXPECT_CALL(*mock_power_library_, line_power_on())
106 .Times(NUM_TIMES) 109 .Times(NUM_TIMES)
107 .WillRepeatedly((Return(true))) // plugged in 110 .WillRepeatedly((Return(true))) // plugged in
108 .RetiresOnSaturation(); 111 .RetiresOnSaturation();
109 EXPECT_CALL(*mock_power_library_, battery_time_to_empty()) 112 EXPECT_CALL(*mock_power_library_, battery_time_to_empty())
110 .Times(NUM_TIMES) 113 .Times(NUM_TIMES)
111 .WillRepeatedly((Return(base::TimeDelta::FromMinutes(42)))) 114 .WillRepeatedly((Return(base::TimeDelta::FromMinutes(42))))
112 .RetiresOnSaturation(); 115 .RetiresOnSaturation();
113 EXPECT_CALL(*mock_power_library_, battery_time_to_full()) 116 EXPECT_CALL(*mock_power_library_, battery_time_to_full())
114 .Times(NUM_TIMES) 117 .Times(NUM_TIMES)
115 .WillRepeatedly((Return(base::TimeDelta::FromMinutes(24)))) 118 .WillRepeatedly((Return(base::TimeDelta::FromMinutes(24))))
116 .RetiresOnSaturation(); 119 .RetiresOnSaturation();
117 120
118 // Test the 16 battery charging states. 121 int index = 0;
119 // NOTE: Use an array rather than just calculating a resource number to avoid
120 // creating implicit ordering dependencies on the resource values.
121 static const int kChargingImages[] = {
122 IDR_STATUSBAR_BATTERY_CHARGING_1,
123 IDR_STATUSBAR_BATTERY_CHARGING_2,
124 IDR_STATUSBAR_BATTERY_CHARGING_3,
125 IDR_STATUSBAR_BATTERY_CHARGING_4,
126 IDR_STATUSBAR_BATTERY_CHARGING_5,
127 IDR_STATUSBAR_BATTERY_CHARGING_6,
128 IDR_STATUSBAR_BATTERY_CHARGING_7,
129 IDR_STATUSBAR_BATTERY_CHARGING_8,
130 IDR_STATUSBAR_BATTERY_CHARGING_9,
131 IDR_STATUSBAR_BATTERY_CHARGING_10,
132 IDR_STATUSBAR_BATTERY_CHARGING_11,
133 IDR_STATUSBAR_BATTERY_CHARGING_12,
134 IDR_STATUSBAR_BATTERY_CHARGING_13,
135 IDR_STATUSBAR_BATTERY_CHARGING_14,
136 IDR_STATUSBAR_BATTERY_CHARGING_15,
137 IDR_STATUSBAR_BATTERY_CHARGING_16,
138 IDR_STATUSBAR_BATTERY_CHARGING_17,
139 IDR_STATUSBAR_BATTERY_CHARGING_18,
140 IDR_STATUSBAR_BATTERY_CHARGING_19,
141 };
142 size_t id = 0;
143 for (float percent = 5.0; percent < 100.0; percent += 5.0) { 122 for (float percent = 5.0; percent < 100.0; percent += 5.0) {
144 EXPECT_CALL(*mock_power_library_, battery_percentage()) 123 EXPECT_CALL(*mock_power_library_, battery_percentage())
145 .WillOnce((Return(percent))) 124 .WillOnce((Return(percent)))
146 .RetiresOnSaturation(); 125 .RetiresOnSaturation();
147 ASSERT_LT(id, arraysize(kChargingImages)); 126 EXPECT_EQ(index, CallPowerChangedAndGetBatteryIndex());
148 EXPECT_EQ(kChargingImages[id], CallPowerChangedAndGetIconId()); 127 index++;
149 id++;
150 } 128 }
151 } 129 }
152 130
153 IN_PROC_BROWSER_TEST_F(PowerMenuButtonTest, BatteryDischargingTest) { 131 IN_PROC_BROWSER_TEST_F(PowerMenuButtonTest, BatteryDischargingTest) {
154 const int NUM_TIMES = 19; 132 const int NUM_TIMES = 19;
155 EXPECT_CALL(*mock_power_library_, battery_is_present()) 133 EXPECT_CALL(*mock_power_library_, battery_is_present())
156 .Times(NUM_TIMES) 134 .Times(NUM_TIMES)
157 .WillRepeatedly((Return(true))) 135 .WillRepeatedly((Return(true)))
158 .RetiresOnSaturation(); 136 .RetiresOnSaturation();
159 EXPECT_CALL(*mock_power_library_, battery_fully_charged()) 137 EXPECT_CALL(*mock_power_library_, battery_fully_charged())
160 .Times(NUM_TIMES) 138 .Times(NUM_TIMES)
161 .WillRepeatedly((Return(false))) 139 .WillRepeatedly((Return(false)))
162 .RetiresOnSaturation(); 140 .RetiresOnSaturation();
163 EXPECT_CALL(*mock_power_library_, line_power_on()) 141 EXPECT_CALL(*mock_power_library_, line_power_on())
164 .Times(NUM_TIMES) 142 .Times(NUM_TIMES)
165 .WillRepeatedly((Return(false))) 143 .WillRepeatedly((Return(false)))
166 .RetiresOnSaturation(); 144 .RetiresOnSaturation();
167 EXPECT_CALL(*mock_power_library_, battery_time_to_empty()) 145 EXPECT_CALL(*mock_power_library_, battery_time_to_empty())
168 .Times(NUM_TIMES) 146 .Times(NUM_TIMES)
169 .WillRepeatedly((Return(base::TimeDelta::FromMinutes(42)))) 147 .WillRepeatedly((Return(base::TimeDelta::FromMinutes(42))))
170 .RetiresOnSaturation(); 148 .RetiresOnSaturation();
171 EXPECT_CALL(*mock_power_library_, battery_time_to_full()) 149 EXPECT_CALL(*mock_power_library_, battery_time_to_full())
172 .Times(NUM_TIMES) 150 .Times(NUM_TIMES)
173 .WillRepeatedly((Return(base::TimeDelta::FromMinutes(24)))) 151 .WillRepeatedly((Return(base::TimeDelta::FromMinutes(24))))
174 .RetiresOnSaturation(); 152 .RetiresOnSaturation();
175 153
176 // Test the 16 battery discharing states. 154 int index = 0;
177 // NOTE: Use an array rather than just calculating a resource number to avoid
178 // creating implicit ordering dependencies on the resource values.
179 static const int kDischargingImages[] = {
180 IDR_STATUSBAR_BATTERY_DISCHARGING_1,
181 IDR_STATUSBAR_BATTERY_DISCHARGING_2,
182 IDR_STATUSBAR_BATTERY_DISCHARGING_3,
183 IDR_STATUSBAR_BATTERY_DISCHARGING_4,
184 IDR_STATUSBAR_BATTERY_DISCHARGING_5,
185 IDR_STATUSBAR_BATTERY_DISCHARGING_6,
186 IDR_STATUSBAR_BATTERY_DISCHARGING_7,
187 IDR_STATUSBAR_BATTERY_DISCHARGING_8,
188 IDR_STATUSBAR_BATTERY_DISCHARGING_9,
189 IDR_STATUSBAR_BATTERY_DISCHARGING_10,
190 IDR_STATUSBAR_BATTERY_DISCHARGING_11,
191 IDR_STATUSBAR_BATTERY_DISCHARGING_12,
192 IDR_STATUSBAR_BATTERY_DISCHARGING_13,
193 IDR_STATUSBAR_BATTERY_DISCHARGING_14,
194 IDR_STATUSBAR_BATTERY_DISCHARGING_15,
195 IDR_STATUSBAR_BATTERY_DISCHARGING_16,
196 IDR_STATUSBAR_BATTERY_DISCHARGING_17,
197 IDR_STATUSBAR_BATTERY_DISCHARGING_18,
198 IDR_STATUSBAR_BATTERY_DISCHARGING_19,
199 };
200 size_t id = 0;
201 for (float percent = 5.0; percent < 100.0; percent += 5.0) { 155 for (float percent = 5.0; percent < 100.0; percent += 5.0) {
202 EXPECT_CALL(*mock_power_library_, battery_percentage()) 156 EXPECT_CALL(*mock_power_library_, battery_percentage())
203 .WillOnce((Return(percent))) 157 .WillOnce((Return(percent)))
204 .RetiresOnSaturation(); 158 .RetiresOnSaturation();
205 ASSERT_LT(id, arraysize(kDischargingImages)); 159 EXPECT_EQ(index, CallPowerChangedAndGetBatteryIndex());
206 EXPECT_EQ(kDischargingImages[id], CallPowerChangedAndGetIconId()); 160 index++;
207 id++;
208 } 161 }
209 } 162 }
210 163
211 } // namespace chromeos 164 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/status/power_menu_button.cc ('k') | chrome/browser/chromeos/status/status_area_button.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698