This source file includes following definitions.
- GetContentsView
- CanResize
- CanMaximize
- caption_button_container
- Layout
- ViewHierarchyChanged
- CenterPointInScreen
- HasStateType
- AllButtonsInNormalState
- CreateWidget
- SetUp
- window_state
- window_state
- minimize_button
- size_button
- close_button
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- SetUp
- TearDown
- TEST_F
#include "ash/frame/caption_buttons/alternate_frame_size_button.h"
#include "ash/ash_switches.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/wm/window_state.h"
#include "base/command_line.h"
#include "base/i18n/rtl.h"
#include "grit/ash_resources.h"
#include "ui/aura/test/event_generator.h"
#include "ui/aura/window.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/events/gestures/gesture_configuration.h"
#include "ui/gfx/display.h"
#include "ui/gfx/screen.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_delegate.h"
namespace ash {
namespace test {
namespace {
class TestWidgetDelegate : public views::WidgetDelegateView {
public:
TestWidgetDelegate() {}
virtual ~TestWidgetDelegate() {}
virtual views::View* GetContentsView() OVERRIDE {
return this;
}
virtual bool CanResize() const OVERRIDE {
return true;
}
virtual bool CanMaximize() const OVERRIDE {
return true;
}
ash::FrameCaptionButtonContainerView* caption_button_container() {
return caption_button_container_;
}
private:
virtual void Layout() OVERRIDE {
caption_button_container_->Layout();
gfx::Size preferred_size = caption_button_container_->GetPreferredSize();
caption_button_container_->SetBounds(width() - preferred_size.width(), 0,
preferred_size.width(), preferred_size.height());
}
virtual void ViewHierarchyChanged(
const ViewHierarchyChangedDetails& details) OVERRIDE {
if (details.is_add && details.child == this) {
caption_button_container_ = new FrameCaptionButtonContainerView(
GetWidget(), FrameCaptionButtonContainerView::MINIMIZE_ALLOWED);
for (int icon = 0; icon < CAPTION_BUTTON_ICON_COUNT; ++icon) {
caption_button_container_->SetButtonImages(
static_cast<CaptionButtonIcon>(icon),
IDR_AURA_WINDOW_CONTROL_ICON_CLOSE,
IDR_AURA_WINDOW_CONTROL_ICON_CLOSE_I,
IDR_AURA_WINDOW_CONTROL_BACKGROUND_H,
IDR_AURA_WINDOW_CONTROL_BACKGROUND_P);
}
AddChildView(caption_button_container_);
}
}
ash::FrameCaptionButtonContainerView* caption_button_container_;
DISALLOW_COPY_AND_ASSIGN(TestWidgetDelegate);
};
}
class AlternateFrameSizeButtonTest : public AshTestBase {
public:
AlternateFrameSizeButtonTest() {}
virtual ~AlternateFrameSizeButtonTest() {}
gfx::Point CenterPointInScreen(views::View* view) {
return view->GetBoundsInScreen().CenterPoint();
}
bool HasStateType(wm::WindowStateType state_type) const {
return window_state()->GetStateType() == state_type;
}
bool AllButtonsInNormalState() const {
return minimize_button_->state() == views::Button::STATE_NORMAL &&
size_button_->state() == views::Button::STATE_NORMAL &&
close_button_->state() == views::Button::STATE_NORMAL;
}
views::Widget* CreateWidget(views::WidgetDelegate* delegate) {
views::Widget* widget = new views::Widget;
views::Widget::InitParams params(
views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
params.context = CurrentContext();
params.delegate = delegate;
params.bounds = gfx::Rect(10, 10, 100, 100);
widget->Init(params);
widget->Show();
return widget;
}
virtual void SetUp() OVERRIDE {
AshTestBase::SetUp();
CommandLine* command_line = CommandLine::ForCurrentProcess();
command_line->AppendSwitch(
switches::kAshEnableAlternateFrameCaptionButtonStyle);
TestWidgetDelegate* delegate = new TestWidgetDelegate();
window_state_ = ash::wm::GetWindowState(
CreateWidget(delegate)->GetNativeWindow());
FrameCaptionButtonContainerView::TestApi test(
delegate->caption_button_container());
minimize_button_ = test.minimize_button();
size_button_ = test.size_button();
static_cast<AlternateFrameSizeButton*>(
size_button_)->set_delay_to_set_buttons_to_snap_mode(0);
close_button_ = test.close_button();
}
ash::wm::WindowState* window_state() { return window_state_; }
const ash::wm::WindowState* window_state() const { return window_state_; }
FrameCaptionButton* minimize_button() { return minimize_button_; }
FrameCaptionButton* size_button() { return size_button_; }
FrameCaptionButton* close_button() { return close_button_; }
private:
ash::wm::WindowState* window_state_;
FrameCaptionButton* minimize_button_;
FrameCaptionButton* size_button_;
FrameCaptionButton* close_button_;
DISALLOW_COPY_AND_ASSIGN(AlternateFrameSizeButtonTest);
};
TEST_F(AlternateFrameSizeButtonTest, PressedState) {
aura::test::EventGenerator& generator = GetEventGenerator();
generator.MoveMouseTo(CenterPointInScreen(size_button()));
generator.PressLeftButton();
EXPECT_EQ(views::Button::STATE_PRESSED, size_button()->state());
generator.ReleaseLeftButton();
RunAllPendingInMessageLoop();
EXPECT_EQ(views::Button::STATE_NORMAL, size_button()->state());
generator.MoveMouseTo(CenterPointInScreen(size_button()));
generator.PressTouchId(3);
EXPECT_EQ(views::Button::STATE_PRESSED, size_button()->state());
generator.ReleaseTouchId(3);
RunAllPendingInMessageLoop();
EXPECT_EQ(views::Button::STATE_NORMAL, size_button()->state());
}
TEST_F(AlternateFrameSizeButtonTest, ClickSizeButtonTogglesMaximize) {
EXPECT_FALSE(window_state()->IsMaximized());
aura::test::EventGenerator& generator = GetEventGenerator();
generator.MoveMouseTo(CenterPointInScreen(size_button()));
generator.ClickLeftButton();
RunAllPendingInMessageLoop();
EXPECT_TRUE(window_state()->IsMaximized());
generator.MoveMouseTo(CenterPointInScreen(size_button()));
generator.ClickLeftButton();
RunAllPendingInMessageLoop();
EXPECT_FALSE(window_state()->IsMaximized());
generator.GestureTapAt(CenterPointInScreen(size_button()));
RunAllPendingInMessageLoop();
EXPECT_TRUE(window_state()->IsMaximized());
generator.GestureTapAt(CenterPointInScreen(size_button()));
RunAllPendingInMessageLoop();
EXPECT_FALSE(window_state()->IsMaximized());
}
TEST_F(AlternateFrameSizeButtonTest, ButtonDrag) {
EXPECT_TRUE(window_state()->IsNormalStateType());
aura::test::EventGenerator& generator = GetEventGenerator();
generator.MoveMouseTo(CenterPointInScreen(size_button()));
generator.PressLeftButton();
generator.MoveMouseTo(CenterPointInScreen(close_button()));
generator.ReleaseLeftButton();
RunAllPendingInMessageLoop();
EXPECT_TRUE(HasStateType(wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED));
generator.MoveMouseTo(CenterPointInScreen(size_button()));
generator.PressLeftButton();
generator.MoveMouseTo(CenterPointInScreen(minimize_button()));
generator.ReleaseLeftButton();
RunAllPendingInMessageLoop();
EXPECT_TRUE(HasStateType(wm::WINDOW_STATE_TYPE_LEFT_SNAPPED));
generator.GestureScrollSequence(
CenterPointInScreen(size_button()),
CenterPointInScreen(close_button()),
base::TimeDelta::FromMilliseconds(100),
3);
RunAllPendingInMessageLoop();
EXPECT_TRUE(HasStateType(wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED));
generator.GestureScrollSequence(
CenterPointInScreen(size_button()),
CenterPointInScreen(minimize_button()),
base::TimeDelta::FromMilliseconds(100),
3);
RunAllPendingInMessageLoop();
EXPECT_TRUE(HasStateType(wm::WINDOW_STATE_TYPE_LEFT_SNAPPED));
const int touch_default_radius =
ui::GestureConfiguration::default_radius();
ui::GestureConfiguration::set_default_radius(0);
generator.MoveMouseTo(CenterPointInScreen(size_button()));
generator.PressMoveAndReleaseTouchTo(CenterPointInScreen(close_button()));
RunAllPendingInMessageLoop();
EXPECT_TRUE(HasStateType(wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED));
generator.MoveMouseTo(CenterPointInScreen(size_button()));
generator.PressMoveAndReleaseTouchTo(CenterPointInScreen(minimize_button()));
RunAllPendingInMessageLoop();
EXPECT_TRUE(HasStateType(wm::WINDOW_STATE_TYPE_LEFT_SNAPPED));
ui::GestureConfiguration::set_default_radius(touch_default_radius);
}
TEST_F(AlternateFrameSizeButtonTest, SnapLeftOvershootMinimize) {
EXPECT_TRUE(window_state()->IsNormalStateType());
aura::test::EventGenerator& generator = GetEventGenerator();
generator.MoveMouseTo(CenterPointInScreen(size_button()));
generator.PressLeftButton();
generator.MoveMouseTo(CenterPointInScreen(minimize_button()));
generator.MoveMouseBy(-minimize_button()->width(), 0);
generator.ReleaseLeftButton();
RunAllPendingInMessageLoop();
EXPECT_TRUE(HasStateType(wm::WINDOW_STATE_TYPE_LEFT_SNAPPED));
}
TEST_F(AlternateFrameSizeButtonTest, RightMouseButton) {
EXPECT_TRUE(window_state()->IsNormalStateType());
aura::test::EventGenerator& generator = GetEventGenerator();
generator.MoveMouseTo(CenterPointInScreen(size_button()));
generator.PressRightButton();
generator.ReleaseRightButton();
RunAllPendingInMessageLoop();
EXPECT_TRUE(window_state()->IsNormalStateType());
}
TEST_F(AlternateFrameSizeButtonTest, ResetButtonsAfterClick) {
EXPECT_EQ(CAPTION_BUTTON_ICON_MINIMIZE, minimize_button()->icon());
EXPECT_EQ(CAPTION_BUTTON_ICON_CLOSE, close_button()->icon());
EXPECT_TRUE(AllButtonsInNormalState());
aura::test::EventGenerator& generator = GetEventGenerator();
generator.MoveMouseTo(CenterPointInScreen(size_button()));
generator.PressLeftButton();
EXPECT_EQ(views::Button::STATE_NORMAL, minimize_button()->state());
EXPECT_EQ(views::Button::STATE_PRESSED, size_button()->state());
EXPECT_EQ(views::Button::STATE_NORMAL, close_button()->state());
EXPECT_EQ(CAPTION_BUTTON_ICON_LEFT_SNAPPED, minimize_button()->icon());
EXPECT_EQ(CAPTION_BUTTON_ICON_RIGHT_SNAPPED, close_button()->icon());
generator.MoveMouseTo(CenterPointInScreen(minimize_button()));
EXPECT_EQ(views::Button::STATE_HOVERED, minimize_button()->state());
EXPECT_EQ(views::Button::STATE_PRESSED, size_button()->state());
EXPECT_EQ(views::Button::STATE_NORMAL, close_button()->state());
EXPECT_EQ(CAPTION_BUTTON_ICON_LEFT_SNAPPED, minimize_button()->icon());
EXPECT_EQ(CAPTION_BUTTON_ICON_RIGHT_SNAPPED, close_button()->icon());
generator.ReleaseLeftButton();
RunAllPendingInMessageLoop();
EXPECT_TRUE(HasStateType(wm::WINDOW_STATE_TYPE_LEFT_SNAPPED));
EXPECT_TRUE(AllButtonsInNormalState());
EXPECT_EQ(CAPTION_BUTTON_ICON_MINIMIZE, minimize_button()->icon());
EXPECT_EQ(CAPTION_BUTTON_ICON_CLOSE, close_button()->icon());
generator.MoveMouseTo(CenterPointInScreen(size_button()));
generator.PressLeftButton();
EXPECT_EQ(views::Button::STATE_NORMAL, minimize_button()->state());
EXPECT_EQ(views::Button::STATE_PRESSED, size_button()->state());
EXPECT_EQ(views::Button::STATE_NORMAL, close_button()->state());
EXPECT_EQ(CAPTION_BUTTON_ICON_LEFT_SNAPPED, minimize_button()->icon());
EXPECT_EQ(CAPTION_BUTTON_ICON_RIGHT_SNAPPED, close_button()->icon());
const gfx::Rect& kWorkAreaBoundsInScreen =
ash::Shell::GetScreen()->GetPrimaryDisplay().work_area();
generator.MoveMouseTo(kWorkAreaBoundsInScreen.bottom_left());
EXPECT_TRUE(AllButtonsInNormalState());
EXPECT_EQ(CAPTION_BUTTON_ICON_LEFT_SNAPPED, minimize_button()->icon());
EXPECT_EQ(CAPTION_BUTTON_ICON_RIGHT_SNAPPED, close_button()->icon());
generator.ReleaseLeftButton();
RunAllPendingInMessageLoop();
EXPECT_TRUE(HasStateType(wm::WINDOW_STATE_TYPE_LEFT_SNAPPED));
EXPECT_TRUE(AllButtonsInNormalState());
EXPECT_EQ(CAPTION_BUTTON_ICON_MINIMIZE, minimize_button()->icon());
EXPECT_EQ(CAPTION_BUTTON_ICON_CLOSE, close_button()->icon());
}
TEST_F(AlternateFrameSizeButtonTest, SizeButtonPressedWhenSnapButtonHovered) {
EXPECT_EQ(CAPTION_BUTTON_ICON_MINIMIZE, minimize_button()->icon());
EXPECT_EQ(CAPTION_BUTTON_ICON_CLOSE, close_button()->icon());
EXPECT_TRUE(AllButtonsInNormalState());
aura::test::EventGenerator& generator = GetEventGenerator();
generator.MoveMouseTo(CenterPointInScreen(size_button()));
generator.PressLeftButton();
EXPECT_EQ(views::Button::STATE_NORMAL, minimize_button()->state());
EXPECT_EQ(views::Button::STATE_PRESSED, size_button()->state());
EXPECT_EQ(views::Button::STATE_NORMAL, close_button()->state());
EXPECT_EQ(CAPTION_BUTTON_ICON_LEFT_SNAPPED, minimize_button()->icon());
EXPECT_EQ(CAPTION_BUTTON_ICON_RIGHT_SNAPPED, close_button()->icon());
generator.MoveMouseTo(CenterPointInScreen(minimize_button()));
EXPECT_EQ(views::Button::STATE_HOVERED, minimize_button()->state());
EXPECT_EQ(views::Button::STATE_PRESSED, size_button()->state());
EXPECT_EQ(views::Button::STATE_NORMAL, close_button()->state());
const gfx::Rect& kWorkAreaBoundsInScreen =
ash::Shell::GetScreen()->GetPrimaryDisplay().work_area();
generator.MoveMouseTo(kWorkAreaBoundsInScreen.bottom_left());
EXPECT_TRUE(AllButtonsInNormalState());
generator.MoveMouseTo(CenterPointInScreen(close_button()));
EXPECT_EQ(views::Button::STATE_NORMAL, minimize_button()->state());
EXPECT_EQ(views::Button::STATE_PRESSED, size_button()->state());
EXPECT_EQ(views::Button::STATE_HOVERED, close_button()->state());
}
class AlternateFrameSizeButtonTestRTL : public AlternateFrameSizeButtonTest {
public:
AlternateFrameSizeButtonTestRTL() {}
virtual ~AlternateFrameSizeButtonTestRTL() {}
virtual void SetUp() OVERRIDE {
original_locale_ = l10n_util::GetApplicationLocale(std::string());
base::i18n::SetICUDefaultLocale("he");
AlternateFrameSizeButtonTest::SetUp();
}
virtual void TearDown() OVERRIDE {
AlternateFrameSizeButtonTest::TearDown();
base::i18n::SetICUDefaultLocale(original_locale_);
}
private:
std::string original_locale_;
DISALLOW_COPY_AND_ASSIGN(AlternateFrameSizeButtonTestRTL);
};
TEST_F(AlternateFrameSizeButtonTestRTL, ButtonDrag) {
ASSERT_LT(close_button()->GetBoundsInScreen().x(),
size_button()->GetBoundsInScreen().x());
ASSERT_LT(size_button()->GetBoundsInScreen().x(),
minimize_button()->GetBoundsInScreen().x());
EXPECT_TRUE(window_state()->IsNormalStateType());
EXPECT_TRUE(AllButtonsInNormalState());
EXPECT_EQ(CAPTION_BUTTON_ICON_MINIMIZE, minimize_button()->icon());
EXPECT_EQ(CAPTION_BUTTON_ICON_CLOSE, close_button()->icon());
aura::test::EventGenerator& generator = GetEventGenerator();
generator.MoveMouseTo(CenterPointInScreen(size_button()));
generator.PressLeftButton();
EXPECT_EQ(views::Button::STATE_NORMAL, minimize_button()->state());
EXPECT_EQ(views::Button::STATE_PRESSED, size_button()->state());
EXPECT_EQ(views::Button::STATE_NORMAL, close_button()->state());
EXPECT_EQ(CAPTION_BUTTON_ICON_RIGHT_SNAPPED, minimize_button()->icon());
EXPECT_EQ(CAPTION_BUTTON_ICON_LEFT_SNAPPED, close_button()->icon());
generator.MoveMouseTo(CenterPointInScreen(minimize_button()));
EXPECT_EQ(views::Button::STATE_HOVERED, minimize_button()->state());
EXPECT_EQ(views::Button::STATE_PRESSED, size_button()->state());
EXPECT_EQ(views::Button::STATE_NORMAL, close_button()->state());
generator.ReleaseLeftButton();
RunAllPendingInMessageLoop();
EXPECT_TRUE(HasStateType(wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED));
EXPECT_TRUE(AllButtonsInNormalState());
EXPECT_EQ(CAPTION_BUTTON_ICON_MINIMIZE, minimize_button()->icon());
EXPECT_EQ(CAPTION_BUTTON_ICON_CLOSE, close_button()->icon());
}
}
}