summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorchocobo@chromium.org <chocobo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-23 18:50:06 +0000
committerchocobo@chromium.org <chocobo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-23 18:50:06 +0000
commit87eb037dbee1b56460aaee272bc18c3db2fd1adf (patch)
tree62a980d94438a44e336a77f19a6d3b20e829a6c2 /chrome/browser
parent89622004872be7f7ddaa24fa1694f76c7b9539b6 (diff)
downloadchromium_src-87eb037dbee1b56460aaee272bc18c3db2fd1adf.zip
chromium_src-87eb037dbee1b56460aaee272bc18c3db2fd1adf.tar.gz
chromium_src-87eb037dbee1b56460aaee272bc18c3db2fd1adf.tar.bz2
Add tests for ClockMenuButton.
Review URL: http://codereview.chromium.org/1130008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@42364 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/chromeos/frame/browser_view.cc17
-rw-r--r--chrome/browser/chromeos/status/clock_menu_button.cc11
-rw-r--r--chrome/browser/chromeos/status/clock_menu_button.h4
-rw-r--r--chrome/browser/chromeos/status/clock_menu_button_browsertest.cc50
-rw-r--r--chrome/browser/view_ids.h9
5 files changed, 71 insertions, 20 deletions
diff --git a/chrome/browser/chromeos/frame/browser_view.cc b/chrome/browser/chromeos/frame/browser_view.cc
index 0520eb6..db06e22 100644
--- a/chrome/browser/chromeos/frame/browser_view.cc
+++ b/chrome/browser/chromeos/frame/browser_view.cc
@@ -17,7 +17,6 @@
#include "chrome/browser/chromeos/status/network_menu_button.h"
#include "chrome/browser/chromeos/status/status_area_button.h"
#include "chrome/browser/chromeos/wm_ipc.h"
-#include "chrome/browser/view_ids.h"
#include "chrome/browser/views/app_launcher.h"
#include "chrome/browser/views/frame/browser_extender.h"
#include "chrome/browser/views/frame/browser_frame_gtk.h"
@@ -27,6 +26,7 @@
#include "chrome/browser/views/tabs/tab_strip.h"
#include "chrome/browser/views/toolbar_view.h"
#include "chrome/browser/views/toolbar_star_toggle.h"
+#include "chrome/browser/view_ids.h"
#include "gfx/canvas.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
@@ -107,17 +107,6 @@ class ChromeosTabStrip : public TabStrip {
DISALLOW_COPY_AND_ASSIGN(ChromeosTabStrip);
};
-// View ID used only in ChromeOS.
-enum ChromeOSViewIds {
- // Start with the offset that is big enough to avoid possible
- // collison.
- VIEW_ID_MAIN_MENU = VIEW_ID_PREDEFINED_COUNT + 10000,
- VIEW_ID_COMPACT_NAV_BAR,
- VIEW_ID_STATUS_AREA,
- VIEW_ID_SPACER,
- VIEW_ID_OTR_AVATAR,
-};
-
} // namespace
namespace chromeos {
@@ -150,7 +139,7 @@ class BrowserViewLayout : public ::BrowserViewLayout {
case VIEW_ID_SPACER:
spacer_ = view;
break;
- case VIEW_ID_MAIN_MENU:
+ case VIEW_ID_APP_MENU_BUTTON:
main_menu_button_ = view;
break;
case VIEW_ID_STATUS_AREA:
@@ -358,7 +347,7 @@ BrowserView::~BrowserView() {
void BrowserView::Init() {
::BrowserView::Init();
main_menu_button_ = new views::ImageButton(this);
- main_menu_button_->SetID(VIEW_ID_MAIN_MENU);
+ main_menu_button_->SetID(VIEW_ID_APP_MENU_BUTTON);
ThemeProvider* theme_provider =
frame()->GetThemeProviderForFrame();
SkBitmap* image = theme_provider->GetBitmapNamed(IDR_APP_LAUNCHER_BUTTON);
diff --git a/chrome/browser/chromeos/status/clock_menu_button.cc b/chrome/browser/chromeos/status/clock_menu_button.cc
index d36d233..efc2767 100644
--- a/chrome/browser/chromeos/status/clock_menu_button.cc
+++ b/chrome/browser/chromeos/status/clock_menu_button.cc
@@ -16,7 +16,6 @@
#include "gfx/canvas.h"
#include "gfx/font.h"
#include "grit/generated_resources.h"
-#include "unicode/calendar.h"
namespace chromeos {
@@ -72,13 +71,13 @@ void ClockMenuButton::UpdateText() {
// Use icu::Calendar because the correct timezone is set on icu::TimeZone's
// default timezone.
UErrorCode error = U_ZERO_ERROR;
- scoped_ptr<icu::Calendar> cal(icu::Calendar::createInstance(error));
- if (!cal.get())
+ cal_.reset(icu::Calendar::createInstance(error));
+ if (!cal_.get())
return;
- int hour = cal->get(UCAL_HOUR, error);
- int minute = cal->get(UCAL_MINUTE, error);
- int ampm = cal->get(UCAL_AM_PM, error);
+ int hour = cal_->get(UCAL_HOUR, error);
+ int minute = cal_->get(UCAL_MINUTE, error);
+ int ampm = cal_->get(UCAL_AM_PM, error);
if (hour == 0)
hour = 12;
diff --git a/chrome/browser/chromeos/status/clock_menu_button.h b/chrome/browser/chromeos/status/clock_menu_button.h
index d94f182..d0cadb4 100644
--- a/chrome/browser/chromeos/status/clock_menu_button.h
+++ b/chrome/browser/chromeos/status/clock_menu_button.h
@@ -10,6 +10,7 @@
#include "chrome/browser/pref_member.h"
#include "chrome/common/notification_observer.h"
#include "chrome/common/notification_service.h"
+#include "unicode/calendar.h"
#include "views/controls/button/menu_button.h"
#include "views/controls/menu/menu_2.h"
#include "views/controls/menu/view_menu_delegate.h"
@@ -51,6 +52,8 @@ class ClockMenuButton : public views::MenuButton,
const NotificationSource& source,
const NotificationDetails& details);
+ const icu::Calendar* calendar() const { return cal_.get(); }
+
// Updates the time on the menu button. Can be called by host if timezone
// changes.
void UpdateText();
@@ -63,6 +66,7 @@ class ClockMenuButton : public views::MenuButton,
void UpdateTextAndSetNextTimer();
base::OneShotTimer<ClockMenuButton> timer_;
+ scoped_ptr<icu::Calendar> cal_;
// The clock menu.
// NOTE: we use a scoped_ptr here as menu calls into 'this' from the
diff --git a/chrome/browser/chromeos/status/clock_menu_button_browsertest.cc b/chrome/browser/chromeos/status/clock_menu_button_browsertest.cc
new file mode 100644
index 0000000..973bafb
--- /dev/null
+++ b/chrome/browser/chromeos/status/clock_menu_button_browsertest.cc
@@ -0,0 +1,50 @@
+// 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/clock_menu_button.h"
+
+#include "base/string_util.h"
+#include "chrome/browser/browser.h"
+#include "chrome/browser/browser_window.h"
+#include "chrome/browser/chromeos/frame/browser_view.h"
+#include "chrome/browser/chromeos/status/browser_status_area_view.h"
+#include "chrome/browser/pref_member.h"
+#include "chrome/browser/profile.h"
+#include "chrome/browser/view_ids.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"
+
+namespace chromeos {
+
+class ClockMenuButtonTest : public InProcessBrowserTest {
+ protected:
+ ClockMenuButtonTest() : InProcessBrowserTest() {}
+ ClockMenuButton* GetClockMenuButton() {
+ BrowserView* view = static_cast<BrowserView*>(browser()->window());
+ return static_cast<BrowserStatusAreaView*>(view->
+ GetViewByID(VIEW_ID_STATUS_AREA))->clock_view();
+ }
+};
+
+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);
+}
+
+} // namespace chromeos
diff --git a/chrome/browser/view_ids.h b/chrome/browser/view_ids.h
index 57943da..0cd6e30 100644
--- a/chrome/browser/view_ids.h
+++ b/chrome/browser/view_ids.h
@@ -71,6 +71,15 @@ enum ViewID {
// The Download shelf.
VIEW_ID_DOWNLOAD_SHELF,
+#if defined(OS_CHROMEOS)
+ // ChromeOS view ids start here.
+ VIEW_ID_APP_MENU_BUTTON = 10000,
+ VIEW_ID_COMPACT_NAV_BAR,
+ VIEW_ID_STATUS_AREA,
+ VIEW_ID_SPACER,
+ VIEW_ID_OTR_AVATAR,
+#endif
+
// Used in chrome/browser/gtk/view_id_util_browsertests.cc
// If you add new ids, make sure the above test passes.
VIEW_ID_PREDEFINED_COUNT