Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(28)

Side by Side Diff: ui/aura/mus/window_tree_client_unittest.cc

Issue 2533213006: Fixes coordinates supplied to WindowTreeHost (Closed)
Patch Set: comment Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "ui/aura/mus/window_tree_client.h" 5 #include "ui/aura/mus/window_tree_client.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 class InputEventBasicTestWindowDelegate : public test::TestWindowDelegate { 442 class InputEventBasicTestWindowDelegate : public test::TestWindowDelegate {
443 public: 443 public:
444 static uint32_t constexpr kEventId = 1; 444 static uint32_t constexpr kEventId = 1;
445 445
446 explicit InputEventBasicTestWindowDelegate(TestWindowTree* test_window_tree) 446 explicit InputEventBasicTestWindowDelegate(TestWindowTree* test_window_tree)
447 : test_window_tree_(test_window_tree) {} 447 : test_window_tree_(test_window_tree) {}
448 ~InputEventBasicTestWindowDelegate() override {} 448 ~InputEventBasicTestWindowDelegate() override {}
449 449
450 bool got_move() const { return got_move_; } 450 bool got_move() const { return got_move_; }
451 bool was_acked() const { return was_acked_; } 451 bool was_acked() const { return was_acked_; }
452 const gfx::Point& last_event_location() const { return last_event_location_; }
452 453
453 // TestWindowDelegate:: 454 // TestWindowDelegate::
454 void OnMouseEvent(ui::MouseEvent* event) override { 455 void OnMouseEvent(ui::MouseEvent* event) override {
455 was_acked_ = test_window_tree_->WasEventAcked(kEventId); 456 was_acked_ = test_window_tree_->WasEventAcked(kEventId);
456 if (event->type() == ui::ET_MOUSE_MOVED) 457 if (event->type() == ui::ET_MOUSE_MOVED)
457 got_move_ = true; 458 got_move_ = true;
459 last_event_location_ = event->location();
460 event->SetHandled();
458 } 461 }
459 462
460 private: 463 private:
461 TestWindowTree* test_window_tree_; 464 TestWindowTree* test_window_tree_;
462 bool was_acked_ = false; 465 bool was_acked_ = false;
463 bool got_move_ = false; 466 bool got_move_ = false;
467 gfx::Point last_event_location_;
464 468
465 DISALLOW_COPY_AND_ASSIGN(InputEventBasicTestWindowDelegate); 469 DISALLOW_COPY_AND_ASSIGN(InputEventBasicTestWindowDelegate);
466 }; 470 };
467 471
468 } // namespace 472 } // namespace
469 473
470 TEST_F(WindowTreeClientClientTest, InputEventBasic) { 474 TEST_F(WindowTreeClientClientTest, InputEventBasic) {
471 InputEventBasicTestWindowDelegate window_delegate(window_tree()); 475 InputEventBasicTestWindowDelegate window_delegate(window_tree());
472 WindowTreeHostMus window_tree_host(window_tree_client_impl()); 476 WindowTreeHostMus window_tree_host(window_tree_client_impl());
473 Window* top_level = window_tree_host.window(); 477 Window* top_level = window_tree_host.window();
474 const gfx::Rect bounds(0, 0, 100, 100); 478 const gfx::Rect bounds(0, 0, 100, 100);
475 window_tree_host.SetBoundsInPixels(bounds); 479 window_tree_host.SetBoundsInPixels(bounds);
476 window_tree_host.Show(); 480 window_tree_host.Show();
477 EXPECT_EQ(bounds, top_level->bounds()); 481 EXPECT_EQ(bounds, top_level->bounds());
478 EXPECT_EQ(bounds, window_tree_host.GetBoundsInPixels()); 482 EXPECT_EQ(bounds, window_tree_host.GetBoundsInPixels());
479 Window child(&window_delegate); 483 Window child(&window_delegate);
480 child.Init(ui::LAYER_NOT_DRAWN); 484 child.Init(ui::LAYER_NOT_DRAWN);
481 top_level->AddChild(&child); 485 top_level->AddChild(&child);
482 child.SetBounds(gfx::Rect(0, 0, 100, 100)); 486 child.SetBounds(gfx::Rect(10, 10, 100, 100));
483 child.Show(); 487 child.Show();
484 EXPECT_FALSE(window_delegate.got_move()); 488 EXPECT_FALSE(window_delegate.got_move());
485 EXPECT_FALSE(window_delegate.was_acked()); 489 EXPECT_FALSE(window_delegate.was_acked());
490 const gfx::Point event_location_in_child(2, 3);
486 std::unique_ptr<ui::Event> ui_event( 491 std::unique_ptr<ui::Event> ui_event(
487 new ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::Point(), gfx::Point(), 492 new ui::MouseEvent(ui::ET_MOUSE_MOVED, event_location_in_child,
488 ui::EventTimeForNow(), ui::EF_NONE, 0)); 493 gfx::Point(), ui::EventTimeForNow(), ui::EF_NONE, 0));
489 window_tree_client()->OnWindowInputEvent( 494 window_tree_client()->OnWindowInputEvent(
490 InputEventBasicTestWindowDelegate::kEventId, server_id(top_level), 495 InputEventBasicTestWindowDelegate::kEventId, server_id(&child),
491 ui::Event::Clone(*ui_event.get()), 0); 496 ui::Event::Clone(*ui_event.get()), 0);
492 EXPECT_TRUE(window_tree()->WasEventAcked(1)); 497 EXPECT_TRUE(window_tree()->WasEventAcked(
498 InputEventBasicTestWindowDelegate::kEventId));
499 EXPECT_EQ(ui::mojom::EventResult::HANDLED,
500 window_tree()->GetEventResult(
501 InputEventBasicTestWindowDelegate::kEventId));
493 EXPECT_TRUE(window_delegate.got_move()); 502 EXPECT_TRUE(window_delegate.got_move());
494 EXPECT_FALSE(window_delegate.was_acked()); 503 EXPECT_FALSE(window_delegate.was_acked());
504 EXPECT_EQ(event_location_in_child, window_delegate.last_event_location());
495 } 505 }
496 506
497 class WindowTreeClientPointerObserverTest : public WindowTreeClientClientTest { 507 class WindowTreeClientPointerObserverTest : public WindowTreeClientClientTest {
498 public: 508 public:
499 WindowTreeClientPointerObserverTest() {} 509 WindowTreeClientPointerObserverTest() {}
500 ~WindowTreeClientPointerObserverTest() override {} 510 ~WindowTreeClientPointerObserverTest() override {}
501 511
502 void DeleteLastEventObserved() { last_event_observed_.reset(); } 512 void DeleteLastEventObserved() { last_event_observed_.reset(); }
503 const ui::PointerEvent* last_event_observed() const { 513 const ui::PointerEvent* last_event_observed() const {
504 return last_event_observed_.get(); 514 return last_event_observed_.get();
(...skipping 853 matching lines...) Expand 10 before | Expand all | Expand 10 after
1358 .CallWmNewDisplayAdded(display, std::move(root_data), parent_drawn); 1368 .CallWmNewDisplayAdded(display, std::move(root_data), parent_drawn);
1359 EXPECT_EQ(display.bounds(), window_tree_host->GetBoundsInPixels()); 1369 EXPECT_EQ(display.bounds(), window_tree_host->GetBoundsInPixels());
1360 // The root window of the WindowTreeHost always has an origin of 0,0. 1370 // The root window of the WindowTreeHost always has an origin of 0,0.
1361 EXPECT_EQ(gfx::Rect(display.bounds().size()), 1371 EXPECT_EQ(gfx::Rect(display.bounds().size()),
1362 window_tree_host->window()->bounds()); 1372 window_tree_host->window()->bounds());
1363 EXPECT_TRUE(window_tree_host->window()->IsVisible()); 1373 EXPECT_TRUE(window_tree_host->window()->IsVisible());
1364 EXPECT_EQ(display.id(), window_tree_host->display_id()); 1374 EXPECT_EQ(display.id(), window_tree_host->display_id());
1365 } 1375 }
1366 1376
1367 } // namespace aura 1377 } // namespace aura
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698