summaryrefslogtreecommitdiffstats
path: root/chromium/ui/views/widget/native_widget_aura_unittest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/ui/views/widget/native_widget_aura_unittest.cc')
-rw-r--r--chromium/ui/views/widget/native_widget_aura_unittest.cc249
1 files changed, 159 insertions, 90 deletions
diff --git a/chromium/ui/views/widget/native_widget_aura_unittest.cc b/chromium/ui/views/widget/native_widget_aura_unittest.cc
index f0f34c76cbd..3c6d3cc49ad 100644
--- a/chromium/ui/views/widget/native_widget_aura_unittest.cc
+++ b/chromium/ui/views/widget/native_widget_aura_unittest.cc
@@ -12,14 +12,16 @@
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/env.h"
#include "ui/aura/layout_manager.h"
-#include "ui/aura/root_window.h"
-#include "ui/aura/test/aura_test_helper.h"
+#include "ui/aura/test/aura_test_base.h"
#include "ui/aura/window.h"
+#include "ui/aura/window_tree_host.h"
#include "ui/events/event.h"
+#include "ui/events/event_utils.h"
#include "ui/gfx/screen.h"
#include "ui/views/layout/fill_layout.h"
#include "ui/views/widget/root_view.h"
#include "ui/views/widget/widget_delegate.h"
+#include "ui/wm/core/default_activation_client.h"
namespace views {
namespace {
@@ -32,40 +34,29 @@ NativeWidgetAura* Init(aura::Window* parent, Widget* widget) {
return static_cast<NativeWidgetAura*>(widget->native_widget());
}
-class NativeWidgetAuraTest : public testing::Test {
+class NativeWidgetAuraTest : public aura::test::AuraTestBase {
public:
NativeWidgetAuraTest() {}
virtual ~NativeWidgetAuraTest() {}
// testing::Test overrides:
virtual void SetUp() OVERRIDE {
- aura_test_helper_.reset(new aura::test::AuraTestHelper(&message_loop_));
- aura_test_helper_->SetUp();
- root_window()->SetBounds(gfx::Rect(0, 0, 640, 480));
- dispatcher()->SetHostSize(gfx::Size(640, 480));
+ AuraTestBase::SetUp();
+ new wm::DefaultActivationClient(root_window());
+ host()->SetBounds(gfx::Rect(640, 480));
}
- virtual void TearDown() OVERRIDE {
- message_loop_.RunUntilIdle();
- aura_test_helper_->TearDown();
- }
-
- protected:
- aura::Window* root_window() { return aura_test_helper_->root_window(); }
- aura::RootWindow* dispatcher() { return aura_test_helper_->dispatcher(); }
private:
- base::MessageLoopForUI message_loop_;
- scoped_ptr<aura::test::AuraTestHelper> aura_test_helper_;
-
DISALLOW_COPY_AND_ASSIGN(NativeWidgetAuraTest);
};
TEST_F(NativeWidgetAuraTest, CenterWindowLargeParent) {
- // Make a parent window larger than the host represented by rootwindow.
+ // Make a parent window larger than the host represented by
+ // WindowEventDispatcher.
scoped_ptr<aura::Window> parent(new aura::Window(NULL));
- parent->Init(ui::LAYER_NOT_DRAWN);
+ parent->Init(aura::WINDOW_LAYER_NOT_DRAWN);
parent->SetBounds(gfx::Rect(0, 0, 1024, 800));
- scoped_ptr<Widget> widget(new Widget());
+ scoped_ptr<Widget> widget(new Widget());
NativeWidgetAura* window = Init(parent.get(), widget.get());
window->CenterWindow(gfx::Size(100, 100));
@@ -77,9 +68,10 @@ TEST_F(NativeWidgetAuraTest, CenterWindowLargeParent) {
}
TEST_F(NativeWidgetAuraTest, CenterWindowSmallParent) {
- // Make a parent window smaller than the host represented by rootwindow.
+ // Make a parent window smaller than the host represented by
+ // WindowEventDispatcher.
scoped_ptr<aura::Window> parent(new aura::Window(NULL));
- parent->Init(ui::LAYER_NOT_DRAWN);
+ parent->Init(aura::WINDOW_LAYER_NOT_DRAWN);
parent->SetBounds(gfx::Rect(0, 0, 480, 320));
scoped_ptr<Widget> widget(new Widget());
NativeWidgetAura* window = Init(parent.get(), widget.get());
@@ -94,10 +86,10 @@ TEST_F(NativeWidgetAuraTest, CenterWindowSmallParent) {
// Verifies CenterWindow() constrains to parent size.
TEST_F(NativeWidgetAuraTest, CenterWindowSmallParentNotAtOrigin) {
- // Make a parent window smaller than the host represented by rootwindow and
- // offset it slightly from the origin.
+ // Make a parent window smaller than the host represented by
+ // WindowEventDispatcher and offset it slightly from the origin.
scoped_ptr<aura::Window> parent(new aura::Window(NULL));
- parent->Init(ui::LAYER_NOT_DRAWN);
+ parent->Init(aura::WINDOW_LAYER_NOT_DRAWN);
parent->SetBounds(gfx::Rect(20, 40, 480, 320));
scoped_ptr<Widget> widget(new Widget());
NativeWidgetAura* window = Init(parent.get(), widget.get());
@@ -108,30 +100,39 @@ TEST_F(NativeWidgetAuraTest, CenterWindowSmallParentNotAtOrigin) {
widget->CloseNow();
}
+class TestLayoutManagerBase : public aura::LayoutManager {
+ public:
+ TestLayoutManagerBase() {}
+ virtual ~TestLayoutManagerBase() {}
+
+ // aura::LayoutManager:
+ virtual void OnWindowResized() OVERRIDE {}
+ virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE {}
+ virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE {}
+ virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE {}
+ virtual void OnChildWindowVisibilityChanged(aura::Window* child,
+ bool visible) OVERRIDE {}
+ virtual void SetChildBounds(aura::Window* child,
+ const gfx::Rect& requested_bounds) OVERRIDE {}
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(TestLayoutManagerBase);
+};
+
// Used by ShowMaximizedDoesntBounceAround. See it for details.
-class TestLayoutManager : public aura::LayoutManager {
+class MaximizeLayoutManager : public TestLayoutManagerBase {
public:
- TestLayoutManager() {}
+ MaximizeLayoutManager() {}
+ virtual ~MaximizeLayoutManager() {}
- virtual void OnWindowResized() OVERRIDE {
- }
+ private:
+ // aura::LayoutManager:
virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE {
// This simulates what happens when adding a maximized window.
SetChildBoundsDirect(child, gfx::Rect(0, 0, 300, 300));
}
- virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE {
- }
- virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE {
- }
- virtual void OnChildWindowVisibilityChanged(aura::Window* child,
- bool visible) OVERRIDE {
- }
- virtual void SetChildBounds(aura::Window* child,
- const gfx::Rect& requested_bounds) OVERRIDE {
- }
- private:
- DISALLOW_COPY_AND_ASSIGN(TestLayoutManager);
+ DISALLOW_COPY_AND_ASSIGN(MaximizeLayoutManager);
};
// This simulates BrowserView, which creates a custom RootView so that
@@ -168,7 +169,7 @@ class TestWidget : public views::Widget {
// leads to noticable flashes.
TEST_F(NativeWidgetAuraTest, ShowMaximizedDoesntBounceAround) {
root_window()->SetBounds(gfx::Rect(0, 0, 640, 480));
- root_window()->SetLayoutManager(new TestLayoutManager);
+ root_window()->SetLayoutManager(new MaximizeLayoutManager);
scoped_ptr<TestWidget> widget(new TestWidget());
Widget::InitParams params(Widget::InitParams::TYPE_WINDOW);
params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
@@ -181,6 +182,70 @@ TEST_F(NativeWidgetAuraTest, ShowMaximizedDoesntBounceAround) {
widget->CloseNow();
}
+class PropertyTestLayoutManager : public TestLayoutManagerBase {
+ public:
+ PropertyTestLayoutManager() : added_(false) {}
+ virtual ~PropertyTestLayoutManager() {}
+
+ bool added() const { return added_; }
+
+ private:
+ // aura::LayoutManager:
+ virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE {
+ EXPECT_TRUE(child->GetProperty(aura::client::kCanMaximizeKey));
+ EXPECT_TRUE(child->GetProperty(aura::client::kCanResizeKey));
+ added_ = true;
+ }
+
+ bool added_;
+
+ DISALLOW_COPY_AND_ASSIGN(PropertyTestLayoutManager);
+};
+
+class PropertyTestWidgetDelegate : public views::WidgetDelegate {
+ public:
+ explicit PropertyTestWidgetDelegate(Widget* widget) : widget_(widget) {}
+ virtual ~PropertyTestWidgetDelegate() {}
+
+ private:
+ // views::WidgetDelegate:
+ virtual bool CanMaximize() const OVERRIDE {
+ return true;
+ }
+ virtual bool CanResize() const OVERRIDE {
+ return true;
+ }
+ virtual void DeleteDelegate() OVERRIDE {
+ delete this;
+ }
+ virtual Widget* GetWidget() OVERRIDE {
+ return widget_;
+ }
+ virtual const Widget* GetWidget() const OVERRIDE {
+ return widget_;
+ }
+
+ Widget* widget_;
+ DISALLOW_COPY_AND_ASSIGN(PropertyTestWidgetDelegate);
+};
+
+// Verifies that the kCanMaximizeKey/kCanReizeKey have the correct
+// value when added to the layout manager.
+TEST_F(NativeWidgetAuraTest, TestPropertiesWhenAddedToLayout) {
+ root_window()->SetBounds(gfx::Rect(0, 0, 640, 480));
+ PropertyTestLayoutManager* layout_manager = new PropertyTestLayoutManager();
+ root_window()->SetLayoutManager(layout_manager);
+ scoped_ptr<TestWidget> widget(new TestWidget());
+ Widget::InitParams params(Widget::InitParams::TYPE_WINDOW);
+ params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
+ params.delegate = new PropertyTestWidgetDelegate(widget.get());
+ params.parent = NULL;
+ params.context = root_window();
+ widget->Init(params);
+ EXPECT_TRUE(layout_manager->added());
+ widget->CloseNow();
+}
+
TEST_F(NativeWidgetAuraTest, GetClientAreaScreenBounds) {
// Create a widget.
Widget::InitParams params(Widget::InitParams::TYPE_WINDOW);
@@ -198,8 +263,6 @@ TEST_F(NativeWidgetAuraTest, GetClientAreaScreenBounds) {
EXPECT_EQ(400, client_bounds.height());
}
-namespace {
-
// View subclass that tracks whether it has gotten a gesture event.
class GestureTrackingView : public views::View {
public:
@@ -235,8 +298,6 @@ class GestureTrackingView : public views::View {
DISALLOW_COPY_AND_ASSIGN(GestureTrackingView);
};
-} // namespace
-
// Verifies a capture isn't set on touch press and that the view that gets
// the press gets the release.
TEST_F(NativeWidgetAuraTest, DontCaptureOnGesture) {
@@ -256,9 +317,11 @@ TEST_F(NativeWidgetAuraTest, DontCaptureOnGesture) {
widget->SetContentsView(view);
widget->Show();
- ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(41, 51), 1,
- base::TimeDelta());
- dispatcher()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press);
+ ui::TouchEvent press(
+ ui::ET_TOUCH_PRESSED, gfx::Point(41, 51), 1, ui::EventTimeForNow());
+ ui::EventDispatchDetails details =
+ event_processor()->OnEventFromSource(&press);
+ ASSERT_FALSE(details.dispatcher_destroyed);
// Both views should get the press.
EXPECT_TRUE(view->got_gesture_event());
EXPECT_TRUE(child->got_gesture_event());
@@ -269,9 +332,10 @@ TEST_F(NativeWidgetAuraTest, DontCaptureOnGesture) {
// Release touch. Only |view| should get the release since that it consumed
// the press.
- ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(250, 251), 1,
- base::TimeDelta());
- dispatcher()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release);
+ ui::TouchEvent release(
+ ui::ET_TOUCH_RELEASED, gfx::Point(250, 251), 1, ui::EventTimeForNow());
+ details = event_processor()->OnEventFromSource(&release);
+ ASSERT_FALSE(details.dispatcher_destroyed);
EXPECT_TRUE(view->got_gesture_event());
EXPECT_FALSE(child->got_gesture_event());
view->clear_got_gesture_event();
@@ -281,39 +345,6 @@ TEST_F(NativeWidgetAuraTest, DontCaptureOnGesture) {
widget->Close();
}
-TEST_F(NativeWidgetAuraTest, ReleaseCaptureOnTouchRelease) {
- GestureTrackingView* view = new GestureTrackingView();
- scoped_ptr<TestWidget> widget(new TestWidget());
- Widget::InitParams params(Widget::InitParams::TYPE_WINDOW_FRAMELESS);
- params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
- params.context = root_window();
- params.bounds = gfx::Rect(0, 0, 100, 200);
- widget->Init(params);
- widget->SetContentsView(view);
- widget->Show();
-
- ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(41, 51), 1,
- base::TimeDelta());
- dispatcher()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press);
- EXPECT_TRUE(view->got_gesture_event());
- view->clear_got_gesture_event();
- // Set the capture.
- widget->SetCapture(view);
- EXPECT_TRUE(widget->HasCapture());
-
- // Generate a release, this should trigger releasing capture.
- ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(41, 51), 1,
- base::TimeDelta());
- dispatcher()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release);
- EXPECT_TRUE(view->got_gesture_event());
- view->clear_got_gesture_event();
- EXPECT_FALSE(widget->HasCapture());
-
- // Work around for bug in NativeWidgetAura.
- // TODO: fix bug and remove this.
- widget->Close();
-}
-
// Verifies views with layers are targeted for events properly.
TEST_F(NativeWidgetAuraTest, PreferViewLayersToChildWindows) {
// Create two widgets: |parent| and |child|. |child| is a child of |parent|.
@@ -399,15 +430,53 @@ TEST_F(NativeWidgetAuraTest, FlashFrame) {
TEST_F(NativeWidgetAuraTest, NoCrashOnThemeAfterClose) {
scoped_ptr<aura::Window> parent(new aura::Window(NULL));
- parent->Init(ui::LAYER_NOT_DRAWN);
+ parent->Init(aura::WINDOW_LAYER_NOT_DRAWN);
parent->SetBounds(gfx::Rect(0, 0, 480, 320));
scoped_ptr<Widget> widget(new Widget());
- NativeWidgetAura* window = Init(parent.get(), widget.get());
- window->Show();
- window->Close();
+ Init(parent.get(), widget.get());
+ widget->Show();
+ widget->Close();
base::MessageLoop::current()->RunUntilIdle();
widget->GetNativeTheme(); // Shouldn't crash.
}
+// Used to track calls to WidgetDelegate::OnWidgetMove().
+class MoveTestWidgetDelegate : public WidgetDelegateView {
+ public:
+ MoveTestWidgetDelegate() : got_move_(false) {}
+ virtual ~MoveTestWidgetDelegate() {}
+
+ void ClearGotMove() { got_move_ = false; }
+ bool got_move() const { return got_move_; }
+
+ // WidgetDelegate overrides:
+ virtual void OnWidgetMove() OVERRIDE { got_move_ = true; }
+
+ private:
+ bool got_move_;
+
+ DISALLOW_COPY_AND_ASSIGN(MoveTestWidgetDelegate);
+};
+
+// This test simulates what happens when a window is normally maximized. That
+// is, it's layer is acquired for animation then the window is maximized.
+// Acquiring the layer resets the bounds of the window. This test verifies the
+// Widget is still notified correctly of a move in this case.
+TEST_F(NativeWidgetAuraTest, OnWidgetMovedInvokedAfterAcquireLayer) {
+ // |delegate| deletes itself when the widget is destroyed.
+ MoveTestWidgetDelegate* delegate = new MoveTestWidgetDelegate;
+ Widget* widget =
+ Widget::CreateWindowWithContextAndBounds(delegate,
+ root_window(),
+ gfx::Rect(10, 10, 100, 200));
+ widget->Show();
+ delegate->ClearGotMove();
+ // Simulate a maximize with animation.
+ delete widget->GetNativeView()->RecreateLayer().release();
+ widget->SetBounds(gfx::Rect(0, 0, 500, 500));
+ EXPECT_TRUE(delegate->got_move());
+ widget->CloseNow();
+}
+
} // namespace
} // namespace views