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

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

Issue 2456623002: Fixes to WindowTreeHostMus (Closed)
Patch Set: merge 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
« no previous file with comments | « ui/aura/mus/window_tree_client.cc ('k') | ui/aura/mus/window_tree_host_mus.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
729 EXPECT_EQ(
730 0u, window_tree()->GetChangeCountForType(WindowTreeChangeType::VISIBLE));
721 731
722 // Make sure all the properties took. 732 // Make sure all the properties took.
723 // EXPECT_TRUE(root2->IsDrawn()); 733 EXPECT_TRUE(IsWindowHostVisible(top_level.get()));
724 EXPECT_TRUE(top_level->TargetVisibility()); 734 EXPECT_TRUE(top_level->TargetVisibility());
725 // TODO: check display_id. 735 // TODO: check display_id.
726 // EXPECT_EQ(1, root2->display_id()); 736 // EXPECT_EQ(1, root2->display_id());
727 EXPECT_EQ(gfx::Rect(1, 2, 3, 4), top_level->bounds()); 737 EXPECT_EQ(gfx::Rect(0, 0, 3, 4), top_level->bounds());
738 EXPECT_EQ(gfx::Rect(1, 2, 3, 4), top_level->GetHost()->GetBounds());
728 } 739 }
729 740
730 TEST_F(WindowTreeClientClientTest, NewWindowGetsAllChangesInFlight) { 741 TEST_F(WindowTreeClientClientTest, NewWindowGetsAllChangesInFlight) {
731 SetPropertyConverter(base::MakeUnique<TestPropertyConverter>()); 742 SetPropertyConverter(base::MakeUnique<TestPropertyConverter>());
732 743
733 Window window(nullptr); 744 std::unique_ptr<Window> top_level(base::MakeUnique<Window>(nullptr));
734 window.Init(ui::LAYER_NOT_DRAWN); 745 top_level->SetType(ui::wm::WINDOW_TYPE_NORMAL);
746 top_level->Init(ui::LAYER_NOT_DRAWN);
735 747
736 EXPECT_FALSE(window.TargetVisibility()); 748 EXPECT_FALSE(top_level->TargetVisibility());
737 749
738 // Make visibility go from false->true->false. Don't ack immediately. 750 // Make visibility go from false->true->false. Don't ack immediately.
739 window.Show(); 751 top_level->Show();
740 window.Hide(); 752 top_level->Hide();
741 753
742 // Change bounds to 5, 6, 7, 8. 754 // Change bounds to 5, 6, 7, 8.
743 window.SetBounds(gfx::Rect(5, 6, 7, 8)); 755 top_level->SetBounds(gfx::Rect(5, 6, 7, 8));
744 756
745 const uint8_t explicitly_set_test_property1_value = 2; 757 const uint8_t explicitly_set_test_property1_value = 2;
746 window.SetProperty(kTestPropertyKey1, explicitly_set_test_property1_value); 758 top_level->SetProperty(kTestPropertyKey1,
759 explicitly_set_test_property1_value);
747 760
748 // Ack the new window top level window. Vis and bounds shouldn't change. 761 // Ack the new window top level top_level Vis and bounds shouldn't change.
749 ui::mojom::WindowDataPtr data = ui::mojom::WindowData::New(); 762 ui::mojom::WindowDataPtr data = ui::mojom::WindowData::New();
750 data->window_id = server_id(&window); 763 data->window_id = server_id(top_level.get());
751 data->bounds.SetRect(1, 2, 3, 4); 764 const gfx::Rect bounds_from_server(1, 2, 3, 4);
765 data->bounds = bounds_from_server;
752 data->visible = true; 766 data->visible = true;
753 const uint8_t server_test_property1_value = 3; 767 const uint8_t server_test_property1_value = 3;
754 data->properties[kTestPropertyServerKey1] = 768 data->properties[kTestPropertyServerKey1] =
755 Uint8ToPropertyTransportValue(server_test_property1_value); 769 Uint8ToPropertyTransportValue(server_test_property1_value);
756 const uint8_t server_test_property2_value = 4; 770 const uint8_t server_test_property2_value = 4;
757 data->properties[kTestPropertyServerKey2] = 771 data->properties[kTestPropertyServerKey2] =
758 Uint8ToPropertyTransportValue(server_test_property2_value); 772 Uint8ToPropertyTransportValue(server_test_property2_value);
759 const int64_t display_id = 1; 773 const int64_t display_id = 1;
760 // Get the id of the in flight change for creating the new window. 774 // Get the id of the in flight change for creating the new top_level.
761 uint32_t new_window_in_flight_change_id; 775 uint32_t new_window_in_flight_change_id;
762 ASSERT_TRUE(window_tree()->GetAndRemoveFirstChangeOfType( 776 ASSERT_TRUE(window_tree()->GetAndRemoveFirstChangeOfType(
763 WindowTreeChangeType::NEW_WINDOW, &new_window_in_flight_change_id)); 777 WindowTreeChangeType::NEW_TOP_LEVEL, &new_window_in_flight_change_id));
764 window_tree_client()->OnTopLevelCreated(new_window_in_flight_change_id, 778 window_tree_client()->OnTopLevelCreated(new_window_in_flight_change_id,
765 std::move(data), display_id, true); 779 std::move(data), display_id, true);
766 780
767 // The only value that should take effect is the property for 'yy' as it was 781 // The only value that should take effect is the property for 'yy' as it was
768 // not in flight. 782 // not in flight.
769 EXPECT_FALSE(window.TargetVisibility()); 783 EXPECT_FALSE(top_level->TargetVisibility());
770 EXPECT_EQ(gfx::Rect(5, 6, 7, 8), window.bounds()); 784 EXPECT_EQ(gfx::Rect(5, 6, 7, 8), top_level->bounds());
771 EXPECT_EQ(explicitly_set_test_property1_value, 785 EXPECT_EQ(explicitly_set_test_property1_value,
772 window.GetProperty(kTestPropertyKey1)); 786 top_level->GetProperty(kTestPropertyKey1));
773 EXPECT_EQ(server_test_property2_value, window.GetProperty(kTestPropertyKey2)); 787 EXPECT_EQ(server_test_property2_value,
788 top_level->GetProperty(kTestPropertyKey2));
774 789
775 // Tell the client the changes failed. This should cause the values to change 790 // Tell the client the changes failed. This should cause the values to change
776 // to that of the server. 791 // to that of the server.
777 ASSERT_TRUE(window_tree()->AckFirstChangeOfType(WindowTreeChangeType::VISIBLE, 792 ASSERT_TRUE(window_tree()->AckFirstChangeOfType(WindowTreeChangeType::VISIBLE,
778 false)); 793 false));
779 EXPECT_FALSE(window.TargetVisibility()); 794 EXPECT_FALSE(top_level->TargetVisibility());
780 ASSERT_TRUE(window_tree()->AckSingleChangeOfType( 795 ASSERT_TRUE(window_tree()->AckSingleChangeOfType(
781 WindowTreeChangeType::VISIBLE, false)); 796 WindowTreeChangeType::VISIBLE, false));
782 EXPECT_TRUE(window.TargetVisibility()); 797 EXPECT_TRUE(top_level->TargetVisibility());
783 window_tree()->AckAllChangesOfType(WindowTreeChangeType::BOUNDS, false); 798 window_tree()->AckAllChangesOfType(WindowTreeChangeType::BOUNDS, false);
784 EXPECT_EQ(gfx::Rect(1, 2, 3, 4), window.bounds()); 799 // The bounds of the top_level is always at the origin.
800 EXPECT_EQ(gfx::Rect(bounds_from_server.size()), top_level->bounds());
801 // But the bounds of the WindowTreeHost is display relative.
802 EXPECT_EQ(bounds_from_server,
803 top_level->GetRootWindow()->GetHost()->GetBounds());
785 ASSERT_TRUE(window_tree()->AckSingleChangeOfType( 804 ASSERT_TRUE(window_tree()->AckSingleChangeOfType(
786 WindowTreeChangeType::PROPERTY, false)); 805 WindowTreeChangeType::PROPERTY, false));
787 EXPECT_EQ(server_test_property1_value, window.GetProperty(kTestPropertyKey1)); 806 EXPECT_EQ(server_test_property1_value,
788 EXPECT_EQ(server_test_property2_value, window.GetProperty(kTestPropertyKey2)); 807 top_level->GetProperty(kTestPropertyKey1));
808 EXPECT_EQ(server_test_property2_value,
809 top_level->GetProperty(kTestPropertyKey2));
789 } 810 }
790 811
791 TEST_F(WindowTreeClientClientTest, NewWindowGetsProperties) { 812 TEST_F(WindowTreeClientClientTest, NewWindowGetsProperties) {
792 SetPropertyConverter(base::MakeUnique<TestPropertyConverter>()); 813 SetPropertyConverter(base::MakeUnique<TestPropertyConverter>());
793 Window window(nullptr); 814 Window window(nullptr);
794 const uint8_t explicitly_set_test_property1_value = 29; 815 const uint8_t explicitly_set_test_property1_value = 29;
795 window.SetProperty(kTestPropertyKey1, explicitly_set_test_property1_value); 816 window.SetProperty(kTestPropertyKey1, explicitly_set_test_property1_value);
796 window.Init(ui::LAYER_NOT_DRAWN); 817 window.Init(ui::LAYER_NOT_DRAWN);
797 mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties = 818 mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties =
798 window_tree()->GetLastNewWindowProperties(); 819 window_tree()->GetLastNewWindowProperties();
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
1070 // Ack change as succeeding. 1091 // Ack change as succeeding.
1071 ASSERT_TRUE( 1092 ASSERT_TRUE(
1072 window_tree()->AckSingleChangeOfType(WindowTreeChangeType::MODAL, true)); 1093 window_tree()->AckSingleChangeOfType(WindowTreeChangeType::MODAL, true));
1073 EXPECT_EQ(ui::MODAL_TYPE_WINDOW, window.GetProperty(client::kModalKey)); 1094 EXPECT_EQ(ui::MODAL_TYPE_WINDOW, window.GetProperty(client::kModalKey));
1074 // There should be no more modal changes. 1095 // There should be no more modal changes.
1075 EXPECT_FALSE( 1096 EXPECT_FALSE(
1076 window_tree()->AckSingleChangeOfType(WindowTreeChangeType::MODAL, false)); 1097 window_tree()->AckSingleChangeOfType(WindowTreeChangeType::MODAL, false));
1077 } 1098 }
1078 1099
1079 } // namespace aura 1100 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/mus/window_tree_client.cc ('k') | ui/aura/mus/window_tree_host_mus.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698