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