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

Side by Side Diff: chrome/browser/media/native_desktop_media_list_unittest.cc

Issue 89683003: Rename DesktopMediaPickerModel[Impl]->[Native]DesktopMediaList (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "chrome/browser/media/desktop_media_picker_model.h" 5 #include "chrome/browser/media/native_desktop_media_list.h"
6 6
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "base/synchronization/lock.h" 9 #include "base/synchronization/lock.h"
10 #include "chrome/browser/media/desktop_media_list_observer.h"
10 #include "content/public/test/test_browser_thread.h" 11 #include "content/public/test/test_browser_thread.h"
11 #include "testing/gmock/include/gmock/gmock.h" 12 #include "testing/gmock/include/gmock/gmock.h"
12 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
13 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" 14 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h"
14 #include "third_party/webrtc/modules/desktop_capture/screen_capturer.h" 15 #include "third_party/webrtc/modules/desktop_capture/screen_capturer.h"
15 #include "third_party/webrtc/modules/desktop_capture/window_capturer.h" 16 #include "third_party/webrtc/modules/desktop_capture/window_capturer.h"
16 17
17 using testing::_; 18 using testing::_;
18 using testing::DoAll; 19 using testing::DoAll;
19 20
20 namespace { 21 namespace {
21 22
22 class MockObserver : public DesktopMediaPickerModel::Observer { 23 class MockObserver : public DesktopMediaListObserver {
23 public: 24 public:
24 MOCK_METHOD1(OnSourceAdded, void(int index)); 25 MOCK_METHOD1(OnSourceAdded, void(int index));
25 MOCK_METHOD1(OnSourceRemoved, void(int index)); 26 MOCK_METHOD1(OnSourceRemoved, void(int index));
26 MOCK_METHOD1(OnSourceNameChanged, void(int index)); 27 MOCK_METHOD1(OnSourceNameChanged, void(int index));
27 MOCK_METHOD1(OnSourceThumbnailChanged, void(int index)); 28 MOCK_METHOD1(OnSourceThumbnailChanged, void(int index));
28 }; 29 };
29 30
30 class FakeScreenCapturer : public webrtc::ScreenCapturer { 31 class FakeScreenCapturer : public webrtc::ScreenCapturer {
31 public: 32 public:
32 FakeScreenCapturer() {} 33 FakeScreenCapturer() {}
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 113
113 WindowId selected_window_id_; 114 WindowId selected_window_id_;
114 115
115 // Frames to be captured per window. 116 // Frames to be captured per window.
116 std::map<WindowId, int8_t> frame_values_; 117 std::map<WindowId, int8_t> frame_values_;
117 base::Lock frame_values_lock_; 118 base::Lock frame_values_lock_;
118 119
119 DISALLOW_COPY_AND_ASSIGN(FakeWindowCapturer); 120 DISALLOW_COPY_AND_ASSIGN(FakeWindowCapturer);
120 }; 121 };
121 122
122 class DesktopMediaPickerModelTest : public testing::Test { 123 class DesktopMediaListTest : public testing::Test {
123 public: 124 public:
124 DesktopMediaPickerModelTest() 125 DesktopMediaListTest()
125 : window_capturer_(NULL), 126 : window_capturer_(NULL),
126 ui_thread_(content::BrowserThread::UI, 127 ui_thread_(content::BrowserThread::UI,
127 &message_loop_) { 128 &message_loop_) {
128 } 129 }
129 130
130 void CreateWithDefaultCapturers() { 131 void CreateWithDefaultCapturers() {
131 window_capturer_ = new FakeWindowCapturer(); 132 window_capturer_ = new FakeWindowCapturer();
132 model_.reset(new DesktopMediaPickerModelImpl( 133 model_.reset(new NativeDesktopMediaList(
133 scoped_ptr<webrtc::ScreenCapturer>(new FakeScreenCapturer()), 134 scoped_ptr<webrtc::ScreenCapturer>(new FakeScreenCapturer()),
134 scoped_ptr<webrtc::WindowCapturer>(window_capturer_))); 135 scoped_ptr<webrtc::WindowCapturer>(window_capturer_)));
135 136
136 // Set update period to reduce the time it takes to run tests. 137 // Set update period to reduce the time it takes to run tests.
137 model_->SetUpdatePeriod(base::TimeDelta::FromMilliseconds(0)); 138 model_->SetUpdatePeriod(base::TimeDelta::FromMilliseconds(0));
138 } 139 }
139 140
140 protected: 141 protected:
141 // Must be listed before |model_|, so it's destroyed last. 142 // Must be listed before |model_|, so it's destroyed last.
142 MockObserver observer_; 143 MockObserver observer_;
143 144
144 // Owned by |model_|; 145 // Owned by |model_|;
145 FakeWindowCapturer* window_capturer_; 146 FakeWindowCapturer* window_capturer_;
146 147
147 scoped_ptr<DesktopMediaPickerModelImpl> model_; 148 scoped_ptr<NativeDesktopMediaList> model_;
148 149
149 base::MessageLoop message_loop_; 150 base::MessageLoop message_loop_;
150 content::TestBrowserThread ui_thread_; 151 content::TestBrowserThread ui_thread_;
151 152
152 DISALLOW_COPY_AND_ASSIGN(DesktopMediaPickerModelTest); 153 DISALLOW_COPY_AND_ASSIGN(DesktopMediaListTest);
153 }; 154 };
154 155
155 ACTION_P2(CheckListSize, model, expected_list_size) { 156 ACTION_P2(CheckListSize, model, expected_list_size) {
156 EXPECT_EQ(expected_list_size, model->source_count()); 157 EXPECT_EQ(expected_list_size, model->GetSourceCount());
157 } 158 }
158 159
159 ACTION_P(QuitMessageLoop, message_loop) { 160 ACTION_P(QuitMessageLoop, message_loop) {
160 message_loop->PostTask(FROM_HERE, base::MessageLoop::QuitClosure()); 161 message_loop->PostTask(FROM_HERE, base::MessageLoop::QuitClosure());
161 } 162 }
162 163
163 TEST_F(DesktopMediaPickerModelTest, InitialSourceList) { 164 TEST_F(DesktopMediaListTest, InitialSourceList) {
164 CreateWithDefaultCapturers(); 165 CreateWithDefaultCapturers();
165 166
166 webrtc::WindowCapturer::WindowList list; 167 webrtc::WindowCapturer::WindowList list;
167 webrtc::WindowCapturer::Window window; 168 webrtc::WindowCapturer::Window window;
168 window.id = 0; 169 window.id = 0;
169 window.title = "Test window"; 170 window.title = "Test window";
170 list.push_back(window); 171 list.push_back(window);
171 window_capturer_->SetWindowList(list); 172 window_capturer_->SetWindowList(list);
172 173
173 { 174 {
174 testing::InSequence dummy; 175 testing::InSequence dummy;
175 EXPECT_CALL(observer_, OnSourceAdded(0)) 176 EXPECT_CALL(observer_, OnSourceAdded(0))
176 .WillOnce(CheckListSize(model_.get(), 1)); 177 .WillOnce(CheckListSize(model_.get(), 1));
177 EXPECT_CALL(observer_, OnSourceAdded(1)) 178 EXPECT_CALL(observer_, OnSourceAdded(1))
178 .WillOnce(CheckListSize(model_.get(), 2)); 179 .WillOnce(CheckListSize(model_.get(), 2));
179 EXPECT_CALL(observer_, OnSourceThumbnailChanged(0)); 180 EXPECT_CALL(observer_, OnSourceThumbnailChanged(0));
180 EXPECT_CALL(observer_, OnSourceThumbnailChanged(1)) 181 EXPECT_CALL(observer_, OnSourceThumbnailChanged(1))
181 .WillOnce(QuitMessageLoop(&message_loop_)); 182 .WillOnce(QuitMessageLoop(&message_loop_));
182 } 183 }
183 model_->StartUpdating(&observer_); 184 model_->StartUpdating(&observer_);
184 185
185 message_loop_.Run(); 186 message_loop_.Run();
186 187
187 EXPECT_EQ(model_->source(0).id.type, content::DesktopMediaID::TYPE_SCREEN); 188 EXPECT_EQ(model_->GetSource(0).id.type, content::DesktopMediaID::TYPE_SCREEN);
188 EXPECT_EQ(model_->source(0).id.id, 0); 189 EXPECT_EQ(model_->GetSource(0).id.id, 0);
189 EXPECT_EQ(model_->source(1).id.type, content::DesktopMediaID::TYPE_WINDOW); 190 EXPECT_EQ(model_->GetSource(1).id.type, content::DesktopMediaID::TYPE_WINDOW);
190 EXPECT_EQ(model_->source(1).id.id, 0); 191 EXPECT_EQ(model_->GetSource(1).id.id, 0);
191 EXPECT_EQ(model_->source(1).name, UTF8ToUTF16(window.title)); 192 EXPECT_EQ(model_->GetSource(1).name, UTF8ToUTF16(window.title));
192 } 193 }
193 194
194 // Verifies that the window specified with SetViewDialogWindowId() is filtered 195 // Verifies that the window specified with SetViewDialogWindowId() is filtered
195 // from the results. 196 // from the results.
196 TEST_F(DesktopMediaPickerModelTest, Filtering) { 197 TEST_F(DesktopMediaListTest, Filtering) {
197 CreateWithDefaultCapturers(); 198 CreateWithDefaultCapturers();
198 199
199 webrtc::WindowCapturer::WindowList list; 200 webrtc::WindowCapturer::WindowList list;
200 webrtc::WindowCapturer::Window window; 201 webrtc::WindowCapturer::Window window;
201 202
202 window.id = 0; 203 window.id = 0;
203 window.title = "Test window"; 204 window.title = "Test window";
204 list.push_back(window); 205 list.push_back(window);
205 206
206 window.id = 1; 207 window.id = 1;
(...skipping 10 matching lines...) Expand all
217 EXPECT_CALL(observer_, OnSourceThumbnailChanged(0)); 218 EXPECT_CALL(observer_, OnSourceThumbnailChanged(0));
218 EXPECT_CALL(observer_, OnSourceThumbnailChanged(1)) 219 EXPECT_CALL(observer_, OnSourceThumbnailChanged(1))
219 .WillOnce(QuitMessageLoop(&message_loop_)); 220 .WillOnce(QuitMessageLoop(&message_loop_));
220 } 221 }
221 222
222 model_->SetViewDialogWindowId(0); 223 model_->SetViewDialogWindowId(0);
223 224
224 model_->StartUpdating(&observer_); 225 model_->StartUpdating(&observer_);
225 message_loop_.Run(); 226 message_loop_.Run();
226 227
227 EXPECT_EQ(model_->source(0).id.type, content::DesktopMediaID::TYPE_SCREEN); 228 EXPECT_EQ(model_->GetSource(0).id.type, content::DesktopMediaID::TYPE_SCREEN);
228 EXPECT_EQ(model_->source(0).id.id, 0); 229 EXPECT_EQ(model_->GetSource(0).id.id, 0);
229 EXPECT_EQ(model_->source(1).id.type, content::DesktopMediaID::TYPE_WINDOW); 230 EXPECT_EQ(model_->GetSource(1).id.type, content::DesktopMediaID::TYPE_WINDOW);
230 EXPECT_EQ(model_->source(1).id.id, 1); 231 EXPECT_EQ(model_->GetSource(1).id.id, 1);
231 EXPECT_EQ(model_->source(1).name, UTF8ToUTF16(window.title)); 232 EXPECT_EQ(model_->GetSource(1).name, UTF8ToUTF16(window.title));
232 } 233 }
233 234
234 TEST_F(DesktopMediaPickerModelTest, WindowsOnly) { 235 TEST_F(DesktopMediaListTest, WindowsOnly) {
235 window_capturer_ = new FakeWindowCapturer(); 236 window_capturer_ = new FakeWindowCapturer();
236 model_.reset(new DesktopMediaPickerModelImpl( 237 model_.reset(new NativeDesktopMediaList(
237 scoped_ptr<webrtc::ScreenCapturer>(), 238 scoped_ptr<webrtc::ScreenCapturer>(),
238 scoped_ptr<webrtc::WindowCapturer>(window_capturer_))); 239 scoped_ptr<webrtc::WindowCapturer>(window_capturer_)));
239 240
240 webrtc::WindowCapturer::WindowList list; 241 webrtc::WindowCapturer::WindowList list;
241 webrtc::WindowCapturer::Window window; 242 webrtc::WindowCapturer::Window window;
242 window.id = 0; 243 window.id = 0;
243 window.title = "Test window"; 244 window.title = "Test window";
244 list.push_back(window); 245 list.push_back(window);
245 window_capturer_->SetWindowList(list); 246 window_capturer_->SetWindowList(list);
246 247
247 { 248 {
248 testing::InSequence dummy; 249 testing::InSequence dummy;
249 EXPECT_CALL(observer_, OnSourceAdded(0)) 250 EXPECT_CALL(observer_, OnSourceAdded(0))
250 .WillOnce(CheckListSize(model_.get(), 1)); 251 .WillOnce(CheckListSize(model_.get(), 1));
251 EXPECT_CALL(observer_, OnSourceThumbnailChanged(0)) 252 EXPECT_CALL(observer_, OnSourceThumbnailChanged(0))
252 .WillOnce(QuitMessageLoop(&message_loop_)); 253 .WillOnce(QuitMessageLoop(&message_loop_));
253 } 254 }
254 model_->StartUpdating(&observer_); 255 model_->StartUpdating(&observer_);
255 256
256 message_loop_.Run(); 257 message_loop_.Run();
257 258
258 EXPECT_EQ(model_->source(0).id.type, content::DesktopMediaID::TYPE_WINDOW); 259 EXPECT_EQ(model_->GetSource(0).id.type, content::DesktopMediaID::TYPE_WINDOW);
259 } 260 }
260 261
261 TEST_F(DesktopMediaPickerModelTest, ScreenOnly) { 262 TEST_F(DesktopMediaListTest, ScreenOnly) {
262 model_.reset(new DesktopMediaPickerModelImpl( 263 model_.reset(new NativeDesktopMediaList(
263 scoped_ptr<webrtc::ScreenCapturer>(new FakeScreenCapturer), 264 scoped_ptr<webrtc::ScreenCapturer>(new FakeScreenCapturer),
264 scoped_ptr<webrtc::WindowCapturer>())); 265 scoped_ptr<webrtc::WindowCapturer>()));
265 266
266 { 267 {
267 testing::InSequence dummy; 268 testing::InSequence dummy;
268 EXPECT_CALL(observer_, OnSourceAdded(0)) 269 EXPECT_CALL(observer_, OnSourceAdded(0))
269 .WillOnce(CheckListSize(model_.get(), 1)); 270 .WillOnce(CheckListSize(model_.get(), 1));
270 EXPECT_CALL(observer_, OnSourceThumbnailChanged(0)) 271 EXPECT_CALL(observer_, OnSourceThumbnailChanged(0))
271 .WillOnce(QuitMessageLoop(&message_loop_)); 272 .WillOnce(QuitMessageLoop(&message_loop_));
272 } 273 }
273 model_->StartUpdating(&observer_); 274 model_->StartUpdating(&observer_);
274 275
275 message_loop_.Run(); 276 message_loop_.Run();
276 277
277 EXPECT_EQ(model_->source(0).id.type, content::DesktopMediaID::TYPE_SCREEN); 278 EXPECT_EQ(model_->GetSource(0).id.type, content::DesktopMediaID::TYPE_SCREEN);
278 } 279 }
279 280
280 TEST_F(DesktopMediaPickerModelTest, AddWindow) { 281 TEST_F(DesktopMediaListTest, AddWindow) {
281 CreateWithDefaultCapturers(); 282 CreateWithDefaultCapturers();
282 283
283 webrtc::WindowCapturer::WindowList list; 284 webrtc::WindowCapturer::WindowList list;
284 webrtc::WindowCapturer::Window window; 285 webrtc::WindowCapturer::Window window;
285 window.id = 1; 286 window.id = 1;
286 window.title = "Test window 1"; 287 window.title = "Test window 1";
287 list.push_back(window); 288 list.push_back(window);
288 window_capturer_->SetWindowList(list); 289 window_capturer_->SetWindowList(list);
289 290
290 { 291 {
(...skipping 16 matching lines...) Expand all
307 .WillOnce(DoAll(CheckListSize(model_.get(), 3), 308 .WillOnce(DoAll(CheckListSize(model_.get(), 3),
308 QuitMessageLoop(&message_loop_))); 309 QuitMessageLoop(&message_loop_)));
309 310
310 window.id = 0; 311 window.id = 0;
311 window.title = "Test window 0"; 312 window.title = "Test window 0";
312 list.push_back(window); 313 list.push_back(window);
313 window_capturer_->SetWindowList(list); 314 window_capturer_->SetWindowList(list);
314 315
315 message_loop_.Run(); 316 message_loop_.Run();
316 317
317 EXPECT_EQ(model_->source(1).id.type, content::DesktopMediaID::TYPE_WINDOW); 318 EXPECT_EQ(model_->GetSource(1).id.type, content::DesktopMediaID::TYPE_WINDOW);
318 EXPECT_EQ(model_->source(1).id.id, 0); 319 EXPECT_EQ(model_->GetSource(1).id.id, 0);
319 } 320 }
320 321
321 TEST_F(DesktopMediaPickerModelTest, RemoveWindow) { 322 TEST_F(DesktopMediaListTest, RemoveWindow) {
322 CreateWithDefaultCapturers(); 323 CreateWithDefaultCapturers();
323 324
324 webrtc::WindowCapturer::WindowList list; 325 webrtc::WindowCapturer::WindowList list;
325 webrtc::WindowCapturer::Window window; 326 webrtc::WindowCapturer::Window window;
326 window.id = 0; 327 window.id = 0;
327 window.title = "Test window 0"; 328 window.title = "Test window 0";
328 list.push_back(window); 329 list.push_back(window);
329 window.id = 1; 330 window.id = 1;
330 window.title = "Test window 1"; 331 window.title = "Test window 1";
331 list.push_back(window); 332 list.push_back(window);
(...skipping 21 matching lines...) Expand all
353 EXPECT_CALL(observer_, OnSourceRemoved(1)) 354 EXPECT_CALL(observer_, OnSourceRemoved(1))
354 .WillOnce(DoAll(CheckListSize(model_.get(), 2), 355 .WillOnce(DoAll(CheckListSize(model_.get(), 2),
355 QuitMessageLoop(&message_loop_))); 356 QuitMessageLoop(&message_loop_)));
356 357
357 list.erase(list.begin()); 358 list.erase(list.begin());
358 window_capturer_->SetWindowList(list); 359 window_capturer_->SetWindowList(list);
359 360
360 message_loop_.Run(); 361 message_loop_.Run();
361 } 362 }
362 363
363 TEST_F(DesktopMediaPickerModelTest, UpdateTitle) { 364 TEST_F(DesktopMediaListTest, UpdateTitle) {
364 CreateWithDefaultCapturers(); 365 CreateWithDefaultCapturers();
365 366
366 webrtc::WindowCapturer::WindowList list; 367 webrtc::WindowCapturer::WindowList list;
367 webrtc::WindowCapturer::Window window; 368 webrtc::WindowCapturer::Window window;
368 window.id = 0; 369 window.id = 0;
369 window.title = "Test window"; 370 window.title = "Test window";
370 list.push_back(window); 371 list.push_back(window);
371 window_capturer_->SetWindowList(list); 372 window_capturer_->SetWindowList(list);
372 373
373 { 374 {
(...skipping 15 matching lines...) Expand all
389 EXPECT_CALL(observer_, OnSourceNameChanged(1)) 390 EXPECT_CALL(observer_, OnSourceNameChanged(1))
390 .WillOnce(QuitMessageLoop(&message_loop_)); 391 .WillOnce(QuitMessageLoop(&message_loop_));
391 392
392 const std::string kTestTitle = "New Title"; 393 const std::string kTestTitle = "New Title";
393 394
394 list[0].title = kTestTitle; 395 list[0].title = kTestTitle;
395 window_capturer_->SetWindowList(list); 396 window_capturer_->SetWindowList(list);
396 397
397 message_loop_.Run(); 398 message_loop_.Run();
398 399
399 EXPECT_EQ(model_->source(1).name, base::UTF8ToUTF16(kTestTitle)); 400 EXPECT_EQ(model_->GetSource(1).name, base::UTF8ToUTF16(kTestTitle));
400 } 401 }
401 402
402 TEST_F(DesktopMediaPickerModelTest, UpdateThumbnail) { 403 TEST_F(DesktopMediaListTest, UpdateThumbnail) {
403 CreateWithDefaultCapturers(); 404 CreateWithDefaultCapturers();
404 405
405 webrtc::WindowCapturer::WindowList list; 406 webrtc::WindowCapturer::WindowList list;
406 webrtc::WindowCapturer::Window window; 407 webrtc::WindowCapturer::Window window;
407 window.id = 0; 408 window.id = 0;
408 window.title = "Test window 1"; 409 window.title = "Test window 1";
409 list.push_back(window); 410 list.push_back(window);
410 window.id = 1; 411 window.id = 1;
411 window.title = "Test window 2"; 412 window.title = "Test window 2";
412 list.push_back(window); 413 list.push_back(window);
(...skipping 21 matching lines...) Expand all
434 EXPECT_CALL(observer_, OnSourceThumbnailChanged(1)) 435 EXPECT_CALL(observer_, OnSourceThumbnailChanged(1))
435 .WillOnce(QuitMessageLoop(&message_loop_)); 436 .WillOnce(QuitMessageLoop(&message_loop_));
436 437
437 // Update frame for the window and verify that we get notification about it. 438 // Update frame for the window and verify that we get notification about it.
438 window_capturer_->SetNextFrameValue(0, 1); 439 window_capturer_->SetNextFrameValue(0, 1);
439 440
440 message_loop_.Run(); 441 message_loop_.Run();
441 } 442 }
442 443
443 } // namespace 444 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/media/native_desktop_media_list.cc ('k') | chrome/browser/ui/cocoa/media_picker/desktop_media_picker_bridge.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698