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

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

Issue 2456623002: Fixes to WindowTreeHostMus (Closed)
Patch Set: std::move Created 4 years, 1 month 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"
11 #include "mojo/common/common_type_converters.h" 11 #include "mojo/common/common_type_converters.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "ui/aura/client/aura_constants.h" 13 #include "ui/aura/client/aura_constants.h"
14 #include "ui/aura/client/capture_client.h" 14 #include "ui/aura/client/capture_client.h"
15 #include "ui/aura/client/focus_client.h" 15 #include "ui/aura/client/focus_client.h"
16 #include "ui/aura/mus/property_converter.h" 16 #include "ui/aura/mus/property_converter.h"
17 #include "ui/aura/mus/window_mus.h" 17 #include "ui/aura/mus/window_mus.h"
18 #include "ui/aura/mus/window_tree_client_delegate.h" 18 #include "ui/aura/mus/window_tree_client_delegate.h"
19 #include "ui/aura/mus/window_tree_client_observer.h" 19 #include "ui/aura/mus/window_tree_client_observer.h"
20 #include "ui/aura/test/aura_mus_test_base.h" 20 #include "ui/aura/test/aura_mus_test_base.h"
21 #include "ui/aura/test/mus/test_window_tree.h" 21 #include "ui/aura/test/mus/test_window_tree.h"
22 #include "ui/aura/test/mus/window_tree_client_private.h" 22 #include "ui/aura/test/mus/window_tree_client_private.h"
23 #include "ui/aura/test/test_window_delegate.h" 23 #include "ui/aura/test/test_window_delegate.h"
24 #include "ui/aura/window.h" 24 #include "ui/aura/window.h"
25 #include "ui/aura/window_property.h" 25 #include "ui/aura/window_property.h"
26 #include "ui/aura/window_tracker.h" 26 #include "ui/aura/window_tracker.h"
27 #include "ui/compositor/compositor.h"
27 #include "ui/events/event.h" 28 #include "ui/events/event.h"
28 #include "ui/events/event_utils.h" 29 #include "ui/events/event_utils.h"
29 #include "ui/gfx/geometry/rect.h" 30 #include "ui/gfx/geometry/rect.h"
30 31
31 DECLARE_WINDOW_PROPERTY_TYPE(uint8_t) 32 DECLARE_WINDOW_PROPERTY_TYPE(uint8_t)
32 33
33 namespace aura { 34 namespace aura {
34 35
35 namespace { 36 namespace {
36 37
37 DEFINE_WINDOW_PROPERTY_KEY(uint8_t, kTestPropertyKey1, 0); 38 DEFINE_WINDOW_PROPERTY_KEY(uint8_t, kTestPropertyKey1, 0);
38 DEFINE_WINDOW_PROPERTY_KEY(uint8_t, kTestPropertyKey2, 0); 39 DEFINE_WINDOW_PROPERTY_KEY(uint8_t, kTestPropertyKey2, 0);
39 40
40 Id server_id(Window* window) { 41 Id server_id(Window* window) {
41 return WindowMus::Get(window)->server_id(); 42 return WindowMus::Get(window)->server_id();
42 } 43 }
43 44
44 void SetWindowVisibility(Window* window, bool visible) { 45 void SetWindowVisibility(Window* window, bool visible) {
45 if (visible) 46 if (visible)
46 window->Show(); 47 window->Show();
47 else 48 else
48 window->Hide(); 49 window->Hide();
49 } 50 }
50 51
51 Window* GetFirstRoot(WindowTreeClient* client) { 52 Window* GetFirstRoot(WindowTreeClient* client) {
52 return client->GetRoots().empty() ? nullptr : *client->GetRoots().begin(); 53 return client->GetRoots().empty() ? nullptr : *client->GetRoots().begin();
53 } 54 }
54 55
56 bool IsWindowHostVisible(Window* window) {
57 return window->GetRootWindow()->GetHost()->compositor()->IsVisible();
58 }
59
55 const char kAlwaysOnTopServerKey[] = "always-on-top-server"; 60 const char kAlwaysOnTopServerKey[] = "always-on-top-server";
56 const char kTestPropertyServerKey1[] = "test-property-server1"; 61 const char kTestPropertyServerKey1[] = "test-property-server1";
57 const char kTestPropertyServerKey2[] = "test-property-server2"; 62 const char kTestPropertyServerKey2[] = "test-property-server2";
58 63
59 class TestPropertyConverter : public PropertyConverter { 64 class TestPropertyConverter : public PropertyConverter {
60 public: 65 public:
61 TestPropertyConverter() {} 66 TestPropertyConverter() {}
62 ~TestPropertyConverter() override {} 67 ~TestPropertyConverter() override {}
63 68
64 // PropertyConverter: 69 // PropertyConverter:
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 DISALLOW_COPY_AND_ASSIGN(InputEventBasicTestWindowDelegate); 432 DISALLOW_COPY_AND_ASSIGN(InputEventBasicTestWindowDelegate);
428 }; 433 };
429 434
430 } // namespace 435 } // namespace
431 436
432 TEST_F(WindowTreeClientClientTest, InputEventBasic) { 437 TEST_F(WindowTreeClientClientTest, InputEventBasic) {
433 InputEventBasicTestWindowDelegate window_delegate(window_tree()); 438 InputEventBasicTestWindowDelegate window_delegate(window_tree());
434 std::unique_ptr<Window> top_level(base::MakeUnique<Window>(&window_delegate)); 439 std::unique_ptr<Window> top_level(base::MakeUnique<Window>(&window_delegate));
435 top_level->SetType(ui::wm::WINDOW_TYPE_NORMAL); 440 top_level->SetType(ui::wm::WINDOW_TYPE_NORMAL);
436 top_level->Init(ui::LAYER_NOT_DRAWN); 441 top_level->Init(ui::LAYER_NOT_DRAWN);
437 top_level->SetBounds(gfx::Rect(0, 0, 100, 100)); 442 WindowTreeHost* window_tree_host = top_level->GetRootWindow()->GetHost();
438 top_level->Show(); 443 const gfx::Rect bounds(0, 0, 100, 100);
444 window_tree_host->SetBounds(bounds);
445 window_tree_host->Show();
446 EXPECT_EQ(bounds, top_level->bounds());
447 EXPECT_EQ(bounds, window_tree_host->window()->bounds());
439 EXPECT_FALSE(window_delegate.got_move()); 448 EXPECT_FALSE(window_delegate.got_move());
440 EXPECT_FALSE(window_delegate.was_acked()); 449 EXPECT_FALSE(window_delegate.was_acked());
441 std::unique_ptr<ui::Event> ui_event( 450 std::unique_ptr<ui::Event> ui_event(
442 new ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::Point(), gfx::Point(), 451 new ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::Point(), gfx::Point(),
443 ui::EventTimeForNow(), ui::EF_NONE, 0)); 452 ui::EventTimeForNow(), ui::EF_NONE, 0));
444 window_tree_client()->OnWindowInputEvent( 453 window_tree_client()->OnWindowInputEvent(
445 InputEventBasicTestWindowDelegate::kEventId, server_id(top_level.get()), 454 InputEventBasicTestWindowDelegate::kEventId, server_id(top_level.get()),
446 ui::Event::Clone(*ui_event.get()), 0); 455 ui::Event::Clone(*ui_event.get()), 0);
447 EXPECT_TRUE(window_tree()->WasEventAcked(1)); 456 EXPECT_TRUE(window_tree()->WasEventAcked(1));
448 EXPECT_TRUE(window_delegate.got_move()); 457 EXPECT_TRUE(window_delegate.got_move());
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
694 703
695 TEST_F(WindowTreeClientClientTest, NewTopLevelWindowGetsPropertiesFromData) { 704 TEST_F(WindowTreeClientClientTest, NewTopLevelWindowGetsPropertiesFromData) {
696 const size_t initial_root_count = 705 const size_t initial_root_count =
697 window_tree_client_impl()->GetRoots().size(); 706 window_tree_client_impl()->GetRoots().size();
698 std::unique_ptr<Window> top_level(base::MakeUnique<Window>(nullptr)); 707 std::unique_ptr<Window> top_level(base::MakeUnique<Window>(nullptr));
699 top_level->SetType(ui::wm::WINDOW_TYPE_NORMAL); 708 top_level->SetType(ui::wm::WINDOW_TYPE_NORMAL);
700 top_level->Init(ui::LAYER_NOT_DRAWN); 709 top_level->Init(ui::LAYER_NOT_DRAWN);
701 EXPECT_EQ(initial_root_count + 1, 710 EXPECT_EQ(initial_root_count + 1,
702 window_tree_client_impl()->GetRoots().size()); 711 window_tree_client_impl()->GetRoots().size());
703 712
704 // TODO: check drawn. 713 EXPECT_FALSE(IsWindowHostVisible(top_level.get()));
705 // EXPECT_FALSE(root2->IsDrawn());
706 EXPECT_FALSE(top_level->TargetVisibility()); 714 EXPECT_FALSE(top_level->TargetVisibility());
707 715
708 // Ack the request to the windowtree to create the new window. 716 // Ack the request to the windowtree to create the new window.
709 EXPECT_EQ(window_tree()->window_id(), server_id(top_level.get())); 717 EXPECT_EQ(window_tree()->window_id(), server_id(top_level.get()));
710 718
711 ui::mojom::WindowDataPtr data = ui::mojom::WindowData::New(); 719 ui::mojom::WindowDataPtr data = ui::mojom::WindowData::New();
712 data->window_id = server_id(top_level.get()); 720 data->window_id = server_id(top_level.get());
713 data->bounds.SetRect(1, 2, 3, 4); 721 data->bounds.SetRect(1, 2, 3, 4);
714 data->visible = true; 722 data->visible = true;
715 const int64_t display_id = 1; 723 const int64_t display_id = 1;
716 uint32_t change_id; 724 uint32_t change_id;
717 ASSERT_TRUE(window_tree()->GetAndRemoveFirstChangeOfType( 725 ASSERT_TRUE(window_tree()->GetAndRemoveFirstChangeOfType(
718 WindowTreeChangeType::NEW_TOP_LEVEL, &change_id)); 726 WindowTreeChangeType::NEW_TOP_LEVEL, &change_id));
719 window_tree_client()->OnTopLevelCreated(change_id, std::move(data), 727 window_tree_client()->OnTopLevelCreated(change_id, std::move(data),
720 display_id, true); 728 display_id, true);
721 729
722 // Make sure all the properties took. 730 // Make sure all the properties took.
723 // EXPECT_TRUE(root2->IsDrawn()); 731 EXPECT_TRUE(IsWindowHostVisible(top_level.get()));
724 EXPECT_TRUE(top_level->TargetVisibility()); 732 EXPECT_TRUE(top_level->TargetVisibility());
725 // TODO: check display_id. 733 // TODO: check display_id.
726 // EXPECT_EQ(1, root2->display_id()); 734 // EXPECT_EQ(1, root2->display_id());
727 EXPECT_EQ(gfx::Rect(1, 2, 3, 4), top_level->bounds()); 735 EXPECT_EQ(gfx::Rect(0, 0, 3, 4), top_level->bounds());
736 EXPECT_EQ(gfx::Rect(1, 2, 3, 4), top_level->GetHost()->GetBounds());
728 } 737 }
729 738
730 TEST_F(WindowTreeClientClientTest, NewWindowGetsAllChangesInFlight) { 739 TEST_F(WindowTreeClientClientTest, NewWindowGetsAllChangesInFlight) {
731 SetPropertyConverter(base::MakeUnique<TestPropertyConverter>()); 740 SetPropertyConverter(base::MakeUnique<TestPropertyConverter>());
732 741
733 Window window(nullptr); 742 std::unique_ptr<Window> top_level(base::MakeUnique<Window>(nullptr));
734 window.Init(ui::LAYER_NOT_DRAWN); 743 top_level->SetType(ui::wm::WINDOW_TYPE_NORMAL);
744 top_level->Init(ui::LAYER_NOT_DRAWN);
735 745
736 EXPECT_FALSE(window.TargetVisibility()); 746 EXPECT_FALSE(top_level->TargetVisibility());
737 747
738 // Make visibility go from false->true->false. Don't ack immediately. 748 // Make visibility go from false->true->false. Don't ack immediately.
739 window.Show(); 749 top_level->Show();
740 window.Hide(); 750 top_level->Hide();
741 751
742 // Change bounds to 5, 6, 7, 8. 752 // Change bounds to 5, 6, 7, 8.
743 window.SetBounds(gfx::Rect(5, 6, 7, 8)); 753 top_level->SetBounds(gfx::Rect(5, 6, 7, 8));
744 754
745 const uint8_t explicitly_set_test_property1_value = 2; 755 const uint8_t explicitly_set_test_property1_value = 2;
746 window.SetProperty(kTestPropertyKey1, explicitly_set_test_property1_value); 756 top_level->SetProperty(kTestPropertyKey1,
757 explicitly_set_test_property1_value);
747 758
748 // Ack the new window top level window. Vis and bounds shouldn't change. 759 // Ack the new window top level top_level Vis and bounds shouldn't change.
749 ui::mojom::WindowDataPtr data = ui::mojom::WindowData::New(); 760 ui::mojom::WindowDataPtr data = ui::mojom::WindowData::New();
750 data->window_id = server_id(&window); 761 data->window_id = server_id(top_level.get());
751 data->bounds.SetRect(1, 2, 3, 4); 762 const gfx::Rect bounds_from_server(1, 2, 3, 4);
763 data->bounds = bounds_from_server;
752 data->visible = true; 764 data->visible = true;
753 const uint8_t server_test_property1_value = 3; 765 const uint8_t server_test_property1_value = 3;
754 data->properties[kTestPropertyServerKey1] = 766 data->properties[kTestPropertyServerKey1] =
755 Uint8ToPropertyTransportValue(server_test_property1_value); 767 Uint8ToPropertyTransportValue(server_test_property1_value);
756 const uint8_t server_test_property2_value = 4; 768 const uint8_t server_test_property2_value = 4;
757 data->properties[kTestPropertyServerKey2] = 769 data->properties[kTestPropertyServerKey2] =
758 Uint8ToPropertyTransportValue(server_test_property2_value); 770 Uint8ToPropertyTransportValue(server_test_property2_value);
759 const int64_t display_id = 1; 771 const int64_t display_id = 1;
760 // Get the id of the in flight change for creating the new window. 772 // Get the id of the in flight change for creating the new top_level.
761 uint32_t new_window_in_flight_change_id; 773 uint32_t new_window_in_flight_change_id;
762 ASSERT_TRUE(window_tree()->GetAndRemoveFirstChangeOfType( 774 ASSERT_TRUE(window_tree()->GetAndRemoveFirstChangeOfType(
763 WindowTreeChangeType::NEW_WINDOW, &new_window_in_flight_change_id)); 775 WindowTreeChangeType::NEW_TOP_LEVEL, &new_window_in_flight_change_id));
764 window_tree_client()->OnTopLevelCreated(new_window_in_flight_change_id, 776 window_tree_client()->OnTopLevelCreated(new_window_in_flight_change_id,
765 std::move(data), display_id, true); 777 std::move(data), display_id, true);
766 778
767 // The only value that should take effect is the property for 'yy' as it was 779 // The only value that should take effect is the property for 'yy' as it was
768 // not in flight. 780 // not in flight.
769 EXPECT_FALSE(window.TargetVisibility()); 781 EXPECT_FALSE(top_level->TargetVisibility());
770 EXPECT_EQ(gfx::Rect(5, 6, 7, 8), window.bounds()); 782 EXPECT_EQ(gfx::Rect(5, 6, 7, 8), top_level->bounds());
771 EXPECT_EQ(explicitly_set_test_property1_value, 783 EXPECT_EQ(explicitly_set_test_property1_value,
772 window.GetProperty(kTestPropertyKey1)); 784 top_level->GetProperty(kTestPropertyKey1));
773 EXPECT_EQ(server_test_property2_value, window.GetProperty(kTestPropertyKey2)); 785 EXPECT_EQ(server_test_property2_value,
786 top_level->GetProperty(kTestPropertyKey2));
774 787
775 // Tell the client the changes failed. This should cause the values to change 788 // Tell the client the changes failed. This should cause the values to change
776 // to that of the server. 789 // to that of the server.
777 ASSERT_TRUE(window_tree()->AckFirstChangeOfType(WindowTreeChangeType::VISIBLE, 790 ASSERT_TRUE(window_tree()->AckFirstChangeOfType(WindowTreeChangeType::VISIBLE,
778 false)); 791 false));
779 EXPECT_FALSE(window.TargetVisibility()); 792 EXPECT_FALSE(top_level->TargetVisibility());
780 ASSERT_TRUE(window_tree()->AckSingleChangeOfType( 793 ASSERT_TRUE(window_tree()->AckSingleChangeOfType(
781 WindowTreeChangeType::VISIBLE, false)); 794 WindowTreeChangeType::VISIBLE, false));
782 EXPECT_TRUE(window.TargetVisibility()); 795 EXPECT_TRUE(top_level->TargetVisibility());
783 window_tree()->AckAllChangesOfType(WindowTreeChangeType::BOUNDS, false); 796 window_tree()->AckAllChangesOfType(WindowTreeChangeType::BOUNDS, false);
784 EXPECT_EQ(gfx::Rect(1, 2, 3, 4), window.bounds()); 797 // The bounds of the top_level is always at the origin.
798 EXPECT_EQ(gfx::Rect(bounds_from_server.size()), top_level->bounds());
799 // But the bounds of the WindowTreeHost is display relative.
800 EXPECT_EQ(bounds_from_server,
801 top_level->GetRootWindow()->GetHost()->GetBounds());
785 ASSERT_TRUE(window_tree()->AckSingleChangeOfType( 802 ASSERT_TRUE(window_tree()->AckSingleChangeOfType(
786 WindowTreeChangeType::PROPERTY, false)); 803 WindowTreeChangeType::PROPERTY, false));
787 EXPECT_EQ(server_test_property1_value, window.GetProperty(kTestPropertyKey1)); 804 EXPECT_EQ(server_test_property1_value,
788 EXPECT_EQ(server_test_property2_value, window.GetProperty(kTestPropertyKey2)); 805 top_level->GetProperty(kTestPropertyKey1));
806 EXPECT_EQ(server_test_property2_value,
807 top_level->GetProperty(kTestPropertyKey2));
789 } 808 }
790 809
791 TEST_F(WindowTreeClientClientTest, NewWindowGetsProperties) { 810 TEST_F(WindowTreeClientClientTest, NewWindowGetsProperties) {
792 SetPropertyConverter(base::MakeUnique<TestPropertyConverter>()); 811 SetPropertyConverter(base::MakeUnique<TestPropertyConverter>());
793 Window window(nullptr); 812 Window window(nullptr);
794 const uint8_t explicitly_set_test_property1_value = 29; 813 const uint8_t explicitly_set_test_property1_value = 29;
795 window.SetProperty(kTestPropertyKey1, explicitly_set_test_property1_value); 814 window.SetProperty(kTestPropertyKey1, explicitly_set_test_property1_value);
796 window.Init(ui::LAYER_NOT_DRAWN); 815 window.Init(ui::LAYER_NOT_DRAWN);
797 mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties = 816 mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties =
798 window_tree()->GetLastNewWindowProperties(); 817 window_tree()->GetLastNewWindowProperties();
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
1042 1061
1043 // Changes originating from server should notify observers too. 1062 // Changes originating from server should notify observers too.
1044 window_tree_client()->OnCaptureChanged(server_id(&child2), 0); 1063 window_tree_client()->OnCaptureChanged(server_id(&child2), 0);
1045 EXPECT_EQ(1, capture_recorder.capture_changed_count()); 1064 EXPECT_EQ(1, capture_recorder.capture_changed_count());
1046 EXPECT_EQ(child2_id, capture_recorder.last_gained_capture_window_id()); 1065 EXPECT_EQ(child2_id, capture_recorder.last_gained_capture_window_id());
1047 EXPECT_EQ(0, capture_recorder.last_lost_capture_window_id()); 1066 EXPECT_EQ(0, capture_recorder.last_lost_capture_window_id());
1048 capture_recorder.reset_capture_captured_count(); 1067 capture_recorder.reset_capture_captured_count();
1049 } 1068 }
1050 1069
1051 } // namespace aura 1070 } // namespace aura
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698