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

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

Issue 1059383003: Make sure observers are not nullptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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 | « base/observer_list.h ('k') | ui/views/widget/widget.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/gfx/display_change_notifier.h"
6 6
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "ui/gfx/display.h" 8 #include "ui/gfx/display.h"
9 #include "ui/gfx/display_observer.h" 9 #include "ui/gfx/display_observer.h"
10 10
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 change_notifier.NotifyDisplaysChanged( 63 change_notifier.NotifyDisplaysChanged(
64 std::vector<Display>(), std::vector<Display>(1, Display())); 64 std::vector<Display>(), std::vector<Display>(1, Display()));
65 EXPECT_EQ(0, observer.display_added()); 65 EXPECT_EQ(0, observer.display_added());
66 66
67 change_notifier.AddObserver(&observer); 67 change_notifier.AddObserver(&observer);
68 change_notifier.NotifyDisplaysChanged( 68 change_notifier.NotifyDisplaysChanged(
69 std::vector<Display>(), std::vector<Display>(1, Display())); 69 std::vector<Display>(), std::vector<Display>(1, Display()));
70 EXPECT_EQ(1, observer.display_added()); 70 EXPECT_EQ(1, observer.display_added());
71 } 71 }
72 72
73 TEST(DisplayChangeNotifierTest, AddObserver_Null) {
74 DisplayChangeNotifier change_notifier;
75
76 change_notifier.AddObserver(NULL);
77 // Should not crash.
78 }
79
80 TEST(DisplayChangeNotifier, RemoveObserver_Smoke) { 73 TEST(DisplayChangeNotifier, RemoveObserver_Smoke) {
81 DisplayChangeNotifier change_notifier; 74 DisplayChangeNotifier change_notifier;
82 MockDisplayObserver observer; 75 MockDisplayObserver observer;
83 76
84 change_notifier.NotifyDisplaysChanged( 77 change_notifier.NotifyDisplaysChanged(
85 std::vector<Display>(), std::vector<Display>(1, Display())); 78 std::vector<Display>(), std::vector<Display>(1, Display()));
86 EXPECT_EQ(0, observer.display_added()); 79 EXPECT_EQ(0, observer.display_added());
87 80
88 change_notifier.AddObserver(&observer); 81 change_notifier.AddObserver(&observer);
89 change_notifier.RemoveObserver(&observer); 82 change_notifier.RemoveObserver(&observer);
90 83
91 change_notifier.NotifyDisplaysChanged( 84 change_notifier.NotifyDisplaysChanged(
92 std::vector<Display>(), std::vector<Display>(1, Display())); 85 std::vector<Display>(), std::vector<Display>(1, Display()));
93 EXPECT_EQ(0, observer.display_added()); 86 EXPECT_EQ(0, observer.display_added());
94 } 87 }
95 88
96 TEST(DisplayChangeNotifierTest, RemoveObserver_Null) {
97 DisplayChangeNotifier change_notifier;
98
99 change_notifier.RemoveObserver(NULL);
100 // Should not crash.
101 }
102
103 TEST(DisplayChangeNotifierTest, RemoveObserver_Unknown) { 89 TEST(DisplayChangeNotifierTest, RemoveObserver_Unknown) {
104 DisplayChangeNotifier change_notifier; 90 DisplayChangeNotifier change_notifier;
105 MockDisplayObserver observer; 91 MockDisplayObserver observer;
106 92
107 change_notifier.RemoveObserver(&observer); 93 change_notifier.RemoveObserver(&observer);
108 // Should not crash. 94 // Should not crash.
109 } 95 }
110 96
111 TEST(DisplayChangeNotifierTest, NotifyDisplaysChanged_Removed) { 97 TEST(DisplayChangeNotifierTest, NotifyDisplaysChanged_Removed) {
112 DisplayChangeNotifier change_notifier; 98 DisplayChangeNotifier change_notifier;
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 change_notifier.NotifyDisplaysChanged(old_displays, new_displays); 471 change_notifier.NotifyDisplaysChanged(old_displays, new_displays);
486 EXPECT_EQ(1, observer.display_changed()); 472 EXPECT_EQ(1, observer.display_changed());
487 uint32_t metrics = DisplayObserver::DISPLAY_METRIC_BOUNDS | 473 uint32_t metrics = DisplayObserver::DISPLAY_METRIC_BOUNDS |
488 DisplayObserver::DISPLAY_METRIC_ROTATION | 474 DisplayObserver::DISPLAY_METRIC_ROTATION |
489 DisplayObserver::DISPLAY_METRIC_WORK_AREA | 475 DisplayObserver::DISPLAY_METRIC_WORK_AREA |
490 DisplayObserver::DISPLAY_METRIC_DEVICE_SCALE_FACTOR; 476 DisplayObserver::DISPLAY_METRIC_DEVICE_SCALE_FACTOR;
491 EXPECT_EQ(metrics, observer.latest_metrics_change()); 477 EXPECT_EQ(metrics, observer.latest_metrics_change());
492 } 478 }
493 479
494 } // namespace gfx 480 } // namespace gfx
OLDNEW
« no previous file with comments | « base/observer_list.h ('k') | ui/views/widget/widget.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698