This source file includes following definitions.
- widget
- app_window
- app_window_views
- SetUp
- TearDown
- TEST_F
- TEST_F
- TEST_F
#include "chrome/browser/ui/views/apps/shaped_app_window_targeter.h"
#include "chrome/browser/ui/views/apps/chrome_native_app_window_views.h"
#include "ui/aura/test/aura_test_base.h"
#include "ui/aura/window.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/views/controls/webview/webview.h"
#include "ui/wm/core/easy_resize_window_targeter.h"
class ShapedAppWindowTargeterTest : public aura::test::AuraTestBase {
public:
ShapedAppWindowTargeterTest()
: web_view_(NULL) {
}
virtual ~ShapedAppWindowTargeterTest() {}
views::Widget* widget() { return widget_.get(); }
apps::NativeAppWindow* app_window() { return &app_window_; }
ChromeNativeAppWindowViews* app_window_views() { return &app_window_; }
protected:
virtual void SetUp() OVERRIDE {
aura::test::AuraTestBase::SetUp();
widget_.reset(new views::Widget);
views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
params.remove_standard_frame = true;
params.bounds = gfx::Rect(30, 30, 100, 100);
params.context = root_window();
params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
widget_->Init(params);
app_window_.set_web_view_for_testing(&web_view_);
app_window_.set_window_for_testing(widget_.get());
widget_->Show();
}
virtual void TearDown() OVERRIDE {
widget_.reset();
aura::test::AuraTestBase::TearDown();
}
private:
views::WebView web_view_;
scoped_ptr<views::Widget> widget_;
ChromeNativeAppWindowViews app_window_;
DISALLOW_COPY_AND_ASSIGN(ShapedAppWindowTargeterTest);
};
TEST_F(ShapedAppWindowTargeterTest, HitTestBasic) {
aura::Window* window = widget()->GetNativeWindow();
{
ui::MouseEvent move(ui::ET_MOUSE_MOVED,
gfx::Point(40, 40), gfx::Point(40, 40),
ui::EF_NONE, ui::EF_NONE);
ui::EventDispatchDetails details =
event_processor()->OnEventFromSource(&move);
ASSERT_FALSE(details.dispatcher_destroyed);
EXPECT_EQ(window, move.target());
}
scoped_ptr<SkRegion> region(new SkRegion);
region->op(SkIRect::MakeXYWH(40, 0, 20, 100), SkRegion::kUnion_Op);
region->op(SkIRect::MakeXYWH(0, 40, 100, 20), SkRegion::kUnion_Op);
app_window()->UpdateShape(region.Pass());
{
ui::MouseEvent move(ui::ET_MOUSE_MOVED,
gfx::Point(40, 40), gfx::Point(40, 40),
ui::EF_NONE, ui::EF_NONE);
ui::EventDispatchDetails details =
event_processor()->OnEventFromSource(&move);
ASSERT_FALSE(details.dispatcher_destroyed);
EXPECT_EQ(root_window(), move.target());
ui::MouseEvent move2(ui::ET_MOUSE_MOVED,
gfx::Point(80, 80), gfx::Point(80, 80),
ui::EF_NONE, ui::EF_NONE);
details = event_processor()->OnEventFromSource(&move2);
ASSERT_FALSE(details.dispatcher_destroyed);
EXPECT_EQ(window, move2.target());
}
}
TEST_F(ShapedAppWindowTargeterTest, HitTestOnlyForShapedWindow) {
gfx::Insets inset(-30, -30, -30, -30);
root_window()->SetEventTargeter(scoped_ptr<ui::EventTargeter>(
new wm::EasyResizeWindowTargeter(root_window(), inset, inset)));
aura::Window* window = widget()->GetNativeWindow();
{
ui::MouseEvent move(ui::ET_MOUSE_MOVED,
gfx::Point(40, 40), gfx::Point(40, 40),
ui::EF_NONE, ui::EF_NONE);
ui::EventDispatchDetails details =
event_processor()->OnEventFromSource(&move);
ASSERT_FALSE(details.dispatcher_destroyed);
EXPECT_EQ(window, move.target());
}
{
ui::MouseEvent move(ui::ET_MOUSE_MOVED,
gfx::Point(10, 10), gfx::Point(10, 10),
ui::EF_NONE, ui::EF_NONE);
ui::EventDispatchDetails details =
event_processor()->OnEventFromSource(&move);
ASSERT_FALSE(details.dispatcher_destroyed);
EXPECT_EQ(window, move.target());
}
scoped_ptr<SkRegion> region(new SkRegion);
region->op(SkIRect::MakeXYWH(40, 0, 20, 100), SkRegion::kUnion_Op);
region->op(SkIRect::MakeXYWH(0, 40, 100, 20), SkRegion::kUnion_Op);
app_window()->UpdateShape(region.Pass());
{
ui::MouseEvent move(ui::ET_MOUSE_MOVED,
gfx::Point(10, 10), gfx::Point(10, 10),
ui::EF_NONE, ui::EF_NONE);
ui::EventDispatchDetails details =
event_processor()->OnEventFromSource(&move);
ASSERT_FALSE(details.dispatcher_destroyed);
EXPECT_EQ(root_window(), move.target());
}
app_window()->UpdateShape(scoped_ptr<SkRegion>());
{
ui::MouseEvent move(ui::ET_MOUSE_MOVED,
gfx::Point(10, 10), gfx::Point(10, 10),
ui::EF_NONE, ui::EF_NONE);
ui::EventDispatchDetails details =
event_processor()->OnEventFromSource(&move);
ASSERT_FALSE(details.dispatcher_destroyed);
EXPECT_EQ(window, move.target());
}
}
TEST_F(ShapedAppWindowTargeterTest, ResizeInsetsWithinBounds) {
aura::Window* window = widget()->GetNativeWindow();
{
ui::MouseEvent move(ui::ET_MOUSE_MOVED,
gfx::Point(80, 80), gfx::Point(80, 80),
ui::EF_NONE, ui::EF_NONE);
ui::EventDispatchDetails details =
event_processor()->OnEventFromSource(&move);
ASSERT_FALSE(details.dispatcher_destroyed);
EXPECT_EQ(window, move.target());
}
{
ui::MouseEvent move(ui::ET_MOUSE_MOVED,
gfx::Point(32, 37), gfx::Point(32, 37),
ui::EF_NONE, ui::EF_NONE);
ui::EventDispatchDetails details =
event_processor()->OnEventFromSource(&move);
ASSERT_FALSE(details.dispatcher_destroyed);
EXPECT_EQ(window, move.target());
}
app_window_views()->InstallEasyResizeTargeterOnContainer();
{
ui::MouseEvent move(ui::ET_MOUSE_MOVED,
gfx::Point(80, 80), gfx::Point(80, 80),
ui::EF_NONE, ui::EF_NONE);
ui::EventDispatchDetails details =
event_processor()->OnEventFromSource(&move);
ASSERT_FALSE(details.dispatcher_destroyed);
EXPECT_EQ(window, move.target());
}
{
ui::MouseEvent move(ui::ET_MOUSE_MOVED,
gfx::Point(32, 37), gfx::Point(32, 37),
ui::EF_NONE, ui::EF_NONE);
ui::EventDispatchDetails details =
event_processor()->OnEventFromSource(&move);
ASSERT_FALSE(details.dispatcher_destroyed);
EXPECT_EQ(root_window(), move.target());
}
}