| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/display/display_list.h" | 5 #include "ui/display/display_list.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "ui/display/display.h" | 12 #include "ui/display/display.h" |
| 13 #include "ui/display/display_observer.h" | 13 #include "ui/display/display_observer.h" |
| 14 | 14 |
| 15 using display::Display; | |
| 16 | |
| 17 namespace display { | 15 namespace display { |
| 18 namespace { | 16 namespace { |
| 19 | 17 |
| 20 class DisplayObserverImpl : public display::DisplayObserver { | 18 class DisplayObserverImpl : public DisplayObserver { |
| 21 public: | 19 public: |
| 22 DisplayObserverImpl() {} | 20 DisplayObserverImpl() {} |
| 23 ~DisplayObserverImpl() override {} | 21 ~DisplayObserverImpl() override {} |
| 24 | 22 |
| 25 std::string GetAndClearChanges() { | 23 std::string GetAndClearChanges() { |
| 26 std::string changes; | 24 std::string changes; |
| 27 std::swap(changes, changes_); | 25 std::swap(changes, changes_); |
| 28 return changes; | 26 return changes; |
| 29 } | 27 } |
| 30 | 28 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 | 66 |
| 69 std::string changes_; | 67 std::string changes_; |
| 70 | 68 |
| 71 DISALLOW_COPY_AND_ASSIGN(DisplayObserverImpl); | 69 DISALLOW_COPY_AND_ASSIGN(DisplayObserverImpl); |
| 72 }; | 70 }; |
| 73 | 71 |
| 74 TEST(DisplayListTest, AddUpdateRemove) { | 72 TEST(DisplayListTest, AddUpdateRemove) { |
| 75 DisplayList display_list; | 73 DisplayList display_list; |
| 76 DisplayObserverImpl observer; | 74 DisplayObserverImpl observer; |
| 77 display_list.AddObserver(&observer); | 75 display_list.AddObserver(&observer); |
| 78 display_list.AddDisplay(display::Display(2, gfx::Rect(0, 0, 801, 802)), | 76 display_list.AddDisplay(Display(2, gfx::Rect(0, 0, 801, 802)), |
| 79 DisplayList::Type::PRIMARY); | 77 DisplayList::Type::PRIMARY); |
| 80 EXPECT_EQ("Added id=2", observer.GetAndClearChanges()); | 78 EXPECT_EQ("Added id=2", observer.GetAndClearChanges()); |
| 81 | 79 |
| 82 // Update the bounds. | 80 // Update the bounds. |
| 83 { | 81 { |
| 84 display::Display updated_display = *(display_list.displays().begin()); | 82 Display updated_display = *(display_list.displays().begin()); |
| 85 updated_display.set_bounds(gfx::Rect(0, 0, 803, 802)); | 83 updated_display.set_bounds(gfx::Rect(0, 0, 803, 802)); |
| 86 display_list.UpdateDisplay(updated_display, DisplayList::Type::PRIMARY); | 84 display_list.UpdateDisplay(updated_display, DisplayList::Type::PRIMARY); |
| 87 EXPECT_EQ("Changed id=2 bounds", observer.GetAndClearChanges()); | 85 EXPECT_EQ("Changed id=2 bounds", observer.GetAndClearChanges()); |
| 88 } | 86 } |
| 89 | 87 |
| 90 // Add another. | 88 // Add another. |
| 91 display_list.AddDisplay(display::Display(3, gfx::Rect(0, 0, 809, 802)), | 89 display_list.AddDisplay(Display(3, gfx::Rect(0, 0, 809, 802)), |
| 92 DisplayList::Type::NOT_PRIMARY); | 90 DisplayList::Type::NOT_PRIMARY); |
| 93 EXPECT_EQ("Added id=3", observer.GetAndClearChanges()); | 91 EXPECT_EQ("Added id=3", observer.GetAndClearChanges()); |
| 94 ASSERT_EQ(2u, display_list.displays().size()); | 92 ASSERT_EQ(2u, display_list.displays().size()); |
| 95 EXPECT_EQ(2, display_list.displays()[0].id()); | 93 EXPECT_EQ(2, display_list.displays()[0].id()); |
| 96 EXPECT_EQ(3, display_list.displays()[1].id()); | 94 EXPECT_EQ(3, display_list.displays()[1].id()); |
| 97 EXPECT_EQ(2, display_list.GetPrimaryDisplayIterator()->id()); | 95 EXPECT_EQ(2, display_list.GetPrimaryDisplayIterator()->id()); |
| 98 | 96 |
| 99 // Make the second the primary. | 97 // Make the second the primary. |
| 100 display_list.UpdateDisplay(display_list.displays()[1], | 98 display_list.UpdateDisplay(display_list.displays()[1], |
| 101 DisplayList::Type::PRIMARY); | 99 DisplayList::Type::PRIMARY); |
| 102 EXPECT_EQ("Changed id=3 primary", observer.GetAndClearChanges()); | 100 EXPECT_EQ("Changed id=3 primary", observer.GetAndClearChanges()); |
| 103 EXPECT_EQ(3, display_list.GetPrimaryDisplayIterator()->id()); | 101 EXPECT_EQ(3, display_list.GetPrimaryDisplayIterator()->id()); |
| 104 | 102 |
| 105 // Delete the first. | 103 // Delete the first. |
| 106 display_list.RemoveDisplay(2); | 104 display_list.RemoveDisplay(2); |
| 107 ASSERT_EQ(1u, display_list.displays().size()); | 105 ASSERT_EQ(1u, display_list.displays().size()); |
| 108 EXPECT_EQ("Removed id=2", observer.GetAndClearChanges()); | 106 EXPECT_EQ("Removed id=2", observer.GetAndClearChanges()); |
| 109 EXPECT_EQ(3, display_list.GetPrimaryDisplayIterator()->id()); | 107 EXPECT_EQ(3, display_list.GetPrimaryDisplayIterator()->id()); |
| 110 } | 108 } |
| 111 | 109 |
| 112 TEST(DisplayListTest, SuspendUpdates) { | 110 TEST(DisplayListTest, SuspendUpdates) { |
| 113 DisplayList display_list; | 111 DisplayList display_list; |
| 114 display_list.AddDisplay(display::Display(2, gfx::Rect(0, 0, 801, 802)), | 112 display_list.AddDisplay(Display(2, gfx::Rect(0, 0, 801, 802)), |
| 115 DisplayList::Type::PRIMARY); | 113 DisplayList::Type::PRIMARY); |
| 116 DisplayObserverImpl observer; | 114 DisplayObserverImpl observer; |
| 117 display_list.AddObserver(&observer); | 115 display_list.AddObserver(&observer); |
| 118 { | 116 { |
| 119 // Suspend updates and add a new display. | 117 // Suspend updates and add a new display. |
| 120 std::unique_ptr<DisplayListObserverLock> lock = | 118 std::unique_ptr<DisplayListObserverLock> lock = |
| 121 display_list.SuspendObserverUpdates(); | 119 display_list.SuspendObserverUpdates(); |
| 122 display_list.AddDisplay(display::Display(3, gfx::Rect(0, 0, 809, 802)), | 120 display_list.AddDisplay(Display(3, gfx::Rect(0, 0, 809, 802)), |
| 123 DisplayList::Type::NOT_PRIMARY); | 121 DisplayList::Type::NOT_PRIMARY); |
| 124 EXPECT_EQ(2u, display_list.displays().size()); | 122 EXPECT_EQ(2u, display_list.displays().size()); |
| 125 // No update should have been generated. | 123 // No update should have been generated. |
| 126 EXPECT_TRUE(observer.GetAndClearChanges().empty()); | 124 EXPECT_TRUE(observer.GetAndClearChanges().empty()); |
| 127 } | 125 } |
| 128 // The lock has been destroyed, but no updates should be sent yet. | 126 // The lock has been destroyed, but no updates should be sent yet. |
| 129 EXPECT_TRUE(observer.GetAndClearChanges().empty()); | 127 EXPECT_TRUE(observer.GetAndClearChanges().empty()); |
| 130 | 128 |
| 131 // Update a display and verify observer called. | 129 // Update a display and verify observer called. |
| 132 display::Display updated_display = display_list.displays()[0]; | 130 Display updated_display = display_list.displays()[0]; |
| 133 updated_display.set_bounds(gfx::Rect(0, 0, 803, 802)); | 131 updated_display.set_bounds(gfx::Rect(0, 0, 803, 802)); |
| 134 display_list.UpdateDisplay(updated_display, DisplayList::Type::PRIMARY); | 132 display_list.UpdateDisplay(updated_display, DisplayList::Type::PRIMARY); |
| 135 EXPECT_EQ("Changed id=2 bounds", observer.GetAndClearChanges()); | 133 EXPECT_EQ("Changed id=2 bounds", observer.GetAndClearChanges()); |
| 136 } | 134 } |
| 137 | 135 |
| 138 } // namespace | 136 } // namespace |
| 139 } // namespace display | 137 } // namespace display |
| OLD | NEW |