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

Side by Side Diff: remoting/host/resizing_host_observer_unittest.cc

Issue 1864213002: Convert //remoting to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Mac IWYU Created 4 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 | « remoting/host/resizing_host_observer.cc ('k') | remoting/host/sas_injector.h » ('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 (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 "remoting/host/resizing_host_observer.h" 5 #include "remoting/host/resizing_host_observer.h"
6 6
7 #include <list> 7 #include <list>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ptr_util.h"
13 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
14 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
15 #include "base/run_loop.h" 16 #include "base/run_loop.h"
16 #include "remoting/host/desktop_resizer.h" 17 #include "remoting/host/desktop_resizer.h"
17 #include "remoting/host/screen_resolution.h" 18 #include "remoting/host/screen_resolution.h"
18 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
19 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" 20 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h"
20 21
21 namespace remoting { 22 namespace remoting {
22 23
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 now_(base::Time::Now()) { 100 now_(base::Time::Now()) {
100 } 101 }
101 102
102 // This needs to be public because the derived test-case class needs to 103 // This needs to be public because the derived test-case class needs to
103 // pass it to Bind, which fails if it's protected. 104 // pass it to Bind, which fails if it's protected.
104 base::Time GetTime() { 105 base::Time GetTime() {
105 return now_; 106 return now_;
106 } 107 }
107 108
108 protected: 109 protected:
109 void SetDesktopResizer(scoped_ptr<FakeDesktopResizer> desktop_resizer) { 110 void SetDesktopResizer(std::unique_ptr<FakeDesktopResizer> desktop_resizer) {
110 CHECK(!desktop_resizer_) << "Call SetDeskopResizer once per test"; 111 CHECK(!desktop_resizer_) << "Call SetDeskopResizer once per test";
111 desktop_resizer_ = desktop_resizer.get(); 112 desktop_resizer_ = desktop_resizer.get();
112 113
113 resizing_host_observer_.reset( 114 resizing_host_observer_.reset(
114 new ResizingHostObserver(std::move(desktop_resizer))); 115 new ResizingHostObserver(std::move(desktop_resizer)));
115 resizing_host_observer_->SetNowFunctionForTesting( 116 resizing_host_observer_->SetNowFunctionForTesting(
116 base::Bind(&ResizingHostObserverTest::GetTimeAndIncrement, 117 base::Bind(&ResizingHostObserverTest::GetTimeAndIncrement,
117 base::Unretained(this))); 118 base::Unretained(this)));
118 } 119 }
119 120
(...skipping 11 matching lines...) Expand all
131 << "Input resolution = " << client_sizes[i]; 132 << "Input resolution = " << client_sizes[i];
132 } 133 }
133 } 134 }
134 135
135 base::Time GetTimeAndIncrement() { 136 base::Time GetTimeAndIncrement() {
136 base::Time result = now_; 137 base::Time result = now_;
137 now_ += base::TimeDelta::FromSeconds(1); 138 now_ += base::TimeDelta::FromSeconds(1);
138 return result; 139 return result;
139 } 140 }
140 141
141 scoped_ptr<ResizingHostObserver> resizing_host_observer_; 142 std::unique_ptr<ResizingHostObserver> resizing_host_observer_;
142 FakeDesktopResizer* desktop_resizer_; 143 FakeDesktopResizer* desktop_resizer_;
143 base::Time now_; 144 base::Time now_;
144 }; 145 };
145 146
146 // Check that the resolution isn't restored if it wasn't changed by this class. 147 // Check that the resolution isn't restored if it wasn't changed by this class.
147 TEST_F(ResizingHostObserverTest, NoRestoreResolution) { 148 TEST_F(ResizingHostObserverTest, NoRestoreResolution) {
148 int restore_resolution_call_count = 0; 149 int restore_resolution_call_count = 0;
149 ScreenResolution initial = MakeResolution(640, 480); 150 ScreenResolution initial = MakeResolution(640, 480);
150 scoped_ptr<FakeDesktopResizer> desktop_resizer( 151 std::unique_ptr<FakeDesktopResizer> desktop_resizer(new FakeDesktopResizer(
151 new FakeDesktopResizer(initial, false, nullptr, 0, 152 initial, false, nullptr, 0, &restore_resolution_call_count));
152 &restore_resolution_call_count));
153 SetDesktopResizer(std::move(desktop_resizer)); 153 SetDesktopResizer(std::move(desktop_resizer));
154 VerifySizes(nullptr, nullptr, 0); 154 VerifySizes(nullptr, nullptr, 0);
155 resizing_host_observer_.reset(); 155 resizing_host_observer_.reset();
156 EXPECT_EQ(0, restore_resolution_call_count); 156 EXPECT_EQ(0, restore_resolution_call_count);
157 } 157 }
158 158
159 // Check that the host is not resized if GetSupportedSizes returns an empty 159 // Check that the host is not resized if GetSupportedSizes returns an empty
160 // list (even if GetCurrentSize is supported). 160 // list (even if GetCurrentSize is supported).
161 TEST_F(ResizingHostObserverTest, EmptyGetSupportedSizes) { 161 TEST_F(ResizingHostObserverTest, EmptyGetSupportedSizes) {
162 int restore_resolution_call_count = 0; 162 int restore_resolution_call_count = 0;
163 ScreenResolution initial = MakeResolution(640, 480); 163 ScreenResolution initial = MakeResolution(640, 480);
164 scoped_ptr<FakeDesktopResizer> desktop_resizer( 164 std::unique_ptr<FakeDesktopResizer> desktop_resizer(new FakeDesktopResizer(
165 new FakeDesktopResizer(initial, false, nullptr, 0, 165 initial, false, nullptr, 0, &restore_resolution_call_count));
166 &restore_resolution_call_count));
167 SetDesktopResizer(std::move(desktop_resizer)); 166 SetDesktopResizer(std::move(desktop_resizer));
168 167
169 ScreenResolution client_sizes[] = { MakeResolution(200, 100), 168 ScreenResolution client_sizes[] = { MakeResolution(200, 100),
170 MakeResolution(100, 200) }; 169 MakeResolution(100, 200) };
171 ScreenResolution expected_sizes[] = { initial, initial }; 170 ScreenResolution expected_sizes[] = { initial, initial };
172 VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes)); 171 VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes));
173 172
174 resizing_host_observer_.reset(); 173 resizing_host_observer_.reset();
175 EXPECT_EQ(0, restore_resolution_call_count); 174 EXPECT_EQ(0, restore_resolution_call_count);
176 } 175 }
177 176
178 // Check that if the implementation supports exact size matching, it is used. 177 // Check that if the implementation supports exact size matching, it is used.
179 TEST_F(ResizingHostObserverTest, SelectExactSize) { 178 TEST_F(ResizingHostObserverTest, SelectExactSize) {
180 int restore_resolution_call_count = 0; 179 int restore_resolution_call_count = 0;
181 scoped_ptr<FakeDesktopResizer> desktop_resizer( 180 std::unique_ptr<FakeDesktopResizer> desktop_resizer(
182 new FakeDesktopResizer(MakeResolution(640, 480), true, nullptr, 0, 181 new FakeDesktopResizer(MakeResolution(640, 480), true, nullptr, 0,
183 &restore_resolution_call_count)); 182 &restore_resolution_call_count));
184 SetDesktopResizer(std::move(desktop_resizer)); 183 SetDesktopResizer(std::move(desktop_resizer));
185 184
186 ScreenResolution client_sizes[] = { MakeResolution(200, 100), 185 ScreenResolution client_sizes[] = { MakeResolution(200, 100),
187 MakeResolution(100, 200), 186 MakeResolution(100, 200),
188 MakeResolution(640, 480), 187 MakeResolution(640, 480),
189 MakeResolution(480, 640), 188 MakeResolution(480, 640),
190 MakeResolution(1280, 1024) }; 189 MakeResolution(1280, 1024) };
191 VerifySizes(client_sizes, client_sizes, arraysize(client_sizes)); 190 VerifySizes(client_sizes, client_sizes, arraysize(client_sizes));
192 resizing_host_observer_.reset(); 191 resizing_host_observer_.reset();
193 EXPECT_EQ(1, restore_resolution_call_count); 192 EXPECT_EQ(1, restore_resolution_call_count);
194 } 193 }
195 194
196 // Check that if the implementation supports a size that is no larger than 195 // Check that if the implementation supports a size that is no larger than
197 // the requested size, then the largest such size is used. 196 // the requested size, then the largest such size is used.
198 TEST_F(ResizingHostObserverTest, SelectBestSmallerSize) { 197 TEST_F(ResizingHostObserverTest, SelectBestSmallerSize) {
199 ScreenResolution supported_sizes[] = { MakeResolution(639, 479), 198 ScreenResolution supported_sizes[] = { MakeResolution(639, 479),
200 MakeResolution(640, 480) }; 199 MakeResolution(640, 480) };
201 scoped_ptr<FakeDesktopResizer> desktop_resizer( 200 std::unique_ptr<FakeDesktopResizer> desktop_resizer(
202 new FakeDesktopResizer(MakeResolution(640, 480), false, 201 new FakeDesktopResizer(MakeResolution(640, 480), false, supported_sizes,
203 supported_sizes, arraysize(supported_sizes), 202 arraysize(supported_sizes), nullptr));
204 nullptr));
205 SetDesktopResizer(std::move(desktop_resizer)); 203 SetDesktopResizer(std::move(desktop_resizer));
206 204
207 ScreenResolution client_sizes[] = { MakeResolution(639, 479), 205 ScreenResolution client_sizes[] = { MakeResolution(639, 479),
208 MakeResolution(640, 480), 206 MakeResolution(640, 480),
209 MakeResolution(641, 481), 207 MakeResolution(641, 481),
210 MakeResolution(999, 999) }; 208 MakeResolution(999, 999) };
211 ScreenResolution expected_sizes[] = { supported_sizes[0], supported_sizes[1], 209 ScreenResolution expected_sizes[] = { supported_sizes[0], supported_sizes[1],
212 supported_sizes[1], supported_sizes[1] }; 210 supported_sizes[1], supported_sizes[1] };
213 VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes)); 211 VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes));
214 } 212 }
215 213
216 // Check that if the implementation supports only sizes that are larger than 214 // Check that if the implementation supports only sizes that are larger than
217 // the requested size, then the one that requires the least down-scaling. 215 // the requested size, then the one that requires the least down-scaling.
218 TEST_F(ResizingHostObserverTest, SelectBestScaleFactor) { 216 TEST_F(ResizingHostObserverTest, SelectBestScaleFactor) {
219 ScreenResolution supported_sizes[] = { MakeResolution(100, 100), 217 ScreenResolution supported_sizes[] = { MakeResolution(100, 100),
220 MakeResolution(200, 100) }; 218 MakeResolution(200, 100) };
221 scoped_ptr<FakeDesktopResizer> desktop_resizer( 219 std::unique_ptr<FakeDesktopResizer> desktop_resizer(
222 new FakeDesktopResizer(MakeResolution(200, 100), false, 220 new FakeDesktopResizer(MakeResolution(200, 100), false, supported_sizes,
223 supported_sizes, arraysize(supported_sizes), 221 arraysize(supported_sizes), nullptr));
224 nullptr));
225 SetDesktopResizer(std::move(desktop_resizer)); 222 SetDesktopResizer(std::move(desktop_resizer));
226 223
227 ScreenResolution client_sizes[] = { MakeResolution(1, 1), 224 ScreenResolution client_sizes[] = { MakeResolution(1, 1),
228 MakeResolution(99, 99), 225 MakeResolution(99, 99),
229 MakeResolution(199, 99) }; 226 MakeResolution(199, 99) };
230 ScreenResolution expected_sizes[] = { supported_sizes[0], supported_sizes[0], 227 ScreenResolution expected_sizes[] = { supported_sizes[0], supported_sizes[0],
231 supported_sizes[1] }; 228 supported_sizes[1] };
232 VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes)); 229 VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes));
233 } 230 }
234 231
235 // 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
236 // resultant scale factor, then the widest one is selected. 233 // resultant scale factor, then the widest one is selected.
237 TEST_F(ResizingHostObserverTest, SelectWidest) { 234 TEST_F(ResizingHostObserverTest, SelectWidest) {
238 ScreenResolution supported_sizes[] = { MakeResolution(640, 480), 235 ScreenResolution supported_sizes[] = { MakeResolution(640, 480),
239 MakeResolution(480, 640) }; 236 MakeResolution(480, 640) };
240 scoped_ptr<FakeDesktopResizer> desktop_resizer( 237 std::unique_ptr<FakeDesktopResizer> desktop_resizer(
241 new FakeDesktopResizer(MakeResolution(480, 640), false, 238 new FakeDesktopResizer(MakeResolution(480, 640), false, supported_sizes,
242 supported_sizes, arraysize(supported_sizes), 239 arraysize(supported_sizes), nullptr));
243 nullptr));
244 SetDesktopResizer(std::move(desktop_resizer)); 240 SetDesktopResizer(std::move(desktop_resizer));
245 241
246 ScreenResolution client_sizes[] = { MakeResolution(100, 100), 242 ScreenResolution client_sizes[] = { MakeResolution(100, 100),
247 MakeResolution(480, 480), 243 MakeResolution(480, 480),
248 MakeResolution(500, 500), 244 MakeResolution(500, 500),
249 MakeResolution(640, 640), 245 MakeResolution(640, 640),
250 MakeResolution(1000, 1000) }; 246 MakeResolution(1000, 1000) };
251 ScreenResolution expected_sizes[] = { supported_sizes[0], supported_sizes[0], 247 ScreenResolution expected_sizes[] = { supported_sizes[0], supported_sizes[0],
252 supported_sizes[0], supported_sizes[0], 248 supported_sizes[0], supported_sizes[0],
253 supported_sizes[0] }; 249 supported_sizes[0] };
254 VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes)); 250 VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes));
255 } 251 }
256 252
257 // Check that if the best match for the client size doesn't change, then we 253 // Check that if the best match for the client size doesn't change, then we
258 // don't call SetSize. 254 // don't call SetSize.
259 TEST_F(ResizingHostObserverTest, NoSetSizeForSameSize) { 255 TEST_F(ResizingHostObserverTest, NoSetSizeForSameSize) {
260 ScreenResolution supported_sizes[] = { MakeResolution(640, 480), 256 ScreenResolution supported_sizes[] = { MakeResolution(640, 480),
261 MakeResolution(480, 640) }; 257 MakeResolution(480, 640) };
262 SetDesktopResizer(make_scoped_ptr(new FakeDesktopResizer( 258 SetDesktopResizer(base::WrapUnique(
263 MakeResolution(480, 640), false, 259 new FakeDesktopResizer(MakeResolution(480, 640), false, supported_sizes,
264 supported_sizes, arraysize(supported_sizes), nullptr))); 260 arraysize(supported_sizes), nullptr)));
265 261
266 ScreenResolution client_sizes[] = { MakeResolution(640, 640), 262 ScreenResolution client_sizes[] = { MakeResolution(640, 640),
267 MakeResolution(1024, 768), 263 MakeResolution(1024, 768),
268 MakeResolution(640, 480) }; 264 MakeResolution(640, 480) };
269 ScreenResolution expected_sizes[] = { MakeResolution(640, 480), 265 ScreenResolution expected_sizes[] = { MakeResolution(640, 480),
270 MakeResolution(640, 480), 266 MakeResolution(640, 480),
271 MakeResolution(640, 480) }; 267 MakeResolution(640, 480) };
272 VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes)); 268 VerifySizes(client_sizes, expected_sizes, arraysize(client_sizes));
273 EXPECT_EQ(desktop_resizer_->set_resolution_call_count(), 1); 269 EXPECT_EQ(desktop_resizer_->set_resolution_call_count(), 1);
274 } 270 }
275 271
276 // Check that desktop resizes are rate-limited, and that if multiple resize 272 // Check that desktop resizes are rate-limited, and that if multiple resize
277 // requests are received in the time-out period, the most recent is respected. 273 // requests are received in the time-out period, the most recent is respected.
278 TEST_F(ResizingHostObserverTest, RateLimited) { 274 TEST_F(ResizingHostObserverTest, RateLimited) {
279 SetDesktopResizer(make_scoped_ptr(new FakeDesktopResizer( 275 SetDesktopResizer(base::WrapUnique(new FakeDesktopResizer(
280 MakeResolution(640, 480), true, nullptr, 0, nullptr))); 276 MakeResolution(640, 480), true, nullptr, 0, nullptr)));
281 resizing_host_observer_->SetNowFunctionForTesting( 277 resizing_host_observer_->SetNowFunctionForTesting(
282 base::Bind(&ResizingHostObserverTest::GetTime, base::Unretained(this))); 278 base::Bind(&ResizingHostObserverTest::GetTime, base::Unretained(this)));
283 279
284 base::MessageLoop message_loop; 280 base::MessageLoop message_loop;
285 base::RunLoop run_loop; 281 base::RunLoop run_loop;
286 282
287 EXPECT_EQ(GetBestResolution(MakeResolution(100, 100)), 283 EXPECT_EQ(GetBestResolution(MakeResolution(100, 100)),
288 MakeResolution(100, 100)); 284 MakeResolution(100, 100));
289 now_ += base::TimeDelta::FromMilliseconds(900); 285 now_ += base::TimeDelta::FromMilliseconds(900);
(...skipping 13 matching lines...) Expand all
303 FROM_HERE, 299 FROM_HERE,
304 run_loop.QuitClosure(), 300 run_loop.QuitClosure(),
305 base::TimeDelta::FromMilliseconds(2)); 301 base::TimeDelta::FromMilliseconds(2));
306 run_loop.Run(); 302 run_loop.Run();
307 303
308 // If the QuitClosure fired before the final resize, it's a test failure. 304 // If the QuitClosure fired before the final resize, it's a test failure.
309 EXPECT_EQ(desktop_resizer_->GetCurrentResolution(), MakeResolution(300, 300)); 305 EXPECT_EQ(desktop_resizer_->GetCurrentResolution(), MakeResolution(300, 300));
310 } 306 }
311 307
312 } // namespace remoting 308 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/resizing_host_observer.cc ('k') | remoting/host/sas_injector.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698