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" | |
11 #include "chrome/browser/chromeos/view_ids.h" | 10 #include "chrome/browser/chromeos/view_ids.h" |
12 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
13 #include "chrome/browser/ui/browser_window.h" | 12 #include "chrome/browser/ui/browser_window.h" |
14 #include "grit/theme_resources.h" | 13 #include "grit/theme_resources.h" |
15 | 14 |
16 namespace { | 15 namespace { |
17 const int kNumBatteryStates = 20; | 16 const int kNumBatteryStates = 20; |
18 } | 17 } |
19 namespace chromeos { | 18 namespace chromeos { |
20 using ::testing::AnyNumber; | 19 using ::testing::AnyNumber; |
21 using ::testing::InvokeWithoutArgs; | 20 using ::testing::InvokeWithoutArgs; |
22 using ::testing::Return; | 21 using ::testing::Return; |
23 using ::testing::ReturnRef; | 22 using ::testing::ReturnRef; |
24 using ::testing::_; | 23 using ::testing::_; |
25 | 24 |
26 class PowerMenuButtonTest : public CrosInProcessBrowserTest { | 25 class PowerMenuButtonTest : public CrosInProcessBrowserTest { |
27 protected: | 26 protected: |
28 PowerMenuButtonTest() : CrosInProcessBrowserTest() { | 27 PowerMenuButtonTest() : CrosInProcessBrowserTest() { |
29 } | 28 } |
30 | 29 |
31 virtual void SetUpInProcessBrowserTestFixture() { | 30 virtual void SetUpInProcessBrowserTestFixture() { |
32 cros_mock_->InitStatusAreaMocks(); | 31 cros_mock_->InitStatusAreaMocks(); |
33 cros_mock_->SetStatusAreaMocksExpectations(); | 32 cros_mock_->SetStatusAreaMocksExpectations(); |
34 } | 33 } |
35 | 34 |
36 PowerMenuButton* GetPowerMenuButton() { | 35 PowerMenuButton* GetPowerMenuButton() { |
37 BrowserView* view = static_cast<BrowserView*>(browser()->window()); | 36 BrowserView* view = static_cast<BrowserView*>(browser()->window()); |
38 PowerMenuButton* power = static_cast<StatusAreaView*>(view-> | 37 return static_cast<PowerMenuButton*>(view->GetViewByID( |
39 GetViewByID(VIEW_ID_STATUS_AREA))->power_view(); | 38 VIEW_ID_STATUS_BUTTON_POWER)); |
40 return power; | |
41 } | 39 } |
42 | 40 |
43 int CallPowerChangedAndGetBatteryIndex(const PowerSupplyStatus& status) { | 41 int CallPowerChangedAndGetBatteryIndex(const PowerSupplyStatus& status) { |
44 PowerMenuButton* power = GetPowerMenuButton(); | 42 PowerMenuButton* power = GetPowerMenuButton(); |
45 power->PowerChanged(status); | 43 power->PowerChanged(status); |
46 return power->battery_index(); | 44 return power->battery_index(); |
47 } | 45 } |
48 }; | 46 }; |
49 | 47 |
50 IN_PROC_BROWSER_TEST_F(PowerMenuButtonTest, BatteryMissingTest) { | 48 IN_PROC_BROWSER_TEST_F(PowerMenuButtonTest, BatteryMissingTest) { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 // Simulate various levels of discharging. | 99 // Simulate various levels of discharging. |
102 int index = 0; | 100 int index = 0; |
103 for (float percent = 5.0; percent < 100.0; percent += 5.0) { | 101 for (float percent = 5.0; percent < 100.0; percent += 5.0) { |
104 status.battery_percentage = percent; | 102 status.battery_percentage = percent; |
105 EXPECT_EQ(index, CallPowerChangedAndGetBatteryIndex(status)); | 103 EXPECT_EQ(index, CallPowerChangedAndGetBatteryIndex(status)); |
106 index++; | 104 index++; |
107 } | 105 } |
108 } | 106 } |
109 | 107 |
110 } // namespace chromeos | 108 } // namespace chromeos |
OLD | NEW |