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

Side by Side Diff: ui/message_center/views/message_list_view_unittest.cc

Issue 2696523002: Stop notifications from being clipped on resize. (Closed)
Patch Set: Add additional comments. Created 3 years, 10 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
« no previous file with comments | « ui/message_center/views/message_list_view.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 <map> 5 #include <map>
6 #include <memory> 6 #include <memory>
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "testing/gmock/include/gmock/gmock.h"
12 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
13 #include "ui/message_center/fake_message_center.h" 14 #include "ui/message_center/fake_message_center.h"
14 #include "ui/message_center/notification.h" 15 #include "ui/message_center/notification.h"
15 #include "ui/message_center/notification_list.h" 16 #include "ui/message_center/notification_list.h"
16 #include "ui/message_center/views/message_center_controller.h" 17 #include "ui/message_center/views/message_center_controller.h"
17 #include "ui/message_center/views/message_list_view.h" 18 #include "ui/message_center/views/message_list_view.h"
18 #include "ui/message_center/views/notification_view.h" 19 #include "ui/message_center/views/notification_view.h"
19 #include "ui/views/test/views_test_base.h" 20 #include "ui/views/test/views_test_base.h"
20 21
22 using ::testing::ElementsAre;
23
21 namespace message_center { 24 namespace message_center {
22 25
23 static const char* kNotificationId1 = "notification id 1"; 26 static const char* kNotificationId1 = "notification id 1";
24 27
25 namespace { 28 namespace {
26 29
27 /* Types **********************************************************************/ 30 /* Types **********************************************************************/
28 31
29 enum CallType { GET_PREFERRED_SIZE, GET_HEIGHT_FOR_WIDTH, LAYOUT }; 32 enum CallType { GET_PREFERRED_SIZE, GET_HEIGHT_FOR_WIDTH, LAYOUT };
30 33
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 message_list_view_.reset(); 120 message_list_view_.reset();
118 121
119 views::ViewsTestBase::TearDown(); 122 views::ViewsTestBase::TearDown();
120 } 123 }
121 124
122 protected: 125 protected:
123 MessageListView* message_list_view() const { 126 MessageListView* message_list_view() const {
124 return message_list_view_.get(); 127 return message_list_view_.get();
125 } 128 }
126 129
130 int& reposition_top() { return message_list_view_->reposition_top_; }
131
132 int& fixed_height() { return message_list_view_->fixed_height_; }
133
134 std::vector<int> ComputeRepositionOffsets(const std::vector<int>& heights,
135 const std::vector<bool>& deleting,
136 int target_index,
137 int padding) {
138 return message_list_view_->ComputeRepositionOffsets(heights, deleting,
139 target_index, padding);
140 }
141
127 MockNotificationView* CreateNotificationView( 142 MockNotificationView* CreateNotificationView(
128 const Notification& notification) { 143 const Notification& notification) {
129 return new MockNotificationView(this, notification, this); 144 return new MockNotificationView(this, notification, this);
130 } 145 }
131 146
132 private: 147 private:
133 // MockNotificationView::Test override 148 // MockNotificationView::Test override
134 void RegisterCall(CallType type) override {} 149 void RegisterCall(CallType type) override {}
135 150
136 // MessageListView::Observer override 151 // MessageListView::Observer override
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 EXPECT_EQ(0, message_list_view()->child_count()); 197 EXPECT_EQ(0, message_list_view()->child_count());
183 EXPECT_FALSE(message_list_view()->Contains(notification_view)); 198 EXPECT_FALSE(message_list_view()->Contains(notification_view));
184 199
185 // Add a notification. 200 // Add a notification.
186 message_list_view()->AddNotificationAt(notification_view, 0); 201 message_list_view()->AddNotificationAt(notification_view, 0);
187 202
188 EXPECT_EQ(1, message_list_view()->child_count()); 203 EXPECT_EQ(1, message_list_view()->child_count());
189 EXPECT_TRUE(message_list_view()->Contains(notification_view)); 204 EXPECT_TRUE(message_list_view()->Contains(notification_view));
190 } 205 }
191 206
207 TEST_F(MessageListViewTest, RepositionOffsets) {
208 const auto insets = message_list_view()->GetInsets();
209 const int top = insets.top();
210 std::vector<int> positions;
211
212 // Notification above grows. |reposition_top| should remain at the same
213 // offset from the bottom.
214 fixed_height() = 4 + insets.height();
215 reposition_top() = 1 + top;
216 positions =
217 ComputeRepositionOffsets({2, 1, 1, 1}, {false, false, false, false},
218 1 /* target_index */, 0 /* padding */);
219 EXPECT_THAT(positions, ElementsAre(top, top + 2, top + 3, top + 4));
220 EXPECT_EQ(4 + insets.height() + 1, fixed_height());
221 EXPECT_EQ(1 + top + 1, reposition_top());
222
223 // Notification above shrinks. |reposition_top| should remain at the same
224 // offset from the bottom.
225 fixed_height() = 5 + insets.height();
226 reposition_top() = 2 + top;
227 positions =
228 ComputeRepositionOffsets({1, 1, 1, 1}, {false, false, false, false},
229 1 /* target_index */, 0 /* padding */);
230 EXPECT_THAT(positions, ElementsAre(top, top + 1, top + 2, top + 3));
231 EXPECT_EQ(4 + insets.height(), fixed_height());
232 EXPECT_EQ(1 + top, reposition_top());
233
234 // Notification above is being deleted. |reposition_top| should remain at the
235 // same offset from the bottom.
236 fixed_height() = 4 + insets.height();
237 reposition_top() = 1 + top;
238 positions =
239 ComputeRepositionOffsets({1, 1, 1, 1}, {true, false, false, false},
240 1 /* target_index */, 0 /* padding */);
241 EXPECT_THAT(positions, ElementsAre(top, top, top + 1, top + 2));
242 EXPECT_EQ(4 + insets.height() - 1, fixed_height());
243 EXPECT_EQ(1 + top - 1, reposition_top());
244
245 // Notification above is inserted. |reposition_top| should remain at the
246 // same offset from the bottom.
247 fixed_height() = 3 + insets.height();
248 reposition_top() = top;
249 positions =
250 ComputeRepositionOffsets({1, 1, 1, 1}, {false, false, false, false},
251 1 /* target_index */, 0 /* padding */);
252 EXPECT_THAT(positions, ElementsAre(top, top + 1, top + 2, top + 3));
253 EXPECT_EQ(3 + insets.height() + 1, fixed_height());
254 EXPECT_EQ(top + 1, reposition_top());
255
256 // Target notification grows with no free space. |reposition_top| is forced to
257 // change its offset from the bottom.
258 fixed_height() = 4 + insets.height();
259 reposition_top() = 1 + top;
260 positions =
261 ComputeRepositionOffsets({1, 2, 1, 1}, {false, false, false, false},
262 1 /* target_index */, 0 /* padding */);
263 EXPECT_THAT(positions, ElementsAre(top, top + 1, top + 3, top + 4));
264 EXPECT_EQ(4 + insets.height() + 1, fixed_height());
265 EXPECT_EQ(1 + top, reposition_top());
266
267 // Target notification grows with free space. |reposition_top| should remain
268 // at the same offset from the bottom.
269 fixed_height() = 5 + insets.height();
270 reposition_top() = 1 + top;
271 positions =
272 ComputeRepositionOffsets({1, 2, 1, 1}, {false, false, false, false},
273 1 /* target_index */, 0 /* padding */);
274 EXPECT_THAT(positions, ElementsAre(top, top + 1, top + 3, top + 4));
275 EXPECT_EQ(5 + insets.height(), fixed_height());
276 EXPECT_EQ(1 + top, reposition_top());
277
278 // Target notification grows with not enough free space. |reposition_top|
279 // should change its offset as little as possible, and consume the free space.
280 fixed_height() = 5 + insets.height();
281 reposition_top() = 1 + top;
282 positions =
283 ComputeRepositionOffsets({1, 3, 1, 1}, {false, false, false, false},
284 1 /* target_index */, 0 /* padding */);
285 EXPECT_THAT(positions, ElementsAre(top, top + 1, top + 4, top + 5));
286 EXPECT_EQ(5 + insets.height() + 1, fixed_height());
287 EXPECT_EQ(1 + top, reposition_top());
288
289 // Target notification shrinks. |reposition_top| should remain at the
290 // same offset from the bottom.
291 fixed_height() = 5 + insets.height();
292 reposition_top() = 1 + top;
293 positions =
294 ComputeRepositionOffsets({1, 1, 1, 1}, {false, false, false, false},
295 1 /* target_index */, 0 /* padding */);
296 EXPECT_THAT(positions, ElementsAre(top, top + 1, top + 2, top + 3));
297 EXPECT_EQ(5 + insets.height(), fixed_height());
298 EXPECT_EQ(1 + top, reposition_top());
299
300 // Notification below grows with no free space. |reposition_top| is forced to
301 // change its offset from the bottom.
302 fixed_height() = 4 + insets.height();
303 reposition_top() = 1 + top;
304 positions =
305 ComputeRepositionOffsets({1, 1, 2, 1}, {false, false, false, false},
306 1 /* target_index */, 0 /* padding */);
307 EXPECT_THAT(positions, ElementsAre(top, top + 1, top + 2, top + 4));
308 EXPECT_EQ(4 + insets.height() + 1, fixed_height());
309 EXPECT_EQ(1 + top, reposition_top());
310
311 // Notification below grows with free space. |reposition_top| should remain
312 // at the same offset from the bottom.
313 fixed_height() = 5 + insets.height();
314 reposition_top() = 1 + top;
315 positions =
316 ComputeRepositionOffsets({1, 1, 2, 1}, {false, false, false, false},
317 1 /* target_index */, 0 /* padding */);
318 EXPECT_THAT(positions, ElementsAre(top, top + 1, top + 2, top + 4));
319 EXPECT_EQ(5 + insets.height(), fixed_height());
320 EXPECT_EQ(1 + top, reposition_top());
321
322 // Notification below shrinks. |reposition_top| should remain at the same
323 // offset from the bottom.
324 fixed_height() = 5 + insets.height();
325 reposition_top() = 1 + top;
326 positions =
327 ComputeRepositionOffsets({1, 1, 1, 1}, {false, false, false, false},
328 1 /* target_index */, 0 /* padding */);
329 EXPECT_THAT(positions, ElementsAre(top, top + 1, top + 2, top + 3));
330 EXPECT_EQ(5 + insets.height(), fixed_height());
331 EXPECT_EQ(1 + top, reposition_top());
332
333 // Notification below is being deleted. |reposition_top| should remain at the
334 // same offset from the bottom.
335 fixed_height() = 4 + insets.height();
336 reposition_top() = 1 + top;
337 positions =
338 ComputeRepositionOffsets({1, 1, 1, 1}, {false, false, true, false},
339 1 /* target_index */, 0 /* padding */);
340 EXPECT_THAT(positions, ElementsAre(top, top + 1, top + 2, top + 2));
341 EXPECT_EQ(4 + insets.height(), fixed_height());
342 EXPECT_EQ(1 + top, reposition_top());
343
344 // Notification below is inserted with free space. |reposition_top| should
345 // remain at the same offset from the bottom.
346 fixed_height() = 4 + insets.height();
347 reposition_top() = 1 + top;
348 positions =
349 ComputeRepositionOffsets({1, 1, 1, 1}, {false, false, false, false},
350 1 /* target_index */, 0 /* padding */);
351 EXPECT_THAT(positions, ElementsAre(top, top + 1, top + 2, top + 3));
352 EXPECT_EQ(4 + insets.height(), fixed_height());
353 EXPECT_EQ(1 + top, reposition_top());
354
355 // Notification below is inserted with no free space. |reposition_top| is
356 // forced to change its offset from the bottom.
357 fixed_height() = 3 + insets.height();
358 reposition_top() = 1 + top;
359 positions =
360 ComputeRepositionOffsets({1, 1, 1, 1}, {false, false, false, false},
361 1 /* target_index */, 0 /* padding */);
362 EXPECT_THAT(positions, ElementsAre(top, top + 1, top + 2, top + 3));
363 EXPECT_EQ(3 + insets.height() + 1, fixed_height());
364 EXPECT_EQ(1 + top, reposition_top());
365
366 // Test padding.
367 fixed_height() = 20 + insets.height();
368 reposition_top() = 5 + top;
369 positions =
370 ComputeRepositionOffsets({5, 3, 3, 3}, {false, false, false, false},
371 1 /* target_index */, 2 /* padding */);
372 EXPECT_THAT(positions,
373 ElementsAre(top, top + 7, top + 7 + 5, top + 7 + 5 + 5));
374 EXPECT_EQ(20 + insets.height() + 2, fixed_height());
375 EXPECT_EQ(5 + top + 2, reposition_top());
376 }
377
192 } // namespace 378 } // namespace
OLDNEW
« no previous file with comments | « ui/message_center/views/message_list_view.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698