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/frame/browser_view.h" | 7 #include "chrome/browser/chromeos/frame/browser_view.h" |
8 #include "chrome/browser/chromeos/view_ids.h" | 8 #include "chrome/browser/chromeos/view_ids.h" |
9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
10 #include "chrome/browser/ui/browser_window.h" | 10 #include "chrome/browser/ui/browser_window.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 } | 21 } |
22 | 22 |
23 PowerMenuButton* GetPowerMenuButton() { | 23 PowerMenuButton* GetPowerMenuButton() { |
24 BrowserView* view = static_cast<BrowserView*>(browser()->window()); | 24 BrowserView* view = static_cast<BrowserView*>(browser()->window()); |
25 return static_cast<PowerMenuButton*>(view->GetViewByID( | 25 return static_cast<PowerMenuButton*>(view->GetViewByID( |
26 VIEW_ID_STATUS_BUTTON_POWER)); | 26 VIEW_ID_STATUS_BUTTON_POWER)); |
27 } | 27 } |
28 | 28 |
29 string16 CallPowerChangedAndGetTooltipText(const PowerSupplyStatus& status) { | 29 string16 CallPowerChangedAndGetTooltipText(const PowerSupplyStatus& status) { |
30 PowerMenuButton* power = GetPowerMenuButton(); | 30 PowerMenuButton* power = GetPowerMenuButton(); |
| 31 |
31 power->PowerChanged(status); | 32 power->PowerChanged(status); |
| 33 EXPECT_TRUE(power->IsVisible()); |
| 34 |
32 string16 tooltip; | 35 string16 tooltip; |
33 // There is static_cast<StatusAreaButton*> because GetTootipText is also | 36 // There is static_cast<StatusAreaButton*> because GetTootipText is also |
34 // declared in MenuDelegate | 37 // declared in MenuDelegate |
35 EXPECT_TRUE(static_cast<StatusAreaButton*>(power)->GetTooltipText( | 38 EXPECT_TRUE(static_cast<StatusAreaButton*>(power)->GetTooltipText( |
36 gfx::Point(0, 0), &tooltip)); | 39 gfx::Point(0, 0), &tooltip)); |
37 return tooltip; | 40 return tooltip; |
38 } | 41 } |
39 | 42 |
40 string16 SetBatteryPercentageTo50AndGetTooltipText() { | 43 string16 SetBatteryPercentageTo50AndGetTooltipText() { |
41 PowerSupplyStatus status; | 44 PowerSupplyStatus status; |
42 // No battery present. | 45 // No battery present. |
43 status.battery_is_present = true; | 46 status.battery_is_present = true; |
44 status.battery_percentage = 50.0; | 47 status.battery_percentage = 50.0; |
45 status.battery_is_full = false; | 48 status.battery_is_full = false; |
46 status.line_power_on = false; | 49 status.line_power_on = false; |
47 status.battery_seconds_to_empty = 42; | 50 status.battery_seconds_to_empty = 42; |
48 status.battery_seconds_to_full = 24; | 51 status.battery_seconds_to_full = 24; |
49 return CallPowerChangedAndGetTooltipText(status); | 52 return CallPowerChangedAndGetTooltipText(status); |
50 } | 53 } |
51 }; | 54 }; |
52 | 55 |
53 IN_PROC_BROWSER_TEST_F(PowerMenuButtonTest, BatteryMissingTest) { | 56 IN_PROC_BROWSER_TEST_F(PowerMenuButtonTest, BatteryMissingTest) { |
54 const string16 tooltip_before = SetBatteryPercentageTo50AndGetTooltipText(); | 57 const string16 tooltip_before = SetBatteryPercentageTo50AndGetTooltipText(); |
55 | 58 |
56 PowerSupplyStatus status; | 59 PowerSupplyStatus status; |
57 // No battery present. | 60 // No battery present. |
58 status.battery_is_present = false; | 61 status.battery_is_present = false; |
59 status.battery_percentage = 42.0; | 62 status.battery_percentage = 42.0; |
60 status.battery_is_full = false; | 63 status.battery_is_full = false; |
| 64 status.line_power_on = true; |
| 65 status.battery_seconds_to_empty = 42; |
| 66 status.battery_seconds_to_full = 24; |
| 67 |
| 68 PowerMenuButton* power = GetPowerMenuButton(); |
| 69 power->PowerChanged(status); |
| 70 |
| 71 EXPECT_FALSE(power->IsVisible()); |
| 72 } |
| 73 |
| 74 IN_PROC_BROWSER_TEST_F(PowerMenuButtonTest, BatteryNotSupportedTest) { |
| 75 PowerSupplyStatus status; |
| 76 // No battery present. |
| 77 status.battery_is_present = false; |
| 78 status.battery_percentage = 42.0; |
| 79 status.battery_is_full = false; |
61 status.line_power_on = false; | 80 status.line_power_on = false; |
62 status.battery_seconds_to_empty = 42; | 81 status.battery_seconds_to_empty = 42; |
63 status.battery_seconds_to_full = 24; | 82 status.battery_seconds_to_full = 24; |
64 | 83 |
65 EXPECT_NE(tooltip_before, CallPowerChangedAndGetTooltipText(status)); | 84 PowerMenuButton* power = GetPowerMenuButton(); |
| 85 power->PowerChanged(status); |
| 86 |
| 87 EXPECT_FALSE(power->IsVisible()); |
66 } | 88 } |
67 | 89 |
68 IN_PROC_BROWSER_TEST_F(PowerMenuButtonTest, BatteryChargedTest) { | 90 IN_PROC_BROWSER_TEST_F(PowerMenuButtonTest, BatteryChargedTest) { |
69 const string16 tooltip_before = SetBatteryPercentageTo50AndGetTooltipText(); | 91 const string16 tooltip_before = SetBatteryPercentageTo50AndGetTooltipText(); |
70 | 92 |
71 PowerSupplyStatus status; | 93 PowerSupplyStatus status; |
72 // The battery is fully charged, and line power is plugged in. | 94 // The battery is fully charged, and line power is plugged in. |
73 status.battery_is_present = true; | 95 status.battery_is_present = true; |
74 status.battery_percentage = 42.0; | 96 status.battery_percentage = 42.0; |
75 status.battery_is_full = true; | 97 status.battery_is_full = true; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 // Simulate various levels of discharging. | 134 // Simulate various levels of discharging. |
113 for (double percent = 5.0; percent < 100.0; percent += 5.0) { | 135 for (double percent = 5.0; percent < 100.0; percent += 5.0) { |
114 status.battery_percentage = percent; | 136 status.battery_percentage = percent; |
115 const string16 tooltip_after = CallPowerChangedAndGetTooltipText(status); | 137 const string16 tooltip_after = CallPowerChangedAndGetTooltipText(status); |
116 EXPECT_NE(tooltip_before, tooltip_after); | 138 EXPECT_NE(tooltip_before, tooltip_after); |
117 tooltip_before = tooltip_after; | 139 tooltip_before = tooltip_after; |
118 } | 140 } |
119 } | 141 } |
120 | 142 |
121 } // namespace chromeos | 143 } // namespace chromeos |
OLD | NEW |