OLD | NEW |
| (Empty) |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ui/views/widget/desktop_aura/desktop_screen_x11.h" | |
6 | |
7 #include "base/message_loop/message_loop.h" | |
8 #include "testing/gtest/include/gtest/gtest.h" | |
9 #include "ui/gfx/display_observer.h" | |
10 | |
11 namespace views { | |
12 | |
13 const int64 kFirstDisplay = 5321829; | |
14 const int64 kSecondDisplay = 928310; | |
15 | |
16 class DesktopScreenX11Test : public testing::Test, | |
17 public gfx::DisplayObserver { | |
18 public: | |
19 DesktopScreenX11Test() {} | |
20 virtual ~DesktopScreenX11Test() {} | |
21 | |
22 // Overridden from testing::Test: | |
23 virtual void SetUp() OVERRIDE { | |
24 // Initialize the world to the single monitor case. | |
25 std::vector<gfx::Display> displays; | |
26 displays.push_back(gfx::Display(kFirstDisplay, gfx::Rect(0, 0, 640, 480))); | |
27 screen_.reset(new DesktopScreenX11(displays)); | |
28 screen_->AddObserver(this); | |
29 } | |
30 virtual void TearDown() OVERRIDE { | |
31 screen_.reset(); | |
32 message_loop_.RunUntilIdle(); | |
33 } | |
34 | |
35 protected: | |
36 std::vector<gfx::Display> changed_display_; | |
37 std::vector<gfx::Display> added_display_; | |
38 std::vector<gfx::Display> removed_display_; | |
39 | |
40 DesktopScreenX11* screen() { return screen_.get(); } | |
41 | |
42 void ResetDisplayChanges() { | |
43 changed_display_.clear(); | |
44 added_display_.clear(); | |
45 removed_display_.clear(); | |
46 } | |
47 | |
48 private: | |
49 // Overridden from gfx::DisplayObserver: | |
50 virtual void OnDisplayBoundsChanged(const gfx::Display& display) OVERRIDE { | |
51 changed_display_.push_back(display); | |
52 } | |
53 | |
54 virtual void OnDisplayAdded(const gfx::Display& new_display) OVERRIDE { | |
55 added_display_.push_back(new_display); | |
56 } | |
57 | |
58 virtual void OnDisplayRemoved(const gfx::Display& old_display) OVERRIDE { | |
59 removed_display_.push_back(old_display); | |
60 } | |
61 | |
62 base::MessageLoopForUI message_loop_; | |
63 scoped_ptr<DesktopScreenX11> screen_; | |
64 | |
65 DISALLOW_COPY_AND_ASSIGN(DesktopScreenX11Test); | |
66 }; | |
67 | |
68 TEST_F(DesktopScreenX11Test, BoundsChangeSingleMonitor) { | |
69 std::vector<gfx::Display> displays; | |
70 displays.push_back(gfx::Display(kFirstDisplay, gfx::Rect(0, 0, 1024, 768))); | |
71 screen()->ProcessDisplayChange(displays); | |
72 | |
73 EXPECT_EQ(1u, changed_display_.size()); | |
74 EXPECT_EQ(0u, added_display_.size()); | |
75 EXPECT_EQ(0u, removed_display_.size()); | |
76 } | |
77 | |
78 TEST_F(DesktopScreenX11Test, AddMonitorToTheRight) { | |
79 std::vector<gfx::Display> displays; | |
80 displays.push_back(gfx::Display(kFirstDisplay, gfx::Rect(0, 0, 640, 480))); | |
81 displays.push_back(gfx::Display(kSecondDisplay, | |
82 gfx::Rect(640, 0, 1024, 768))); | |
83 screen()->ProcessDisplayChange(displays); | |
84 | |
85 EXPECT_EQ(0u, changed_display_.size()); | |
86 EXPECT_EQ(1u, added_display_.size()); | |
87 EXPECT_EQ(0u, removed_display_.size()); | |
88 } | |
89 | |
90 TEST_F(DesktopScreenX11Test, AddMonitorToTheLeft) { | |
91 std::vector<gfx::Display> displays; | |
92 displays.push_back(gfx::Display(kSecondDisplay, gfx::Rect(0, 0, 1024, 768))); | |
93 displays.push_back(gfx::Display(kFirstDisplay, gfx::Rect(1024, 0, 640, 480))); | |
94 screen()->ProcessDisplayChange(displays); | |
95 | |
96 EXPECT_EQ(1u, changed_display_.size()); | |
97 EXPECT_EQ(1u, added_display_.size()); | |
98 EXPECT_EQ(0u, removed_display_.size()); | |
99 } | |
100 | |
101 TEST_F(DesktopScreenX11Test, RemoveMonitorOnRight) { | |
102 std::vector<gfx::Display> displays; | |
103 displays.push_back(gfx::Display(kFirstDisplay, gfx::Rect(0, 0, 640, 480))); | |
104 displays.push_back(gfx::Display(kSecondDisplay, | |
105 gfx::Rect(640, 0, 1024, 768))); | |
106 screen()->ProcessDisplayChange(displays); | |
107 | |
108 ResetDisplayChanges(); | |
109 | |
110 displays.clear(); | |
111 displays.push_back(gfx::Display(kFirstDisplay, gfx::Rect(0, 0, 640, 480))); | |
112 screen()->ProcessDisplayChange(displays); | |
113 | |
114 EXPECT_EQ(0u, changed_display_.size()); | |
115 EXPECT_EQ(0u, added_display_.size()); | |
116 EXPECT_EQ(1u, removed_display_.size()); | |
117 } | |
118 | |
119 TEST_F(DesktopScreenX11Test, RemoveMonitorOnLeft) { | |
120 std::vector<gfx::Display> displays; | |
121 displays.push_back(gfx::Display(kFirstDisplay, gfx::Rect(0, 0, 640, 480))); | |
122 displays.push_back(gfx::Display(kSecondDisplay, | |
123 gfx::Rect(640, 0, 1024, 768))); | |
124 screen()->ProcessDisplayChange(displays); | |
125 | |
126 ResetDisplayChanges(); | |
127 | |
128 displays.clear(); | |
129 displays.push_back(gfx::Display(kSecondDisplay, gfx::Rect(0, 0, 1024, 768))); | |
130 screen()->ProcessDisplayChange(displays); | |
131 | |
132 EXPECT_EQ(1u, changed_display_.size()); | |
133 EXPECT_EQ(0u, added_display_.size()); | |
134 EXPECT_EQ(1u, removed_display_.size()); | |
135 } | |
136 | |
137 TEST_F(DesktopScreenX11Test, GetDisplayNearestPoint) { | |
138 std::vector<gfx::Display> displays; | |
139 displays.push_back(gfx::Display(kFirstDisplay, gfx::Rect(0, 0, 640, 480))); | |
140 displays.push_back(gfx::Display(kSecondDisplay, | |
141 gfx::Rect(640, 0, 1024, 768))); | |
142 screen()->ProcessDisplayChange(displays); | |
143 | |
144 EXPECT_EQ(kSecondDisplay, | |
145 screen()->GetDisplayNearestPoint(gfx::Point(650, 10)).id()); | |
146 EXPECT_EQ(kFirstDisplay, | |
147 screen()->GetDisplayNearestPoint(gfx::Point(10, 10)).id()); | |
148 EXPECT_EQ(kFirstDisplay, | |
149 screen()->GetDisplayNearestPoint(gfx::Point(10000, 10000)).id()); | |
150 } | |
151 | |
152 TEST_F(DesktopScreenX11Test, GetDisplayMatchingBasic) { | |
153 std::vector<gfx::Display> displays; | |
154 displays.push_back(gfx::Display(kFirstDisplay, gfx::Rect(0, 0, 640, 480))); | |
155 displays.push_back(gfx::Display(kSecondDisplay, | |
156 gfx::Rect(640, 0, 1024, 768))); | |
157 screen()->ProcessDisplayChange(displays); | |
158 | |
159 EXPECT_EQ(kSecondDisplay, | |
160 screen()->GetDisplayMatching(gfx::Rect(700, 20, 100, 100)).id()); | |
161 } | |
162 | |
163 TEST_F(DesktopScreenX11Test, GetDisplayMatchingOverlap) { | |
164 std::vector<gfx::Display> displays; | |
165 displays.push_back(gfx::Display(kFirstDisplay, gfx::Rect(0, 0, 640, 480))); | |
166 displays.push_back(gfx::Display(kSecondDisplay, | |
167 gfx::Rect(640, 0, 1024, 768))); | |
168 screen()->ProcessDisplayChange(displays); | |
169 | |
170 EXPECT_EQ(kSecondDisplay, | |
171 screen()->GetDisplayMatching(gfx::Rect(630, 20, 100, 100)).id()); | |
172 } | |
173 | |
174 TEST_F(DesktopScreenX11Test, GetPrimaryDisplay) { | |
175 std::vector<gfx::Display> displays; | |
176 displays.push_back(gfx::Display(kFirstDisplay, | |
177 gfx::Rect(640, 0, 1024, 768))); | |
178 displays.push_back(gfx::Display(kSecondDisplay, gfx::Rect(0, 0, 640, 480))); | |
179 screen()->ProcessDisplayChange(displays); | |
180 | |
181 // The first display in the list is always the primary, even if other | |
182 // displays are to the left in screen layout. | |
183 EXPECT_EQ(kFirstDisplay, screen()->GetPrimaryDisplay().id()); | |
184 } | |
185 | |
186 } // namespace views | |
OLD | NEW |