| OLD | NEW |
| 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 "ash/mus/layout_manager.h" | 5 #include "ash/mus/layout_manager.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "services/ui/public/cpp/tests/test_window.h" | 10 #include "services/ui/public/cpp/tests/test_window.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 12 |
| 13 namespace ash { | 13 namespace ash { |
| 14 namespace mus { | 14 namespace mus { |
| 15 | 15 |
| 16 class TestLayoutManager : public LayoutManager { | 16 class TestLayoutManager : public LayoutManager { |
| 17 public: | 17 public: |
| 18 explicit TestLayoutManager(::ui::Window* window) | 18 explicit TestLayoutManager(ui::Window* window) |
| 19 : LayoutManager(window), layout_called_(false) {} | 19 : LayoutManager(window), layout_called_(false) {} |
| 20 ~TestLayoutManager() override {} | 20 ~TestLayoutManager() override {} |
| 21 | 21 |
| 22 bool GetAndResetLayoutCalled() { | 22 bool GetAndResetLayoutCalled() { |
| 23 bool was_layout_called = layout_called_; | 23 bool was_layout_called = layout_called_; |
| 24 layout_called_ = false; | 24 layout_called_ = false; |
| 25 return was_layout_called; | 25 return was_layout_called; |
| 26 } | 26 } |
| 27 | 27 |
| 28 private: | 28 private: |
| 29 // LayoutManager: | 29 // LayoutManager: |
| 30 void LayoutWindow(::ui::Window* window) override { layout_called_ = true; } | 30 void LayoutWindow(ui::Window* window) override { layout_called_ = true; } |
| 31 | 31 |
| 32 bool layout_called_; | 32 bool layout_called_; |
| 33 | 33 |
| 34 DISALLOW_COPY_AND_ASSIGN(TestLayoutManager); | 34 DISALLOW_COPY_AND_ASSIGN(TestLayoutManager); |
| 35 }; | 35 }; |
| 36 | 36 |
| 37 // Tests that owning window can be destroyed before the layout manager. | 37 // Tests that owning window can be destroyed before the layout manager. |
| 38 TEST(LayoutManagerTest, OwningWindowDestroyedFirst) { | 38 TEST(LayoutManagerTest, OwningWindowDestroyedFirst) { |
| 39 std::unique_ptr<::ui::TestWindow> parent(new ::ui::TestWindow(1)); | 39 std::unique_ptr<ui::TestWindow> parent(new ui::TestWindow(1)); |
| 40 ::ui::TestWindow child(2); | 40 ui::TestWindow child(2); |
| 41 TestLayoutManager layout_manager(parent.get()); | 41 TestLayoutManager layout_manager(parent.get()); |
| 42 parent->AddChild(&child); | 42 parent->AddChild(&child); |
| 43 EXPECT_TRUE(layout_manager.GetAndResetLayoutCalled()); | 43 EXPECT_TRUE(layout_manager.GetAndResetLayoutCalled()); |
| 44 parent.reset(); | 44 parent.reset(); |
| 45 child.SetBounds(gfx::Rect(100, 200)); | 45 child.SetBounds(gfx::Rect(100, 200)); |
| 46 } | 46 } |
| 47 | 47 |
| 48 // Tests that the layout manager can be destroyed before the owning window. | 48 // Tests that the layout manager can be destroyed before the owning window. |
| 49 TEST(LayoutManagerTest, LayoutManagerDestroyedFirst) { | 49 TEST(LayoutManagerTest, LayoutManagerDestroyedFirst) { |
| 50 ::ui::TestWindow parent(1); | 50 ui::TestWindow parent(1); |
| 51 ::ui::TestWindow child(2); | 51 ui::TestWindow child(2); |
| 52 std::unique_ptr<TestLayoutManager> layout_manager( | 52 std::unique_ptr<TestLayoutManager> layout_manager( |
| 53 new TestLayoutManager(&parent)); | 53 new TestLayoutManager(&parent)); |
| 54 parent.AddChild(&child); | 54 parent.AddChild(&child); |
| 55 EXPECT_TRUE(layout_manager->GetAndResetLayoutCalled()); | 55 EXPECT_TRUE(layout_manager->GetAndResetLayoutCalled()); |
| 56 | 56 |
| 57 parent.SetBounds(gfx::Rect(100, 200)); | 57 parent.SetBounds(gfx::Rect(100, 200)); |
| 58 EXPECT_TRUE(layout_manager->GetAndResetLayoutCalled()); | 58 EXPECT_TRUE(layout_manager->GetAndResetLayoutCalled()); |
| 59 | 59 |
| 60 layout_manager.reset(); | 60 layout_manager.reset(); |
| 61 parent.SetBounds(gfx::Rect(200, 100)); | 61 parent.SetBounds(gfx::Rect(200, 100)); |
| 62 } | 62 } |
| 63 | 63 |
| 64 } // namespace mus | 64 } // namespace mus |
| 65 } // namespace ash | 65 } // namespace ash |
| OLD | NEW |