OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <list> | 5 #include <list> |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 bool exact_size_supported_; | 85 bool exact_size_supported_; |
86 std::list<ScreenResolution> supported_resolutions_; | 86 std::list<ScreenResolution> supported_resolutions_; |
87 | 87 |
88 int set_resolution_call_count_; | 88 int set_resolution_call_count_; |
89 int* restore_resolution_call_count_; | 89 int* restore_resolution_call_count_; |
90 }; | 90 }; |
91 | 91 |
92 class ResizingHostObserverTest : public testing::Test { | 92 class ResizingHostObserverTest : public testing::Test { |
93 public: | 93 public: |
94 ResizingHostObserverTest() | 94 ResizingHostObserverTest() |
95 : desktop_resizer_(NULL), | 95 : desktop_resizer_(nullptr), |
96 now_(base::Time::Now()) { | 96 now_(base::Time::Now()) { |
97 } | 97 } |
98 | 98 |
99 // This needs to be public because the derived test-case class needs to | 99 // This needs to be public because the derived test-case class needs to |
100 // pass it to Bind, which fails if it's protected. | 100 // pass it to Bind, which fails if it's protected. |
101 base::Time GetTime() { | 101 base::Time GetTime() { |
102 return now_; | 102 return now_; |
103 } | 103 } |
104 | 104 |
105 protected: | 105 protected: |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 scoped_ptr<ResizingHostObserver> resizing_host_observer_; | 138 scoped_ptr<ResizingHostObserver> resizing_host_observer_; |
139 FakeDesktopResizer* desktop_resizer_; | 139 FakeDesktopResizer* desktop_resizer_; |
140 base::Time now_; | 140 base::Time now_; |
141 }; | 141 }; |
142 | 142 |
143 // Check that the resolution isn't restored if it wasn't changed by this class. | 143 // Check that the resolution isn't restored if it wasn't changed by this class. |
144 TEST_F(ResizingHostObserverTest, NoRestoreResolution) { | 144 TEST_F(ResizingHostObserverTest, NoRestoreResolution) { |
145 int restore_resolution_call_count = 0; | 145 int restore_resolution_call_count = 0; |
146 ScreenResolution initial = MakeResolution(640, 480); | 146 ScreenResolution initial = MakeResolution(640, 480); |
147 scoped_ptr<FakeDesktopResizer> desktop_resizer( | 147 scoped_ptr<FakeDesktopResizer> desktop_resizer( |
148 new FakeDesktopResizer(initial, false, NULL, 0, | 148 new FakeDesktopResizer(initial, false, nullptr, 0, |
149 &restore_resolution_call_count)); | 149 &restore_resolution_call_count)); |
150 SetDesktopResizer(desktop_resizer.Pass()); | 150 SetDesktopResizer(desktop_resizer.Pass()); |
151 VerifySizes(NULL, NULL, 0); | 151 VerifySizes(nullptr, nullptr, 0); |
152 resizing_host_observer_.reset(); | 152 resizing_host_observer_.reset(); |
153 EXPECT_EQ(0, restore_resolution_call_count); | 153 EXPECT_EQ(0, restore_resolution_call_count); |
154 } | 154 } |
155 | 155 |
156 // Check that the host is not resized if GetSupportedSizes returns an empty | 156 // Check that the host is not resized if GetSupportedSizes returns an empty |
157 // list (even if GetCurrentSize is supported). | 157 // list (even if GetCurrentSize is supported). |
158 TEST_F(ResizingHostObserverTest, EmptyGetSupportedSizes) { | 158 TEST_F(ResizingHostObserverTest, EmptyGetSupportedSizes) { |
159 int restore_resolution_call_count = 0; | 159 int restore_resolution_call_count = 0; |
160 ScreenResolution initial = MakeResolution(640, 480); | 160 ScreenResolution initial = MakeResolution(640, 480); |
161 scoped_ptr<FakeDesktopResizer> desktop_resizer( | 161 scoped_ptr<FakeDesktopResizer> desktop_resizer( |
162 new FakeDesktopResizer(initial, false, NULL, 0, | 162 new FakeDesktopResizer(initial, false, nullptr, 0, |
163 &restore_resolution_call_count)); | 163 &restore_resolution_call_count)); |
164 SetDesktopResizer(desktop_resizer.Pass()); | 164 SetDesktopResizer(desktop_resizer.Pass()); |
165 | 165 |
166 ScreenResolution client_sizes[] = { MakeResolution(200, 100), | 166 ScreenResolution client_sizes[] = { MakeResolution(200, 100), |
167 MakeResolution(100, 200) }; | 167 MakeResolution(100, 200) }; |
168 ScreenResolution expected_sizes[] = { initial, initial }; | 168 ScreenResolution expected_sizes[] = { initial, initial }; |
169 VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes)); | 169 VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes)); |
170 | 170 |
171 resizing_host_observer_.reset(); | 171 resizing_host_observer_.reset(); |
172 EXPECT_EQ(0, restore_resolution_call_count); | 172 EXPECT_EQ(0, restore_resolution_call_count); |
173 } | 173 } |
174 | 174 |
175 // Check that if the implementation supports exact size matching, it is used. | 175 // Check that if the implementation supports exact size matching, it is used. |
176 TEST_F(ResizingHostObserverTest, SelectExactSize) { | 176 TEST_F(ResizingHostObserverTest, SelectExactSize) { |
177 int restore_resolution_call_count = 0; | 177 int restore_resolution_call_count = 0; |
178 scoped_ptr<FakeDesktopResizer> desktop_resizer( | 178 scoped_ptr<FakeDesktopResizer> desktop_resizer( |
179 new FakeDesktopResizer(MakeResolution(640, 480), true, NULL, 0, | 179 new FakeDesktopResizer(MakeResolution(640, 480), true, nullptr, 0, |
180 &restore_resolution_call_count)); | 180 &restore_resolution_call_count)); |
181 SetDesktopResizer(desktop_resizer.Pass()); | 181 SetDesktopResizer(desktop_resizer.Pass()); |
182 | 182 |
183 ScreenResolution client_sizes[] = { MakeResolution(200, 100), | 183 ScreenResolution client_sizes[] = { MakeResolution(200, 100), |
184 MakeResolution(100, 200), | 184 MakeResolution(100, 200), |
185 MakeResolution(640, 480), | 185 MakeResolution(640, 480), |
186 MakeResolution(480, 640), | 186 MakeResolution(480, 640), |
187 MakeResolution(1280, 1024) }; | 187 MakeResolution(1280, 1024) }; |
188 VerifySizes(client_sizes, client_sizes, arraysize(client_sizes)); | 188 VerifySizes(client_sizes, client_sizes, arraysize(client_sizes)); |
189 resizing_host_observer_.reset(); | 189 resizing_host_observer_.reset(); |
190 EXPECT_EQ(1, restore_resolution_call_count); | 190 EXPECT_EQ(1, restore_resolution_call_count); |
191 } | 191 } |
192 | 192 |
193 // Check that if the implementation supports a size that is no larger than | 193 // Check that if the implementation supports a size that is no larger than |
194 // the requested size, then the largest such size is used. | 194 // the requested size, then the largest such size is used. |
195 TEST_F(ResizingHostObserverTest, SelectBestSmallerSize) { | 195 TEST_F(ResizingHostObserverTest, SelectBestSmallerSize) { |
196 ScreenResolution supported_sizes[] = { MakeResolution(639, 479), | 196 ScreenResolution supported_sizes[] = { MakeResolution(639, 479), |
197 MakeResolution(640, 480) }; | 197 MakeResolution(640, 480) }; |
198 scoped_ptr<FakeDesktopResizer> desktop_resizer( | 198 scoped_ptr<FakeDesktopResizer> desktop_resizer( |
199 new FakeDesktopResizer(MakeResolution(640, 480), false, | 199 new FakeDesktopResizer(MakeResolution(640, 480), false, |
200 supported_sizes, arraysize(supported_sizes), | 200 supported_sizes, arraysize(supported_sizes), |
201 NULL)); | 201 nullptr)); |
202 SetDesktopResizer(desktop_resizer.Pass()); | 202 SetDesktopResizer(desktop_resizer.Pass()); |
203 | 203 |
204 ScreenResolution client_sizes[] = { MakeResolution(639, 479), | 204 ScreenResolution client_sizes[] = { MakeResolution(639, 479), |
205 MakeResolution(640, 480), | 205 MakeResolution(640, 480), |
206 MakeResolution(641, 481), | 206 MakeResolution(641, 481), |
207 MakeResolution(999, 999) }; | 207 MakeResolution(999, 999) }; |
208 ScreenResolution expected_sizes[] = { supported_sizes[0], supported_sizes[1], | 208 ScreenResolution expected_sizes[] = { supported_sizes[0], supported_sizes[1], |
209 supported_sizes[1], supported_sizes[1] }; | 209 supported_sizes[1], supported_sizes[1] }; |
210 VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes)); | 210 VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes)); |
211 } | 211 } |
212 | 212 |
213 // Check that if the implementation supports only sizes that are larger than | 213 // Check that if the implementation supports only sizes that are larger than |
214 // the requested size, then the one that requires the least down-scaling. | 214 // the requested size, then the one that requires the least down-scaling. |
215 TEST_F(ResizingHostObserverTest, SelectBestScaleFactor) { | 215 TEST_F(ResizingHostObserverTest, SelectBestScaleFactor) { |
216 ScreenResolution supported_sizes[] = { MakeResolution(100, 100), | 216 ScreenResolution supported_sizes[] = { MakeResolution(100, 100), |
217 MakeResolution(200, 100) }; | 217 MakeResolution(200, 100) }; |
218 scoped_ptr<FakeDesktopResizer> desktop_resizer( | 218 scoped_ptr<FakeDesktopResizer> desktop_resizer( |
219 new FakeDesktopResizer(MakeResolution(200, 100), false, | 219 new FakeDesktopResizer(MakeResolution(200, 100), false, |
220 supported_sizes, arraysize(supported_sizes), | 220 supported_sizes, arraysize(supported_sizes), |
221 NULL)); | 221 nullptr)); |
222 SetDesktopResizer(desktop_resizer.Pass()); | 222 SetDesktopResizer(desktop_resizer.Pass()); |
223 | 223 |
224 ScreenResolution client_sizes[] = { MakeResolution(1, 1), | 224 ScreenResolution client_sizes[] = { MakeResolution(1, 1), |
225 MakeResolution(99, 99), | 225 MakeResolution(99, 99), |
226 MakeResolution(199, 99) }; | 226 MakeResolution(199, 99) }; |
227 ScreenResolution expected_sizes[] = { supported_sizes[0], supported_sizes[0], | 227 ScreenResolution expected_sizes[] = { supported_sizes[0], supported_sizes[0], |
228 supported_sizes[1] }; | 228 supported_sizes[1] }; |
229 VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes)); | 229 VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes)); |
230 } | 230 } |
231 | 231 |
232 // Check that if the implementation supports two sizes that have the same | 232 // Check that if the implementation supports two sizes that have the same |
233 // resultant scale factor, then the widest one is selected. | 233 // resultant scale factor, then the widest one is selected. |
234 TEST_F(ResizingHostObserverTest, SelectWidest) { | 234 TEST_F(ResizingHostObserverTest, SelectWidest) { |
235 ScreenResolution supported_sizes[] = { MakeResolution(640, 480), | 235 ScreenResolution supported_sizes[] = { MakeResolution(640, 480), |
236 MakeResolution(480, 640) }; | 236 MakeResolution(480, 640) }; |
237 scoped_ptr<FakeDesktopResizer> desktop_resizer( | 237 scoped_ptr<FakeDesktopResizer> desktop_resizer( |
238 new FakeDesktopResizer(MakeResolution(480, 640), false, | 238 new FakeDesktopResizer(MakeResolution(480, 640), false, |
239 supported_sizes, arraysize(supported_sizes), | 239 supported_sizes, arraysize(supported_sizes), |
240 NULL)); | 240 nullptr)); |
241 SetDesktopResizer(desktop_resizer.Pass()); | 241 SetDesktopResizer(desktop_resizer.Pass()); |
242 | 242 |
243 ScreenResolution client_sizes[] = { MakeResolution(100, 100), | 243 ScreenResolution client_sizes[] = { MakeResolution(100, 100), |
244 MakeResolution(480, 480), | 244 MakeResolution(480, 480), |
245 MakeResolution(500, 500), | 245 MakeResolution(500, 500), |
246 MakeResolution(640, 640), | 246 MakeResolution(640, 640), |
247 MakeResolution(1000, 1000) }; | 247 MakeResolution(1000, 1000) }; |
248 ScreenResolution expected_sizes[] = { supported_sizes[0], supported_sizes[0], | 248 ScreenResolution expected_sizes[] = { supported_sizes[0], supported_sizes[0], |
249 supported_sizes[0], supported_sizes[0], | 249 supported_sizes[0], supported_sizes[0], |
250 supported_sizes[0] }; | 250 supported_sizes[0] }; |
251 VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes)); | 251 VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes)); |
252 } | 252 } |
253 | 253 |
254 // Check that if the best match for the client size doesn't change, then we | 254 // Check that if the best match for the client size doesn't change, then we |
255 // don't call SetSize. | 255 // don't call SetSize. |
256 TEST_F(ResizingHostObserverTest, NoSetSizeForSameSize) { | 256 TEST_F(ResizingHostObserverTest, NoSetSizeForSameSize) { |
257 ScreenResolution supported_sizes[] = { MakeResolution(640, 480), | 257 ScreenResolution supported_sizes[] = { MakeResolution(640, 480), |
258 MakeResolution(480, 640) }; | 258 MakeResolution(480, 640) }; |
259 SetDesktopResizer(make_scoped_ptr(new FakeDesktopResizer( | 259 SetDesktopResizer(make_scoped_ptr(new FakeDesktopResizer( |
260 MakeResolution(480, 640), false, | 260 MakeResolution(480, 640), false, |
261 supported_sizes, arraysize(supported_sizes), NULL))); | 261 supported_sizes, arraysize(supported_sizes), nullptr))); |
262 | 262 |
263 ScreenResolution client_sizes[] = { MakeResolution(640, 640), | 263 ScreenResolution client_sizes[] = { MakeResolution(640, 640), |
264 MakeResolution(1024, 768), | 264 MakeResolution(1024, 768), |
265 MakeResolution(640, 480) }; | 265 MakeResolution(640, 480) }; |
266 ScreenResolution expected_sizes[] = { MakeResolution(640, 480), | 266 ScreenResolution expected_sizes[] = { MakeResolution(640, 480), |
267 MakeResolution(640, 480), | 267 MakeResolution(640, 480), |
268 MakeResolution(640, 480) }; | 268 MakeResolution(640, 480) }; |
269 VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes)); | 269 VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes)); |
270 EXPECT_EQ(desktop_resizer_->set_resolution_call_count(), 1); | 270 EXPECT_EQ(desktop_resizer_->set_resolution_call_count(), 1); |
271 } | 271 } |
272 | 272 |
273 // Check that desktop resizes are rate-limited, and that if multiple resize | 273 // Check that desktop resizes are rate-limited, and that if multiple resize |
274 // requests are received in the time-out period, the most recent is respected. | 274 // requests are received in the time-out period, the most recent is respected. |
275 TEST_F(ResizingHostObserverTest, RateLimited) { | 275 TEST_F(ResizingHostObserverTest, RateLimited) { |
276 SetDesktopResizer(make_scoped_ptr( | 276 SetDesktopResizer(make_scoped_ptr(new FakeDesktopResizer( |
277 new FakeDesktopResizer(MakeResolution(640, 480), true, NULL, 0, NULL))); | 277 MakeResolution(640, 480), true, nullptr, 0, nullptr))); |
278 resizing_host_observer_->SetNowFunctionForTesting( | 278 resizing_host_observer_->SetNowFunctionForTesting( |
279 base::Bind(&ResizingHostObserverTest::GetTime, base::Unretained(this))); | 279 base::Bind(&ResizingHostObserverTest::GetTime, base::Unretained(this))); |
280 | 280 |
281 base::MessageLoop message_loop; | 281 base::MessageLoop message_loop; |
282 base::RunLoop run_loop; | 282 base::RunLoop run_loop; |
283 | 283 |
284 EXPECT_EQ(GetBestResolution(MakeResolution(100, 100)), | 284 EXPECT_EQ(GetBestResolution(MakeResolution(100, 100)), |
285 MakeResolution(100, 100)); | 285 MakeResolution(100, 100)); |
286 now_ += base::TimeDelta::FromMilliseconds(900); | 286 now_ += base::TimeDelta::FromMilliseconds(900); |
287 EXPECT_EQ(GetBestResolution(MakeResolution(200, 200)), | 287 EXPECT_EQ(GetBestResolution(MakeResolution(200, 200)), |
(...skipping 12 matching lines...) Expand all Loading... |
300 FROM_HERE, | 300 FROM_HERE, |
301 run_loop.QuitClosure(), | 301 run_loop.QuitClosure(), |
302 base::TimeDelta::FromMilliseconds(2)); | 302 base::TimeDelta::FromMilliseconds(2)); |
303 run_loop.Run(); | 303 run_loop.Run(); |
304 | 304 |
305 // If the QuitClosure fired before the final resize, it's a test failure. | 305 // If the QuitClosure fired before the final resize, it's a test failure. |
306 EXPECT_EQ(desktop_resizer_->GetCurrentResolution(), MakeResolution(300, 300)); | 306 EXPECT_EQ(desktop_resizer_->GetCurrentResolution(), MakeResolution(300, 300)); |
307 } | 307 } |
308 | 308 |
309 } // namespace remoting | 309 } // namespace remoting |
OLD | NEW |