| 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 <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" |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 // offset from the bottom. | 213 // offset from the bottom. |
| 214 fixed_height() = 4 + insets.height(); | 214 fixed_height() = 4 + insets.height(); |
| 215 reposition_top() = 1 + top; | 215 reposition_top() = 1 + top; |
| 216 positions = | 216 positions = |
| 217 ComputeRepositionOffsets({2, 1, 1, 1}, {false, false, false, false}, | 217 ComputeRepositionOffsets({2, 1, 1, 1}, {false, false, false, false}, |
| 218 1 /* target_index */, 0 /* padding */); | 218 1 /* target_index */, 0 /* padding */); |
| 219 EXPECT_THAT(positions, ElementsAre(top, top + 2, top + 3, top + 4)); | 219 EXPECT_THAT(positions, ElementsAre(top, top + 2, top + 3, top + 4)); |
| 220 EXPECT_EQ(4 + insets.height() + 1, fixed_height()); | 220 EXPECT_EQ(4 + insets.height() + 1, fixed_height()); |
| 221 EXPECT_EQ(1 + top + 1, reposition_top()); | 221 EXPECT_EQ(1 + top + 1, reposition_top()); |
| 222 | 222 |
| 223 // Notification above shrinks. |reposition_top| should remain at the same | 223 // Notification above shrinks. The message center keeps its height. |
| 224 // offset from the bottom. | 224 // All notifications should remain at the same position from the top. |
| 225 fixed_height() = 5 + insets.height(); | 225 fixed_height() = 5 + insets.height(); |
| 226 reposition_top() = 2 + top; | 226 reposition_top() = 2 + top; |
| 227 positions = | 227 positions = |
| 228 ComputeRepositionOffsets({1, 1, 1, 1}, {false, false, false, false}, | 228 ComputeRepositionOffsets({1, 1, 1, 1}, {false, false, false, false}, |
| 229 1 /* target_index */, 0 /* padding */); | 229 1 /* target_index */, 0 /* padding */); |
| 230 EXPECT_THAT(positions, ElementsAre(top, top + 1, top + 2, top + 3)); | 230 EXPECT_THAT(positions, ElementsAre(top, top + 2, top + 3, top + 4)); |
| 231 EXPECT_EQ(4 + insets.height(), fixed_height()); | 231 EXPECT_EQ(5 + insets.height(), fixed_height()); |
| 232 EXPECT_EQ(1 + top, reposition_top()); | 232 EXPECT_EQ(2 + top, reposition_top()); |
| 233 | 233 |
| 234 // Notification above is being deleted. |reposition_top| should remain at the | 234 // Notification above is being deleted. |reposition_top| should remain at the |
| 235 // same offset from the bottom. | 235 // same place. |
| 236 fixed_height() = 4 + insets.height(); | 236 fixed_height() = 5 + insets.height(); |
| 237 reposition_top() = 1 + top; | 237 reposition_top() = 2 + top; |
| 238 positions = | 238 positions = |
| 239 ComputeRepositionOffsets({1, 1, 1, 1}, {true, false, false, false}, | 239 ComputeRepositionOffsets({1, 1, 1, 1}, {true, false, false, false}, |
| 240 1 /* target_index */, 0 /* padding */); | 240 1 /* target_index */, 0 /* padding */); |
| 241 EXPECT_THAT(positions, ElementsAre(top, top, top + 1, top + 2)); | 241 EXPECT_THAT(positions, ElementsAre(top, top + 2, top + 3, top + 4)); |
| 242 EXPECT_EQ(4 + insets.height() - 1, fixed_height()); | 242 EXPECT_EQ(5 + insets.height(), fixed_height()); |
| 243 EXPECT_EQ(1 + top - 1, reposition_top()); | 243 EXPECT_EQ(2 + top, reposition_top()); |
| 244 | 244 |
| 245 // Notification above is inserted. |reposition_top| should remain at the | 245 // Notification above is inserted. |reposition_top| should remain at the |
| 246 // same offset from the bottom. | 246 // same offset from the bottom. |
| 247 fixed_height() = 3 + insets.height(); | 247 fixed_height() = 5 + insets.height(); |
| 248 reposition_top() = top; | 248 reposition_top() = 2 + top; |
| 249 positions = | 249 positions = |
| 250 ComputeRepositionOffsets({1, 1, 1, 1}, {false, false, false, false}, | 250 ComputeRepositionOffsets({1, 1, 1, 1}, {false, false, false, false}, |
| 251 1 /* target_index */, 0 /* padding */); | 251 1 /* target_index */, 0 /* padding */); |
| 252 EXPECT_THAT(positions, ElementsAre(top, top + 1, top + 2, top + 3)); | 252 EXPECT_THAT(positions, ElementsAre(top, top + 2, top + 3, top + 4)); |
| 253 EXPECT_EQ(3 + insets.height() + 1, fixed_height()); | 253 EXPECT_EQ(5 + insets.height(), fixed_height()); |
| 254 EXPECT_EQ(top + 1, reposition_top()); | 254 EXPECT_EQ(top + 2, reposition_top()); |
| 255 | 255 |
| 256 // Target notification grows with no free space. |reposition_top| is forced to | 256 // Target notification grows with no free space. |reposition_top| is forced to |
| 257 // change its offset from the bottom. | 257 // change its offset from the bottom. |
| 258 fixed_height() = 4 + insets.height(); | 258 fixed_height() = 5 + insets.height(); |
| 259 reposition_top() = 1 + top; | 259 reposition_top() = 2 + top; |
| 260 positions = | 260 positions = |
| 261 ComputeRepositionOffsets({1, 2, 1, 1}, {false, false, false, false}, | 261 ComputeRepositionOffsets({1, 2, 1, 1}, {false, false, false, false}, |
| 262 1 /* target_index */, 0 /* padding */); | 262 1 /* target_index */, 0 /* padding */); |
| 263 EXPECT_THAT(positions, ElementsAre(top, top + 1, top + 3, top + 4)); | 263 EXPECT_THAT(positions, ElementsAre(top, top + 2, top + 4, top + 5)); |
| 264 EXPECT_EQ(4 + insets.height() + 1, fixed_height()); | 264 EXPECT_EQ(5 + insets.height() + 1, fixed_height()); |
| 265 EXPECT_EQ(1 + top, reposition_top()); | 265 EXPECT_EQ(2 + top, reposition_top()); |
| 266 | 266 |
| 267 // Target notification grows with free space. |reposition_top| should remain | 267 // Target notification grows with free space. |reposition_top| should remain |
| 268 // at the same offset from the bottom. | 268 // at the same offset from the bottom. |
| 269 fixed_height() = 5 + insets.height(); | 269 fixed_height() = 6 + insets.height(); |
| 270 reposition_top() = 1 + top; | 270 reposition_top() = 2 + top; |
| 271 positions = | 271 positions = |
| 272 ComputeRepositionOffsets({1, 2, 1, 1}, {false, false, false, false}, | 272 ComputeRepositionOffsets({1, 2, 1, 1}, {false, false, false, false}, |
| 273 1 /* target_index */, 0 /* padding */); | 273 1 /* target_index */, 0 /* padding */); |
| 274 EXPECT_THAT(positions, ElementsAre(top, top + 1, top + 3, top + 4)); | 274 EXPECT_THAT(positions, ElementsAre(top, top + 2, top + 4, top + 5)); |
| 275 EXPECT_EQ(5 + insets.height(), fixed_height()); | 275 EXPECT_EQ(6 + insets.height(), fixed_height()); |
| 276 EXPECT_EQ(1 + top, reposition_top()); | 276 EXPECT_EQ(2 + top, reposition_top()); |
| 277 | 277 |
| 278 // Target notification grows with not enough free space. |reposition_top| | 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. | 279 // should change its offset as little as possible, and consume the free space. |
| 280 fixed_height() = 5 + insets.height(); | 280 fixed_height() = 6 + insets.height(); |
| 281 reposition_top() = 1 + top; | 281 reposition_top() = 2 + top; |
| 282 positions = | 282 positions = |
| 283 ComputeRepositionOffsets({1, 3, 1, 1}, {false, false, false, false}, | 283 ComputeRepositionOffsets({1, 3, 1, 1}, {false, false, false, false}, |
| 284 1 /* target_index */, 0 /* padding */); | 284 1 /* target_index */, 0 /* padding */); |
| 285 EXPECT_THAT(positions, ElementsAre(top, top + 1, top + 4, top + 5)); | 285 EXPECT_THAT(positions, ElementsAre(top, top + 2, top + 5, top + 6)); |
| 286 EXPECT_EQ(5 + insets.height() + 1, fixed_height()); | 286 EXPECT_EQ(6 + insets.height() + 1, fixed_height()); |
| 287 EXPECT_EQ(1 + top, reposition_top()); | 287 EXPECT_EQ(2 + top, reposition_top()); |
| 288 | 288 |
| 289 // Target notification shrinks. |reposition_top| should remain at the | 289 // Target notification shrinks. |reposition_top| should remain at the |
| 290 // same offset from the bottom. | 290 // same offset from the bottom. |
| 291 fixed_height() = 5 + insets.height(); | 291 fixed_height() = 7 + insets.height(); |
| 292 reposition_top() = 1 + top; | 292 reposition_top() = 2 + top; |
| 293 positions = | 293 positions = |
| 294 ComputeRepositionOffsets({1, 1, 1, 1}, {false, false, false, false}, | 294 ComputeRepositionOffsets({1, 1, 1, 1}, {false, false, false, false}, |
| 295 1 /* target_index */, 0 /* padding */); | 295 1 /* target_index */, 0 /* padding */); |
| 296 EXPECT_THAT(positions, ElementsAre(top, top + 1, top + 2, top + 3)); | 296 EXPECT_THAT(positions, ElementsAre(top, top + 2, top + 3, top + 4)); |
| 297 EXPECT_EQ(5 + insets.height(), fixed_height()); | 297 EXPECT_EQ(7 + insets.height(), fixed_height()); |
| 298 EXPECT_EQ(1 + top, reposition_top()); | 298 EXPECT_EQ(2 + top, reposition_top()); |
| 299 | 299 |
| 300 // Notification below grows with no free space. |reposition_top| is forced to | 300 // Notification below grows with no free space. |reposition_top| is forced to |
| 301 // change its offset from the bottom. | 301 // change its offset from the bottom. |
| 302 fixed_height() = 4 + insets.height(); | 302 fixed_height() = 7 + insets.height(); |
| 303 reposition_top() = 1 + top; | 303 reposition_top() = 2 + top; |
| 304 positions = |
| 305 ComputeRepositionOffsets({1, 1, 4, 1}, {false, false, false, false}, |
| 306 1 /* target_index */, 0 /* padding */); |
| 307 EXPECT_THAT(positions, ElementsAre(top, top + 2, top + 3, top + 7)); |
| 308 EXPECT_EQ(7 + insets.height() + 1, fixed_height()); |
| 309 EXPECT_EQ(2 + 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() = 8 + insets.height(); |
| 314 reposition_top() = 2 + top; |
| 304 positions = | 315 positions = |
| 305 ComputeRepositionOffsets({1, 1, 2, 1}, {false, false, false, false}, | 316 ComputeRepositionOffsets({1, 1, 2, 1}, {false, false, false, false}, |
| 306 1 /* target_index */, 0 /* padding */); | 317 1 /* target_index */, 0 /* padding */); |
| 307 EXPECT_THAT(positions, ElementsAre(top, top + 1, top + 2, top + 4)); | 318 EXPECT_THAT(positions, ElementsAre(top, top + 2, top + 3, top + 5)); |
| 308 EXPECT_EQ(4 + insets.height() + 1, fixed_height()); | 319 EXPECT_EQ(8 + insets.height(), fixed_height()); |
| 309 EXPECT_EQ(1 + top, reposition_top()); | 320 EXPECT_EQ(2 + 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 | 321 |
| 322 // Notification below shrinks. |reposition_top| should remain at the same | 322 // Notification below shrinks. |reposition_top| should remain at the same |
| 323 // offset from the bottom. | 323 // offset from the bottom. |
| 324 fixed_height() = 5 + insets.height(); | 324 fixed_height() = 8 + insets.height(); |
| 325 reposition_top() = 1 + top; | 325 reposition_top() = 2 + top; |
| 326 positions = | 326 positions = |
| 327 ComputeRepositionOffsets({1, 1, 1, 1}, {false, false, false, false}, | 327 ComputeRepositionOffsets({1, 1, 1, 1}, {false, false, false, false}, |
| 328 1 /* target_index */, 0 /* padding */); | 328 1 /* target_index */, 0 /* padding */); |
| 329 EXPECT_THAT(positions, ElementsAre(top, top + 1, top + 2, top + 3)); | 329 EXPECT_THAT(positions, ElementsAre(top, top + 2, top + 3, top + 4)); |
| 330 EXPECT_EQ(5 + insets.height(), fixed_height()); | 330 EXPECT_EQ(8 + insets.height(), fixed_height()); |
| 331 EXPECT_EQ(1 + top, reposition_top()); | 331 EXPECT_EQ(2 + top, reposition_top()); |
| 332 | 332 |
| 333 // Notification below is being deleted. |reposition_top| should remain at the | 333 // Notification below is being deleted. |reposition_top| should remain at the |
| 334 // same offset from the bottom. | 334 // same offset from the bottom. |
| 335 fixed_height() = 4 + insets.height(); | 335 fixed_height() = 8 + insets.height(); |
| 336 reposition_top() = 1 + top; | 336 reposition_top() = 2 + top; |
| 337 positions = | 337 positions = |
| 338 ComputeRepositionOffsets({1, 1, 1, 1}, {false, false, true, false}, | 338 ComputeRepositionOffsets({1, 1, 1, 1}, {false, false, true, false}, |
| 339 1 /* target_index */, 0 /* padding */); | 339 1 /* target_index */, 0 /* padding */); |
| 340 EXPECT_THAT(positions, ElementsAre(top, top + 1, top + 2, top + 2)); | 340 EXPECT_THAT(positions, ElementsAre(top, top + 2, top + 3, top + 3)); |
| 341 EXPECT_EQ(4 + insets.height(), fixed_height()); | 341 EXPECT_EQ(8 + insets.height(), fixed_height()); |
| 342 EXPECT_EQ(1 + top, reposition_top()); | 342 EXPECT_EQ(2 + top, reposition_top()); |
| 343 | 343 |
| 344 // Notification below is inserted with free space. |reposition_top| should | 344 // Notification below is inserted with free space. |reposition_top| should |
| 345 // remain at the same offset from the bottom. | 345 // remain at the same offset from the bottom. |
| 346 fixed_height() = 4 + insets.height(); | 346 fixed_height() = 8 + insets.height(); |
| 347 reposition_top() = 1 + top; | 347 reposition_top() = 2 + top; |
| 348 positions = | 348 positions = |
| 349 ComputeRepositionOffsets({1, 1, 1, 1}, {false, false, false, false}, | 349 ComputeRepositionOffsets({1, 1, 1, 1}, {false, false, false, false}, |
| 350 1 /* target_index */, 0 /* padding */); | 350 1 /* target_index */, 0 /* padding */); |
| 351 EXPECT_THAT(positions, ElementsAre(top, top + 1, top + 2, top + 3)); | 351 EXPECT_THAT(positions, ElementsAre(top, top + 2, top + 3, top + 4)); |
| 352 EXPECT_EQ(4 + insets.height(), fixed_height()); | 352 EXPECT_EQ(8 + insets.height(), fixed_height()); |
| 353 EXPECT_EQ(1 + top, reposition_top()); | 353 EXPECT_EQ(2 + top, reposition_top()); |
| 354 | 354 |
| 355 // Notification below is inserted with no free space. |reposition_top| is | 355 // Notification below is inserted with no free space. |reposition_top| is |
| 356 // forced to change its offset from the bottom. | 356 // forced to change its offset from the bottom. |
| 357 fixed_height() = 3 + insets.height(); | 357 fixed_height() = 8 + insets.height(); |
| 358 reposition_top() = 1 + top; | 358 reposition_top() = 2 + top; |
| 359 positions = | 359 positions = ComputeRepositionOffsets({1, 1, 1, 4, 1}, |
| 360 ComputeRepositionOffsets({1, 1, 1, 1}, {false, false, false, false}, | 360 {false, false, false, false, false}, |
| 361 1 /* target_index */, 0 /* padding */); | 361 1 /* target_index */, 0 /* padding */); |
| 362 EXPECT_THAT(positions, ElementsAre(top, top + 1, top + 2, top + 3)); | 362 EXPECT_THAT(positions, ElementsAre(top, top + 2, top + 3, top + 4, top + 8)); |
| 363 EXPECT_EQ(3 + insets.height() + 1, fixed_height()); | 363 EXPECT_EQ(8 + insets.height() + 1, fixed_height()); |
| 364 EXPECT_EQ(1 + top, reposition_top()); | 364 EXPECT_EQ(2 + top, reposition_top()); |
| 365 | 365 |
| 366 // Test padding. | 366 // Test padding. |
| 367 fixed_height() = 20 + insets.height(); | 367 fixed_height() = 20 + insets.height(); |
| 368 reposition_top() = 5 + top; | 368 reposition_top() = 5 + top; |
| 369 positions = | 369 positions = |
| 370 ComputeRepositionOffsets({5, 3, 3, 3}, {false, false, false, false}, | 370 ComputeRepositionOffsets({5, 3, 3, 3}, {false, false, false, false}, |
| 371 1 /* target_index */, 2 /* padding */); | 371 1 /* target_index */, 2 /* padding */); |
| 372 EXPECT_THAT(positions, | 372 EXPECT_THAT(positions, |
| 373 ElementsAre(top, top + 7, top + 7 + 5, top + 7 + 5 + 5)); | 373 ElementsAre(top, top + 7, top + 7 + 5, top + 7 + 5 + 5)); |
| 374 EXPECT_EQ(20 + insets.height() + 2, fixed_height()); | 374 EXPECT_EQ(20 + insets.height() + 2, fixed_height()); |
| 375 EXPECT_EQ(5 + top + 2, reposition_top()); | 375 EXPECT_EQ(5 + top + 2, reposition_top()); |
| 376 } | 376 } |
| 377 | 377 |
| 378 } // namespace | 378 } // namespace |
| OLD | NEW |