| 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 "components/exo/sub_surface.h" | 5 #include "components/exo/sub_surface.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "components/exo/surface.h" | 8 #include "components/exo/surface.h" |
| 9 #include "components/exo/test/exo_test_base.h" | 9 #include "components/exo/test/exo_test_base.h" |
| 10 #include "components/exo/test/exo_test_helper.h" | 10 #include "components/exo/test/exo_test_helper.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 12 |
| 13 namespace exo { | 13 namespace exo { |
| 14 namespace { | 14 namespace { |
| 15 | 15 |
| 16 class SubSurfaceTest : public test::ExoTestBase, | 16 using SubSurfaceTest = test::ExoTestBase; |
| 17 public ::testing::WithParamInterface<bool> { | |
| 18 void SetUp() override { | |
| 19 Surface::SetUseSurfaceLayer(GetParam()); | |
| 20 test::ExoTestBase::SetUp(); | |
| 21 } | |
| 22 }; | |
| 23 | 17 |
| 24 TEST_P(SubSurfaceTest, SetPosition) { | 18 TEST_F(SubSurfaceTest, SetPosition) { |
| 25 std::unique_ptr<Surface> parent(new Surface); | 19 std::unique_ptr<Surface> parent(new Surface); |
| 26 std::unique_ptr<Surface> surface(new Surface); | 20 std::unique_ptr<Surface> surface(new Surface); |
| 27 std::unique_ptr<SubSurface> sub_surface( | 21 std::unique_ptr<SubSurface> sub_surface( |
| 28 new SubSurface(surface.get(), parent.get())); | 22 new SubSurface(surface.get(), parent.get())); |
| 29 | 23 |
| 30 // Initial position is at the origin. | 24 // Initial position is at the origin. |
| 31 EXPECT_EQ(gfx::Point().ToString(), | 25 EXPECT_EQ(gfx::Point().ToString(), |
| 32 surface->window()->bounds().origin().ToString()); | 26 surface->window()->bounds().origin().ToString()); |
| 33 | 27 |
| 34 // Set position to 10, 10. | 28 // Set position to 10, 10. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 47 // Create and commit a new sub-surface using the same surface. | 41 // Create and commit a new sub-surface using the same surface. |
| 48 sub_surface.reset(); | 42 sub_surface.reset(); |
| 49 sub_surface = base::WrapUnique(new SubSurface(surface.get(), parent.get())); | 43 sub_surface = base::WrapUnique(new SubSurface(surface.get(), parent.get())); |
| 50 parent->Commit(); | 44 parent->Commit(); |
| 51 | 45 |
| 52 // Initial position should be reset to origin. | 46 // Initial position should be reset to origin. |
| 53 EXPECT_EQ(gfx::Point().ToString(), | 47 EXPECT_EQ(gfx::Point().ToString(), |
| 54 surface->window()->bounds().origin().ToString()); | 48 surface->window()->bounds().origin().ToString()); |
| 55 } | 49 } |
| 56 | 50 |
| 57 TEST_P(SubSurfaceTest, PlaceAbove) { | 51 TEST_F(SubSurfaceTest, PlaceAbove) { |
| 58 std::unique_ptr<Surface> parent(new Surface); | 52 std::unique_ptr<Surface> parent(new Surface); |
| 59 std::unique_ptr<Surface> surface1(new Surface); | 53 std::unique_ptr<Surface> surface1(new Surface); |
| 60 std::unique_ptr<Surface> surface2(new Surface); | 54 std::unique_ptr<Surface> surface2(new Surface); |
| 61 std::unique_ptr<Surface> non_sibling_surface(new Surface); | 55 std::unique_ptr<Surface> non_sibling_surface(new Surface); |
| 62 std::unique_ptr<SubSurface> sub_surface1( | 56 std::unique_ptr<SubSurface> sub_surface1( |
| 63 new SubSurface(surface1.get(), parent.get())); | 57 new SubSurface(surface1.get(), parent.get())); |
| 64 std::unique_ptr<SubSurface> sub_surface2( | 58 std::unique_ptr<SubSurface> sub_surface2( |
| 65 new SubSurface(surface2.get(), parent.get())); | 59 new SubSurface(surface2.get(), parent.get())); |
| 66 | 60 |
| 67 ASSERT_EQ(2u, parent->window()->children().size()); | 61 ASSERT_EQ(2u, parent->window()->children().size()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 78 EXPECT_EQ(surface1->window(), parent->window()->children()[0]); | 72 EXPECT_EQ(surface1->window(), parent->window()->children()[0]); |
| 79 EXPECT_EQ(surface2->window(), parent->window()->children()[1]); | 73 EXPECT_EQ(surface2->window(), parent->window()->children()[1]); |
| 80 | 74 |
| 81 parent->Commit(); | 75 parent->Commit(); |
| 82 | 76 |
| 83 // surface1 should now be stacked above surface2. | 77 // surface1 should now be stacked above surface2. |
| 84 EXPECT_EQ(surface2->window(), parent->window()->children()[0]); | 78 EXPECT_EQ(surface2->window(), parent->window()->children()[0]); |
| 85 EXPECT_EQ(surface1->window(), parent->window()->children()[1]); | 79 EXPECT_EQ(surface1->window(), parent->window()->children()[1]); |
| 86 } | 80 } |
| 87 | 81 |
| 88 TEST_P(SubSurfaceTest, PlaceBelow) { | 82 TEST_F(SubSurfaceTest, PlaceBelow) { |
| 89 std::unique_ptr<Surface> parent(new Surface); | 83 std::unique_ptr<Surface> parent(new Surface); |
| 90 std::unique_ptr<Surface> surface1(new Surface); | 84 std::unique_ptr<Surface> surface1(new Surface); |
| 91 std::unique_ptr<Surface> surface2(new Surface); | 85 std::unique_ptr<Surface> surface2(new Surface); |
| 92 std::unique_ptr<Surface> non_sibling_surface(new Surface); | 86 std::unique_ptr<Surface> non_sibling_surface(new Surface); |
| 93 std::unique_ptr<SubSurface> sub_surface1( | 87 std::unique_ptr<SubSurface> sub_surface1( |
| 94 new SubSurface(surface1.get(), parent.get())); | 88 new SubSurface(surface1.get(), parent.get())); |
| 95 std::unique_ptr<SubSurface> sub_surface2( | 89 std::unique_ptr<SubSurface> sub_surface2( |
| 96 new SubSurface(surface2.get(), parent.get())); | 90 new SubSurface(surface2.get(), parent.get())); |
| 97 | 91 |
| 98 ASSERT_EQ(2u, parent->window()->children().size()); | 92 ASSERT_EQ(2u, parent->window()->children().size()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 109 EXPECT_EQ(surface1->window(), parent->window()->children()[0]); | 103 EXPECT_EQ(surface1->window(), parent->window()->children()[0]); |
| 110 EXPECT_EQ(surface2->window(), parent->window()->children()[1]); | 104 EXPECT_EQ(surface2->window(), parent->window()->children()[1]); |
| 111 | 105 |
| 112 parent->Commit(); | 106 parent->Commit(); |
| 113 | 107 |
| 114 // surface1 should now be stacked above surface2. | 108 // surface1 should now be stacked above surface2. |
| 115 EXPECT_EQ(surface2->window(), parent->window()->children()[0]); | 109 EXPECT_EQ(surface2->window(), parent->window()->children()[0]); |
| 116 EXPECT_EQ(surface1->window(), parent->window()->children()[1]); | 110 EXPECT_EQ(surface1->window(), parent->window()->children()[1]); |
| 117 } | 111 } |
| 118 | 112 |
| 119 TEST_P(SubSurfaceTest, SetCommitBehavior) { | 113 TEST_F(SubSurfaceTest, SetCommitBehavior) { |
| 120 std::unique_ptr<Surface> parent(new Surface); | 114 std::unique_ptr<Surface> parent(new Surface); |
| 121 std::unique_ptr<Surface> child(new Surface); | 115 std::unique_ptr<Surface> child(new Surface); |
| 122 std::unique_ptr<Surface> grandchild(new Surface); | 116 std::unique_ptr<Surface> grandchild(new Surface); |
| 123 std::unique_ptr<SubSurface> child_sub_surface( | 117 std::unique_ptr<SubSurface> child_sub_surface( |
| 124 new SubSurface(child.get(), parent.get())); | 118 new SubSurface(child.get(), parent.get())); |
| 125 std::unique_ptr<SubSurface> grandchild_sub_surface( | 119 std::unique_ptr<SubSurface> grandchild_sub_surface( |
| 126 new SubSurface(grandchild.get(), child.get())); | 120 new SubSurface(grandchild.get(), child.get())); |
| 127 | 121 |
| 128 // Initial position is at the origin. | 122 // Initial position is at the origin. |
| 129 EXPECT_EQ(gfx::Point().ToString(), | 123 EXPECT_EQ(gfx::Point().ToString(), |
| (...skipping 25 matching lines...) Expand all Loading... |
| 155 gfx::Point position2(20, 20); | 149 gfx::Point position2(20, 20); |
| 156 grandchild_sub_surface->SetPosition(position2); | 150 grandchild_sub_surface->SetPosition(position2); |
| 157 child->Commit(); | 151 child->Commit(); |
| 158 | 152 |
| 159 // A Commit() call on child should be sufficient for the position of | 153 // A Commit() call on child should be sufficient for the position of |
| 160 // grandchild to take effect when synchronous is disabled. | 154 // grandchild to take effect when synchronous is disabled. |
| 161 EXPECT_EQ(position2.ToString(), | 155 EXPECT_EQ(position2.ToString(), |
| 162 grandchild->window()->bounds().origin().ToString()); | 156 grandchild->window()->bounds().origin().ToString()); |
| 163 } | 157 } |
| 164 | 158 |
| 165 INSTANTIATE_TEST_CASE_P(, SubSurfaceTest, ::testing::Bool()); | |
| 166 | |
| 167 } // namespace | 159 } // namespace |
| 168 } // namespace exo | 160 } // namespace exo |
| OLD | NEW |