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

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

Issue 3158014: Added tooltips to stats bar items. (Closed)
Patch Set: Fixed browser tests. Created 10 years, 3 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
« no previous file with comments | « chrome/browser/chromeos/status/power_menu_button.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/browser.h" 7 #include "chrome/browser/browser.h"
8 #include "chrome/browser/browser_window.h" 8 #include "chrome/browser/browser_window.h"
9 #include "chrome/browser/chromeos/cros/cros_in_process_browser_test.h" 9 #include "chrome/browser/chromeos/cros/cros_in_process_browser_test.h"
10 #include "chrome/browser/chromeos/cros/mock_power_library.h" 10 #include "chrome/browser/chromeos/cros/mock_power_library.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 43
44 int CallPowerChangedAndGetIconId() { 44 int CallPowerChangedAndGetIconId() {
45 PowerMenuButton* power = GetPowerMenuButton(); 45 PowerMenuButton* power = GetPowerMenuButton();
46 power->PowerChanged(mock_power_library_); 46 power->PowerChanged(mock_power_library_);
47 return power->icon_id(); 47 return power->icon_id();
48 } 48 }
49 }; 49 };
50 50
51 IN_PROC_BROWSER_TEST_F(PowerMenuButtonTest, BatteryMissingTest) { 51 IN_PROC_BROWSER_TEST_F(PowerMenuButtonTest, BatteryMissingTest) {
52 EXPECT_CALL(*mock_power_library_, battery_is_present()) 52 EXPECT_CALL(*mock_power_library_, battery_is_present())
53 .WillRepeatedly((Return(false))); 53 .WillOnce((Return(false))) // no battery
54 .RetiresOnSaturation();
55 EXPECT_CALL(*mock_power_library_, battery_percentage())
56 .WillOnce((Return(42.0)))
57 .RetiresOnSaturation();
58 EXPECT_CALL(*mock_power_library_, battery_fully_charged())
59 .WillOnce((Return(false)))
60 .RetiresOnSaturation();
61 EXPECT_CALL(*mock_power_library_, line_power_on())
62 .WillOnce((Return(false)))
63 .RetiresOnSaturation();
64 EXPECT_CALL(*mock_power_library_, battery_time_to_empty())
65 .WillOnce((Return(base::TimeDelta::FromMinutes(42))))
66 .RetiresOnSaturation();
67 EXPECT_CALL(*mock_power_library_, battery_time_to_full())
68 .WillOnce((Return(base::TimeDelta::FromMinutes(24))))
69 .RetiresOnSaturation();
54 EXPECT_EQ(IDR_STATUSBAR_BATTERY_MISSING, CallPowerChangedAndGetIconId()); 70 EXPECT_EQ(IDR_STATUSBAR_BATTERY_MISSING, CallPowerChangedAndGetIconId());
55 } 71 }
56 72
57 IN_PROC_BROWSER_TEST_F(PowerMenuButtonTest, BatteryChargedTest) { 73 IN_PROC_BROWSER_TEST_F(PowerMenuButtonTest, BatteryChargedTest) {
58 EXPECT_CALL(*mock_power_library_, battery_is_present()) 74 EXPECT_CALL(*mock_power_library_, battery_is_present())
59 .WillRepeatedly((Return(true))); 75 .WillOnce((Return(true)))
76 .RetiresOnSaturation();
77 EXPECT_CALL(*mock_power_library_, battery_percentage())
78 .WillOnce((Return(42.0)))
79 .RetiresOnSaturation();
60 EXPECT_CALL(*mock_power_library_, battery_fully_charged()) 80 EXPECT_CALL(*mock_power_library_, battery_fully_charged())
61 .WillRepeatedly((Return(true))); 81 .WillOnce((Return(true))) // fully charged
82 .RetiresOnSaturation();
62 EXPECT_CALL(*mock_power_library_, line_power_on()) 83 EXPECT_CALL(*mock_power_library_, line_power_on())
63 .WillRepeatedly((Return(true))); 84 .WillOnce((Return(true))) // plugged in
85 .RetiresOnSaturation();
86 EXPECT_CALL(*mock_power_library_, battery_time_to_empty())
87 .WillOnce((Return(base::TimeDelta::FromMinutes(42))))
88 .RetiresOnSaturation();
89 EXPECT_CALL(*mock_power_library_, battery_time_to_full())
90 .WillOnce((Return(base::TimeDelta::FromMinutes(0))))
91 .RetiresOnSaturation();
64 EXPECT_EQ(IDR_STATUSBAR_BATTERY_CHARGED, CallPowerChangedAndGetIconId()); 92 EXPECT_EQ(IDR_STATUSBAR_BATTERY_CHARGED, CallPowerChangedAndGetIconId());
65 } 93 }
66 94
67 IN_PROC_BROWSER_TEST_F(PowerMenuButtonTest, BatteryChargingTest) { 95 IN_PROC_BROWSER_TEST_F(PowerMenuButtonTest, BatteryChargingTest) {
96 const int NUM_TIMES = 12; // 6 + 8*12 = 102
68 EXPECT_CALL(*mock_power_library_, battery_is_present()) 97 EXPECT_CALL(*mock_power_library_, battery_is_present())
69 .WillRepeatedly((Return(true))); 98 .Times(NUM_TIMES)
99 .WillRepeatedly((Return(true)))
100 .RetiresOnSaturation();
70 EXPECT_CALL(*mock_power_library_, battery_fully_charged()) 101 EXPECT_CALL(*mock_power_library_, battery_fully_charged())
71 .WillRepeatedly((Return(false))); 102 .Times(NUM_TIMES)
103 .WillRepeatedly((Return(false)))
104 .RetiresOnSaturation();
72 EXPECT_CALL(*mock_power_library_, line_power_on()) 105 EXPECT_CALL(*mock_power_library_, line_power_on())
73 .WillRepeatedly((Return(true))); 106 .Times(NUM_TIMES)
107 .WillRepeatedly((Return(true))) // plugged in
108 .RetiresOnSaturation();
109 EXPECT_CALL(*mock_power_library_, battery_time_to_empty())
110 .Times(NUM_TIMES)
111 .WillRepeatedly((Return(base::TimeDelta::FromMinutes(42))))
112 .RetiresOnSaturation();
113 EXPECT_CALL(*mock_power_library_, battery_time_to_full())
114 .Times(NUM_TIMES)
115 .WillRepeatedly((Return(base::TimeDelta::FromMinutes(24))))
116 .RetiresOnSaturation();
74 117
75 // Test the 12 battery charging states. 118 // Test the 12 battery charging states.
76 // NOTE: Use an array rather than just calculating a resource number to avoid 119 // NOTE: Use an array rather than just calculating a resource number to avoid
77 // creating implicit ordering dependencies on the resource values. 120 // creating implicit ordering dependencies on the resource values.
78 static const int kChargingImages[] = { 121 static const int kChargingImages[] = {
79 IDR_STATUSBAR_BATTERY_CHARGING_1, 122 IDR_STATUSBAR_BATTERY_CHARGING_1,
80 IDR_STATUSBAR_BATTERY_CHARGING_2, 123 IDR_STATUSBAR_BATTERY_CHARGING_2,
81 IDR_STATUSBAR_BATTERY_CHARGING_3, 124 IDR_STATUSBAR_BATTERY_CHARGING_3,
82 IDR_STATUSBAR_BATTERY_CHARGING_4, 125 IDR_STATUSBAR_BATTERY_CHARGING_4,
83 IDR_STATUSBAR_BATTERY_CHARGING_5, 126 IDR_STATUSBAR_BATTERY_CHARGING_5,
84 IDR_STATUSBAR_BATTERY_CHARGING_6, 127 IDR_STATUSBAR_BATTERY_CHARGING_6,
85 IDR_STATUSBAR_BATTERY_CHARGING_7, 128 IDR_STATUSBAR_BATTERY_CHARGING_7,
86 IDR_STATUSBAR_BATTERY_CHARGING_8, 129 IDR_STATUSBAR_BATTERY_CHARGING_8,
87 IDR_STATUSBAR_BATTERY_CHARGING_9, 130 IDR_STATUSBAR_BATTERY_CHARGING_9,
88 IDR_STATUSBAR_BATTERY_CHARGING_10, 131 IDR_STATUSBAR_BATTERY_CHARGING_10,
89 IDR_STATUSBAR_BATTERY_CHARGING_11, 132 IDR_STATUSBAR_BATTERY_CHARGING_11,
90 IDR_STATUSBAR_BATTERY_CHARGING_12, 133 IDR_STATUSBAR_BATTERY_CHARGING_12,
91 }; 134 };
92 size_t id = 0; 135 size_t id = 0;
93 for (float percent = 6.0; percent < 100.0; percent += 8.0) { 136 for (float percent = 6.0; percent < 100.0; percent += 8.0) {
94 EXPECT_CALL(*mock_power_library_, battery_percentage()) 137 EXPECT_CALL(*mock_power_library_, battery_percentage())
95 .WillRepeatedly((Return(percent))); 138 .WillOnce((Return(percent)))
139 .RetiresOnSaturation();
96 ASSERT_LT(id, arraysize(kChargingImages)); 140 ASSERT_LT(id, arraysize(kChargingImages));
97 EXPECT_EQ(kChargingImages[id], CallPowerChangedAndGetIconId()); 141 EXPECT_EQ(kChargingImages[id], CallPowerChangedAndGetIconId());
98 id++; 142 id++;
99 } 143 }
100 } 144 }
101 145
102 IN_PROC_BROWSER_TEST_F(PowerMenuButtonTest, BatteryDischargingTest) { 146 IN_PROC_BROWSER_TEST_F(PowerMenuButtonTest, BatteryDischargingTest) {
147 const int NUM_TIMES = 12; // 6 + 8*12 = 102
103 EXPECT_CALL(*mock_power_library_, battery_is_present()) 148 EXPECT_CALL(*mock_power_library_, battery_is_present())
104 .WillRepeatedly((Return(true))); 149 .Times(NUM_TIMES)
150 .WillRepeatedly((Return(true)))
151 .RetiresOnSaturation();
105 EXPECT_CALL(*mock_power_library_, battery_fully_charged()) 152 EXPECT_CALL(*mock_power_library_, battery_fully_charged())
106 .WillRepeatedly((Return(false))); 153 .Times(NUM_TIMES)
154 .WillRepeatedly((Return(false)))
155 .RetiresOnSaturation();
107 EXPECT_CALL(*mock_power_library_, line_power_on()) 156 EXPECT_CALL(*mock_power_library_, line_power_on())
108 .WillRepeatedly((Return(false))); 157 .Times(NUM_TIMES)
158 .WillRepeatedly((Return(false)))
159 .RetiresOnSaturation();
160 EXPECT_CALL(*mock_power_library_, battery_time_to_empty())
161 .Times(NUM_TIMES)
162 .WillRepeatedly((Return(base::TimeDelta::FromMinutes(42))))
163 .RetiresOnSaturation();
164 EXPECT_CALL(*mock_power_library_, battery_time_to_full())
165 .Times(NUM_TIMES)
166 .WillRepeatedly((Return(base::TimeDelta::FromMinutes(24))))
167 .RetiresOnSaturation();
109 168
110 // Test the 12 battery discharing states. 169 // Test the 12 battery discharing states.
111 // NOTE: Use an array rather than just calculating a resource number to avoid 170 // NOTE: Use an array rather than just calculating a resource number to avoid
112 // creating implicit ordering dependencies on the resource values. 171 // creating implicit ordering dependencies on the resource values.
113 static const int kDischargingImages[] = { 172 static const int kDischargingImages[] = {
114 IDR_STATUSBAR_BATTERY_DISCHARGING_1, 173 IDR_STATUSBAR_BATTERY_DISCHARGING_1,
115 IDR_STATUSBAR_BATTERY_DISCHARGING_2, 174 IDR_STATUSBAR_BATTERY_DISCHARGING_2,
116 IDR_STATUSBAR_BATTERY_DISCHARGING_3, 175 IDR_STATUSBAR_BATTERY_DISCHARGING_3,
117 IDR_STATUSBAR_BATTERY_DISCHARGING_4, 176 IDR_STATUSBAR_BATTERY_DISCHARGING_4,
118 IDR_STATUSBAR_BATTERY_DISCHARGING_5, 177 IDR_STATUSBAR_BATTERY_DISCHARGING_5,
119 IDR_STATUSBAR_BATTERY_DISCHARGING_6, 178 IDR_STATUSBAR_BATTERY_DISCHARGING_6,
120 IDR_STATUSBAR_BATTERY_DISCHARGING_7, 179 IDR_STATUSBAR_BATTERY_DISCHARGING_7,
121 IDR_STATUSBAR_BATTERY_DISCHARGING_8, 180 IDR_STATUSBAR_BATTERY_DISCHARGING_8,
122 IDR_STATUSBAR_BATTERY_DISCHARGING_9, 181 IDR_STATUSBAR_BATTERY_DISCHARGING_9,
123 IDR_STATUSBAR_BATTERY_DISCHARGING_10, 182 IDR_STATUSBAR_BATTERY_DISCHARGING_10,
124 IDR_STATUSBAR_BATTERY_DISCHARGING_11, 183 IDR_STATUSBAR_BATTERY_DISCHARGING_11,
125 IDR_STATUSBAR_BATTERY_DISCHARGING_12, 184 IDR_STATUSBAR_BATTERY_DISCHARGING_12,
126 }; 185 };
127 size_t id = 0; 186 size_t id = 0;
128 for (float percent = 6.0; percent < 100.0; percent += 8.0) { 187 for (float percent = 6.0; percent < 100.0; percent += 8.0) {
129 EXPECT_CALL(*mock_power_library_, battery_percentage()) 188 EXPECT_CALL(*mock_power_library_, battery_percentage())
130 .WillRepeatedly((Return(percent))); 189 .WillOnce((Return(percent)))
190 .RetiresOnSaturation();
131 ASSERT_LT(id, arraysize(kDischargingImages)); 191 ASSERT_LT(id, arraysize(kDischargingImages));
132 EXPECT_EQ(kDischargingImages[id], CallPowerChangedAndGetIconId()); 192 EXPECT_EQ(kDischargingImages[id], CallPowerChangedAndGetIconId());
133 id++; 193 id++;
134 } 194 }
135 } 195 }
136 196
137 } // namespace chromeos 197 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/status/power_menu_button.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698