Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/clock_menu_button.h" | 5 #include "chrome/browser/chromeos/status/power_menu_button.h" |
| 6 | 6 |
| 7 #include "base/string_util.h" | |
| 8 #include "chrome/browser/browser.h" | 7 #include "chrome/browser/browser.h" |
| 9 #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" | |
| 10 #include "chrome/browser/chromeos/cros/mock_power_library.h" | |
| 10 #include "chrome/browser/chromeos/frame/browser_view.h" | 11 #include "chrome/browser/chromeos/frame/browser_view.h" |
| 11 #include "chrome/browser/chromeos/status/browser_status_area_view.h" | 12 #include "chrome/browser/chromeos/status/browser_status_area_view.h" |
| 12 #include "chrome/browser/chromeos/view_ids.h" | 13 #include "chrome/browser/chromeos/view_ids.h" |
| 13 #include "chrome/browser/pref_member.h" | 14 #include "grit/theme_resources.h" |
| 14 #include "chrome/browser/profile.h" | |
| 15 #include "chrome/common/pref_names.h" | |
| 16 #include "chrome/test/in_process_browser_test.h" | |
| 17 #include "testing/gtest/include/gtest/gtest.h" | |
| 18 #include "unicode/calendar.h" | |
| 19 #include "unicode/timezone.h" | |
| 20 | 15 |
| 21 namespace chromeos { | 16 namespace chromeos { |
| 17 using ::testing::AnyNumber; | |
| 18 using ::testing::InvokeWithoutArgs; | |
| 19 using ::testing::Return; | |
| 20 using ::testing::ReturnRef; | |
| 21 using ::testing::_; | |
| 22 | 22 |
| 23 class ClockMenuButtonTest : public InProcessBrowserTest { | 23 class PowerMenuButtonTest : public CrosInProcessBrowserTest { |
| 24 protected: | 24 protected: |
| 25 ClockMenuButtonTest() : InProcessBrowserTest() {} | 25 PowerMenuButtonTest() : CrosInProcessBrowserTest() {} |
| 26 ClockMenuButton* GetClockMenuButton() { | 26 |
| 27 PowerMenuButton* GetPowerMenuButton() { | |
| 27 BrowserView* view = static_cast<BrowserView*>(browser()->window()); | 28 BrowserView* view = static_cast<BrowserView*>(browser()->window()); |
| 28 return static_cast<BrowserStatusAreaView*>(view-> | 29 PowerMenuButton* power = static_cast<BrowserStatusAreaView*>(view-> |
| 29 GetViewByID(VIEW_ID_STATUS_AREA))->clock_view(); | 30 GetViewByID(VIEW_ID_STATUS_AREA))->power_view(); |
| 31 return power; | |
| 32 } | |
| 33 | |
| 34 int CallPowerChangedAndGetIconId() { | |
| 35 PowerMenuButton* power = GetPowerMenuButton(); | |
| 36 power->PowerChanged(mock_power_library_); | |
| 37 return power->icon_id(); | |
| 30 } | 38 } |
| 31 }; | 39 }; |
| 32 | 40 |
| 33 IN_PROC_BROWSER_TEST_F(ClockMenuButtonTest, TimezoneTest) { | 41 IN_PROC_BROWSER_TEST_F(PowerMenuButtonTest, BatteryMissingTest) { |
| 34 ClockMenuButton* clock = GetClockMenuButton(); | 42 EXPECT_CALL(*mock_power_library_, battery_is_present()) |
| 35 ASSERT_TRUE(clock != NULL); | 43 .WillRepeatedly((Return(false))); |
| 36 // Make sure clock has a calendar. | 44 EXPECT_EQ(IDR_STATUSBAR_BATTERY_MISSING, CallPowerChangedAndGetIconId()); |
| 37 ASSERT_TRUE(clock->calendar() != NULL); | 45 } |
| 38 // Update timezone and make sure clock timezone changes. | 46 |
| 39 icu::UnicodeString id; | 47 IN_PROC_BROWSER_TEST_F(PowerMenuButtonTest, BatteryChargedTest) { |
| 40 clock->calendar()->getTimeZone().getID(id); | 48 EXPECT_CALL(*mock_power_library_, battery_is_present()) |
| 41 UErrorCode error = U_ZERO_ERROR; | 49 .WillRepeatedly((Return(true))); |
| 42 int zone_offset = clock->calendar()->get(UCAL_ZONE_OFFSET, error); | 50 EXPECT_CALL(*mock_power_library_, battery_fully_charged()) |
| 43 StringPrefMember timezone; | 51 .WillRepeatedly((Return(true))); |
| 44 timezone.Init(prefs::kTimeZone, browser()->profile()->GetPrefs(), NULL); | 52 EXPECT_CALL(*mock_power_library_, line_power_on()) |
| 45 timezone.SetValue(ASCIIToWide("Asia/Hong_Kong")); | 53 .WillRepeatedly((Return(true))); |
| 46 int zone_offset_after = clock->calendar()->get(UCAL_ZONE_OFFSET, error); | 54 EXPECT_EQ(IDR_STATUSBAR_BATTERY_CHARGED, CallPowerChangedAndGetIconId()); |
| 47 EXPECT_NE(zone_offset, zone_offset_after); | 55 } |
| 56 | |
| 57 IN_PROC_BROWSER_TEST_F(PowerMenuButtonTest, BatteryChargingTest) { | |
| 58 EXPECT_CALL(*mock_power_library_, battery_is_present()) | |
| 59 .WillRepeatedly((Return(true))); | |
| 60 EXPECT_CALL(*mock_power_library_, battery_fully_charged()) | |
| 61 .WillRepeatedly((Return(false))); | |
| 62 EXPECT_CALL(*mock_power_library_, line_power_on()) | |
| 63 .WillRepeatedly((Return(true))); | |
| 64 | |
| 65 // Test the 12 battery charging states. | |
| 66 int id = IDR_STATUSBAR_BATTERY_CHARGING_1; | |
| 67 for (float precent = 6.0; precent < 100.0; precent += 8.0) { | |
| 68 EXPECT_CALL(*mock_power_library_, battery_percentage()) | |
| 69 .WillRepeatedly((Return(precent))); | |
| 70 EXPECT_EQ(id, CallPowerChangedAndGetIconId()); | |
|
zel
2010/03/25 21:11:11
This might not actually work the way you expect it
| |
| 71 id++; | |
| 72 } | |
| 73 } | |
| 74 | |
| 75 IN_PROC_BROWSER_TEST_F(PowerMenuButtonTest, BatteryDischargingTest) { | |
| 76 EXPECT_CALL(*mock_power_library_, battery_is_present()) | |
| 77 .WillRepeatedly((Return(true))); | |
| 78 EXPECT_CALL(*mock_power_library_, battery_fully_charged()) | |
| 79 .WillRepeatedly((Return(false))); | |
| 80 EXPECT_CALL(*mock_power_library_, line_power_on()) | |
| 81 .WillRepeatedly((Return(false))); | |
| 82 | |
| 83 // Test the 12 battery discharing states. | |
| 84 int id = IDR_STATUSBAR_BATTERY_DISCHARGING_1; | |
| 85 for (float precent = 6.0; precent < 100.0; precent += 8.0) { | |
| 86 EXPECT_CALL(*mock_power_library_, battery_percentage()) | |
| 87 .WillRepeatedly((Return(precent))); | |
| 88 EXPECT_EQ(id, CallPowerChangedAndGetIconId()); | |
| 89 id++; | |
| 90 } | |
| 48 } | 91 } |
| 49 | 92 |
| 50 } // namespace chromeos | 93 } // namespace chromeos |
| OLD | NEW |