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 "ui/wm/core/window_util.h" | 5 #include "ui/wm/core/window_util.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
| 9 #include "base/bind.h" |
9 #include "ui/aura/test/aura_test_base.h" | 10 #include "ui/aura/test/aura_test_base.h" |
10 #include "ui/aura/test/test_windows.h" | 11 #include "ui/aura/test/test_windows.h" |
11 #include "ui/aura/window.h" | 12 #include "ui/aura/window.h" |
12 #include "ui/compositor/layer.h" | 13 #include "ui/compositor/layer.h" |
13 #include "ui/compositor/layer_tree_owner.h" | 14 #include "ui/compositor/layer_tree_owner.h" |
14 | 15 |
15 namespace wm { | 16 namespace wm { |
16 | 17 |
17 typedef aura::test::AuraTestBase WindowUtilTest; | 18 typedef aura::test::AuraTestBase WindowUtilTest; |
18 | 19 |
(...skipping 24 matching lines...) Expand all Loading... |
43 | 44 |
44 // The original window should have both. | 45 // The original window should have both. |
45 ASSERT_EQ(2u, window1->layer()->children().size()); | 46 ASSERT_EQ(2u, window1->layer()->children().size()); |
46 EXPECT_EQ(window11->layer(), window1->layer()->children()[0]); | 47 EXPECT_EQ(window11->layer(), window1->layer()->children()[0]); |
47 EXPECT_EQ(window12->layer(), window1->layer()->children()[1]); | 48 EXPECT_EQ(window12->layer(), window1->layer()->children()[1]); |
48 | 49 |
49 // Delete the window before the acquired layer is deleted. | 50 // Delete the window before the acquired layer is deleted. |
50 window11.reset(); | 51 window11.reset(); |
51 } | 52 } |
52 | 53 |
| 54 // Test if map_func is correctly executed in RecreateLayerWithClosure. |
| 55 TEST_F(WindowUtilTest, RecreateLayersWithClosure) { |
| 56 std::unique_ptr<aura::Window> window1( |
| 57 aura::test::CreateTestWindowWithId(0, NULL)); |
| 58 std::unique_ptr<aura::Window> window11( |
| 59 aura::test::CreateTestWindowWithId(1, window1.get())); |
| 60 std::unique_ptr<aura::Window> window12( |
| 61 aura::test::CreateTestWindowWithId(2, window1.get())); |
| 62 |
| 63 ASSERT_EQ(2u, window1->layer()->children().size()); |
| 64 |
| 65 auto tree_empty = wm::RecreateLayersWithClosure( |
| 66 window1.get(), |
| 67 base::BindRepeating( |
| 68 [](const aura::Window* to_filter, |
| 69 ui::LayerOwner* owner) -> std::unique_ptr<ui::Layer> { |
| 70 if (owner->layer() == to_filter->layer()) |
| 71 return nullptr; |
| 72 return owner->RecreateLayer(); |
| 73 }, |
| 74 window1.get())); |
| 75 |
| 76 // The root is filtered. RecreateLayersWithClosure should return nullptr. |
| 77 ASSERT_FALSE(tree_empty); |
| 78 |
| 79 auto tree = wm::RecreateLayersWithClosure( |
| 80 window1.get(), |
| 81 base::BindRepeating( |
| 82 [](const aura::Window* to_filter, |
| 83 ui::LayerOwner* owner) -> std::unique_ptr<ui::Layer> { |
| 84 if (owner->layer() == to_filter->layer()) |
| 85 return nullptr; |
| 86 return owner->RecreateLayer(); |
| 87 }, |
| 88 window12.get())); |
| 89 |
| 90 ASSERT_TRUE(tree); |
| 91 // window12 is filtered out in the above recreation logic. |
| 92 ASSERT_EQ(1u, tree->root()->children().size()); |
| 93 // Child layer is new instance. |
| 94 EXPECT_NE(window11->layer(), tree->root()->children()[0]); |
| 95 |
| 96 // The original window should have both. |
| 97 ASSERT_EQ(2u, window1->layer()->children().size()); |
| 98 EXPECT_EQ(window11->layer(), window1->layer()->children()[0]); |
| 99 EXPECT_EQ(window12->layer(), window1->layer()->children()[1]); |
| 100 } |
| 101 |
53 } // namespace wm | 102 } // namespace wm |
OLD | NEW |