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

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

Issue 1964153002: Move Screen, its impls, DisplayObserver and DisplayChangeNotifier to ui/display (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix tabs Created 4 years, 7 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/display/display_change_notifier.cc ('k') | ui/display/display_finder.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/gfx/display_change_notifier.h" 5 #include "ui/display/display_change_notifier.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "ui/gfx/display.h" 11 #include "ui/display/display.h"
12 #include "ui/gfx/display_observer.h" 12 #include "ui/display/display_observer.h"
13 13
14 namespace gfx { 14 namespace display {
15 15
16 class MockDisplayObserver : public DisplayObserver { 16 class MockDisplayObserver : public DisplayObserver {
17 public: 17 public:
18 MockDisplayObserver() 18 MockDisplayObserver()
19 : display_added_(0), 19 : display_added_(0),
20 display_removed_(0), 20 display_removed_(0),
21 display_changed_(0), 21 display_changed_(0),
22 latest_metrics_change_(DisplayObserver::DISPLAY_METRIC_NONE) 22 latest_metrics_change_(DisplayObserver::DISPLAY_METRIC_NONE) {}
23 {}
24 23
25 ~MockDisplayObserver() override {} 24 ~MockDisplayObserver() override {}
26 25
27 void OnDisplayAdded(const Display& display) override { display_added_++; } 26 void OnDisplayAdded(const Display& display) override { display_added_++; }
28 27
29 void OnDisplayRemoved(const Display& display) override { display_removed_++; } 28 void OnDisplayRemoved(const Display& display) override { display_removed_++; }
30 29
31 void OnDisplayMetricsChanged(const Display& display, 30 void OnDisplayMetricsChanged(const Display& display,
32 uint32_t metrics) override { 31 uint32_t metrics) override {
33 display_changed_++; 32 display_changed_++;
34 latest_metrics_change_ = metrics; 33 latest_metrics_change_ = metrics;
35 } 34 }
36 35
37 int display_added() const { 36 int display_added() const { return display_added_; }
38 return display_added_;
39 }
40 37
41 int display_removed() const { 38 int display_removed() const { return display_removed_; }
42 return display_removed_;
43 }
44 39
45 int display_changed() const { 40 int display_changed() const { return display_changed_; }
46 return display_changed_;
47 }
48 41
49 uint32_t latest_metrics_change() const { 42 uint32_t latest_metrics_change() const { return latest_metrics_change_; }
50 return latest_metrics_change_;
51 }
52 43
53 protected: 44 protected:
54 int display_added_; 45 int display_added_;
55 int display_removed_; 46 int display_removed_;
56 int display_changed_; 47 int display_changed_;
57 uint32_t latest_metrics_change_; 48 uint32_t latest_metrics_change_;
58 49
59 DISALLOW_COPY_AND_ASSIGN(MockDisplayObserver); 50 DISALLOW_COPY_AND_ASSIGN(MockDisplayObserver);
60 }; 51 };
61 52
62 TEST(DisplayChangeNotifierTest, AddObserver_Smoke) { 53 TEST(DisplayChangeNotifierTest, AddObserver_Smoke) {
63 DisplayChangeNotifier change_notifier; 54 DisplayChangeNotifier change_notifier;
64 MockDisplayObserver observer; 55 MockDisplayObserver observer;
65 56
66 change_notifier.NotifyDisplaysChanged( 57 change_notifier.NotifyDisplaysChanged(std::vector<Display>(),
67 std::vector<Display>(), std::vector<Display>(1, Display())); 58 std::vector<Display>(1, Display()));
68 EXPECT_EQ(0, observer.display_added()); 59 EXPECT_EQ(0, observer.display_added());
69 60
70 change_notifier.AddObserver(&observer); 61 change_notifier.AddObserver(&observer);
71 change_notifier.NotifyDisplaysChanged( 62 change_notifier.NotifyDisplaysChanged(std::vector<Display>(),
72 std::vector<Display>(), std::vector<Display>(1, Display())); 63 std::vector<Display>(1, Display()));
73 EXPECT_EQ(1, observer.display_added()); 64 EXPECT_EQ(1, observer.display_added());
74 } 65 }
75 66
76 TEST(DisplayChangeNotifier, RemoveObserver_Smoke) { 67 TEST(DisplayChangeNotifier, RemoveObserver_Smoke) {
77 DisplayChangeNotifier change_notifier; 68 DisplayChangeNotifier change_notifier;
78 MockDisplayObserver observer; 69 MockDisplayObserver observer;
79 70
80 change_notifier.NotifyDisplaysChanged( 71 change_notifier.NotifyDisplaysChanged(std::vector<Display>(),
81 std::vector<Display>(), std::vector<Display>(1, Display())); 72 std::vector<Display>(1, Display()));
82 EXPECT_EQ(0, observer.display_added()); 73 EXPECT_EQ(0, observer.display_added());
83 74
84 change_notifier.AddObserver(&observer); 75 change_notifier.AddObserver(&observer);
85 change_notifier.RemoveObserver(&observer); 76 change_notifier.RemoveObserver(&observer);
86 77
87 change_notifier.NotifyDisplaysChanged( 78 change_notifier.NotifyDisplaysChanged(std::vector<Display>(),
88 std::vector<Display>(), std::vector<Display>(1, Display())); 79 std::vector<Display>(1, Display()));
89 EXPECT_EQ(0, observer.display_added()); 80 EXPECT_EQ(0, observer.display_added());
90 } 81 }
91 82
92 TEST(DisplayChangeNotifierTest, RemoveObserver_Unknown) { 83 TEST(DisplayChangeNotifierTest, RemoveObserver_Unknown) {
93 DisplayChangeNotifier change_notifier; 84 DisplayChangeNotifier change_notifier;
94 MockDisplayObserver observer; 85 MockDisplayObserver observer;
95 86
96 change_notifier.RemoveObserver(&observer); 87 change_notifier.RemoveObserver(&observer);
97 // Should not crash. 88 // Should not crash.
98 } 89 }
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 } 320 }
330 321
331 TEST(DisplayChangeNotifierTest, NotifyDisplaysChanged_Changed_Bounds) { 322 TEST(DisplayChangeNotifierTest, NotifyDisplaysChanged_Changed_Bounds) {
332 DisplayChangeNotifier change_notifier; 323 DisplayChangeNotifier change_notifier;
333 324
334 { 325 {
335 MockDisplayObserver observer; 326 MockDisplayObserver observer;
336 change_notifier.AddObserver(&observer); 327 change_notifier.AddObserver(&observer);
337 328
338 std::vector<Display> old_displays, new_displays; 329 std::vector<Display> old_displays, new_displays;
339 old_displays.push_back(Display(1, Rect(0, 0, 200, 200))); 330 old_displays.push_back(Display(1, gfx::Rect(0, 0, 200, 200)));
340 new_displays.push_back(Display(1, Rect(0, 0, 200, 200))); 331 new_displays.push_back(Display(1, gfx::Rect(0, 0, 200, 200)));
341 332
342 change_notifier.NotifyDisplaysChanged(old_displays, new_displays); 333 change_notifier.NotifyDisplaysChanged(old_displays, new_displays);
343 EXPECT_EQ(0, observer.display_changed()); 334 EXPECT_EQ(0, observer.display_changed());
344 335
345 change_notifier.RemoveObserver(&observer); 336 change_notifier.RemoveObserver(&observer);
346 } 337 }
347 338
348 { 339 {
349 MockDisplayObserver observer; 340 MockDisplayObserver observer;
350 change_notifier.AddObserver(&observer); 341 change_notifier.AddObserver(&observer);
351 342
352 std::vector<Display> old_displays, new_displays; 343 std::vector<Display> old_displays, new_displays;
353 old_displays.push_back(Display(1, Rect(0, 0, 200, 200))); 344 old_displays.push_back(Display(1, gfx::Rect(0, 0, 200, 200)));
354 new_displays.push_back(Display(1, Rect(10, 10, 300, 300))); 345 new_displays.push_back(Display(1, gfx::Rect(10, 10, 300, 300)));
355 346
356 change_notifier.NotifyDisplaysChanged(old_displays, new_displays); 347 change_notifier.NotifyDisplaysChanged(old_displays, new_displays);
357 EXPECT_EQ(1, observer.display_changed()); 348 EXPECT_EQ(1, observer.display_changed());
358 uint32_t metrics_change = DisplayObserver::DISPLAY_METRIC_BOUNDS | 349 uint32_t metrics_change = DisplayObserver::DISPLAY_METRIC_BOUNDS |
359 DisplayObserver::DISPLAY_METRIC_WORK_AREA; 350 DisplayObserver::DISPLAY_METRIC_WORK_AREA;
360 EXPECT_EQ(metrics_change, observer.latest_metrics_change()); 351 EXPECT_EQ(metrics_change, observer.latest_metrics_change());
361 352
362 change_notifier.RemoveObserver(&observer); 353 change_notifier.RemoveObserver(&observer);
363 } 354 }
364 355
365 { 356 {
366 MockDisplayObserver observer; 357 MockDisplayObserver observer;
367 change_notifier.AddObserver(&observer); 358 change_notifier.AddObserver(&observer);
368 359
369 std::vector<Display> old_displays, new_displays; 360 std::vector<Display> old_displays, new_displays;
370 old_displays.push_back(Display(1, Rect(0, 0, 200, 200))); 361 old_displays.push_back(Display(1, gfx::Rect(0, 0, 200, 200)));
371 new_displays.push_back(Display(1, Rect(0, 0, 200, 200))); 362 new_displays.push_back(Display(1, gfx::Rect(0, 0, 200, 200)));
372 new_displays[0].set_bounds(Rect(10, 10, 300, 300)); 363 new_displays[0].set_bounds(gfx::Rect(10, 10, 300, 300));
373 364
374 change_notifier.NotifyDisplaysChanged(old_displays, new_displays); 365 change_notifier.NotifyDisplaysChanged(old_displays, new_displays);
375 EXPECT_EQ(1, observer.display_changed()); 366 EXPECT_EQ(1, observer.display_changed());
376 EXPECT_EQ(DisplayObserver::DISPLAY_METRIC_BOUNDS, 367 EXPECT_EQ(DisplayObserver::DISPLAY_METRIC_BOUNDS,
377 observer.latest_metrics_change()); 368 observer.latest_metrics_change());
378 369
379 change_notifier.RemoveObserver(&observer); 370 change_notifier.RemoveObserver(&observer);
380 } 371 }
381 } 372 }
382 373
(...skipping 14 matching lines...) Expand all
397 observer.latest_metrics_change()); 388 observer.latest_metrics_change());
398 } 389 }
399 390
400 TEST(DisplayChangeNotifierTest, NotifyDisplaysChanged_Changed_WorkArea) { 391 TEST(DisplayChangeNotifierTest, NotifyDisplaysChanged_Changed_WorkArea) {
401 DisplayChangeNotifier change_notifier; 392 DisplayChangeNotifier change_notifier;
402 MockDisplayObserver observer; 393 MockDisplayObserver observer;
403 change_notifier.AddObserver(&observer); 394 change_notifier.AddObserver(&observer);
404 395
405 std::vector<Display> old_displays, new_displays; 396 std::vector<Display> old_displays, new_displays;
406 old_displays.push_back(Display(1)); 397 old_displays.push_back(Display(1));
407 old_displays[0].set_work_area(Rect(0, 0, 200, 200)); 398 old_displays[0].set_work_area(gfx::Rect(0, 0, 200, 200));
408 new_displays.push_back(Display(1)); 399 new_displays.push_back(Display(1));
409 new_displays[0].set_work_area(Rect(20, 20, 300, 300)); 400 new_displays[0].set_work_area(gfx::Rect(20, 20, 300, 300));
410 401
411 change_notifier.NotifyDisplaysChanged(old_displays, new_displays); 402 change_notifier.NotifyDisplaysChanged(old_displays, new_displays);
412 EXPECT_EQ(1, observer.display_changed()); 403 EXPECT_EQ(1, observer.display_changed());
413 EXPECT_EQ(DisplayObserver::DISPLAY_METRIC_WORK_AREA, 404 EXPECT_EQ(DisplayObserver::DISPLAY_METRIC_WORK_AREA,
414 observer.latest_metrics_change()); 405 observer.latest_metrics_change());
415 } 406 }
416 407
417 TEST(DisplayChangeNotifierTest, NotifyDisplaysChanged_Changed_DSF) { 408 TEST(DisplayChangeNotifierTest, NotifyDisplaysChanged_Changed_DSF) {
418 DisplayChangeNotifier change_notifier; 409 DisplayChangeNotifier change_notifier;
419 MockDisplayObserver observer; 410 MockDisplayObserver observer;
(...skipping 20 matching lines...) Expand all
440 old_displays.push_back(Display(1)); 431 old_displays.push_back(Display(1));
441 old_displays.push_back(Display(2)); 432 old_displays.push_back(Display(2));
442 old_displays.push_back(Display(3)); 433 old_displays.push_back(Display(3));
443 new_displays.push_back(Display(1)); 434 new_displays.push_back(Display(1));
444 new_displays.push_back(Display(2)); 435 new_displays.push_back(Display(2));
445 new_displays.push_back(Display(3)); 436 new_displays.push_back(Display(3));
446 437
447 old_displays[0].set_device_scale_factor(1.f); 438 old_displays[0].set_device_scale_factor(1.f);
448 new_displays[0].set_device_scale_factor(2.f); 439 new_displays[0].set_device_scale_factor(2.f);
449 440
450 old_displays[1].set_bounds(Rect(0, 0, 200, 200)); 441 old_displays[1].set_bounds(gfx::Rect(0, 0, 200, 200));
451 new_displays[1].set_bounds(Rect(0, 0, 400, 400)); 442 new_displays[1].set_bounds(gfx::Rect(0, 0, 400, 400));
452 443
453 old_displays[2].SetRotationAsDegree(0); 444 old_displays[2].SetRotationAsDegree(0);
454 new_displays[2].SetRotationAsDegree(90); 445 new_displays[2].SetRotationAsDegree(90);
455 446
456 change_notifier.NotifyDisplaysChanged(old_displays, new_displays); 447 change_notifier.NotifyDisplaysChanged(old_displays, new_displays);
457 EXPECT_EQ(3, observer.display_changed()); 448 EXPECT_EQ(3, observer.display_changed());
458 } 449 }
459 450
460 TEST(DisplayChangeNotifierTest, NotifyDisplaysChanged_Changed_Multi_Metrics) { 451 TEST(DisplayChangeNotifierTest, NotifyDisplaysChanged_Changed_Multi_Metrics) {
461 DisplayChangeNotifier change_notifier; 452 DisplayChangeNotifier change_notifier;
462 MockDisplayObserver observer; 453 MockDisplayObserver observer;
463 change_notifier.AddObserver(&observer); 454 change_notifier.AddObserver(&observer);
464 455
465 std::vector<Display> old_displays, new_displays; 456 std::vector<Display> old_displays, new_displays;
466 old_displays.push_back(Display(1, Rect(0, 0, 200, 200))); 457 old_displays.push_back(Display(1, gfx::Rect(0, 0, 200, 200)));
467 old_displays[0].set_device_scale_factor(1.f); 458 old_displays[0].set_device_scale_factor(1.f);
468 old_displays[0].SetRotationAsDegree(0); 459 old_displays[0].SetRotationAsDegree(0);
469 460
470 new_displays.push_back(Display(1, Rect(100, 100, 200, 200))); 461 new_displays.push_back(Display(1, gfx::Rect(100, 100, 200, 200)));
471 new_displays[0].set_device_scale_factor(2.f); 462 new_displays[0].set_device_scale_factor(2.f);
472 new_displays[0].SetRotationAsDegree(90); 463 new_displays[0].SetRotationAsDegree(90);
473 464
474 change_notifier.NotifyDisplaysChanged(old_displays, new_displays); 465 change_notifier.NotifyDisplaysChanged(old_displays, new_displays);
475 EXPECT_EQ(1, observer.display_changed()); 466 EXPECT_EQ(1, observer.display_changed());
476 uint32_t metrics = DisplayObserver::DISPLAY_METRIC_BOUNDS | 467 uint32_t metrics = DisplayObserver::DISPLAY_METRIC_BOUNDS |
477 DisplayObserver::DISPLAY_METRIC_ROTATION | 468 DisplayObserver::DISPLAY_METRIC_ROTATION |
478 DisplayObserver::DISPLAY_METRIC_WORK_AREA | 469 DisplayObserver::DISPLAY_METRIC_WORK_AREA |
479 DisplayObserver::DISPLAY_METRIC_DEVICE_SCALE_FACTOR; 470 DisplayObserver::DISPLAY_METRIC_DEVICE_SCALE_FACTOR;
480 EXPECT_EQ(metrics, observer.latest_metrics_change()); 471 EXPECT_EQ(metrics, observer.latest_metrics_change());
481 } 472 }
482 473
483 } // namespace gfx 474 } // namespace display
OLDNEW
« no previous file with comments | « ui/display/display_change_notifier.cc ('k') | ui/display/display_finder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698