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

Unified Diff: chrome/browser/chromeos/status/power_menu_button_browsertest.cc

Issue 1338003: Add test for power_menu_button. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 10 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/chromeos/status/power_menu_button.cc ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chromeos/status/power_menu_button_browsertest.cc
===================================================================
--- chrome/browser/chromeos/status/power_menu_button_browsertest.cc (revision 42551)
+++ chrome/browser/chromeos/status/power_menu_button_browsertest.cc (working copy)
@@ -2,49 +2,92 @@
// 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/clock_menu_button.h"
+#include "chrome/browser/chromeos/status/power_menu_button.h"
-#include "base/string_util.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 "chrome/browser/pref_member.h"
-#include "chrome/browser/profile.h"
-#include "chrome/common/pref_names.h"
-#include "chrome/test/in_process_browser_test.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "unicode/calendar.h"
-#include "unicode/timezone.h"
+#include "grit/theme_resources.h"
namespace chromeos {
+using ::testing::AnyNumber;
+using ::testing::InvokeWithoutArgs;
+using ::testing::Return;
+using ::testing::ReturnRef;
+using ::testing::_;
-class ClockMenuButtonTest : public InProcessBrowserTest {
+class PowerMenuButtonTest : public CrosInProcessBrowserTest {
protected:
- ClockMenuButtonTest() : InProcessBrowserTest() {}
- ClockMenuButton* GetClockMenuButton() {
+ PowerMenuButtonTest() : CrosInProcessBrowserTest() {}
+
+ PowerMenuButton* GetPowerMenuButton() {
BrowserView* view = static_cast<BrowserView*>(browser()->window());
- return static_cast<BrowserStatusAreaView*>(view->
- GetViewByID(VIEW_ID_STATUS_AREA))->clock_view();
+ 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(ClockMenuButtonTest, TimezoneTest) {
- ClockMenuButton* clock = GetClockMenuButton();
- ASSERT_TRUE(clock != NULL);
- // Make sure clock has a calendar.
- ASSERT_TRUE(clock->calendar() != NULL);
- // Update timezone and make sure clock timezone changes.
- icu::UnicodeString id;
- clock->calendar()->getTimeZone().getID(id);
- UErrorCode error = U_ZERO_ERROR;
- int zone_offset = clock->calendar()->get(UCAL_ZONE_OFFSET, error);
- StringPrefMember timezone;
- timezone.Init(prefs::kTimeZone, browser()->profile()->GetPrefs(), NULL);
- timezone.SetValue(ASCIIToWide("Asia/Hong_Kong"));
- int zone_offset_after = clock->calendar()->get(UCAL_ZONE_OFFSET, error);
- EXPECT_NE(zone_offset, zone_offset_after);
+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());
zel 2010/03/25 21:11:11 This might not actually work the way you expect it
+ 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
« no previous file with comments | « chrome/browser/chromeos/status/power_menu_button.cc ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698