Commit 3701b4ea authored by derat@chromium.org's avatar derat@chromium.org

aura: Fix Chrome OS status area browser tests.

The tests for StatusAreaView, PowerMenuButton, and
CapsLockMenuButton were crashing when they tried to get the
StatusAreaView from chromeos::BrowserView, which isn't used
in Aura builds.  This change makes them instead get the
status area from the Aura shell.

BUG=103501,103495,104666
TEST=ran tests

Review URL: http://codereview.chromium.org/8591003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@111006 0039d316-1c4b-4281-b951-d872f2087c98
parent 317932e4
......@@ -18,7 +18,6 @@
#include "chrome/browser/chromeos/status/status_area_button.h"
#include "chrome/browser/chromeos/status/status_area_view_chromeos.h"
#include "chrome/browser/chromeos/system/runtime_environment.h"
#include "chrome/browser/chromeos/view_ids.h"
#include "chrome/browser/themes/theme_service.h"
#include "chrome/browser/themes/theme_service_factory.h"
#include "chrome/browser/ui/gtk/gtk_util.h"
......@@ -355,11 +354,9 @@ void BrowserView::Init() {
::BrowserView::Init();
status_area_ = new StatusAreaViewChromeos();
status_area_->Init(this, StatusAreaViewChromeos::BROWSER_MODE);
status_area_->set_id(VIEW_ID_STATUS_AREA);
AddChildView(status_area_);
layout_mode_button_ = new LayoutModeButton();
layout_mode_button_->set_id(VIEW_ID_LAYOUT_MODE_BUTTON);
AddChildView(layout_mode_button_);
layout_mode_button_->Init();
......
......@@ -6,6 +6,7 @@
#include "base/logging.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/chromeos/view_ids.h"
#include "chrome/common/chrome_notification_types.h"
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_source.h"
......@@ -28,6 +29,7 @@ namespace chromeos {
LayoutModeButton::LayoutModeButton()
: ALLOW_THIS_IN_INITIALIZER_LIST(ImageButton(this)) {
set_id(VIEW_ID_LAYOUT_MODE_BUTTON);
}
LayoutModeButton::~LayoutModeButton() {
......
......@@ -12,6 +12,10 @@
#include "chrome/browser/ui/browser_window.h"
#include "grit/theme_resources.h"
#if defined(USE_AURA)
#include "chrome/browser/ui/views/aura/chrome_shell_delegate.h"
#endif
namespace chromeos {
class CapsLockMenuButtonTest : public CrosInProcessBrowserTest {
......@@ -25,15 +29,20 @@ class CapsLockMenuButtonTest : public CrosInProcessBrowserTest {
cros_mock_->SetStatusAreaMocksExpectations();
}
CapsLockMenuButton* GetCapsLockMenuButton() {
BrowserView* view = static_cast<BrowserView*>(browser()->window());
return static_cast<CapsLockMenuButton*>(view->GetViewByID(
VIEW_ID_STATUS_BUTTON_CAPS_LOCK));
const CapsLockMenuButton* GetCapsLockMenuButton() {
const views::View* view =
#if defined(USE_AURA)
ChromeShellDelegate::instance()->GetStatusAreaForTest();
#else
static_cast<BrowserView*>(browser()->window());
#endif
return static_cast<const CapsLockMenuButton*>(
view->GetViewByID(VIEW_ID_STATUS_BUTTON_CAPS_LOCK));
}
};
IN_PROC_BROWSER_TEST_F(CapsLockMenuButtonTest, InitialIndicatorTest) {
CapsLockMenuButton* caps_lock = GetCapsLockMenuButton();
const CapsLockMenuButton* caps_lock = GetCapsLockMenuButton();
ASSERT_TRUE(caps_lock != NULL);
// By default, the indicator shouldn't be shown.
......
......@@ -34,12 +34,12 @@ class ClockMenuButtonTest : public InProcessBrowserTest {
const ClockMenuButton* GetClockMenuButton() {
const views::View* parent = NULL;
#if defined(USE_AURA)
parent = ChromeShellDelegate::instance()->GetStatusArea();
parent = ChromeShellDelegate::instance()->GetStatusAreaForTest();
#else
parent = static_cast<const BrowserView*>(browser()->window());
#endif
return static_cast<const ClockMenuButton*>(parent->GetViewByID(
VIEW_ID_STATUS_BUTTON_CLOCK));
return static_cast<const ClockMenuButton*>(
parent->GetViewByID(VIEW_ID_STATUS_BUTTON_CLOCK));
}
};
......
......@@ -9,6 +9,11 @@
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "views/view.h"
#if defined(USE_AURA)
#include "chrome/browser/ui/views/aura/chrome_shell_delegate.h"
#endif
namespace chromeos {
......@@ -21,9 +26,14 @@ class PowerMenuButtonTest : public InProcessBrowserTest {
}
PowerMenuButton* GetPowerMenuButton() {
BrowserView* view = static_cast<BrowserView*>(browser()->window());
return static_cast<PowerMenuButton*>(view->GetViewByID(
VIEW_ID_STATUS_BUTTON_POWER));
views::View* view =
#if defined(USE_AURA)
ChromeShellDelegate::instance()->GetStatusAreaForTest();
#else
static_cast<BrowserView*>(browser()->window());
#endif
return static_cast<PowerMenuButton*>(
view->GetViewByID(VIEW_ID_STATUS_BUTTON_POWER));
}
string16 CallPowerChangedAndGetTooltipText(const PowerSupplyStatus& status) {
......
......@@ -9,6 +9,7 @@
#include "base/bind.h"
#include "base/command_line.h"
#include "base/message_loop.h"
#include "chrome/browser/chromeos/view_ids.h"
#include "ui/gfx/canvas.h"
#include "views/border.h"
......@@ -21,6 +22,7 @@ const int kSeparation = 0;
StatusAreaView::StatusAreaView()
: need_return_focus_(false) {
set_id(VIEW_ID_STATUS_AREA);
}
StatusAreaView::~StatusAreaView() {
......
......@@ -7,20 +7,31 @@
#include "chrome/browser/chromeos/view_ids.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "views/view.h"
#if defined(USE_AURA)
#include "chrome/browser/ui/views/aura/chrome_shell_delegate.h"
#endif
namespace chromeos {
class StatusAreaViewTest : public InProcessBrowserTest {
protected:
StatusAreaViewTest() : InProcessBrowserTest() {}
StatusAreaView* GetStatusAreaView() {
BrowserView* view = static_cast<BrowserView*>(browser()->window());
return static_cast<StatusAreaView*>(view->GetViewByID(VIEW_ID_STATUS_AREA));
const StatusAreaView* GetStatusAreaView() {
const views::View* view =
#if defined(USE_AURA)
ChromeShellDelegate::instance()->GetStatusAreaForTest();
#else
static_cast<BrowserView*>(browser()->window());
#endif
return static_cast<const StatusAreaView*>(
view->GetViewByID(VIEW_ID_STATUS_AREA));
}
};
IN_PROC_BROWSER_TEST_F(StatusAreaViewTest, VisibleTest) {
StatusAreaView* status = GetStatusAreaView();
const StatusAreaView* status = GetStatusAreaView();
EXPECT_TRUE(status->IsVisibleInRootView());
EXPECT_FALSE(status->size().IsEmpty());
}
......
......@@ -24,8 +24,8 @@ ChromeShellDelegate::~ChromeShellDelegate() {
instance_ = NULL;
}
const views::View* ChromeShellDelegate::GetStatusArea() const {
return status_area_host_->GetStatusArea();
views::View* ChromeShellDelegate::GetStatusAreaForTest() {
return status_area_host_->GetStatusAreaForTest();
}
// static
......
......@@ -26,7 +26,7 @@ class ChromeShellDelegate : public aura_shell::ShellDelegate {
static ChromeShellDelegate* instance() { return instance_; }
const views::View* GetStatusArea() const;
views::View* GetStatusAreaForTest();
// Returns whether a launcher item should be created for |browser|. If an item
// should be created |type| is set to the launcher type to create.
......
......@@ -31,7 +31,7 @@ StatusAreaHostAura::StatusAreaHostAura()
StatusAreaHostAura::~StatusAreaHostAura() {
}
const views::View* StatusAreaHostAura::GetStatusArea() const {
views::View* StatusAreaHostAura::GetStatusAreaForTest() {
return status_area_view_;
}
......
......@@ -23,7 +23,7 @@ class StatusAreaHostAura : public StatusAreaButton::Delegate {
virtual ~StatusAreaHostAura();
// Returns the view housing the status area. Exposed for testing.
const views::View* GetStatusArea() const;
views::View* GetStatusAreaForTest();
// Instantiates and sets |status_area_view_|, and sets it as the contents of
// a new views::Widget |status_area_widget_| which is returned.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment