Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <string> | 5 #include <string> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "components/mus/common/types.h" | 9 #include "components/mus/common/types.h" |
| 10 #include "components/mus/common/util.h" | 10 #include "components/mus/common/util.h" |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 117 tracker_.OnWindowSharedPropertyChanged(window, name, new_data.Pass()); | 117 tracker_.OnWindowSharedPropertyChanged(window, name, new_data.Pass()); |
| 118 } | 118 } |
| 119 void OnWindowInputEvent(uint32_t event_id, | 119 void OnWindowInputEvent(uint32_t event_id, |
| 120 uint32_t window, | 120 uint32_t window, |
| 121 EventPtr event) override { | 121 EventPtr event) override { |
| 122 tracker_.OnWindowInputEvent(window, event.Pass()); | 122 tracker_.OnWindowInputEvent(window, event.Pass()); |
| 123 } | 123 } |
| 124 void OnWindowFocused(uint32_t focused_window_id) override { | 124 void OnWindowFocused(uint32_t focused_window_id) override { |
| 125 tracker_.OnWindowFocused(focused_window_id); | 125 tracker_.OnWindowFocused(focused_window_id); |
| 126 } | 126 } |
| 127 void OnWindowSetPredefinedCursor(uint32 window_id, | |
| 128 mojom::Cursor cursor_id) override { | |
| 129 tracker_.OnWindowSetPredefinedCursor(window_id, cursor_id); | |
| 130 } | |
| 127 void OnChangeCompleted(uint32_t change_id, bool success) override {} | 131 void OnChangeCompleted(uint32_t change_id, bool success) override {} |
| 128 void WmSetBounds(uint32_t change_id, | 132 void WmSetBounds(uint32_t change_id, |
| 129 Id window_id, | 133 Id window_id, |
| 130 mojo::RectPtr bounds) override {} | 134 mojo::RectPtr bounds) override {} |
| 131 void WmSetProperty(uint32_t change_id, | 135 void WmSetProperty(uint32_t change_id, |
| 132 Id window_id, | 136 Id window_id, |
| 133 const mojo::String& name, | 137 const mojo::String& name, |
| 134 mojo::Array<uint8_t> transit_data) override {} | 138 mojo::Array<uint8_t> transit_data) override {} |
| 135 | 139 |
| 136 TestChangeTracker tracker_; | 140 TestChangeTracker tracker_; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 213 mus::mojom::WindowTree::ACCESS_POLICY_EMBED_ROOT, | 217 mus::mojom::WindowTree::ACCESS_POLICY_EMBED_ROOT, |
| 214 mus::mojom::WindowTreeClientPtr())); | 218 mus::mojom::WindowTreeClientPtr())); |
| 215 } | 219 } |
| 216 DISALLOW_COPY_AND_ASSIGN(TestWindowTreeHostConnection); | 220 DISALLOW_COPY_AND_ASSIGN(TestWindowTreeHostConnection); |
| 217 }; | 221 }; |
| 218 | 222 |
| 219 // ----------------------------------------------------------------------------- | 223 // ----------------------------------------------------------------------------- |
| 220 // Empty implementation of DisplayManager. | 224 // Empty implementation of DisplayManager. |
| 221 class TestDisplayManager : public DisplayManager { | 225 class TestDisplayManager : public DisplayManager { |
| 222 public: | 226 public: |
| 223 TestDisplayManager() {} | 227 TestDisplayManager(int32_t* cursor_id_storage) |
|
sky
2015/12/02 21:42:35
nit: explicit
| |
| 228 : cursor_id_storage_(cursor_id_storage) {} | |
| 224 ~TestDisplayManager() override {} | 229 ~TestDisplayManager() override {} |
| 225 | 230 |
| 226 // DisplayManager: | 231 // DisplayManager: |
| 227 void Init(DisplayManagerDelegate* delegate) override { | 232 void Init(DisplayManagerDelegate* delegate) override { |
| 228 // It is necessary to tell the delegate about the ViewportMetrics to make | 233 // It is necessary to tell the delegate about the ViewportMetrics to make |
| 229 // sure that the WindowTreeHostConnection is correctly initialized (and a | 234 // sure that the WindowTreeHostConnection is correctly initialized (and a |
| 230 // root-window is created). | 235 // root-window is created). |
| 231 mojom::ViewportMetrics metrics; | 236 mojom::ViewportMetrics metrics; |
| 232 metrics.size_in_pixels = mojo::Size::From(gfx::Size(400, 300)); | 237 metrics.size_in_pixels = mojo::Size::From(gfx::Size(400, 300)); |
| 233 metrics.device_pixel_ratio = 1.f; | 238 metrics.device_pixel_ratio = 1.f; |
| 234 delegate->OnViewportMetricsChanged(mojom::ViewportMetrics(), metrics); | 239 delegate->OnViewportMetricsChanged(mojom::ViewportMetrics(), metrics); |
| 235 } | 240 } |
| 236 void SchedulePaint(const ServerWindow* window, | 241 void SchedulePaint(const ServerWindow* window, |
| 237 const gfx::Rect& bounds) override {} | 242 const gfx::Rect& bounds) override {} |
| 238 void SetViewportSize(const gfx::Size& size) override {} | 243 void SetViewportSize(const gfx::Size& size) override {} |
| 239 void SetTitle(const base::string16& title) override {} | 244 void SetTitle(const base::string16& title) override {} |
| 245 void SetCursorById(int32_t cursor) override { *cursor_id_storage_ = cursor; } | |
| 240 const mojom::ViewportMetrics& GetViewportMetrics() override { | 246 const mojom::ViewportMetrics& GetViewportMetrics() override { |
| 241 return display_metrices_; | 247 return display_metrices_; |
| 242 } | 248 } |
| 243 void UpdateTextInputState(const ui::TextInputState& state) override {} | 249 void UpdateTextInputState(const ui::TextInputState& state) override {} |
| 244 void SetImeVisibility(bool visible) override {} | 250 void SetImeVisibility(bool visible) override {} |
| 245 bool IsFramePending() const override { return false; } | 251 bool IsFramePending() const override { return false; } |
| 246 | 252 |
| 247 private: | 253 private: |
| 248 mojom::ViewportMetrics display_metrices_; | 254 mojom::ViewportMetrics display_metrices_; |
| 249 | 255 |
| 256 int32_t* cursor_id_storage_; | |
| 257 | |
| 250 DISALLOW_COPY_AND_ASSIGN(TestDisplayManager); | 258 DISALLOW_COPY_AND_ASSIGN(TestDisplayManager); |
| 251 }; | 259 }; |
| 252 | 260 |
| 253 // Factory that dispenses TestDisplayManagers. | 261 // Factory that dispenses TestDisplayManagers. |
| 254 class TestDisplayManagerFactory : public DisplayManagerFactory { | 262 class TestDisplayManagerFactory : public DisplayManagerFactory { |
| 255 public: | 263 public: |
| 256 TestDisplayManagerFactory() {} | 264 TestDisplayManagerFactory(int32_t* cursor_id_storage) |
|
sky
2015/12/02 21:42:35
explicit
| |
| 265 : cursor_id_storage_(cursor_id_storage) {} | |
| 257 ~TestDisplayManagerFactory() {} | 266 ~TestDisplayManagerFactory() {} |
| 258 DisplayManager* CreateDisplayManager( | 267 DisplayManager* CreateDisplayManager( |
| 259 mojo::ApplicationImpl* app_impl, | 268 mojo::ApplicationImpl* app_impl, |
| 260 const scoped_refptr<GpuState>& gpu_state, | 269 const scoped_refptr<GpuState>& gpu_state, |
| 261 const scoped_refptr<mus::SurfacesState>& surfaces_state) override { | 270 const scoped_refptr<mus::SurfacesState>& surfaces_state) override { |
| 262 return new TestDisplayManager(); | 271 return new TestDisplayManager(cursor_id_storage_); |
| 263 } | 272 } |
| 264 | 273 |
| 265 private: | 274 private: |
| 275 int32_t* cursor_id_storage_; | |
| 276 | |
| 266 DISALLOW_COPY_AND_ASSIGN(TestDisplayManagerFactory); | 277 DISALLOW_COPY_AND_ASSIGN(TestDisplayManagerFactory); |
| 267 }; | 278 }; |
| 268 | 279 |
| 269 EventPtr CreatePointerDownEvent(int x, int y) { | 280 EventPtr CreatePointerDownEvent(int x, int y) { |
| 270 EventPtr event(Event::New()); | 281 EventPtr event(Event::New()); |
| 271 event->action = mus::mojom::EVENT_TYPE_POINTER_DOWN; | 282 event->action = mus::mojom::EVENT_TYPE_POINTER_DOWN; |
| 272 event->pointer_data = PointerData::New(); | 283 event->pointer_data = PointerData::New(); |
| 273 event->pointer_data->pointer_id = 1u; | 284 event->pointer_data->pointer_id = 1u; |
| 274 event->pointer_data->location = LocationData::New(); | 285 event->pointer_data->location = LocationData::New(); |
| 275 event->pointer_data->location->x = x; | 286 event->pointer_data->location->x = x; |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 301 event->pointer_data->kind = mojom::POINTER_KIND_MOUSE; | 312 event->pointer_data->kind = mojom::POINTER_KIND_MOUSE; |
| 302 return event.Pass(); | 313 return event.Pass(); |
| 303 } | 314 } |
| 304 | 315 |
| 305 } // namespace | 316 } // namespace |
| 306 | 317 |
| 307 // ----------------------------------------------------------------------------- | 318 // ----------------------------------------------------------------------------- |
| 308 | 319 |
| 309 class WindowTreeTest : public testing::Test { | 320 class WindowTreeTest : public testing::Test { |
| 310 public: | 321 public: |
| 311 WindowTreeTest() : wm_client_(nullptr) {} | 322 WindowTreeTest() |
| 323 : wm_client_(nullptr), | |
| 324 cursor_id_(0), | |
| 325 display_manager_factory_(&cursor_id_) {} | |
| 312 ~WindowTreeTest() override {} | 326 ~WindowTreeTest() override {} |
| 313 | 327 |
| 314 // WindowTreeImpl for the window manager. | 328 // WindowTreeImpl for the window manager. |
| 315 WindowTreeImpl* wm_connection() { | 329 WindowTreeImpl* wm_connection() { |
| 316 return connection_manager_->GetConnection(1); | 330 return connection_manager_->GetConnection(1); |
| 317 } | 331 } |
| 318 | 332 |
| 319 TestWindowTreeClient* last_window_tree_client() { | 333 TestWindowTreeClient* last_window_tree_client() { |
| 320 return delegate_.last_client(); | 334 return delegate_.last_client(); |
| 321 } | 335 } |
| 322 | 336 |
| 323 TestClientConnection* last_client_connection() { | 337 TestClientConnection* last_client_connection() { |
| 324 return delegate_.last_connection(); | 338 return delegate_.last_connection(); |
| 325 } | 339 } |
| 326 | 340 |
| 327 ConnectionManager* connection_manager() { return connection_manager_.get(); } | 341 ConnectionManager* connection_manager() { return connection_manager_.get(); } |
| 328 | 342 |
| 329 TestWindowTreeClient* wm_client() { return wm_client_; } | 343 TestWindowTreeClient* wm_client() { return wm_client_; } |
| 344 int32_t cursor_id() { return cursor_id_; } | |
| 330 | 345 |
| 331 TestWindowTreeHostConnection* host_connection() { return host_connection_; } | 346 TestWindowTreeHostConnection* host_connection() { return host_connection_; } |
| 332 | 347 |
| 333 void DispatchEventWithoutAck(mojom::EventPtr event) { | 348 void DispatchEventWithoutAck(mojom::EventPtr event) { |
| 334 host_connection()->window_tree_host()->OnEvent(event.Pass()); | 349 host_connection()->window_tree_host()->OnEvent(event.Pass()); |
| 335 } | 350 } |
| 336 | 351 |
| 337 void AckPreviousEvent() { | 352 void AckPreviousEvent() { |
| 338 host_connection() | 353 host_connection() |
| 339 ->window_tree_host() | 354 ->window_tree_host() |
| 340 ->tree_awaiting_input_ack_->OnWindowInputEventAck(0); | 355 ->tree_awaiting_input_ack_->OnWindowInputEventAck(0); |
| 341 } | 356 } |
| 342 | 357 |
| 343 void DispatchEventAndAckImmediately(mojom::EventPtr event) { | 358 void DispatchEventAndAckImmediately(mojom::EventPtr event) { |
| 344 DispatchEventWithoutAck(event.Pass()); | 359 DispatchEventWithoutAck(event.Pass()); |
| 345 AckPreviousEvent(); | 360 AckPreviousEvent(); |
| 346 } | 361 } |
| 347 | 362 |
| 363 void SetupEventTargeting(TestWindowTreeClient** out_client, | |
|
sky
2015/12/02 21:42:35
Add description.
| |
| 364 ServerWindow** out_window); | |
| 365 | |
| 348 protected: | 366 protected: |
| 349 // testing::Test: | 367 // testing::Test: |
| 350 void SetUp() override { | 368 void SetUp() override { |
| 351 DisplayManager::set_factory_for_testing(&display_manager_factory_); | 369 DisplayManager::set_factory_for_testing(&display_manager_factory_); |
| 352 // TODO(fsamuel): This is probably broken. We need a root. | 370 // TODO(fsamuel): This is probably broken. We need a root. |
| 353 connection_manager_.reset( | 371 connection_manager_.reset( |
| 354 new ConnectionManager(&delegate_, scoped_refptr<SurfacesState>())); | 372 new ConnectionManager(&delegate_, scoped_refptr<SurfacesState>())); |
| 355 WindowTreeHostImpl* host = new WindowTreeHostImpl( | 373 WindowTreeHostImpl* host = new WindowTreeHostImpl( |
| 356 mus::mojom::WindowTreeHostClientPtr(), connection_manager_.get(), | 374 mus::mojom::WindowTreeHostClientPtr(), connection_manager_.get(), |
| 357 nullptr, scoped_refptr<GpuState>(), scoped_refptr<mus::SurfacesState>(), | 375 nullptr, scoped_refptr<GpuState>(), scoped_refptr<mus::SurfacesState>(), |
| 358 nullptr); | 376 nullptr); |
| 359 // TODO(fsamuel): This is way too magical. We need to find a better way to | 377 // TODO(fsamuel): This is way too magical. We need to find a better way to |
| 360 // manage lifetime. | 378 // manage lifetime. |
| 361 host_connection_ = new TestWindowTreeHostConnection( | 379 host_connection_ = new TestWindowTreeHostConnection( |
| 362 make_scoped_ptr(host), connection_manager_.get()); | 380 make_scoped_ptr(host), connection_manager_.get()); |
| 363 host->Init(host_connection_); | 381 host->Init(host_connection_); |
| 364 wm_client_ = delegate_.last_client(); | 382 wm_client_ = delegate_.last_client(); |
| 365 } | 383 } |
| 366 | 384 |
| 367 private: | 385 private: |
| 368 // TestWindowTreeClient that is used for the WM connection. | 386 // TestWindowTreeClient that is used for the WM connection. |
| 369 TestWindowTreeClient* wm_client_; | 387 TestWindowTreeClient* wm_client_; |
| 388 int32_t cursor_id_; | |
| 370 TestDisplayManagerFactory display_manager_factory_; | 389 TestDisplayManagerFactory display_manager_factory_; |
| 371 TestConnectionManagerDelegate delegate_; | 390 TestConnectionManagerDelegate delegate_; |
| 372 TestWindowTreeHostConnection* host_connection_; | 391 TestWindowTreeHostConnection* host_connection_; |
| 373 scoped_ptr<ConnectionManager> connection_manager_; | 392 scoped_ptr<ConnectionManager> connection_manager_; |
| 374 base::MessageLoop message_loop_; | 393 base::MessageLoop message_loop_; |
| 375 | 394 |
| 376 DISALLOW_COPY_AND_ASSIGN(WindowTreeTest); | 395 DISALLOW_COPY_AND_ASSIGN(WindowTreeTest); |
| 377 }; | 396 }; |
| 378 | 397 |
| 398 void WindowTreeTest::SetupEventTargeting(TestWindowTreeClient** out_client, | |
|
sky
2015/12/02 21:42:35
Make sure you wrap calls to this in EXPECT_NO_FATA
| |
| 399 ServerWindow** out_window) { | |
| 400 const WindowId embed_window_id(wm_connection()->id(), 1); | |
| 401 EXPECT_TRUE( | |
| 402 wm_connection()->NewWindow(embed_window_id, ServerWindow::Properties())); | |
| 403 EXPECT_TRUE(wm_connection()->SetWindowVisibility(embed_window_id, true)); | |
| 404 EXPECT_TRUE( | |
| 405 wm_connection()->AddWindow(*(wm_connection()->root()), embed_window_id)); | |
| 406 host_connection()->window_tree_host()->root_window()->SetBounds( | |
| 407 gfx::Rect(0, 0, 100, 100)); | |
| 408 mojom::WindowTreeClientPtr client; | |
| 409 mojo::InterfaceRequest<mojom::WindowTreeClient> client_request = | |
| 410 GetProxy(&client); | |
| 411 wm_client()->Bind(client_request.Pass()); | |
| 412 ConnectionSpecificId connection_id = 0; | |
| 413 wm_connection()->Embed(embed_window_id, client.Pass(), | |
| 414 mojom::WindowTree::ACCESS_POLICY_DEFAULT, | |
| 415 &connection_id); | |
| 416 WindowTreeImpl* connection1 = | |
| 417 connection_manager()->GetConnectionWithRoot(embed_window_id); | |
| 418 ASSERT_TRUE(connection1 != nullptr); | |
| 419 ASSERT_NE(connection1, wm_connection()); | |
| 420 | |
| 421 connection_manager() | |
| 422 ->GetWindow(embed_window_id) | |
| 423 ->SetBounds(gfx::Rect(0, 0, 50, 50)); | |
| 424 | |
| 425 const WindowId child1(connection1->id(), 1); | |
| 426 EXPECT_TRUE(connection1->NewWindow(child1, ServerWindow::Properties())); | |
| 427 EXPECT_TRUE(connection1->AddWindow(embed_window_id, child1)); | |
| 428 connection1->GetHost()->AddActivationParent( | |
| 429 WindowIdToTransportId(embed_window_id)); | |
| 430 | |
| 431 ServerWindow* v1 = connection1->GetWindow(child1); | |
| 432 v1->SetVisible(true); | |
| 433 v1->SetBounds(gfx::Rect(20, 20, 20, 20)); | |
| 434 EnableHitTest(v1); | |
| 435 | |
| 436 TestWindowTreeClient* embed_connection = last_window_tree_client(); | |
| 437 embed_connection->tracker()->changes()->clear(); | |
| 438 wm_client()->tracker()->changes()->clear(); | |
| 439 | |
| 440 *out_client = embed_connection; | |
| 441 *out_window = v1; | |
| 442 } | |
| 443 | |
| 379 // Verifies focus correctly changes on pointer events. | 444 // Verifies focus correctly changes on pointer events. |
| 380 TEST_F(WindowTreeTest, FocusOnPointer) { | 445 TEST_F(WindowTreeTest, FocusOnPointer) { |
| 381 const WindowId embed_window_id(wm_connection()->id(), 1); | 446 const WindowId embed_window_id(wm_connection()->id(), 1); |
| 382 EXPECT_TRUE( | 447 EXPECT_TRUE( |
| 383 wm_connection()->NewWindow(embed_window_id, ServerWindow::Properties())); | 448 wm_connection()->NewWindow(embed_window_id, ServerWindow::Properties())); |
| 384 EXPECT_TRUE(wm_connection()->SetWindowVisibility(embed_window_id, true)); | 449 EXPECT_TRUE(wm_connection()->SetWindowVisibility(embed_window_id, true)); |
| 385 EXPECT_TRUE( | 450 EXPECT_TRUE( |
| 386 wm_connection()->AddWindow(*(wm_connection()->root()), embed_window_id)); | 451 wm_connection()->AddWindow(*(wm_connection()->root()), embed_window_id)); |
| 387 host_connection()->window_tree_host()->root_window()->SetBounds( | 452 host_connection()->window_tree_host()->root_window()->SetBounds( |
| 388 gfx::Rect(0, 0, 100, 100)); | 453 gfx::Rect(0, 0, 100, 100)); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 457 DispatchEventAndAckImmediately(CreatePointerDownEvent(61, 22)); | 522 DispatchEventAndAckImmediately(CreatePointerDownEvent(61, 22)); |
| 458 EXPECT_EQ(v1, host_connection()->window_tree_host()->GetFocusedWindow()); | 523 EXPECT_EQ(v1, host_connection()->window_tree_host()->GetFocusedWindow()); |
| 459 ASSERT_EQ(wm_client()->tracker()->changes()->size(), 1u) | 524 ASSERT_EQ(wm_client()->tracker()->changes()->size(), 1u) |
| 460 << SingleChangeToDescription(*wm_client()->tracker()->changes()); | 525 << SingleChangeToDescription(*wm_client()->tracker()->changes()); |
| 461 EXPECT_EQ("InputEvent window=0,2 event_action=4", | 526 EXPECT_EQ("InputEvent window=0,2 event_action=4", |
| 462 ChangesToDescription1(*wm_client()->tracker()->changes())[0]); | 527 ChangesToDescription1(*wm_client()->tracker()->changes())[0]); |
| 463 EXPECT_TRUE(connection1_client->tracker()->changes()->empty()); | 528 EXPECT_TRUE(connection1_client->tracker()->changes()->empty()); |
| 464 } | 529 } |
| 465 | 530 |
| 466 TEST_F(WindowTreeTest, BasicInputEventTarget) { | 531 TEST_F(WindowTreeTest, BasicInputEventTarget) { |
| 467 const WindowId embed_window_id(wm_connection()->id(), 1); | 532 TestWindowTreeClient* embed_connection; |
| 468 EXPECT_TRUE( | 533 ServerWindow* out_window = nullptr; |
| 469 wm_connection()->NewWindow(embed_window_id, ServerWindow::Properties())); | 534 SetupEventTargeting(&embed_connection, &out_window); |
| 470 EXPECT_TRUE(wm_connection()->SetWindowVisibility(embed_window_id, true)); | |
| 471 EXPECT_TRUE( | |
| 472 wm_connection()->AddWindow(*(wm_connection()->root()), embed_window_id)); | |
| 473 host_connection()->window_tree_host()->root_window()->SetBounds( | |
| 474 gfx::Rect(0, 0, 100, 100)); | |
| 475 mojom::WindowTreeClientPtr client; | |
| 476 mojo::InterfaceRequest<mojom::WindowTreeClient> client_request = | |
| 477 GetProxy(&client); | |
| 478 wm_client()->Bind(client_request.Pass()); | |
| 479 ConnectionSpecificId connection_id = 0; | |
| 480 wm_connection()->Embed(embed_window_id, | |
| 481 client.Pass(), | |
| 482 mojom::WindowTree::ACCESS_POLICY_DEFAULT, | |
| 483 &connection_id); | |
| 484 WindowTreeImpl* connection1 = | |
| 485 connection_manager()->GetConnectionWithRoot(embed_window_id); | |
| 486 ASSERT_TRUE(connection1 != nullptr); | |
| 487 ASSERT_NE(connection1, wm_connection()); | |
| 488 | |
| 489 connection_manager() | |
| 490 ->GetWindow(embed_window_id) | |
| 491 ->SetBounds(gfx::Rect(0, 0, 50, 50)); | |
| 492 | |
| 493 const WindowId child1(connection1->id(), 1); | |
| 494 EXPECT_TRUE(connection1->NewWindow(child1, ServerWindow::Properties())); | |
| 495 EXPECT_TRUE(connection1->AddWindow(embed_window_id, child1)); | |
| 496 connection1->GetHost()->AddActivationParent( | |
| 497 WindowIdToTransportId(embed_window_id)); | |
| 498 | |
| 499 ServerWindow* v1 = connection1->GetWindow(child1); | |
| 500 v1->SetVisible(true); | |
| 501 v1->SetBounds(gfx::Rect(20, 20, 20, 20)); | |
| 502 EnableHitTest(v1); | |
| 503 | |
| 504 TestWindowTreeClient* embed_connection = last_window_tree_client(); | |
| 505 embed_connection->tracker()->changes()->clear(); | |
| 506 wm_client()->tracker()->changes()->clear(); | |
| 507 | 535 |
| 508 // Send an event to |v1|. |embed_connection| should get the event, not | 536 // Send an event to |v1|. |embed_connection| should get the event, not |
| 509 // |wm_client|, since |v1| lives inside an embedded window. | 537 // |wm_client|, since |v1| lives inside an embedded window. |
| 510 DispatchEventAndAckImmediately(CreatePointerDownEvent(21, 22)); | 538 DispatchEventAndAckImmediately(CreatePointerDownEvent(21, 22)); |
| 511 ASSERT_EQ(1u, wm_client()->tracker()->changes()->size()); | 539 ASSERT_EQ(1u, wm_client()->tracker()->changes()->size()); |
| 512 EXPECT_EQ("Focused id=2,1", | 540 EXPECT_EQ("Focused id=2,1", |
| 513 ChangesToDescription1(*wm_client()->tracker()->changes())[0]); | 541 ChangesToDescription1(*wm_client()->tracker()->changes())[0]); |
| 514 ASSERT_EQ(2u, embed_connection->tracker()->changes()->size()); | 542 ASSERT_EQ(2u, embed_connection->tracker()->changes()->size()); |
| 515 EXPECT_EQ("Focused id=2,1", | 543 EXPECT_EQ("Focused id=2,1", |
| 516 ChangesToDescription1(*embed_connection->tracker()->changes())[0]); | 544 ChangesToDescription1(*embed_connection->tracker()->changes())[0]); |
| 517 EXPECT_EQ("InputEvent window=2,1 event_action=4", | 545 EXPECT_EQ("InputEvent window=2,1 event_action=4", |
| 518 ChangesToDescription1(*embed_connection->tracker()->changes())[1]); | 546 ChangesToDescription1(*embed_connection->tracker()->changes())[1]); |
| 519 } | 547 } |
| 520 | 548 |
| 549 TEST_F(WindowTreeTest, CursorChangesWhenMouseOverWindowAndWindowSetsCursor) { | |
| 550 TestWindowTreeClient* embed_connection = nullptr; | |
| 551 ServerWindow* out_window = nullptr; | |
| 552 SetupEventTargeting(&embed_connection, &out_window); | |
| 553 | |
| 554 // Like in BasicInputEventTarget, we send a pointer down event to be | |
| 555 // dispatched. This is only to place the mouse cursor over that window though. | |
| 556 DispatchEventAndAckImmediately(CreateMouseMoveEvent(21, 22)); | |
| 557 | |
| 558 out_window->SetPredefinedCursor(mojom::Cursor::CURSOR_IBEAM); | |
| 559 | |
| 560 // Because the cursor is over the window when SetCursor was called, we should | |
| 561 // have immediately changed the cursor. | |
| 562 EXPECT_EQ(mojom::Cursor::CURSOR_IBEAM, cursor_id()); | |
| 563 } | |
| 564 | |
| 565 TEST_F(WindowTreeTest, CursorChangesWhenEnteringWindowWithDifferentCursor) { | |
| 566 TestWindowTreeClient* embed_connection = nullptr; | |
| 567 ServerWindow* out_window = nullptr; | |
| 568 SetupEventTargeting(&embed_connection, &out_window); | |
| 569 | |
| 570 // Let's create a pointer event outside the window and then move the pointer | |
| 571 // inside. | |
| 572 DispatchEventAndAckImmediately(CreateMouseMoveEvent(5, 5)); | |
| 573 out_window->SetPredefinedCursor(mojom::Cursor::CURSOR_IBEAM); | |
| 574 EXPECT_EQ(mojom::Cursor::CURSOR_NULL, cursor_id()); | |
| 575 | |
| 576 DispatchEventAndAckImmediately(CreateMouseMoveEvent(21, 22)); | |
| 577 EXPECT_EQ(mojom::Cursor::CURSOR_IBEAM, cursor_id()); | |
| 578 } | |
| 579 | |
| 580 TEST_F(WindowTreeTest, TouchesDontChangeCursor) { | |
| 581 TestWindowTreeClient* embed_connection = nullptr; | |
| 582 ServerWindow* out_window = nullptr; | |
| 583 SetupEventTargeting(&embed_connection, &out_window); | |
| 584 | |
| 585 // Let's create a pointer event outside the window and then move the pointer | |
| 586 // inside. | |
| 587 DispatchEventAndAckImmediately(CreateMouseMoveEvent(5, 5)); | |
| 588 out_window->SetPredefinedCursor(mojom::Cursor::CURSOR_IBEAM); | |
| 589 EXPECT_EQ(mojom::Cursor::CURSOR_NULL, cursor_id()); | |
| 590 | |
| 591 // With a touch event, we shouldn't update the cursor. | |
| 592 DispatchEventAndAckImmediately(CreatePointerDownEvent(21, 22)); | |
| 593 EXPECT_EQ(mojom::Cursor::CURSOR_NULL, cursor_id()); | |
| 594 } | |
| 595 | |
| 521 TEST_F(WindowTreeTest, EventAck) { | 596 TEST_F(WindowTreeTest, EventAck) { |
| 522 const WindowId embed_window_id(wm_connection()->id(), 1); | 597 const WindowId embed_window_id(wm_connection()->id(), 1); |
| 523 EXPECT_TRUE( | 598 EXPECT_TRUE( |
| 524 wm_connection()->NewWindow(embed_window_id, ServerWindow::Properties())); | 599 wm_connection()->NewWindow(embed_window_id, ServerWindow::Properties())); |
| 525 EXPECT_TRUE(wm_connection()->SetWindowVisibility(embed_window_id, true)); | 600 EXPECT_TRUE(wm_connection()->SetWindowVisibility(embed_window_id, true)); |
| 526 EXPECT_TRUE( | 601 EXPECT_TRUE( |
| 527 wm_connection()->AddWindow(*(wm_connection()->root()), embed_window_id)); | 602 wm_connection()->AddWindow(*(wm_connection()->root()), embed_window_id)); |
| 528 host_connection()->window_tree_host()->root_window()->SetBounds( | 603 host_connection()->window_tree_host()->root_window()->SetBounds( |
| 529 gfx::Rect(0, 0, 100, 100)); | 604 gfx::Rect(0, 0, 100, 100)); |
| 530 | 605 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 542 // Ack the first event. That should trigger the dispatch of the second event. | 617 // Ack the first event. That should trigger the dispatch of the second event. |
| 543 AckPreviousEvent(); | 618 AckPreviousEvent(); |
| 544 ASSERT_EQ(1u, wm_client()->tracker()->changes()->size()); | 619 ASSERT_EQ(1u, wm_client()->tracker()->changes()->size()); |
| 545 EXPECT_EQ("InputEvent window=0,2 event_action=5", | 620 EXPECT_EQ("InputEvent window=0,2 event_action=5", |
| 546 ChangesToDescription1(*wm_client()->tracker()->changes())[0]); | 621 ChangesToDescription1(*wm_client()->tracker()->changes())[0]); |
| 547 } | 622 } |
| 548 | 623 |
| 549 } // namespace ws | 624 } // namespace ws |
| 550 | 625 |
| 551 } // namespace mus | 626 } // namespace mus |
| OLD | NEW |