diff options
author | chocobo@chromium.org <chocobo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-25 23:43:16 +0000 |
---|---|---|
committer | chocobo@chromium.org <chocobo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-25 23:43:16 +0000 |
commit | 90342a74214caedb3f9063375ab153563afb81fe (patch) | |
tree | d5c67d03ecdb87ddec31236fd216df53039f5e52 /chrome/browser/chromeos/status/power_menu_button_browsertest.cc | |
parent | 25edef40e0b04e7537d6a876eeba312c3d1ebb78 (diff) | |
download | chromium_src-90342a74214caedb3f9063375ab153563afb81fe.zip chromium_src-90342a74214caedb3f9063375ab153563afb81fe.tar.gz chromium_src-90342a74214caedb3f9063375ab153563afb81fe.tar.bz2 |
Add test for power_menu_button.
BUG=none
TEST=power_menu_button_browsertest
Review URL: http://codereview.chromium.org/1338003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@42695 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/chromeos/status/power_menu_button_browsertest.cc')
-rw-r--r-- | chrome/browser/chromeos/status/power_menu_button_browsertest.cc | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/chrome/browser/chromeos/status/power_menu_button_browsertest.cc b/chrome/browser/chromeos/status/power_menu_button_browsertest.cc new file mode 100644 index 0000000..fe627df --- /dev/null +++ b/chrome/browser/chromeos/status/power_menu_button_browsertest.cc @@ -0,0 +1,93 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/chromeos/status/power_menu_button.h" + +#include "chrome/browser/browser.h" +#include "chrome/browser/browser_window.h" +#include "chrome/browser/chromeos/cros/cros_in_process_browser_test.h" +#include "chrome/browser/chromeos/cros/mock_power_library.h" +#include "chrome/browser/chromeos/frame/browser_view.h" +#include "chrome/browser/chromeos/status/browser_status_area_view.h" +#include "chrome/browser/chromeos/view_ids.h" +#include "grit/theme_resources.h" + +namespace chromeos { +using ::testing::AnyNumber; +using ::testing::InvokeWithoutArgs; +using ::testing::Return; +using ::testing::ReturnRef; +using ::testing::_; + +class PowerMenuButtonTest : public CrosInProcessBrowserTest { + protected: + PowerMenuButtonTest() : CrosInProcessBrowserTest() {} + + PowerMenuButton* GetPowerMenuButton() { + BrowserView* view = static_cast<BrowserView*>(browser()->window()); + PowerMenuButton* power = static_cast<BrowserStatusAreaView*>(view-> + GetViewByID(VIEW_ID_STATUS_AREA))->power_view(); + return power; + } + + int CallPowerChangedAndGetIconId() { + PowerMenuButton* power = GetPowerMenuButton(); + power->PowerChanged(mock_power_library_); + return power->icon_id(); + } +}; + +IN_PROC_BROWSER_TEST_F(PowerMenuButtonTest, BatteryMissingTest) { + EXPECT_CALL(*mock_power_library_, battery_is_present()) + .WillRepeatedly((Return(false))); + EXPECT_EQ(IDR_STATUSBAR_BATTERY_MISSING, CallPowerChangedAndGetIconId()); +} + +IN_PROC_BROWSER_TEST_F(PowerMenuButtonTest, BatteryChargedTest) { + EXPECT_CALL(*mock_power_library_, battery_is_present()) + .WillRepeatedly((Return(true))); + EXPECT_CALL(*mock_power_library_, battery_fully_charged()) + .WillRepeatedly((Return(true))); + EXPECT_CALL(*mock_power_library_, line_power_on()) + .WillRepeatedly((Return(true))); + EXPECT_EQ(IDR_STATUSBAR_BATTERY_CHARGED, CallPowerChangedAndGetIconId()); +} + +IN_PROC_BROWSER_TEST_F(PowerMenuButtonTest, BatteryChargingTest) { + EXPECT_CALL(*mock_power_library_, battery_is_present()) + .WillRepeatedly((Return(true))); + EXPECT_CALL(*mock_power_library_, battery_fully_charged()) + .WillRepeatedly((Return(false))); + EXPECT_CALL(*mock_power_library_, line_power_on()) + .WillRepeatedly((Return(true))); + + // Test the 12 battery charging states. + int id = IDR_STATUSBAR_BATTERY_CHARGING_1; + for (float precent = 6.0; precent < 100.0; precent += 8.0) { + EXPECT_CALL(*mock_power_library_, battery_percentage()) + .WillRepeatedly((Return(precent))); + EXPECT_EQ(id, CallPowerChangedAndGetIconId()); + id++; + } +} + +IN_PROC_BROWSER_TEST_F(PowerMenuButtonTest, BatteryDischargingTest) { + EXPECT_CALL(*mock_power_library_, battery_is_present()) + .WillRepeatedly((Return(true))); + EXPECT_CALL(*mock_power_library_, battery_fully_charged()) + .WillRepeatedly((Return(false))); + EXPECT_CALL(*mock_power_library_, line_power_on()) + .WillRepeatedly((Return(false))); + + // Test the 12 battery discharing states. + int id = IDR_STATUSBAR_BATTERY_DISCHARGING_1; + for (float precent = 6.0; precent < 100.0; precent += 8.0) { + EXPECT_CALL(*mock_power_library_, battery_percentage()) + .WillRepeatedly((Return(precent))); + EXPECT_EQ(id, CallPowerChangedAndGetIconId()); + id++; + } +} + +} // namespace chromeos |