| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "services/ui/common/util.h" | 12 #include "services/ui/common/util.h" |
| 13 #include "services/ui/ws/window_server_test_base.h" | 13 #include "services/ui/ws/window_server_test_base.h" |
| 14 #include "ui/aura/client/transient_window_client.h" |
| 14 #include "ui/aura/env.h" | 15 #include "ui/aura/env.h" |
| 15 #include "ui/aura/mus/window_port_mus.h" | 16 #include "ui/aura/mus/window_port_mus.h" |
| 16 #include "ui/aura/mus/window_tree_client.h" | 17 #include "ui/aura/mus/window_tree_client.h" |
| 17 #include "ui/aura/mus/window_tree_client_delegate.h" | 18 #include "ui/aura/mus/window_tree_client_delegate.h" |
| 18 #include "ui/aura/mus/window_tree_host_mus.h" | 19 #include "ui/aura/mus/window_tree_host_mus.h" |
| 19 #include "ui/aura/test/mus/window_tree_client_private.h" | 20 #include "ui/aura/test/mus/window_tree_client_private.h" |
| 20 #include "ui/aura/window.h" | 21 #include "ui/aura/window.h" |
| 21 #include "ui/aura/window_observer.h" | 22 #include "ui/aura/window_observer.h" |
| 22 #include "ui/aura/window_tracker.h" | 23 #include "ui/aura/window_tracker.h" |
| 23 #include "ui/gfx/geometry/rect.h" | 24 #include "ui/gfx/geometry/rect.h" |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 DISALLOW_COPY_AND_ASSIGN(BoundsChangeObserver); | 105 DISALLOW_COPY_AND_ASSIGN(BoundsChangeObserver); |
| 105 }; | 106 }; |
| 106 | 107 |
| 107 // Wait until the bounds of the supplied window change; returns false on | 108 // Wait until the bounds of the supplied window change; returns false on |
| 108 // timeout. | 109 // timeout. |
| 109 bool WaitForBoundsToChange(aura::Window* window) { | 110 bool WaitForBoundsToChange(aura::Window* window) { |
| 110 BoundsChangeObserver observer(window); | 111 BoundsChangeObserver observer(window); |
| 111 return WindowServerTestBase::DoRunLoopWithTimeout(); | 112 return WindowServerTestBase::DoRunLoopWithTimeout(); |
| 112 } | 113 } |
| 113 | 114 |
| 114 | |
| 115 // Spins a run loop until the tree beginning at |root| has |tree_size| windows | 115 // Spins a run loop until the tree beginning at |root| has |tree_size| windows |
| 116 // (including |root|). | 116 // (including |root|). |
| 117 class TreeSizeMatchesObserver : public aura::WindowObserver { | 117 class TreeSizeMatchesObserver : public aura::WindowObserver { |
| 118 public: | 118 public: |
| 119 TreeSizeMatchesObserver(aura::Window* tree, size_t tree_size) | 119 TreeSizeMatchesObserver(aura::Window* tree, size_t tree_size) |
| 120 : tree_(tree), tree_size_(tree_size) { | 120 : tree_(tree), tree_size_(tree_size) { |
| 121 tree_->AddObserver(this); | 121 tree_->AddObserver(this); |
| 122 } | 122 } |
| 123 ~TreeSizeMatchesObserver() override { tree_->RemoveObserver(this); } | 123 ~TreeSizeMatchesObserver() override { tree_->RemoveObserver(this); } |
| 124 | 124 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 void OnWindowDestroyed(aura::Window* window) override { | 197 void OnWindowDestroyed(aura::Window* window) override { |
| 198 DCHECK_EQ(window, window_); | 198 DCHECK_EQ(window, window_); |
| 199 window_ = nullptr; | 199 window_ = nullptr; |
| 200 } | 200 } |
| 201 | 201 |
| 202 aura::Window* window_; | 202 aura::Window* window_; |
| 203 | 203 |
| 204 DISALLOW_COPY_AND_ASSIGN(WindowTracker); | 204 DISALLOW_COPY_AND_ASSIGN(WindowTracker); |
| 205 }; | 205 }; |
| 206 | 206 |
| 207 // Creates a new Window parented to |parent| that is made visible. | 207 // Creates a new visible Window. If |parent| is non-null the newly created |
| 208 // window is added to it. |
| 208 aura::Window* NewVisibleWindow(aura::Window* parent, | 209 aura::Window* NewVisibleWindow(aura::Window* parent, |
| 209 aura::WindowTreeClient* client) { | 210 aura::WindowTreeClient* client) { |
| 210 std::unique_ptr<aura::WindowPortMus> window_port_mus = | 211 std::unique_ptr<aura::WindowPortMus> window_port_mus = |
| 211 base::MakeUnique<aura::WindowPortMus>(client, aura::WindowMusType::LOCAL); | 212 base::MakeUnique<aura::WindowPortMus>(client, aura::WindowMusType::LOCAL); |
| 212 aura::Window* window = new aura::Window(nullptr, std::move(window_port_mus)); | 213 aura::Window* window = new aura::Window(nullptr, std::move(window_port_mus)); |
| 213 window->Init(ui::LAYER_NOT_DRAWN); | 214 window->Init(ui::LAYER_NOT_DRAWN); |
| 214 window->Show(); | 215 window->Show(); |
| 215 parent->AddChild(window); | 216 if (parent) |
| 217 parent->AddChild(window); |
| 216 return window; | 218 return window; |
| 217 } | 219 } |
| 218 | 220 |
| 219 } // namespace | 221 } // namespace |
| 220 | 222 |
| 221 // WindowServer | 223 // WindowServer |
| 222 // ----------------------------------------------------------------- | 224 // ----------------------------------------------------------------- |
| 223 | 225 |
| 224 struct EmbedResult { | 226 struct EmbedResult { |
| 225 bool IsValid() const { | 227 bool IsValid() const { |
| (...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 711 | 713 |
| 712 // Change the bounds in the wm, and make sure the child sees it. | 714 // Change the bounds in the wm, and make sure the child sees it. |
| 713 const gfx::Rect window_bounds(1, 11, 12, 101); | 715 const gfx::Rect window_bounds(1, 11, 12, 101); |
| 714 window_in_wm->SetBounds(window_bounds); | 716 window_in_wm->SetBounds(window_bounds); |
| 715 ASSERT_TRUE( | 717 ASSERT_TRUE( |
| 716 WaitForBoundsToChange(window_tree_host_in_second_client.window())); | 718 WaitForBoundsToChange(window_tree_host_in_second_client.window())); |
| 717 EXPECT_EQ(window_bounds, | 719 EXPECT_EQ(window_bounds, |
| 718 window_tree_host_in_second_client.GetBoundsInPixels()); | 720 window_tree_host_in_second_client.GetBoundsInPixels()); |
| 719 } | 721 } |
| 720 | 722 |
| 723 TEST_F(WindowServerTest, OnWindowHierarchyChangedIncludesTransientParent) { |
| 724 // Create a second connection. In the second connection create a window, |
| 725 // parent it to the root, create another window, mark it as a transient parent |
| 726 // of the first window and then add it. |
| 727 EstablishConnectionViaFactoryDelegate delegate(window_manager()); |
| 728 set_window_manager_delegate(&delegate); |
| 729 aura::WindowTreeClient second_client(connector(), this); |
| 730 second_client.ConnectViaWindowTreeFactory(); |
| 731 aura::WindowTreeHostMus window_tree_host_in_second_client(&second_client); |
| 732 aura::Window* second_client_child = NewVisibleWindow( |
| 733 window_tree_host_in_second_client.window(), &second_client); |
| 734 std::unique_ptr<aura::WindowPortMus> window_port_mus = |
| 735 base::MakeUnique<aura::WindowPortMus>(&second_client, |
| 736 aura::WindowMusType::LOCAL); |
| 737 // Create the transient without a parent, set transient parent, then add. |
| 738 aura::Window* transient = NewVisibleWindow(nullptr, &second_client); |
| 739 aura::client::TransientWindowClient* transient_window_client = |
| 740 aura::client::GetTransientWindowClient(); |
| 741 transient_window_client->AddTransientChild(second_client_child, transient); |
| 742 second_client_child->AddChild(transient); |
| 743 |
| 744 // Wait for the top-level to appear in the window manager. |
| 745 ASSERT_TRUE(delegate.QuitOnCreate()); |
| 746 aura::Window* top_level_in_wm = delegate.created_window(); |
| 747 |
| 748 // Makes sure the window manager sees the same structure and the transient |
| 749 // parent is connected correctly. |
| 750 ASSERT_TRUE(WaitForTreeSizeToMatch(top_level_in_wm, 3u)); |
| 751 ASSERT_EQ(1u, top_level_in_wm->children().size()); |
| 752 aura::Window* second_client_child_in_wm = top_level_in_wm->children()[0]; |
| 753 ASSERT_EQ(1u, second_client_child_in_wm->children().size()); |
| 754 aura::Window* transient_in_wm = second_client_child_in_wm->children()[0]; |
| 755 ASSERT_EQ(second_client_child_in_wm, |
| 756 transient_window_client->GetTransientParent(transient_in_wm)); |
| 757 } |
| 758 |
| 721 } // namespace ws | 759 } // namespace ws |
| 722 } // namespace ui | 760 } // namespace ui |
| OLD | NEW |