Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(761)

Side by Side Diff: ui/display/display_list_unittest.cc

Issue 2378923002: Adds ability to suspend notifying observers when display list is changed (Closed)
Patch Set: cleanup Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« ui/display/display_list.h ('K') | « ui/display/display_list.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 EXPECT_EQ("Changed id=3 primary", observer.GetAndClearChanges()); 102 EXPECT_EQ("Changed id=3 primary", observer.GetAndClearChanges());
103 EXPECT_EQ(3, display_list.GetPrimaryDisplayIterator()->id()); 103 EXPECT_EQ(3, display_list.GetPrimaryDisplayIterator()->id());
104 104
105 // Delete the first. 105 // Delete the first.
106 display_list.RemoveDisplay(2); 106 display_list.RemoveDisplay(2);
107 ASSERT_EQ(1u, display_list.displays().size()); 107 ASSERT_EQ(1u, display_list.displays().size());
108 EXPECT_EQ("Removed id=2", observer.GetAndClearChanges()); 108 EXPECT_EQ("Removed id=2", observer.GetAndClearChanges());
109 EXPECT_EQ(3, display_list.GetPrimaryDisplayIterator()->id()); 109 EXPECT_EQ(3, display_list.GetPrimaryDisplayIterator()->id());
110 } 110 }
111 111
112 TEST(DisplayListTest, SuspendUpdates) {
113 DisplayList display_list;
114 display_list.AddDisplay(display::Display(2, gfx::Rect(0, 0, 801, 802)),
115 DisplayList::Type::PRIMARY);
116
117 DisplayObserverImpl observer;
118 display_list.AddObserver(&observer);
119 {
120 // Suspend updates and add a new display.
121 std::unique_ptr<DisplayListObserverLock> lock =
122 display_list.SuspendObserverUpdates();
123 display_list.AddDisplay(display::Display(3, gfx::Rect(0, 0, 809, 802)),
124 DisplayList::Type::NOT_PRIMARY);
125 EXPECT_EQ(2u, display_list.displays().size());
126 // No update should have been generated.
127 EXPECT_TRUE(observer.GetAndClearChanges().empty());
128 }
129 // The lock has been destroyed and should now notify observers.
130 EXPECT_EQ("Added id=3", observer.GetAndClearChanges());
131
132 // Two locks with an add followed by an update.
133 {
134 std::unique_ptr<DisplayListObserverLock> lock1 =
135 display_list.SuspendObserverUpdates();
136 {
137 std::unique_ptr<DisplayListObserverLock> lock2 =
138 display_list.SuspendObserverUpdates();
139 display_list.AddDisplay(display::Display(4, gfx::Rect(0, 0, 809, 802)),
140 DisplayList::Type::NOT_PRIMARY);
141 EXPECT_TRUE(observer.GetAndClearChanges().empty());
142 EXPECT_EQ(3u, display_list.displays().size());
143 }
144 // No updates should have been generated as there is still a valid lock.
145 EXPECT_TRUE(observer.GetAndClearChanges().empty());
146
147 // Update the display. Lock still held, so no updates.
148 display::Display updated_display = display_list.displays()[2];
149 updated_display.set_bounds(gfx::Rect(0, 0, 803, 802));
150 display_list.UpdateDisplay(updated_display, DisplayList::Type::NOT_PRIMARY);
151 EXPECT_TRUE(observer.GetAndClearChanges().empty());
152 }
153 // All locks have been destroyed, so observer should be called.
154 EXPECT_EQ("Added id=4", observer.GetAndClearChanges());
155 }
156
112 } // namespace 157 } // namespace
113 } // namespace display 158 } // namespace display
OLDNEW
« ui/display/display_list.h ('K') | « ui/display/display_list.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698