| Index: ui/views/widget/widget_unittest.cc
|
| diff --git a/ui/views/widget/widget_unittest.cc b/ui/views/widget/widget_unittest.cc
|
| index d21d64f0561abb292d08882b9cb7e2931a7e9aa7..a41c7ae8767e83600c230c762a818ee13dc43a26 100644
|
| --- a/ui/views/widget/widget_unittest.cc
|
| +++ b/ui/views/widget/widget_unittest.cc
|
| @@ -18,7 +18,7 @@
|
| #include "ui/views/bubble/bubble_delegate.h"
|
| #include "ui/views/controls/textfield/textfield.h"
|
| #include "ui/views/test/test_views_delegate.h"
|
| -#include "ui/views/test/views_test_base.h"
|
| +#include "ui/views/test/widget_test.h"
|
| #include "ui/views/views_delegate.h"
|
| #include "ui/views/widget/native_widget_delegate.h"
|
| #include "ui/views/widget/root_view.h"
|
| @@ -26,7 +26,6 @@
|
|
|
| #if defined(USE_AURA)
|
| #include "ui/aura/client/aura_constants.h"
|
| -#include "ui/aura/env.h"
|
| #include "ui/aura/root_window.h"
|
| #include "ui/aura/test/test_cursor_client.h"
|
| #include "ui/aura/test/test_window_delegate.h"
|
| @@ -42,99 +41,6 @@
|
| namespace views {
|
| namespace test {
|
|
|
| -// A generic typedef to pick up relevant NativeWidget implementations.
|
| -#if defined(USE_AURA)
|
| -typedef NativeWidgetAura NativeWidgetPlatform;
|
| -#elif defined(OS_WIN)
|
| -typedef NativeWidgetWin NativeWidgetPlatform;
|
| -#endif
|
| -
|
| -// A widget that assumes mouse capture always works. It won't on Aura in
|
| -// testing, so we mock it.
|
| -#if defined(USE_AURA)
|
| -class NativeWidgetCapture : public NativeWidgetPlatform {
|
| - public:
|
| - explicit NativeWidgetCapture(internal::NativeWidgetDelegate* delegate)
|
| - : NativeWidgetPlatform(delegate),
|
| - mouse_capture_(false) {}
|
| - virtual ~NativeWidgetCapture() {}
|
| -
|
| - virtual void SetCapture() OVERRIDE {
|
| - mouse_capture_ = true;
|
| - }
|
| - virtual void ReleaseCapture() OVERRIDE {
|
| - if (mouse_capture_)
|
| - delegate()->OnMouseCaptureLost();
|
| - mouse_capture_ = false;
|
| - }
|
| - virtual bool HasCapture() const OVERRIDE {
|
| - return mouse_capture_;
|
| - }
|
| -
|
| - private:
|
| - bool mouse_capture_;
|
| -
|
| - DISALLOW_COPY_AND_ASSIGN(NativeWidgetCapture);
|
| -};
|
| -#endif
|
| -
|
| -// A typedef that inserts our mock-capture NativeWidget implementation for
|
| -// relevant platforms.
|
| -#if defined(USE_AURA)
|
| -typedef NativeWidgetCapture NativeWidgetPlatformForTest;
|
| -#elif defined(OS_WIN)
|
| -typedef NativeWidgetWin NativeWidgetPlatformForTest;
|
| -#endif
|
| -
|
| -// A view that always processes all mouse events.
|
| -class MouseView : public View {
|
| - public:
|
| - MouseView()
|
| - : View(),
|
| - entered_(0),
|
| - exited_(0),
|
| - pressed_(0) {
|
| - }
|
| - virtual ~MouseView() {}
|
| -
|
| - virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE {
|
| - pressed_++;
|
| - return true;
|
| - }
|
| -
|
| - virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE {
|
| - entered_++;
|
| - }
|
| -
|
| - virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE {
|
| - exited_++;
|
| - }
|
| -
|
| - // Return the number of OnMouseEntered calls and reset the counter.
|
| - int EnteredCalls() {
|
| - int i = entered_;
|
| - entered_ = 0;
|
| - return i;
|
| - }
|
| -
|
| - // Return the number of OnMouseExited calls and reset the counter.
|
| - int ExitedCalls() {
|
| - int i = exited_;
|
| - exited_ = 0;
|
| - return i;
|
| - }
|
| -
|
| - int pressed() const { return pressed_; }
|
| -
|
| - private:
|
| - int entered_;
|
| - int exited_;
|
| -
|
| - int pressed_;
|
| -
|
| - DISALLOW_COPY_AND_ASSIGN(MouseView);
|
| -};
|
| -
|
| // A view that keeps track of the events it receives, but consumes no events.
|
| class EventCountView : public View {
|
| public:
|
| @@ -203,24 +109,6 @@ class ScrollableEventCountView : public EventCountView {
|
| DISALLOW_COPY_AND_ASSIGN(ScrollableEventCountView);
|
| };
|
|
|
| -// A view that does a capture on gesture-begin events.
|
| -class GestureCaptureView : public View {
|
| - public:
|
| - GestureCaptureView() {}
|
| - virtual ~GestureCaptureView() {}
|
| -
|
| - private:
|
| - // Overridden from View:
|
| - virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE {
|
| - if (event->type() == ui::ET_GESTURE_BEGIN) {
|
| - GetWidget()->SetCapture(this);
|
| - event->StopPropagation();
|
| - }
|
| - }
|
| -
|
| - DISALLOW_COPY_AND_ASSIGN(GestureCaptureView);
|
| -};
|
| -
|
| // A view that implements GetMinimumSize.
|
| class MinimumSizeFrameView : public NativeFrameView {
|
| public:
|
| @@ -268,147 +156,6 @@ class EventCountHandler : public ui::EventHandler {
|
| DISALLOW_COPY_AND_ASSIGN(EventCountHandler);
|
| };
|
|
|
| -// A View that shows a different widget, sets capture on that widget, and
|
| -// initiates a nested message-loop when it receives a mouse-press event.
|
| -class NestedLoopCaptureView : public View {
|
| - public:
|
| - explicit NestedLoopCaptureView(Widget* widget) : widget_(widget) {}
|
| - virtual ~NestedLoopCaptureView() {}
|
| -
|
| - private:
|
| - // Overridden from View:
|
| - virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE {
|
| - // Start a nested loop.
|
| - widget_->Show();
|
| - widget_->SetCapture(widget_->GetContentsView());
|
| - EXPECT_TRUE(widget_->HasCapture());
|
| -
|
| - base::MessageLoopForUI* loop = base::MessageLoopForUI::current();
|
| - base::MessageLoop::ScopedNestableTaskAllower allow(loop);
|
| -
|
| - base::RunLoop run_loop;
|
| -#if defined(USE_AURA)
|
| - run_loop.set_dispatcher(aura::Env::GetInstance()->GetDispatcher());
|
| -#endif
|
| - run_loop.Run();
|
| - return true;
|
| - }
|
| -
|
| - Widget* widget_;
|
| -
|
| - DISALLOW_COPY_AND_ASSIGN(NestedLoopCaptureView);
|
| -};
|
| -
|
| -// A View that closes the Widget and exits the current message-loop when it
|
| -// receives a mouse-release event.
|
| -class ExitLoopOnRelease : public View {
|
| - public:
|
| - ExitLoopOnRelease() {}
|
| - virtual ~ExitLoopOnRelease() {}
|
| -
|
| - private:
|
| - // Overridden from View:
|
| - virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE {
|
| - GetWidget()->Close();
|
| - base::MessageLoop::current()->QuitNow();
|
| - }
|
| -
|
| - DISALLOW_COPY_AND_ASSIGN(ExitLoopOnRelease);
|
| -};
|
| -
|
| -class WidgetTest : public ViewsTestBase {
|
| - public:
|
| - WidgetTest() {}
|
| - virtual ~WidgetTest() {}
|
| -
|
| - NativeWidget* CreatePlatformNativeWidget(
|
| - internal::NativeWidgetDelegate* delegate) {
|
| - return new NativeWidgetPlatformForTest(delegate);
|
| - }
|
| -
|
| - Widget* CreateTopLevelPlatformWidget() {
|
| - Widget* toplevel = new Widget;
|
| - Widget::InitParams toplevel_params =
|
| - CreateParams(Widget::InitParams::TYPE_WINDOW);
|
| - toplevel_params.native_widget = CreatePlatformNativeWidget(toplevel);
|
| - toplevel->Init(toplevel_params);
|
| - return toplevel;
|
| - }
|
| -
|
| - Widget* CreateTopLevelFramelessPlatformWidget() {
|
| - Widget* toplevel = new Widget;
|
| - Widget::InitParams toplevel_params =
|
| - CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS);
|
| - toplevel_params.native_widget = CreatePlatformNativeWidget(toplevel);
|
| - toplevel->Init(toplevel_params);
|
| - return toplevel;
|
| - }
|
| -
|
| - Widget* CreateChildPlatformWidget(gfx::NativeView parent_native_view) {
|
| - Widget* child = new Widget;
|
| - Widget::InitParams child_params =
|
| - CreateParams(Widget::InitParams::TYPE_CONTROL);
|
| - child_params.native_widget = CreatePlatformNativeWidget(child);
|
| - child_params.parent = parent_native_view;
|
| - child->Init(child_params);
|
| - child->SetContentsView(new View);
|
| - return child;
|
| - }
|
| -
|
| -#if defined(OS_WIN) && !defined(USE_AURA)
|
| - // On Windows, it is possible for us to have a child window that is
|
| - // TYPE_POPUP.
|
| - Widget* CreateChildPopupPlatformWidget(gfx::NativeView parent_native_view) {
|
| - Widget* child = new Widget;
|
| - Widget::InitParams child_params =
|
| - CreateParams(Widget::InitParams::TYPE_POPUP);
|
| - child_params.child = true;
|
| - child_params.native_widget = CreatePlatformNativeWidget(child);
|
| - child_params.parent = parent_native_view;
|
| - child->Init(child_params);
|
| - child->SetContentsView(new View);
|
| - return child;
|
| - }
|
| -#endif
|
| -
|
| - Widget* CreateTopLevelNativeWidget() {
|
| - Widget* toplevel = new Widget;
|
| - Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW);
|
| - toplevel->Init(params);
|
| - return toplevel;
|
| - }
|
| -
|
| - Widget* CreateChildNativeWidgetWithParent(Widget* parent) {
|
| - Widget* child = new Widget;
|
| - Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_CONTROL);
|
| - params.parent = parent->GetNativeView();
|
| - child->Init(params);
|
| - child->SetContentsView(new View);
|
| - return child;
|
| - }
|
| -
|
| - Widget* CreateChildNativeWidget() {
|
| - return CreateChildNativeWidgetWithParent(NULL);
|
| - }
|
| -
|
| - View* GetMousePressedHandler(internal::RootView* root_view) {
|
| - return root_view->mouse_pressed_handler_;
|
| - }
|
| -
|
| - View* GetMouseMoveHandler(internal::RootView* root_view) {
|
| - return root_view->mouse_move_handler_;
|
| - }
|
| -
|
| - View* GetGestureHandler(internal::RootView* root_view) {
|
| - return root_view->gesture_handler_;
|
| - }
|
| -};
|
| -
|
| -bool WidgetHasMouseCapture(const Widget* widget) {
|
| - return static_cast<const internal::NativeWidgetPrivate*>(widget->
|
| - native_widget())->HasCapture();
|
| -}
|
| -
|
| ui::WindowShowState GetWidgetShowState(const Widget* widget) {
|
| // Use IsMaximized/IsMinimized/IsFullScreen instead of GetWindowPlacement
|
| // because the former is implemented on all platforms but the latter is not.
|
| @@ -455,112 +202,6 @@ TEST_F(WidgetTest, GetTopLevelWidget_Native) {
|
| // |child| should be automatically destroyed with |toplevel|.
|
| }
|
|
|
| -// Tests some grab/ungrab events.
|
| -TEST_F(WidgetTest, DISABLED_GrabUngrab) {
|
| - Widget* toplevel = CreateTopLevelPlatformWidget();
|
| - Widget* child1 = CreateChildNativeWidgetWithParent(toplevel);
|
| - Widget* child2 = CreateChildNativeWidgetWithParent(toplevel);
|
| -
|
| - toplevel->SetBounds(gfx::Rect(0, 0, 500, 500));
|
| -
|
| - child1->SetBounds(gfx::Rect(10, 10, 300, 300));
|
| - View* view = new MouseView();
|
| - view->SetBounds(0, 0, 300, 300);
|
| - child1->GetRootView()->AddChildView(view);
|
| -
|
| - child2->SetBounds(gfx::Rect(200, 10, 200, 200));
|
| - view = new MouseView();
|
| - view->SetBounds(0, 0, 200, 200);
|
| - child2->GetRootView()->AddChildView(view);
|
| -
|
| - toplevel->Show();
|
| - RunPendingMessages();
|
| -
|
| - // Click on child1
|
| - gfx::Point p1(45, 45);
|
| - ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED, p1, p1,
|
| - ui::EF_LEFT_MOUSE_BUTTON);
|
| - toplevel->OnMouseEvent(&pressed);
|
| -
|
| - EXPECT_TRUE(WidgetHasMouseCapture(toplevel));
|
| - EXPECT_TRUE(WidgetHasMouseCapture(child1));
|
| - EXPECT_FALSE(WidgetHasMouseCapture(child2));
|
| -
|
| - ui::MouseEvent released(ui::ET_MOUSE_RELEASED, p1, p1,
|
| - ui::EF_LEFT_MOUSE_BUTTON);
|
| - toplevel->OnMouseEvent(&released);
|
| -
|
| - EXPECT_FALSE(WidgetHasMouseCapture(toplevel));
|
| - EXPECT_FALSE(WidgetHasMouseCapture(child1));
|
| - EXPECT_FALSE(WidgetHasMouseCapture(child2));
|
| -
|
| - RunPendingMessages();
|
| -
|
| - // Click on child2
|
| - gfx::Point p2(315, 45);
|
| - ui::MouseEvent pressed2(ui::ET_MOUSE_PRESSED, p2, p2,
|
| - ui::EF_LEFT_MOUSE_BUTTON);
|
| - toplevel->OnMouseEvent(&pressed2);
|
| - EXPECT_TRUE(pressed2.handled());
|
| - EXPECT_TRUE(WidgetHasMouseCapture(toplevel));
|
| - EXPECT_TRUE(WidgetHasMouseCapture(child2));
|
| - EXPECT_FALSE(WidgetHasMouseCapture(child1));
|
| -
|
| - ui::MouseEvent released2(ui::ET_MOUSE_RELEASED, p2, p2,
|
| - ui::EF_LEFT_MOUSE_BUTTON);
|
| - toplevel->OnMouseEvent(&released2);
|
| - EXPECT_FALSE(WidgetHasMouseCapture(toplevel));
|
| - EXPECT_FALSE(WidgetHasMouseCapture(child1));
|
| - EXPECT_FALSE(WidgetHasMouseCapture(child2));
|
| -
|
| - toplevel->CloseNow();
|
| -}
|
| -
|
| -// Tests mouse move outside of the window into the "resize controller" and back
|
| -// will still generate an OnMouseEntered and OnMouseExited event..
|
| -TEST_F(WidgetTest, CheckResizeControllerEvents) {
|
| - Widget* toplevel = CreateTopLevelPlatformWidget();
|
| -
|
| - toplevel->SetBounds(gfx::Rect(0, 0, 100, 100));
|
| -
|
| - MouseView* view = new MouseView();
|
| - view->SetBounds(90, 90, 10, 10);
|
| - toplevel->GetRootView()->AddChildView(view);
|
| -
|
| - toplevel->Show();
|
| - RunPendingMessages();
|
| -
|
| - // Move to an outside position.
|
| - gfx::Point p1(200, 200);
|
| - ui::MouseEvent moved_out(ui::ET_MOUSE_MOVED, p1, p1, ui::EF_NONE);
|
| - toplevel->OnMouseEvent(&moved_out);
|
| - EXPECT_EQ(0, view->EnteredCalls());
|
| - EXPECT_EQ(0, view->ExitedCalls());
|
| -
|
| - // Move onto the active view.
|
| - gfx::Point p2(95, 95);
|
| - ui::MouseEvent moved_over(ui::ET_MOUSE_MOVED, p2, p2, ui::EF_NONE);
|
| - toplevel->OnMouseEvent(&moved_over);
|
| - EXPECT_EQ(1, view->EnteredCalls());
|
| - EXPECT_EQ(0, view->ExitedCalls());
|
| -
|
| - // Move onto the outer resizing border.
|
| - gfx::Point p3(102, 95);
|
| - ui::MouseEvent moved_resizer(ui::ET_MOUSE_MOVED, p3, p3, ui::EF_NONE);
|
| - toplevel->OnMouseEvent(&moved_resizer);
|
| - EXPECT_EQ(0, view->EnteredCalls());
|
| - EXPECT_EQ(1, view->ExitedCalls());
|
| -
|
| - // Move onto the view again.
|
| - toplevel->OnMouseEvent(&moved_over);
|
| - EXPECT_EQ(1, view->EnteredCalls());
|
| - EXPECT_EQ(0, view->ExitedCalls());
|
| -
|
| - RunPendingMessages();
|
| -
|
| - toplevel->CloseNow();
|
| -}
|
| -
|
| // Test if a focus manager and an inputmethod work without CHECK failure
|
| // when window activation changes.
|
| TEST_F(WidgetTest, ChangeActivation) {
|
| @@ -1274,102 +915,6 @@ TEST_F(WidgetTest, ExitFullscreenRestoreState) {
|
| RunPendingMessages();
|
| }
|
|
|
| -// Checks that if a mouse-press triggers a capture on a different widget (which
|
| -// consumes the mouse-release event), then the target of the press does not have
|
| -// capture.
|
| -// Fails on chromium.webkit Windows bot, see crbug.com/264872.
|
| -#if defined(OS_WIN)
|
| -#define MAYBE_DisableCaptureWidgetFromMousePress\
|
| - DISABLED_CaptureWidgetFromMousePress
|
| -#else
|
| -#define MAYBE_DisableCaptureWidgetFromMousePress\
|
| - CaptureWidgetFromMousePress
|
| -#endif
|
| -TEST_F(WidgetTest, MAYBE_DisableCaptureWidgetFromMousePress) {
|
| - // The test creates two widgets: |first| and |second|.
|
| - // The View in |first| makes |second| visible, sets capture on it, and starts
|
| - // a nested loop (like a menu does). The View in |second| terminates the
|
| - // nested loop and closes the widget.
|
| - // The test sends a mouse-press event to |first|, and posts a task to send a
|
| - // release event to |second|, to make sure that the release event is
|
| - // dispatched after the nested loop starts.
|
| -
|
| - Widget* first = CreateTopLevelFramelessPlatformWidget();
|
| - Widget* second = CreateTopLevelFramelessPlatformWidget();
|
| -
|
| - View* container = new NestedLoopCaptureView(second);
|
| - first->SetContentsView(container);
|
| -
|
| - second->SetContentsView(new ExitLoopOnRelease());
|
| -
|
| - first->SetSize(gfx::Size(100, 100));
|
| - first->Show();
|
| -
|
| - gfx::Point location(20, 20);
|
| - base::MessageLoop::current()->PostTask(FROM_HERE,
|
| - base::Bind(&Widget::OnMouseEvent,
|
| - base::Unretained(second),
|
| - base::Owned(new ui::MouseEvent(ui::ET_MOUSE_RELEASED,
|
| - location,
|
| - location,
|
| - ui::EF_LEFT_MOUSE_BUTTON))));
|
| - ui::MouseEvent press(ui::ET_MOUSE_PRESSED, location, location,
|
| - ui::EF_LEFT_MOUSE_BUTTON);
|
| - first->OnMouseEvent(&press);
|
| - EXPECT_FALSE(first->HasCapture());
|
| - first->Close();
|
| - RunPendingMessages();
|
| -}
|
| -
|
| -TEST_F(WidgetTest, ResetCaptureOnGestureEnd) {
|
| - Widget* toplevel = CreateTopLevelFramelessPlatformWidget();
|
| - View* container = new View;
|
| - toplevel->SetContentsView(container);
|
| -
|
| - View* gesture = new GestureCaptureView;
|
| - gesture->SetBounds(0, 0, 30, 30);
|
| - container->AddChildView(gesture);
|
| -
|
| - MouseView* mouse = new MouseView;
|
| - mouse->SetBounds(30, 0, 30, 30);
|
| - container->AddChildView(mouse);
|
| -
|
| - toplevel->SetSize(gfx::Size(100, 100));
|
| - toplevel->Show();
|
| -
|
| - // Start a gesture on |gesture|.
|
| - ui::GestureEvent begin(ui::ET_GESTURE_BEGIN,
|
| - 15, 15, 0, base::TimeDelta(),
|
| - ui::GestureEventDetails(ui::ET_GESTURE_BEGIN, 0, 0), 1);
|
| - ui::GestureEvent end(ui::ET_GESTURE_END,
|
| - 15, 15, 0, base::TimeDelta(),
|
| - ui::GestureEventDetails(ui::ET_GESTURE_END, 0, 0), 1);
|
| - toplevel->OnGestureEvent(&begin);
|
| -
|
| - // Now try to click on |mouse|. Since |gesture| will have capture, |mouse|
|
| - // will not receive the event.
|
| - gfx::Point click_location(45, 15);
|
| -
|
| - ui::MouseEvent press(ui::ET_MOUSE_PRESSED, click_location, click_location,
|
| - ui::EF_LEFT_MOUSE_BUTTON);
|
| - ui::MouseEvent release(ui::ET_MOUSE_RELEASED, click_location, click_location,
|
| - ui::EF_LEFT_MOUSE_BUTTON);
|
| -
|
| - toplevel->OnMouseEvent(&press);
|
| - toplevel->OnMouseEvent(&release);
|
| - EXPECT_EQ(0, mouse->pressed());
|
| -
|
| - // The end of the gesture should release the capture, and pressing on |mouse|
|
| - // should now reach |mouse|.
|
| - toplevel->OnGestureEvent(&end);
|
| - toplevel->OnMouseEvent(&press);
|
| - toplevel->OnMouseEvent(&release);
|
| - EXPECT_EQ(1, mouse->pressed());
|
| -
|
| - toplevel->Close();
|
| - RunPendingMessages();
|
| -}
|
| -
|
| #if defined(USE_AURA)
|
| // The key-event propagation from Widget happens differently on aura and
|
| // non-aura systems because of the difference in IME. So this test works only on
|
|
|