| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stdint.h> | 5 #include <stdint.h> |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 #include "ui/gfx/geometry/rect.h" | 30 #include "ui/gfx/geometry/rect.h" |
| 31 | 31 |
| 32 namespace ui { | 32 namespace ui { |
| 33 namespace ws { | 33 namespace ws { |
| 34 namespace test { | 34 namespace test { |
| 35 | 35 |
| 36 const UserId kTestId1 = "20"; | 36 const UserId kTestId1 = "20"; |
| 37 | 37 |
| 38 class CursorTest : public testing::Test { | 38 class CursorTest : public testing::Test { |
| 39 public: | 39 public: |
| 40 CursorTest() : cursor_id_(-1), platform_display_factory_(&cursor_id_) {} | 40 CursorTest() {} |
| 41 ~CursorTest() override {} | 41 ~CursorTest() override {} |
| 42 | 42 |
| 43 WindowServer* window_server() { return ws_test_helper_.window_server(); } |
| 44 TestWindowServerDelegate* window_server_delegate() { |
| 45 return ws_test_helper_.window_server_delegate(); |
| 46 } |
| 47 int32_t cursor_id() const { return ws_test_helper_.cursor_id(); } |
| 48 |
| 43 protected: | 49 protected: |
| 44 // testing::Test: | 50 // testing::Test: |
| 45 void SetUp() override { | 51 void SetUp() override { |
| 46 PlatformDisplay::set_factory_for_testing(&platform_display_factory_); | 52 window_server_delegate()->set_num_displays_to_create(1); |
| 47 window_server_.reset(new WindowServer(&window_server_delegate_)); | |
| 48 window_server_delegate_.set_window_server(window_server_.get()); | |
| 49 | |
| 50 window_server_delegate_.set_num_displays_to_create(1); | |
| 51 | 53 |
| 52 // As a side effect, this allocates Displays. | 54 // As a side effect, this allocates Displays. |
| 53 WindowManagerWindowTreeFactorySetTestApi( | 55 WindowManagerWindowTreeFactorySetTestApi( |
| 54 window_server_->window_manager_window_tree_factory_set()) | 56 window_server()->window_manager_window_tree_factory_set()) |
| 55 .Add(kTestId1); | 57 .Add(kTestId1); |
| 56 window_server_->user_id_tracker()->AddUserId(kTestId1); | 58 window_server()->user_id_tracker()->AddUserId(kTestId1); |
| 57 window_server_->user_id_tracker()->SetActiveUserId(kTestId1); | 59 window_server()->user_id_tracker()->SetActiveUserId(kTestId1); |
| 58 } | 60 } |
| 59 | 61 |
| 60 ServerWindow* GetRoot() { | 62 ServerWindow* GetRoot() { |
| 61 DisplayManager* display_manager = window_server_->display_manager(); | 63 DisplayManager* display_manager = window_server()->display_manager(); |
| 62 // ASSERT_EQ(1u, display_manager->displays().size()); | 64 // ASSERT_EQ(1u, display_manager->displays().size()); |
| 63 Display* display = *display_manager->displays().begin(); | 65 Display* display = *display_manager->displays().begin(); |
| 64 return display->GetWindowManagerDisplayRootForUser(kTestId1)->root(); | 66 return display->GetWindowManagerDisplayRootForUser(kTestId1)->root(); |
| 65 } | 67 } |
| 66 | 68 |
| 67 // Create a 30x30 window where the outer 10 pixels is non-client. | 69 // Create a 30x30 window where the outer 10 pixels is non-client. |
| 68 ServerWindow* BuildServerWindow() { | 70 ServerWindow* BuildServerWindow() { |
| 69 DisplayManager* display_manager = window_server_->display_manager(); | 71 DisplayManager* display_manager = window_server()->display_manager(); |
| 70 Display* display = *display_manager->displays().begin(); | 72 Display* display = *display_manager->displays().begin(); |
| 71 WindowManagerDisplayRoot* active_display_root = | 73 WindowManagerDisplayRoot* active_display_root = |
| 72 display->GetActiveWindowManagerDisplayRoot(); | 74 display->GetActiveWindowManagerDisplayRoot(); |
| 73 WindowTree* tree = | 75 WindowTree* tree = |
| 74 active_display_root->window_manager_state()->window_tree(); | 76 active_display_root->window_manager_state()->window_tree(); |
| 75 ClientWindowId child_window_id; | 77 ClientWindowId child_window_id; |
| 76 if (!NewWindowInTree(tree, &child_window_id)) | 78 if (!NewWindowInTree(tree, &child_window_id)) |
| 77 return nullptr; | 79 return nullptr; |
| 78 | 80 |
| 79 ServerWindow* w = tree->GetWindowByClientId(child_window_id); | 81 ServerWindow* w = tree->GetWindowByClientId(child_window_id); |
| 80 w->SetBounds(gfx::Rect(10, 10, 30, 30)); | 82 w->SetBounds(gfx::Rect(10, 10, 30, 30)); |
| 81 w->SetClientArea(gfx::Insets(10, 10), std::vector<gfx::Rect>()); | 83 w->SetClientArea(gfx::Insets(10, 10), std::vector<gfx::Rect>()); |
| 82 w->SetVisible(true); | 84 w->SetVisible(true); |
| 83 | 85 |
| 84 ServerWindowSurfaceManagerTestApi test_api(w->GetOrCreateSurfaceManager()); | 86 ServerWindowSurfaceManagerTestApi test_api(w->GetOrCreateSurfaceManager()); |
| 85 test_api.CreateEmptyDefaultSurface(); | 87 test_api.CreateEmptyDefaultSurface(); |
| 86 | 88 |
| 87 return w; | 89 return w; |
| 88 } | 90 } |
| 89 | 91 |
| 90 void MoveCursorTo(const gfx::Point& p) { | 92 void MoveCursorTo(const gfx::Point& p) { |
| 91 DisplayManager* display_manager = window_server_->display_manager(); | 93 DisplayManager* display_manager = window_server()->display_manager(); |
| 92 ASSERT_EQ(1u, display_manager->displays().size()); | 94 ASSERT_EQ(1u, display_manager->displays().size()); |
| 93 Display* display = *display_manager->displays().begin(); | 95 Display* display = *display_manager->displays().begin(); |
| 94 WindowManagerDisplayRoot* active_display_root = | 96 WindowManagerDisplayRoot* active_display_root = |
| 95 display->GetActiveWindowManagerDisplayRoot(); | 97 display->GetActiveWindowManagerDisplayRoot(); |
| 96 ASSERT_TRUE(active_display_root); | 98 ASSERT_TRUE(active_display_root); |
| 97 static_cast<PlatformDisplayDelegate*>(display)->OnEvent(ui::PointerEvent( | 99 static_cast<PlatformDisplayDelegate*>(display)->OnEvent(ui::PointerEvent( |
| 98 ui::MouseEvent(ui::ET_MOUSE_MOVED, p, p, base::TimeTicks(), 0, 0))); | 100 ui::MouseEvent(ui::ET_MOUSE_MOVED, p, p, base::TimeTicks(), 0, 0))); |
| 99 WindowManagerState* wms = active_display_root->window_manager_state(); | 101 WindowManagerState* wms = active_display_root->window_manager_state(); |
| 100 wms->OnEventAck(wms->window_tree(), mojom::EventResult::HANDLED); | 102 wms->OnEventAck(wms->window_tree(), mojom::EventResult::HANDLED); |
| 101 } | 103 } |
| 102 | 104 |
| 103 protected: | |
| 104 int32_t cursor_id_; | |
| 105 TestPlatformDisplayFactory platform_display_factory_; | |
| 106 TestWindowServerDelegate window_server_delegate_; | |
| 107 std::unique_ptr<WindowServer> window_server_; | |
| 108 base::MessageLoop message_loop_; | |
| 109 | |
| 110 private: | 105 private: |
| 106 WindowServerTestHelper ws_test_helper_; |
| 111 DISALLOW_COPY_AND_ASSIGN(CursorTest); | 107 DISALLOW_COPY_AND_ASSIGN(CursorTest); |
| 112 }; | 108 }; |
| 113 | 109 |
| 114 TEST_F(CursorTest, ChangeByMouseMove) { | 110 TEST_F(CursorTest, ChangeByMouseMove) { |
| 115 ServerWindow* win = BuildServerWindow(); | 111 ServerWindow* win = BuildServerWindow(); |
| 116 win->SetPredefinedCursor(mojom::Cursor::IBEAM); | 112 win->SetPredefinedCursor(mojom::Cursor::IBEAM); |
| 117 EXPECT_EQ(mojom::Cursor::IBEAM, mojom::Cursor(win->cursor())); | 113 EXPECT_EQ(mojom::Cursor::IBEAM, mojom::Cursor(win->cursor())); |
| 118 win->SetNonClientCursor(mojom::Cursor::EAST_RESIZE); | 114 win->SetNonClientCursor(mojom::Cursor::EAST_RESIZE); |
| 119 EXPECT_EQ(mojom::Cursor::EAST_RESIZE, | 115 EXPECT_EQ(mojom::Cursor::EAST_RESIZE, |
| 120 mojom::Cursor(win->non_client_cursor())); | 116 mojom::Cursor(win->non_client_cursor())); |
| 121 | 117 |
| 122 // Non client area | 118 // Non client area |
| 123 MoveCursorTo(gfx::Point(15, 15)); | 119 MoveCursorTo(gfx::Point(15, 15)); |
| 124 EXPECT_EQ(mojom::Cursor::EAST_RESIZE, mojom::Cursor(cursor_id_)); | 120 EXPECT_EQ(mojom::Cursor::EAST_RESIZE, mojom::Cursor(cursor_id())); |
| 125 | 121 |
| 126 // Client area | 122 // Client area |
| 127 MoveCursorTo(gfx::Point(25, 25)); | 123 MoveCursorTo(gfx::Point(25, 25)); |
| 128 EXPECT_EQ(mojom::Cursor::IBEAM, mojom::Cursor(cursor_id_)); | 124 EXPECT_EQ(mojom::Cursor::IBEAM, mojom::Cursor(cursor_id())); |
| 129 } | 125 } |
| 130 | 126 |
| 131 TEST_F(CursorTest, ChangeByClientAreaChange) { | 127 TEST_F(CursorTest, ChangeByClientAreaChange) { |
| 132 ServerWindow* win = BuildServerWindow(); | 128 ServerWindow* win = BuildServerWindow(); |
| 133 win->SetPredefinedCursor(mojom::Cursor::IBEAM); | 129 win->SetPredefinedCursor(mojom::Cursor::IBEAM); |
| 134 EXPECT_EQ(mojom::Cursor::IBEAM, mojom::Cursor(win->cursor())); | 130 EXPECT_EQ(mojom::Cursor::IBEAM, mojom::Cursor(win->cursor())); |
| 135 win->SetNonClientCursor(mojom::Cursor::EAST_RESIZE); | 131 win->SetNonClientCursor(mojom::Cursor::EAST_RESIZE); |
| 136 EXPECT_EQ(mojom::Cursor::EAST_RESIZE, | 132 EXPECT_EQ(mojom::Cursor::EAST_RESIZE, |
| 137 mojom::Cursor(win->non_client_cursor())); | 133 mojom::Cursor(win->non_client_cursor())); |
| 138 | 134 |
| 139 // Non client area before we move. | 135 // Non client area before we move. |
| 140 MoveCursorTo(gfx::Point(15, 15)); | 136 MoveCursorTo(gfx::Point(15, 15)); |
| 141 EXPECT_EQ(mojom::Cursor::EAST_RESIZE, mojom::Cursor(cursor_id_)); | 137 EXPECT_EQ(mojom::Cursor::EAST_RESIZE, mojom::Cursor(cursor_id())); |
| 142 | 138 |
| 143 // Changing the client area should cause a change. | 139 // Changing the client area should cause a change. |
| 144 win->SetClientArea(gfx::Insets(1, 1), std::vector<gfx::Rect>()); | 140 win->SetClientArea(gfx::Insets(1, 1), std::vector<gfx::Rect>()); |
| 145 EXPECT_EQ(mojom::Cursor::IBEAM, mojom::Cursor(cursor_id_)); | 141 EXPECT_EQ(mojom::Cursor::IBEAM, mojom::Cursor(cursor_id())); |
| 146 } | 142 } |
| 147 | 143 |
| 148 TEST_F(CursorTest, NonClientCursorChange) { | 144 TEST_F(CursorTest, NonClientCursorChange) { |
| 149 ServerWindow* win = BuildServerWindow(); | 145 ServerWindow* win = BuildServerWindow(); |
| 150 win->SetPredefinedCursor(mojom::Cursor::IBEAM); | 146 win->SetPredefinedCursor(mojom::Cursor::IBEAM); |
| 151 EXPECT_EQ(mojom::Cursor::IBEAM, mojom::Cursor(win->cursor())); | 147 EXPECT_EQ(mojom::Cursor::IBEAM, mojom::Cursor(win->cursor())); |
| 152 win->SetNonClientCursor(mojom::Cursor::EAST_RESIZE); | 148 win->SetNonClientCursor(mojom::Cursor::EAST_RESIZE); |
| 153 EXPECT_EQ(mojom::Cursor::EAST_RESIZE, | 149 EXPECT_EQ(mojom::Cursor::EAST_RESIZE, |
| 154 mojom::Cursor(win->non_client_cursor())); | 150 mojom::Cursor(win->non_client_cursor())); |
| 155 | 151 |
| 156 MoveCursorTo(gfx::Point(15, 15)); | 152 MoveCursorTo(gfx::Point(15, 15)); |
| 157 EXPECT_EQ(mojom::Cursor::EAST_RESIZE, mojom::Cursor(cursor_id_)); | 153 EXPECT_EQ(mojom::Cursor::EAST_RESIZE, mojom::Cursor(cursor_id())); |
| 158 | 154 |
| 159 win->SetNonClientCursor(mojom::Cursor::WEST_RESIZE); | 155 win->SetNonClientCursor(mojom::Cursor::WEST_RESIZE); |
| 160 EXPECT_EQ(mojom::Cursor::WEST_RESIZE, mojom::Cursor(cursor_id_)); | 156 EXPECT_EQ(mojom::Cursor::WEST_RESIZE, mojom::Cursor(cursor_id())); |
| 161 } | 157 } |
| 162 | 158 |
| 163 TEST_F(CursorTest, IgnoreClientCursorChangeInNonClientArea) { | 159 TEST_F(CursorTest, IgnoreClientCursorChangeInNonClientArea) { |
| 164 ServerWindow* win = BuildServerWindow(); | 160 ServerWindow* win = BuildServerWindow(); |
| 165 win->SetPredefinedCursor(mojom::Cursor::IBEAM); | 161 win->SetPredefinedCursor(mojom::Cursor::IBEAM); |
| 166 EXPECT_EQ(mojom::Cursor::IBEAM, mojom::Cursor(win->cursor())); | 162 EXPECT_EQ(mojom::Cursor::IBEAM, mojom::Cursor(win->cursor())); |
| 167 win->SetNonClientCursor(mojom::Cursor::EAST_RESIZE); | 163 win->SetNonClientCursor(mojom::Cursor::EAST_RESIZE); |
| 168 EXPECT_EQ(mojom::Cursor::EAST_RESIZE, | 164 EXPECT_EQ(mojom::Cursor::EAST_RESIZE, |
| 169 mojom::Cursor(win->non_client_cursor())); | 165 mojom::Cursor(win->non_client_cursor())); |
| 170 | 166 |
| 171 MoveCursorTo(gfx::Point(15, 15)); | 167 MoveCursorTo(gfx::Point(15, 15)); |
| 172 EXPECT_EQ(mojom::Cursor::EAST_RESIZE, mojom::Cursor(cursor_id_)); | 168 EXPECT_EQ(mojom::Cursor::EAST_RESIZE, mojom::Cursor(cursor_id())); |
| 173 | 169 |
| 174 win->SetPredefinedCursor(mojom::Cursor::HELP); | 170 win->SetPredefinedCursor(mojom::Cursor::HELP); |
| 175 EXPECT_EQ(mojom::Cursor::EAST_RESIZE, mojom::Cursor(cursor_id_)); | 171 EXPECT_EQ(mojom::Cursor::EAST_RESIZE, mojom::Cursor(cursor_id())); |
| 176 } | 172 } |
| 177 | 173 |
| 178 TEST_F(CursorTest, NonClientToClientByBoundsChange) { | 174 TEST_F(CursorTest, NonClientToClientByBoundsChange) { |
| 179 ServerWindow* win = BuildServerWindow(); | 175 ServerWindow* win = BuildServerWindow(); |
| 180 win->SetPredefinedCursor(mojom::Cursor::IBEAM); | 176 win->SetPredefinedCursor(mojom::Cursor::IBEAM); |
| 181 EXPECT_EQ(mojom::Cursor::IBEAM, mojom::Cursor(win->cursor())); | 177 EXPECT_EQ(mojom::Cursor::IBEAM, mojom::Cursor(win->cursor())); |
| 182 win->SetNonClientCursor(mojom::Cursor::EAST_RESIZE); | 178 win->SetNonClientCursor(mojom::Cursor::EAST_RESIZE); |
| 183 EXPECT_EQ(mojom::Cursor::EAST_RESIZE, | 179 EXPECT_EQ(mojom::Cursor::EAST_RESIZE, |
| 184 mojom::Cursor(win->non_client_cursor())); | 180 mojom::Cursor(win->non_client_cursor())); |
| 185 | 181 |
| 186 // Non client area before we move. | 182 // Non client area before we move. |
| 187 MoveCursorTo(gfx::Point(15, 15)); | 183 MoveCursorTo(gfx::Point(15, 15)); |
| 188 EXPECT_EQ(mojom::Cursor::EAST_RESIZE, mojom::Cursor(cursor_id_)); | 184 EXPECT_EQ(mojom::Cursor::EAST_RESIZE, mojom::Cursor(cursor_id())); |
| 189 | 185 |
| 190 win->SetBounds(gfx::Rect(0, 0, 30, 30)); | 186 win->SetBounds(gfx::Rect(0, 0, 30, 30)); |
| 191 EXPECT_EQ(mojom::Cursor::IBEAM, mojom::Cursor(cursor_id_)); | 187 EXPECT_EQ(mojom::Cursor::IBEAM, mojom::Cursor(cursor_id())); |
| 192 } | 188 } |
| 193 | 189 |
| 194 } // namespace test | 190 } // namespace test |
| 195 } // namespace ws | 191 } // namespace ws |
| 196 } // namespace ui | 192 } // namespace ui |
| OLD | NEW |