Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/native_desktop_media_list.h" | 5 #include "chrome/browser/media/native_desktop_media_list.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <string.h> | 9 #include <string.h> |
| 10 #include <vector> | |
| 10 | 11 |
| 11 #include "base/location.h" | 12 #include "base/location.h" |
| 12 #include "base/macros.h" | 13 #include "base/macros.h" |
| 13 #include "base/message_loop/message_loop.h" | |
| 14 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 16 #include "base/synchronization/lock.h" | 16 #include "base/synchronization/lock.h" |
| 17 #include "chrome/browser/media/desktop_media_list_observer.h" | 17 #include "chrome/browser/media/desktop_media_list_observer.h" |
| 18 #include "content/public/test/test_browser_thread.h" | 18 #include "content/public/test/test_browser_thread.h" |
| 19 #include "testing/gmock/include/gmock/gmock.h" | 19 #include "testing/gmock/include/gmock/gmock.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 21 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" | 21 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" |
| 22 #include "third_party/webrtc/modules/desktop_capture/screen_capturer.h" | 22 #include "third_party/webrtc/modules/desktop_capture/screen_capturer.h" |
| 23 #include "third_party/webrtc/modules/desktop_capture/window_capturer.h" | 23 #include "third_party/webrtc/modules/desktop_capture/window_capturer.h" |
| 24 #include "ui/aura/window.h" | |
| 25 #include "ui/aura/window_tree_host.h" | |
| 26 #include "ui/views/test/views_test_base.h" | |
| 27 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" | |
| 28 #include "ui/views/widget/widget.h" | |
| 24 | 29 |
| 30 using content::DesktopMediaID; | |
| 25 using testing::_; | 31 using testing::_; |
| 26 using testing::DoAll; | 32 using testing::DoAll; |
| 27 | 33 |
| 28 namespace { | 34 namespace { |
| 29 | 35 |
| 36 static const int kDefaultWindowCount = 2; | |
| 37 #if defined(USE_AURA) | |
| 38 static const int kDefaultAuraCount = 1; | |
| 39 #else | |
| 40 static const int kDefaultAuraCount = 0; | |
| 41 #endif | |
| 42 | |
| 30 class MockObserver : public DesktopMediaListObserver { | 43 class MockObserver : public DesktopMediaListObserver { |
| 31 public: | 44 public: |
| 32 MOCK_METHOD2(OnSourceAdded, void(DesktopMediaList* list, int index)); | 45 MOCK_METHOD2(OnSourceAdded, void(DesktopMediaList* list, int index)); |
| 33 MOCK_METHOD2(OnSourceRemoved, void(DesktopMediaList* list, int index)); | 46 MOCK_METHOD2(OnSourceRemoved, void(DesktopMediaList* list, int index)); |
| 34 MOCK_METHOD3(OnSourceMoved, | 47 MOCK_METHOD3(OnSourceMoved, |
| 35 void(DesktopMediaList* list, int old_index, int new_index)); | 48 void(DesktopMediaList* list, int old_index, int new_index)); |
| 36 MOCK_METHOD2(OnSourceNameChanged, void(DesktopMediaList* list, int index)); | 49 MOCK_METHOD2(OnSourceNameChanged, void(DesktopMediaList* list, int index)); |
| 37 MOCK_METHOD2(OnSourceThumbnailChanged, | 50 MOCK_METHOD2(OnSourceThumbnailChanged, |
| 38 void(DesktopMediaList* list, int index)); | 51 void(DesktopMediaList* list, int index)); |
| 39 }; | 52 }; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 128 | 141 |
| 129 WindowId selected_window_id_; | 142 WindowId selected_window_id_; |
| 130 | 143 |
| 131 // Frames to be captured per window. | 144 // Frames to be captured per window. |
| 132 std::map<WindowId, int8_t> frame_values_; | 145 std::map<WindowId, int8_t> frame_values_; |
| 133 base::Lock frame_values_lock_; | 146 base::Lock frame_values_lock_; |
| 134 | 147 |
| 135 DISALLOW_COPY_AND_ASSIGN(FakeWindowCapturer); | 148 DISALLOW_COPY_AND_ASSIGN(FakeWindowCapturer); |
| 136 }; | 149 }; |
| 137 | 150 |
| 151 } // namespace | |
| 152 | |
| 138 ACTION_P2(CheckListSize, model, expected_list_size) { | 153 ACTION_P2(CheckListSize, model, expected_list_size) { |
| 139 EXPECT_EQ(expected_list_size, model->GetSourceCount()); | 154 EXPECT_EQ(expected_list_size, model->GetSourceCount()); |
| 140 } | 155 } |
| 141 | 156 |
| 142 ACTION_P(QuitMessageLoop, message_loop) { | 157 ACTION_P(QuitMessageLoop, message_loop) { |
| 143 message_loop->task_runner()->PostTask( | 158 message_loop->task_runner()->PostTask( |
| 144 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); | 159 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); |
| 145 } | 160 } |
| 146 | 161 |
| 147 class DesktopMediaListTest : public testing::Test { | 162 class DesktopMediaListTest : public views::ViewsTestBase { |
|
Sergey Ulanov
2016/04/07 00:20:14
This should be NativeDesktopMediaListTest. Can you
GeorgeZ
2016/04/07 17:36:43
Done.
| |
| 148 public: | 163 public: |
| 149 DesktopMediaListTest() | 164 DesktopMediaListTest() |
| 150 : window_capturer_(NULL), | 165 : ui_thread_(content::BrowserThread::UI, message_loop()) {} |
| 151 ui_thread_(content::BrowserThread::UI, | 166 |
| 152 &message_loop_) { | 167 void TearDown() override { |
| 168 for (size_t i = 0; i < desktop_widgets_.size(); i++) | |
| 169 desktop_widgets_[i].reset(); | |
| 170 | |
| 171 ViewsTestBase::TearDown(); | |
| 153 } | 172 } |
| 154 | 173 |
| 155 void CreateWithDefaultCapturers() { | 174 void CreateWithCapturers(bool screen, bool window) { |
| 156 window_capturer_ = new FakeWindowCapturer(); | 175 webrtc::ScreenCapturer* screen_capturer = NULL; |
|
Sergey Ulanov
2016/04/07 00:20:14
nullptr
GeorgeZ
2016/04/07 17:36:42
Done.
| |
| 176 if (screen) | |
| 177 screen_capturer = new FakeScreenCapturer(); | |
| 178 | |
| 179 if (window) | |
| 180 window_capturer_ = new FakeWindowCapturer(); | |
| 181 else | |
| 182 window_capturer_ = NULL; | |
|
Sergey Ulanov
2016/04/07 00:20:14
nullptr
GeorgeZ
2016/04/07 17:36:43
Done.
| |
| 183 | |
| 157 model_.reset(new NativeDesktopMediaList( | 184 model_.reset(new NativeDesktopMediaList( |
| 158 scoped_ptr<webrtc::ScreenCapturer>(new FakeScreenCapturer()), | 185 scoped_ptr<webrtc::ScreenCapturer>(screen_capturer), |
| 159 scoped_ptr<webrtc::WindowCapturer>(window_capturer_))); | 186 scoped_ptr<webrtc::WindowCapturer>(window_capturer_))); |
| 160 | 187 |
| 161 // Set update period to reduce the time it takes to run tests. | 188 // Set update period to reduce the time it takes to run tests. |
| 162 model_->SetUpdatePeriod(base::TimeDelta::FromMilliseconds(0)); | 189 model_->SetUpdatePeriod(base::TimeDelta::FromMilliseconds(5)); |
| 163 } | 190 } |
| 164 | 191 |
| 165 webrtc::WindowCapturer::WindowList AddWindowsAndVerify( | 192 #if defined(USE_AURA) |
| 166 size_t count, bool window_only) { | 193 views::Widget* CreateDesktopWidget() { |
|
Sergey Ulanov
2016/04/07 00:20:14
use std::unique_ptr<> for the result.
GeorgeZ
2016/04/07 17:36:42
Done.
| |
| 167 webrtc::WindowCapturer::WindowList list; | 194 views::Widget* widget = new views::Widget; |
|
Sergey Ulanov
2016/04/07 00:20:14
std::unique_ptr<>
GeorgeZ
2016/04/07 17:36:43
done.
What's the benefit of std::unique_ptr over
| |
| 168 for (size_t i = 0; i < count; ++i) { | 195 views::Widget::InitParams params; |
| 169 webrtc::WindowCapturer::Window window; | 196 params.type = views::Widget::InitParams::TYPE_WINDOW_FRAMELESS; |
| 170 window.id = i + 1; | 197 params.accept_events = false; |
| 171 window.title = "Test window"; | 198 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 172 list.push_back(window); | 199 params.native_widget = new views::DesktopNativeWidgetAura(widget); |
| 200 params.bounds = gfx::Rect(0, 0, 20, 20); | |
| 201 widget->Init(params); | |
| 202 widget->Show(); | |
| 203 return widget; | |
| 204 } | |
| 205 | |
| 206 void AddAuraWindow() { | |
| 207 webrtc::WindowCapturer::Window window; | |
| 208 window.title = "Test window"; | |
| 209 // Create a aura native widow through a widget. | |
| 210 desktop_widgets_.push_back(make_scoped_ptr(CreateDesktopWidget())); | |
| 211 // Get the native window's id. | |
| 212 aura::Window* aura_window = desktop_widgets_.back()->GetNativeWindow(); | |
| 213 gfx::AcceleratedWidget widget = | |
| 214 aura_window->GetHost()->GetAcceleratedWidget(); | |
| 215 #if defined(OS_WIN) | |
| 216 window.id = reinterpret_cast<DesktopMediaID::Id>(widget); | |
|
Sergey Ulanov
2016/04/07 00:20:14
I think this should compile on non-windows platfor
GeorgeZ
2016/04/07 17:36:42
window.id = reinterpret_cast<DesktopMediaID::Id>(w
| |
| 217 #else | |
| 218 window.id = widget; | |
| 219 #endif | |
| 220 // Get the aura window's id. | |
| 221 DesktopMediaID aura_id = DesktopMediaID::RegisterAuraWindow( | |
| 222 DesktopMediaID::TYPE_WINDOW, aura_window); | |
| 223 native_aura_id_map_[window.id] = aura_id.aura_id; | |
| 224 | |
| 225 window_list_.push_back(window); | |
| 226 } | |
| 227 #endif // defined(USE_AURA) | |
| 228 | |
| 229 void AddWindowsAndVerify(bool screen, | |
| 230 size_t window_count, | |
| 231 size_t aura_count, | |
| 232 bool has_view_dialog = false) { | |
|
Sergey Ulanov
2016/04/07 00:20:14
Style guide doesn't allow optional parameters.
GeorgeZ
2016/04/07 17:36:42
Done.
| |
| 233 // Create model_. | |
| 234 CreateWithCapturers(screen, window_count > 0); | |
| 235 | |
| 236 #if !defined(USE_AURA) | |
| 237 aura_count = 0; | |
| 238 #endif | |
| 239 if (aura_count >= window_count) | |
| 240 aura_count = window_count - 1; | |
| 241 | |
| 242 if (window_count == 0) | |
| 243 has_view_dialog = false; | |
| 244 | |
| 245 // Set up widows. | |
| 246 size_t aura_window_first_index = window_count - aura_count; | |
| 247 for (size_t i = 0; i < window_count; ++i) { | |
| 248 if (i < aura_window_first_index) { | |
| 249 webrtc::WindowCapturer::Window window; | |
| 250 window.id = i + 1; | |
| 251 window.title = "Test window"; | |
| 252 window_list_.push_back(window); | |
| 253 } else { | |
| 254 #if defined(USE_AURA) | |
| 255 AddAuraWindow(); | |
| 256 #endif | |
| 257 } | |
| 173 } | 258 } |
| 174 window_capturer_->SetWindowList(list); | 259 |
| 260 if (window_capturer_) | |
| 261 window_capturer_->SetWindowList(window_list_); | |
| 262 | |
| 263 // Set view dialog window ID as the first window id. | |
| 264 if (has_view_dialog) { | |
| 265 DesktopMediaID dialog_window_id(DesktopMediaID::TYPE_WINDOW, | |
| 266 window_list_[0].id); | |
| 267 model_->SetViewDialogWindowId(dialog_window_id); | |
| 268 window_count--; | |
| 269 aura_window_first_index--; | |
| 270 } | |
| 175 | 271 |
| 176 { | 272 { |
| 177 testing::InSequence dummy; | 273 testing::InSequence dummy; |
| 178 size_t source_count = window_only ? count : count + 1; | 274 size_t source_count = screen ? window_count + 1 : window_count; |
| 179 for (size_t i = 0; i < source_count; ++i) { | 275 for (size_t i = 0; i < source_count; ++i) { |
| 180 EXPECT_CALL(observer_, OnSourceAdded(model_.get(), i)) | 276 EXPECT_CALL(observer_, OnSourceAdded(model_.get(), i)) |
| 181 .WillOnce(CheckListSize(model_.get(), static_cast<int>(i + 1))); | 277 .WillOnce(CheckListSize(model_.get(), static_cast<int>(i + 1))); |
| 182 } | 278 } |
| 183 for (size_t i = 0; i < source_count - 1; ++i) { | 279 for (size_t i = 0; i < source_count - 1; ++i) { |
| 184 EXPECT_CALL(observer_, OnSourceThumbnailChanged(model_.get(), i)); | 280 EXPECT_CALL(observer_, OnSourceThumbnailChanged(model_.get(), i)); |
| 185 } | 281 } |
| 186 EXPECT_CALL(observer_, | 282 EXPECT_CALL(observer_, |
| 187 OnSourceThumbnailChanged(model_.get(), source_count - 1)) | 283 OnSourceThumbnailChanged(model_.get(), source_count - 1)) |
| 188 .WillOnce(QuitMessageLoop(&message_loop_)); | 284 .WillOnce(QuitMessageLoop(message_loop())); |
| 189 } | 285 } |
| 190 model_->StartUpdating(&observer_); | 286 model_->StartUpdating(&observer_); |
| 191 message_loop_.Run(); | 287 message_loop()->Run(); |
| 192 | 288 |
| 193 for (size_t i = 0; i < count; ++i) { | 289 if (screen) { |
| 194 size_t source_index = window_only ? i : i + 1; | 290 EXPECT_EQ(model_->GetSource(0).id.type, DesktopMediaID::TYPE_SCREEN); |
| 291 EXPECT_EQ(model_->GetSource(0).id.id, 0); | |
| 292 } | |
| 293 | |
| 294 for (size_t i = 0; i < window_count; ++i) { | |
| 295 size_t source_index = screen ? i + 1 : i; | |
| 195 EXPECT_EQ(model_->GetSource(source_index).id.type, | 296 EXPECT_EQ(model_->GetSource(source_index).id.type, |
| 196 content::DesktopMediaID::TYPE_WINDOW); | 297 DesktopMediaID::TYPE_WINDOW); |
| 197 EXPECT_EQ(model_->GetSource(source_index).id.id, static_cast<int>(i + 1)); | |
| 198 EXPECT_EQ(model_->GetSource(source_index).name, | 298 EXPECT_EQ(model_->GetSource(source_index).name, |
| 199 base::UTF8ToUTF16("Test window")); | 299 base::UTF8ToUTF16("Test window")); |
| 300 int index = has_view_dialog ? i + 1 : i; | |
| 301 int native_id = window_list_[index].id; | |
| 302 EXPECT_EQ(model_->GetSource(source_index).id.id, native_id); | |
| 303 #if defined(USE_AURA) | |
| 304 if (i >= aura_window_first_index) | |
| 305 EXPECT_EQ(model_->GetSource(source_index).id.aura_id, | |
| 306 native_aura_id_map_[native_id]); | |
| 307 #endif | |
| 200 } | 308 } |
| 201 testing::Mock::VerifyAndClearExpectations(&observer_); | 309 testing::Mock::VerifyAndClearExpectations(&observer_); |
| 202 return list; | |
| 203 } | 310 } |
| 204 | 311 |
| 205 protected: | 312 protected: |
| 206 // Must be listed before |model_|, so it's destroyed last. | 313 // Must be listed before |model_|, so it's destroyed last. |
| 207 MockObserver observer_; | 314 MockObserver observer_; |
| 208 | 315 |
| 209 // Owned by |model_|; | 316 // Owned by |model_|; |
| 210 FakeWindowCapturer* window_capturer_; | 317 FakeWindowCapturer* window_capturer_; |
| 211 | 318 |
| 319 webrtc::WindowCapturer::WindowList window_list_; | |
| 320 std::vector<scoped_ptr<views::Widget>> desktop_widgets_; | |
| 321 std::map<DesktopMediaID::Id, DesktopMediaID::Id> native_aura_id_map_; | |
| 212 scoped_ptr<NativeDesktopMediaList> model_; | 322 scoped_ptr<NativeDesktopMediaList> model_; |
| 213 | 323 |
| 214 base::MessageLoop message_loop_; | |
| 215 content::TestBrowserThread ui_thread_; | 324 content::TestBrowserThread ui_thread_; |
| 216 | 325 |
| 217 DISALLOW_COPY_AND_ASSIGN(DesktopMediaListTest); | 326 DISALLOW_COPY_AND_ASSIGN(DesktopMediaListTest); |
| 218 }; | 327 }; |
| 219 | 328 |
| 220 TEST_F(DesktopMediaListTest, InitialSourceList) { | 329 TEST_F(DesktopMediaListTest, WindowsOnly) { |
| 221 CreateWithDefaultCapturers(); | 330 AddWindowsAndVerify(false, kDefaultWindowCount, kDefaultAuraCount); |
| 222 webrtc::WindowCapturer::WindowList list = AddWindowsAndVerify(1, false); | 331 } |
| 223 | 332 |
| 224 EXPECT_EQ(model_->GetSource(0).id.type, content::DesktopMediaID::TYPE_SCREEN); | 333 TEST_F(DesktopMediaListTest, ScreenOnly) { |
| 225 EXPECT_EQ(model_->GetSource(0).id.id, 0); | 334 AddWindowsAndVerify(true, 0, 0); |
| 226 } | 335 } |
| 227 | 336 |
| 228 // Verifies that the window specified with SetViewDialogWindowId() is filtered | 337 // Verifies that the window specified with SetViewDialogWindowId() is filtered |
| 229 // from the results. | 338 // from the results. |
| 230 TEST_F(DesktopMediaListTest, Filtering) { | 339 TEST_F(DesktopMediaListTest, Filtering) { |
| 231 CreateWithDefaultCapturers(); | 340 AddWindowsAndVerify(true, kDefaultWindowCount, kDefaultAuraCount, true); |
| 232 webrtc::WindowCapturer::WindowList list = AddWindowsAndVerify(2, false); | |
| 233 | |
| 234 EXPECT_EQ(model_->GetSource(0).id.type, content::DesktopMediaID::TYPE_SCREEN); | |
| 235 EXPECT_EQ(model_->GetSource(0).id.id, 0); | |
| 236 } | 341 } |
| 237 | 342 |
| 238 TEST_F(DesktopMediaListTest, WindowsOnly) { | 343 TEST_F(DesktopMediaListTest, AddNativeWindow) { |
| 239 window_capturer_ = new FakeWindowCapturer(); | 344 AddWindowsAndVerify(true, kDefaultWindowCount, kDefaultAuraCount); |
| 240 model_.reset(new NativeDesktopMediaList( | 345 |
| 241 scoped_ptr<webrtc::ScreenCapturer>(), | 346 const int index = kDefaultWindowCount + 1; |
| 242 scoped_ptr<webrtc::WindowCapturer>(window_capturer_))); | 347 EXPECT_CALL(observer_, OnSourceAdded(model_.get(), index)) |
| 243 AddWindowsAndVerify(1, true); | 348 .WillOnce(DoAll(CheckListSize(model_.get(), index + 1), |
| 349 QuitMessageLoop(message_loop()))); | |
| 350 | |
| 351 webrtc::WindowCapturer::Window window; | |
| 352 window.id = kDefaultWindowCount + 1; | |
| 353 window.title = "Test window"; | |
| 354 window_list_.push_back(window); | |
| 355 window_capturer_->SetWindowList(window_list_); | |
| 356 | |
| 357 message_loop()->Run(); | |
| 358 | |
| 359 EXPECT_EQ(model_->GetSource(index).id.type, DesktopMediaID::TYPE_WINDOW); | |
| 360 EXPECT_EQ(model_->GetSource(index).id.id, window.id); | |
| 244 } | 361 } |
| 245 | 362 |
| 246 TEST_F(DesktopMediaListTest, ScreenOnly) { | 363 #if defined(USE_AURA) |
| 247 model_.reset(new NativeDesktopMediaList( | 364 TEST_F(DesktopMediaListTest, AddAuraWindow) { |
| 248 scoped_ptr<webrtc::ScreenCapturer>(new FakeScreenCapturer), | 365 AddWindowsAndVerify(true, kDefaultWindowCount, kDefaultAuraCount); |
| 249 scoped_ptr<webrtc::WindowCapturer>())); | |
| 250 | 366 |
| 251 { | 367 const int index = kDefaultWindowCount + 1; |
| 252 testing::InSequence dummy; | 368 EXPECT_CALL(observer_, OnSourceAdded(model_.get(), index)) |
| 253 EXPECT_CALL(observer_, OnSourceAdded(model_.get(), 0)) | 369 .WillOnce(DoAll(CheckListSize(model_.get(), index + 1), |
| 254 .WillOnce(CheckListSize(model_.get(), 1)); | 370 QuitMessageLoop(message_loop()))); |
| 255 EXPECT_CALL(observer_, OnSourceThumbnailChanged(model_.get(), 0)) | |
| 256 .WillOnce(QuitMessageLoop(&message_loop_)); | |
| 257 } | |
| 258 model_->StartUpdating(&observer_); | |
| 259 | 371 |
| 260 message_loop_.Run(); | 372 AddAuraWindow(); |
| 373 window_capturer_->SetWindowList(window_list_); | |
| 261 | 374 |
| 262 EXPECT_EQ(model_->GetSource(0).id.type, content::DesktopMediaID::TYPE_SCREEN); | 375 message_loop()->Run(); |
| 376 | |
| 377 int native_id = window_list_.back().id; | |
| 378 EXPECT_EQ(model_->GetSource(index).id.type, DesktopMediaID::TYPE_WINDOW); | |
| 379 EXPECT_EQ(model_->GetSource(index).id.id, native_id); | |
| 380 EXPECT_EQ(model_->GetSource(index).id.aura_id, | |
| 381 native_aura_id_map_[native_id]); | |
| 263 } | 382 } |
| 264 | 383 #endif // defined(USE_AURA) |
| 265 TEST_F(DesktopMediaListTest, AddWindow) { | |
| 266 CreateWithDefaultCapturers(); | |
| 267 webrtc::WindowCapturer::WindowList list = AddWindowsAndVerify(1, false); | |
| 268 | |
| 269 EXPECT_CALL(observer_, OnSourceAdded(model_.get(), 2)) | |
| 270 .WillOnce(DoAll(CheckListSize(model_.get(), 3), | |
| 271 QuitMessageLoop(&message_loop_))); | |
| 272 | |
| 273 webrtc::WindowCapturer::Window window; | |
| 274 window.id = 10; // id=0 is invalid. | |
| 275 window.title = "Test window 10"; | |
| 276 list.push_back(window); | |
| 277 window_capturer_->SetWindowList(list); | |
| 278 | |
| 279 message_loop_.Run(); | |
| 280 | |
| 281 EXPECT_EQ(model_->GetSource(2).id.type, content::DesktopMediaID::TYPE_WINDOW); | |
| 282 EXPECT_EQ(model_->GetSource(2).id.id, 10); | |
| 283 } | |
| 284 | 384 |
| 285 TEST_F(DesktopMediaListTest, RemoveWindow) { | 385 TEST_F(DesktopMediaListTest, RemoveWindow) { |
| 286 CreateWithDefaultCapturers(); | 386 AddWindowsAndVerify(true, kDefaultWindowCount, kDefaultAuraCount); |
| 287 webrtc::WindowCapturer::WindowList list = AddWindowsAndVerify(2, false); | |
| 288 | 387 |
| 289 EXPECT_CALL(observer_, OnSourceRemoved(model_.get(), 2)) | 388 EXPECT_CALL(observer_, OnSourceRemoved(model_.get(), kDefaultWindowCount)) |
| 290 .WillOnce(DoAll(CheckListSize(model_.get(), 2), | 389 .WillOnce(DoAll(CheckListSize(model_.get(), kDefaultWindowCount), |
| 291 QuitMessageLoop(&message_loop_))); | 390 QuitMessageLoop(message_loop()))); |
| 292 | 391 |
| 293 list.erase(list.begin() + 1); | 392 window_list_.erase(window_list_.begin() + 1); |
| 294 window_capturer_->SetWindowList(list); | 393 window_capturer_->SetWindowList(window_list_); |
| 295 | 394 |
| 296 message_loop_.Run(); | 395 message_loop()->Run(); |
| 297 } | 396 } |
| 298 | 397 |
| 299 TEST_F(DesktopMediaListTest, RemoveAllWindows) { | 398 TEST_F(DesktopMediaListTest, RemoveAllWindows) { |
| 300 CreateWithDefaultCapturers(); | 399 AddWindowsAndVerify(true, kDefaultWindowCount, kDefaultAuraCount); |
| 301 webrtc::WindowCapturer::WindowList list = AddWindowsAndVerify(2, false); | |
| 302 | 400 |
| 303 testing::InSequence seq; | 401 testing::InSequence seq; |
| 304 EXPECT_CALL(observer_, OnSourceRemoved(model_.get(), 1)) | 402 for (int i = 0; i < kDefaultWindowCount - 1; i++) { |
| 305 .WillOnce(CheckListSize(model_.get(), 2)); | 403 EXPECT_CALL(observer_, OnSourceRemoved(model_.get(), 1)) |
| 404 .WillOnce(CheckListSize(model_.get(), kDefaultWindowCount - i)); | |
| 405 } | |
| 306 EXPECT_CALL(observer_, OnSourceRemoved(model_.get(), 1)) | 406 EXPECT_CALL(observer_, OnSourceRemoved(model_.get(), 1)) |
| 307 .WillOnce(DoAll(CheckListSize(model_.get(), 1), | 407 .WillOnce(DoAll(CheckListSize(model_.get(), 1), |
| 308 QuitMessageLoop(&message_loop_))); | 408 QuitMessageLoop(message_loop()))); |
| 309 | 409 |
| 310 list.erase(list.begin(), list.end()); | 410 window_list_.clear(); |
| 311 window_capturer_->SetWindowList(list); | 411 window_capturer_->SetWindowList(window_list_); |
| 312 | 412 |
| 313 message_loop_.Run(); | 413 message_loop()->Run(); |
| 314 } | 414 } |
| 315 | 415 |
| 316 TEST_F(DesktopMediaListTest, UpdateTitle) { | 416 TEST_F(DesktopMediaListTest, UpdateTitle) { |
| 317 CreateWithDefaultCapturers(); | 417 AddWindowsAndVerify(true, kDefaultWindowCount, kDefaultAuraCount); |
| 318 webrtc::WindowCapturer::WindowList list = AddWindowsAndVerify(1, false); | |
| 319 | 418 |
| 320 EXPECT_CALL(observer_, OnSourceNameChanged(model_.get(), 1)) | 419 EXPECT_CALL(observer_, OnSourceNameChanged(model_.get(), 1)) |
| 321 .WillOnce(QuitMessageLoop(&message_loop_)); | 420 .WillOnce(QuitMessageLoop(message_loop())); |
| 322 | 421 |
| 323 const std::string kTestTitle = "New Title"; | 422 const std::string kTestTitle = "New Title"; |
| 423 window_list_[0].title = kTestTitle; | |
| 424 window_capturer_->SetWindowList(window_list_); | |
| 324 | 425 |
| 325 list[0].title = kTestTitle; | 426 message_loop()->Run(); |
| 326 window_capturer_->SetWindowList(list); | |
| 327 | |
| 328 message_loop_.Run(); | |
| 329 | 427 |
| 330 EXPECT_EQ(model_->GetSource(1).name, base::UTF8ToUTF16(kTestTitle)); | 428 EXPECT_EQ(model_->GetSource(1).name, base::UTF8ToUTF16(kTestTitle)); |
| 331 } | 429 } |
| 332 | 430 |
| 333 TEST_F(DesktopMediaListTest, UpdateThumbnail) { | 431 TEST_F(DesktopMediaListTest, UpdateThumbnail) { |
| 334 CreateWithDefaultCapturers(); | 432 DCHECK_GT(kDefaultWindowCount, kDefaultAuraCount); |
| 335 AddWindowsAndVerify(2, false); | 433 AddWindowsAndVerify(true, kDefaultWindowCount, kDefaultAuraCount); |
| 336 | 434 |
| 337 EXPECT_CALL(observer_, OnSourceThumbnailChanged(model_.get(), 1)) | 435 EXPECT_CALL(observer_, OnSourceThumbnailChanged(model_.get(), 1)) |
| 338 .WillOnce(QuitMessageLoop(&message_loop_)); | 436 .WillOnce(QuitMessageLoop(message_loop())); |
| 437 | |
| 339 // 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. |
| 340 window_capturer_->SetNextFrameValue(1, 1); | 439 window_capturer_->SetNextFrameValue(1, 10); |
| 341 | 440 |
| 342 message_loop_.Run(); | 441 message_loop()->Run(); |
| 343 } | 442 } |
| 344 | 443 |
| 345 TEST_F(DesktopMediaListTest, MoveWindow) { | 444 TEST_F(DesktopMediaListTest, MoveWindow) { |
| 346 CreateWithDefaultCapturers(); | 445 DCHECK_GE(kDefaultWindowCount, 2); |
|
Sergey Ulanov
2016/04/07 00:20:14
This can be replaced with a COMPILE_ASSERT()
GeorgeZ
2016/04/07 17:36:42
COMPILE_ASSERT() from
"chrome/installer/mini_insta
| |
| 347 webrtc::WindowCapturer::WindowList list = AddWindowsAndVerify(2, false); | 446 AddWindowsAndVerify(true, kDefaultWindowCount, kDefaultAuraCount); |
| 348 | 447 |
| 349 EXPECT_CALL(observer_, OnSourceMoved(model_.get(), 2, 1)) | 448 EXPECT_CALL(observer_, OnSourceMoved(model_.get(), 2, 1)) |
| 350 .WillOnce(DoAll(CheckListSize(model_.get(), 3), | 449 .WillOnce(DoAll(CheckListSize(model_.get(), kDefaultWindowCount + 1), |
| 351 QuitMessageLoop(&message_loop_))); | 450 QuitMessageLoop(message_loop()))); |
| 352 | 451 |
| 353 // Swap the two windows. | 452 // Swap the two windows. |
| 354 webrtc::WindowCapturer::Window temp = list[0]; | 453 webrtc::WindowCapturer::Window temp = window_list_[0]; |
| 355 list[0] = list[1]; | 454 window_list_[0] = window_list_[1]; |
| 356 list[1] = temp; | 455 window_list_[1] = temp; |
| 357 window_capturer_->SetWindowList(list); | 456 window_capturer_->SetWindowList(window_list_); |
| 358 | 457 |
| 359 message_loop_.Run(); | 458 message_loop()->Run(); |
| 360 } | 459 } |
| 361 | |
| 362 } // namespace | |
| OLD | NEW |