This source file includes following definitions.
- CreateNonClientFrameView
- custom_frame_view
- GetMinimumSize
- GetMaximumSize
- GetContentsView
- CanMaximize
- set_minimum_size
- set_maximum_size
- GetFrameCaptionButtonContainerViewBounds
- GetTitleBarHeight
- CreateWidget
- GetTestSessionStateDelegate
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
#include "ash/frame/custom_frame_view_ash.h"
#include "ash/frame/caption_buttons/frame_caption_button.h"
#include "ash/frame/caption_buttons/frame_caption_button_container_view.h"
#include "ash/shell.h"
#include "ash/test/ash_test_base.h"
#include "ash/test/test_session_state_delegate.h"
#include "base/memory/scoped_ptr.h"
#include "grit/ash_resources.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/rect.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_delegate.h"
namespace ash {
class TestWidgetDelegate : public views::WidgetDelegateView {
public:
TestWidgetDelegate() {}
virtual ~TestWidgetDelegate() {}
virtual views::NonClientFrameView* CreateNonClientFrameView(
views::Widget* widget) OVERRIDE {
custom_frame_view_ = new CustomFrameViewAsh(widget);
return custom_frame_view_;
}
CustomFrameViewAsh* custom_frame_view() const {
return custom_frame_view_;
}
private:
CustomFrameViewAsh* custom_frame_view_;
DISALLOW_COPY_AND_ASSIGN(TestWidgetDelegate);
};
class TestWidgetConstraintsDelegate : public TestWidgetDelegate {
public:
TestWidgetConstraintsDelegate() {}
virtual ~TestWidgetConstraintsDelegate() {}
virtual gfx::Size GetMinimumSize() OVERRIDE {
return minimum_size_;
}
virtual gfx::Size GetMaximumSize() OVERRIDE {
return maximum_size_;
}
virtual views::View* GetContentsView() OVERRIDE {
return this;
}
virtual bool CanMaximize() const OVERRIDE {
return true;
}
void set_minimum_size(const gfx::Size& min_size) {
minimum_size_ = min_size;
}
void set_maximum_size(const gfx::Size& max_size) {
maximum_size_ = max_size;
}
const gfx::Rect& GetFrameCaptionButtonContainerViewBounds() {
return custom_frame_view()->GetFrameCaptionButtonContainerViewForTest()->
bounds();
}
int GetTitleBarHeight() const {
return custom_frame_view()->NonClientTopBorderHeight();
}
private:
gfx::Size minimum_size_;
gfx::Size maximum_size_;
DISALLOW_COPY_AND_ASSIGN(TestWidgetConstraintsDelegate);
};
class CustomFrameViewAshTest : public test::AshTestBase {
public:
CustomFrameViewAshTest() {}
virtual ~CustomFrameViewAshTest() {}
protected:
scoped_ptr<views::Widget> CreateWidget(TestWidgetDelegate* delegate) {
scoped_ptr<views::Widget> widget(new views::Widget);
views::Widget::InitParams params;
params.delegate = delegate;
params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
params.bounds = gfx::Rect(0, 0, 100, 100);
params.context = CurrentContext();
widget->Init(params);
return widget.Pass();
}
test::TestSessionStateDelegate* GetTestSessionStateDelegate() {
return static_cast<ash::test::TestSessionStateDelegate*>(
Shell::GetInstance()->session_state_delegate());
}
private:
DISALLOW_COPY_AND_ASSIGN(CustomFrameViewAshTest);
};
TEST_F(CustomFrameViewAshTest, HeaderHeight) {
TestWidgetDelegate* delegate = new TestWidgetDelegate;
scoped_ptr<views::Widget> widget(CreateWidget(delegate));
widget->Show();
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
gfx::ImageSkia* close_button =
rb.GetImageSkiaNamed(IDR_AURA_WINDOW_CONTROL_BACKGROUND_H);
EXPECT_EQ(close_button->height(),
delegate->custom_frame_view()->GetHeaderView()->height());
}
TEST_F(CustomFrameViewAshTest, NoSizeConstraints) {
TestWidgetConstraintsDelegate* delegate = new TestWidgetConstraintsDelegate;
scoped_ptr<views::Widget> widget(CreateWidget(delegate));
CustomFrameViewAsh* custom_frame_view = delegate->custom_frame_view();
gfx::Size min_frame_size = custom_frame_view->GetMinimumSize();
gfx::Size max_frame_size = custom_frame_view->GetMaximumSize();
EXPECT_EQ(delegate->GetTitleBarHeight(), min_frame_size.height());
EXPECT_EQ(0, max_frame_size.width());
EXPECT_EQ(0, max_frame_size.height());
}
TEST_F(CustomFrameViewAshTest, MinimumAndMaximumSize) {
gfx::Size min_client_size(500, 500);
gfx::Size max_client_size(800, 800);
TestWidgetConstraintsDelegate* delegate = new TestWidgetConstraintsDelegate;
delegate->set_minimum_size(min_client_size);
delegate->set_maximum_size(max_client_size);
scoped_ptr<views::Widget> widget(CreateWidget(delegate));
CustomFrameViewAsh* custom_frame_view = delegate->custom_frame_view();
gfx::Size min_frame_size = custom_frame_view->GetMinimumSize();
gfx::Size max_frame_size = custom_frame_view->GetMaximumSize();
EXPECT_EQ(min_client_size.width(), min_frame_size.width());
EXPECT_EQ(max_client_size.width(), max_frame_size.width());
EXPECT_EQ(min_client_size.height() + delegate->GetTitleBarHeight(),
min_frame_size.height());
EXPECT_EQ(max_client_size.height() + delegate->GetTitleBarHeight(),
max_frame_size.height());
}
TEST_F(CustomFrameViewAshTest, AvatarIcon) {
TestWidgetConstraintsDelegate* delegate = new TestWidgetConstraintsDelegate;
scoped_ptr<views::Widget> widget(CreateWidget(delegate));
CustomFrameViewAsh* custom_frame_view = delegate->custom_frame_view();
EXPECT_FALSE(custom_frame_view->GetAvatarIconViewForTest());
const gfx::ImageSkia user_image =
*ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
IDR_AURA_UBER_TRAY_GUEST_ICON);
GetTestSessionStateDelegate()->SetUserImage(user_image);
widget->Hide();
widget->Show();
EXPECT_TRUE(custom_frame_view->GetAvatarIconViewForTest());
GetTestSessionStateDelegate()->SetUserImage(gfx::ImageSkia());
widget->Hide();
widget->Show();
EXPECT_FALSE(custom_frame_view->GetAvatarIconViewForTest());
}
TEST_F(CustomFrameViewAshTest, HeaderViewNotifiedOfChildSizeChange) {
TestWidgetConstraintsDelegate* delegate = new TestWidgetConstraintsDelegate;
scoped_ptr<views::Widget> widget(CreateWidget(delegate));
const gfx::Rect initial = delegate->
GetFrameCaptionButtonContainerViewBounds();
Shell::GetInstance()->EnableMaximizeModeWindowManager(true);
const gfx::Rect maximize_mode_bounds = delegate->
GetFrameCaptionButtonContainerViewBounds();
EXPECT_GT(initial.width(), maximize_mode_bounds.width());
Shell::GetInstance()->EnableMaximizeModeWindowManager(false);
const gfx::Rect after_restore = delegate->
GetFrameCaptionButtonContainerViewBounds();
EXPECT_EQ(initial, after_restore);
}
}