Chromium Code Reviews| Index: ui/aura/window_unittest.cc |
| diff --git a/ui/aura/window_unittest.cc b/ui/aura/window_unittest.cc |
| index d332cb1dcaf3d8b17d3caa3c2f006ba1a9a19a78..49ba5002f41000ddb8a82444c091d4b47d5d0b40 100644 |
| --- a/ui/aura/window_unittest.cc |
| +++ b/ui/aura/window_unittest.cc |
| @@ -15,12 +15,14 @@ |
| #include "ui/aura/hit_test.h" |
| #include "ui/aura/root_window.h" |
| #include "ui/aura/test/aura_test_base.h" |
| +#include "ui/aura/test/event_generator.h" |
| #include "ui/aura/test/test_desktop_delegate.h" |
| #include "ui/aura/test/test_window_delegate.h" |
| #include "ui/aura/window_delegate.h" |
| #include "ui/aura/window_observer.h" |
| #include "ui/gfx/canvas_skia.h" |
| #include "ui/gfx/compositor/layer.h" |
| +#include "ui/gfx/screen.h" |
| #include "ui/base/keycodes/keyboard_codes.h" |
| namespace aura { |
| @@ -351,7 +353,6 @@ TEST_F(WindowTest, MoveChildToFront) { |
| // Various destruction assertions. |
| TEST_F(WindowTest, CaptureTests) { |
| - Desktop* desktop = Desktop::GetInstance(); |
| CaptureWindowDelegateImpl delegate; |
| scoped_ptr<Window> window(CreateTestWindowWithDelegate( |
| &delegate, 0, gfx::Rect(0, 0, 20, 20), NULL)); |
| @@ -361,12 +362,11 @@ TEST_F(WindowTest, CaptureTests) { |
| window->SetCapture(); |
| EXPECT_TRUE(window->HasCapture()); |
| EXPECT_EQ(0, delegate.capture_lost_count()); |
| - |
| - desktop->OnMouseEvent(MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(50, 50), |
| - ui::EF_LEFT_BUTTON_DOWN)); |
| + EventGenerator generator(gfx::Point(50, 50)); |
| + generator.PressLeftButton(); |
| EXPECT_EQ(1, delegate.mouse_event_count()); |
| - desktop->OnMouseEvent(MouseEvent(ui::ET_MOUSE_RELEASED, gfx::Point(50, 50), |
| - ui::EF_LEFT_BUTTON_DOWN)); |
| + generator.ReleaseLeftButton(); |
| + |
| EXPECT_EQ(2, delegate.mouse_event_count()); |
| delegate.set_mouse_event_count(0); |
| @@ -374,8 +374,7 @@ TEST_F(WindowTest, CaptureTests) { |
| EXPECT_FALSE(window->HasCapture()); |
| EXPECT_EQ(1, delegate.capture_lost_count()); |
| - desktop->OnMouseEvent(MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(50, 50), |
| - ui::EF_LEFT_BUTTON_DOWN)); |
| + generator.PressLeftButton(); |
| EXPECT_EQ(0, delegate.mouse_event_count()); |
| } |
| @@ -470,6 +469,13 @@ class ActivateWindowDelegate : public TestWindowDelegate { |
| should_activate_count_(0) { |
| } |
| + ActivateWindowDelegate(bool activate) |
| + : activate_(activate), |
| + activated_count_(0), |
| + lost_active_count_(0), |
| + should_activate_count_(0) { |
| + } |
| + |
| void set_activate(bool v) { activate_ = v; } |
| int activated_count() const { return activated_count_; } |
| int lost_active_count() const { return lost_active_count_; } |
| @@ -524,8 +530,8 @@ TEST_F(WindowTest, ActivateOnMouse) { |
| // Click on window2. |
| gfx::Point press_point = w2->bounds().CenterPoint(); |
| Window::ConvertPointToWindow(w2->parent(), desktop->window(), &press_point); |
| - desktop->OnMouseEvent(MouseEvent(ui::ET_MOUSE_PRESSED, press_point, 0)); |
| - desktop->OnMouseEvent(MouseEvent(ui::ET_MOUSE_RELEASED, press_point, 0)); |
| + EventGenerator generator(press_point); |
| + generator.ClickLeftButton(); |
| // Window2 should have become active. |
| EXPECT_EQ(w2.get(), desktop->active_window()); |
| @@ -541,8 +547,7 @@ TEST_F(WindowTest, ActivateOnMouse) { |
| press_point = w1->bounds().CenterPoint(); |
| Window::ConvertPointToWindow(w1->parent(), desktop->window(), &press_point); |
| d1.set_activate(false); |
| - desktop->OnMouseEvent(MouseEvent(ui::ET_MOUSE_PRESSED, press_point, 0)); |
| - desktop->OnMouseEvent(MouseEvent(ui::ET_MOUSE_RELEASED, press_point, 0)); |
| + generator.ClickLeftButton(); |
| // Window2 should still be active and focused. |
| EXPECT_EQ(w2.get(), desktop->active_window()); |
| @@ -722,13 +727,22 @@ TEST_F(WindowTest, Fullscreen) { |
| EXPECT_EQ(ui::SHOW_STATE_NORMAL, w->show_state()); |
| EXPECT_EQ(original_bounds, w->bounds()); |
| - // Fullscreen twice |
| + // Calling Fullscreen() twice should have no additional effect. |
| w->Fullscreen(); |
| w->Fullscreen(); |
| EXPECT_EQ(desktop_bounds, w->bounds()); |
| w->Restore(); |
| EXPECT_EQ(ui::SHOW_STATE_NORMAL, w->show_state()); |
| EXPECT_EQ(original_bounds, w->bounds()); |
| + |
| + // Calling SetBounds() in fullscreen mode should only update the |
| + // restore bounds not change the bounds of the window. |
| + gfx::Rect new_bounds(50, 50, 50, 50); |
| + w->Fullscreen(); |
| + w->SetBounds(new_bounds); |
| + EXPECT_EQ(desktop_bounds, w->bounds()); |
| + w->Restore(); |
| + EXPECT_EQ(new_bounds, w->bounds()); |
| } |
| TEST_F(WindowTest, Maximized) { |
| @@ -770,6 +784,15 @@ TEST_F(WindowTest, Maximized) { |
| w->Restore(); |
| EXPECT_EQ(ui::SHOW_STATE_NORMAL, w->show_state()); |
| EXPECT_EQ(original_bounds, w->bounds()); |
| + |
| + // Calling SetBounds() in maximized mode mode should only update the |
| + // restore bounds not change the bounds of the window. |
| + gfx::Rect new_bounds(50, 50, 50, 50); |
| + w->Maximize(); |
| + w->SetBounds(new_bounds); |
| + EXPECT_EQ(max_bounds, w->bounds()); |
| + w->Restore(); |
| + EXPECT_EQ(new_bounds, w->bounds()); |
| } |
| // Various assertions for activating/deactivating. |
| @@ -819,6 +842,160 @@ TEST_F(WindowTest, IsOrContainsFullscreenWindow) { |
| EXPECT_FALSE(root->IsOrContainsFullscreenWindow()); |
| } |
| +class ToplevelWindowTest : public WindowTest { |
| + public: |
| + ToplevelWindowTest() {} |
| + virtual ~ToplevelWindowTest() {} |
| + |
| + virtual void SetUp() OVERRIDE { |
| + WindowTest::SetUp(); |
| + toplevel_container_.Init(); |
| + toplevel_container_.SetParent(aura::Desktop::GetInstance()->window()); |
| + toplevel_container_.SetBounds( |
| + aura::Desktop::GetInstance()->window()->bounds()); |
| + toplevel_container_.Show(); |
| + } |
| + |
| + virtual void TearDown() OVERRIDE { |
| + toplevel_container_.Hide(); |
| + toplevel_container_.SetParent(NULL); |
| + WindowTest::TearDown(); |
| + } |
| + |
| + Window* CreateTestToplevelWindow( |
| + WindowDelegate* delegate, const gfx::Rect& bounds) { |
| + return CreateTestWindowWithDelegate( |
| + delegate, 0 /* id */, bounds, &toplevel_container_); |
| + } |
| + |
| + ToplevelWindowContainer toplevel_container_; |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(ToplevelWindowTest); |
| +}; |
| + |
| +// A window delegate that returns the specified window component type. |
| +// Default type is |HTNOWHERE|. |
| +class ComponentWindowDelegate : public TestWindowDelegate { |
|
Ben Goodger (Google)
2011/10/15 05:36:30
This class and the test class above looks very sim
|
| + public: |
| + ComponentWindowDelegate() : window_component_(HTNOWHERE) {} |
| + ComponentWindowDelegate(int component) : window_component_(component) {} |
| + virtual ~ComponentWindowDelegate() {} |
| + |
| + virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE { |
| + return window_component_; |
| + } |
| + |
| + void set_window_component(int component) { |
| + window_component_ = component; |
| + } |
| + |
| + private: |
| + int window_component_; |
| +}; |
| + |
| +TEST_F(ToplevelWindowTest, TopMostActivate) { |
| + ActivateWindowDelegate activate; |
| + ActivateWindowDelegate non_activate(false); |
| + |
| + scoped_ptr<Window> w1(CreateTestToplevelWindow(&non_activate, gfx::Rect())); |
| + scoped_ptr<Window> w2(CreateTestToplevelWindow(&activate, gfx::Rect())); |
| + scoped_ptr<Window> w3(CreateTestToplevelWindow(&non_activate, gfx::Rect())); |
| + EXPECT_EQ(w2.get(), toplevel_container_.GetTopmostWindowToActivate(NULL)); |
| +} |
| + |
| +TEST_F(ToplevelWindowTest, WindowDrag) { |
| + ComponentWindowDelegate dd(HTCAPTION); |
| + gfx::Rect bounds(100, 100, 100, 100); |
| + scoped_ptr<Window> w1(CreateTestToplevelWindow(&dd, bounds)); |
| + |
| + EXPECT_EQ(bounds, w1->bounds()); |
| + EventGenerator generator; |
| + generator.MoveMouseTo(150, 150); |
| + generator.DragMouseTo(300, 200); |
| + EXPECT_EQ(gfx::Rect(250, 150, 100, 100), w1->bounds()); |
| + |
| + // Maximized window cannot be dragged. |
| + w1->Maximize(); |
| + generator.DragMouseTo(200, 150); |
| + gfx::Rect workarea = gfx::Screen::GetMonitorWorkAreaNearestWindow(w1.get()); |
| + EXPECT_EQ(workarea, w1->bounds()); |
| + w1->Restore(); |
| + |
| + // Fullscreen cannot be dragged either. |
| + w1->Fullscreen(); |
| + gfx::Rect monitor = gfx::Screen::GetMonitorAreaNearestWindow(w1.get()); |
| + generator.DragMouseTo(250, 200); |
| + EXPECT_EQ(monitor, w1->bounds()); |
| +} |
| + |
| +TEST_F(ToplevelWindowTest, WindowResize) { |
|
Ben Goodger (Google)
2011/10/15 05:36:30
We already have tests for this in toplevel_event_f
|
| + ComponentWindowDelegate dd; |
| + gfx::Rect bounds(100, 100, 100, 100); |
| + scoped_ptr<Window> w1(CreateTestToplevelWindow(&dd, bounds)); |
| + EXPECT_EQ(bounds, w1->bounds()); |
| + |
| + // Resize using left edge. |
| + dd.set_window_component(HTLEFT); |
| + EventGenerator generator; |
| + generator.MoveMouseTo(110, 150); |
| + generator.DragMouseTo(50, 1000); |
| + EXPECT_EQ(gfx::Rect(40, 100, 160, 100), w1->bounds()); |
| + // Move y coord to normal and drag again to right. |
| + generator.MoveMouseTo(50, 150); |
| + generator.DragMouseTo(70, 1000); |
| + EXPECT_EQ(gfx::Rect(60, 100, 140, 100), w1->bounds()); |
| + |
| + // Resize using right edge. |
| + w1->SetBounds(bounds); |
| + dd.set_window_component(HTRIGHT); |
| + generator.MoveMouseTo(190, 150); |
| + generator.DragMouseTo(250, 1000); |
| + EXPECT_EQ(gfx::Rect(100, 100, 160, 100), w1->bounds()); |
| + // Move y coord to normal and drag again to left. |
| + generator.MoveMouseTo(250, 100); |
| + generator.DragMouseTo(150, 1000); |
| + EXPECT_EQ(gfx::Rect(100, 100, 60, 100), w1->bounds()); |
| + |
| + // Resize using top edge. |
| + w1->SetBounds(bounds); |
| + dd.set_window_component(HTTOP); |
| + generator.MoveMouseTo(150, 110); |
| + generator.DragMouseTo(1000, 50); |
| + EXPECT_EQ(gfx::Rect(100, 40, 100, 160), w1->bounds()); |
| + // Move x coord to normal and drag again to bottom. |
| + generator.MoveMouseTo(150, 50); |
| + generator.DragMouseTo(1000, 150); |
| + EXPECT_EQ(gfx::Rect(100, 140, 100, 60), w1->bounds()); |
| + |
| + // Resize using bottom edge. |
| + w1->SetBounds(bounds); |
| + dd.set_window_component(HTBOTTOM); |
| + generator.MoveMouseTo(150, 190); |
| + generator.DragMouseTo(1000, 250); |
| + EXPECT_EQ(gfx::Rect(100, 100, 100, 160), w1->bounds()); |
| + // Move x coord to normal and drag again to bottom. |
| + generator.MoveMouseTo(150, 250); |
| + generator.DragMouseTo(1000, 150); |
| + EXPECT_EQ(gfx::Rect(100, 100, 100, 60), w1->bounds()); |
| + |
| + // Resize using bottom right edge. |
| + w1->SetBounds(bounds); |
| + dd.set_window_component(HTBOTTOMRIGHT); |
| + generator.MoveMouseTo(190, 190); |
| + generator.DragMouseTo(300, 300); |
| + EXPECT_EQ(gfx::Rect(100, 100, 210, 210), w1->bounds()); |
| + generator.DragMouseTo(150, 150); |
| + EXPECT_EQ(gfx::Rect(100, 100, 60, 60), w1->bounds()); |
| + |
| + // Minimum size must be enforced. |
| + w1->set_minimum_size(gfx::Size(30, 30)); |
|
Ben Goodger (Google)
2011/10/15 05:36:30
...except for this bit, which you can add a new te
|
| + generator.DragMouseTo(100, 100); |
| + EXPECT_EQ(gfx::Rect(100, 100, 30, 30), w1->bounds()); |
| + generator.DragMouseTo(50, 50); |
| + EXPECT_EQ(gfx::Rect(100, 100, 30, 30), w1->bounds()); |
| +} |
| + |
| class WindowObserverTest : public WindowTest, |
| public WindowObserver { |
| public: |