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/desktop_media_picker_model.h" | 5 #include "chrome/browser/media/desktop_media_picker_model.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 "content/public/test/test_browser_thread.h" | 10 #include "content/public/test/test_browser_thread.h" |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 class DesktopMediaPickerModelTest : public testing::Test { | 122 class DesktopMediaPickerModelTest : public testing::Test { |
123 public: | 123 public: |
124 DesktopMediaPickerModelTest() | 124 DesktopMediaPickerModelTest() |
125 : window_capturer_(NULL), | 125 : window_capturer_(NULL), |
126 ui_thread_(content::BrowserThread::UI, | 126 ui_thread_(content::BrowserThread::UI, |
127 &message_loop_) { | 127 &message_loop_) { |
128 } | 128 } |
129 | 129 |
130 void CreateWithDefaultCapturers() { | 130 void CreateWithDefaultCapturers() { |
131 window_capturer_ = new FakeWindowCapturer(); | 131 window_capturer_ = new FakeWindowCapturer(); |
132 model_.reset(new DesktopMediaPickerModel( | 132 model_.reset(new DesktopMediaPickerModelImpl( |
133 scoped_ptr<webrtc::ScreenCapturer>(new FakeScreenCapturer()), | 133 scoped_ptr<webrtc::ScreenCapturer>(new FakeScreenCapturer()), |
134 scoped_ptr<webrtc::WindowCapturer>(window_capturer_))); | 134 scoped_ptr<webrtc::WindowCapturer>(window_capturer_))); |
135 | 135 |
136 // Set update period to reduce the time it takes to run tests. | 136 // Set update period to reduce the time it takes to run tests. |
137 model_->SetUpdatePeriod(base::TimeDelta::FromMilliseconds(0)); | 137 model_->SetUpdatePeriod(base::TimeDelta::FromMilliseconds(0)); |
138 } | 138 } |
139 | 139 |
140 protected: | 140 protected: |
141 // Must be listed before |model_|, so it's destroyed last. | 141 // Must be listed before |model_|, so it's destroyed last. |
142 MockObserver observer_; | 142 MockObserver observer_; |
143 | 143 |
144 // Owned by |model_|; | 144 // Owned by |model_|; |
145 FakeWindowCapturer* window_capturer_; | 145 FakeWindowCapturer* window_capturer_; |
146 | 146 |
147 scoped_ptr<DesktopMediaPickerModel> model_; | 147 scoped_ptr<DesktopMediaPickerModelImpl> model_; |
148 | 148 |
149 base::MessageLoop message_loop_; | 149 base::MessageLoop message_loop_; |
150 content::TestBrowserThread ui_thread_; | 150 content::TestBrowserThread ui_thread_; |
151 | 151 |
152 DISALLOW_COPY_AND_ASSIGN(DesktopMediaPickerModelTest); | 152 DISALLOW_COPY_AND_ASSIGN(DesktopMediaPickerModelTest); |
153 }; | 153 }; |
154 | 154 |
155 ACTION_P2(CheckListSize, model, expected_list_size) { | 155 ACTION_P2(CheckListSize, model, expected_list_size) { |
156 EXPECT_EQ(expected_list_size, model->source_count()); | 156 EXPECT_EQ(expected_list_size, model->source_count()); |
157 } | 157 } |
(...skipping 28 matching lines...) Expand all Loading... |
186 | 186 |
187 EXPECT_EQ(model_->source(0).id.type, content::DesktopMediaID::TYPE_SCREEN); | 187 EXPECT_EQ(model_->source(0).id.type, content::DesktopMediaID::TYPE_SCREEN); |
188 EXPECT_EQ(model_->source(0).id.id, 0); | 188 EXPECT_EQ(model_->source(0).id.id, 0); |
189 EXPECT_EQ(model_->source(1).id.type, content::DesktopMediaID::TYPE_WINDOW); | 189 EXPECT_EQ(model_->source(1).id.type, content::DesktopMediaID::TYPE_WINDOW); |
190 EXPECT_EQ(model_->source(1).id.id, 0); | 190 EXPECT_EQ(model_->source(1).id.id, 0); |
191 EXPECT_EQ(model_->source(1).name, UTF8ToUTF16(window.title)); | 191 EXPECT_EQ(model_->source(1).name, UTF8ToUTF16(window.title)); |
192 } | 192 } |
193 | 193 |
194 TEST_F(DesktopMediaPickerModelTest, WindowsOnly) { | 194 TEST_F(DesktopMediaPickerModelTest, WindowsOnly) { |
195 window_capturer_ = new FakeWindowCapturer(); | 195 window_capturer_ = new FakeWindowCapturer(); |
196 model_.reset(new DesktopMediaPickerModel( | 196 model_.reset(new DesktopMediaPickerModelImpl( |
197 scoped_ptr<webrtc::ScreenCapturer>(), | 197 scoped_ptr<webrtc::ScreenCapturer>(), |
198 scoped_ptr<webrtc::WindowCapturer>(window_capturer_))); | 198 scoped_ptr<webrtc::WindowCapturer>(window_capturer_))); |
199 | 199 |
200 webrtc::WindowCapturer::WindowList list; | 200 webrtc::WindowCapturer::WindowList list; |
201 webrtc::WindowCapturer::Window window; | 201 webrtc::WindowCapturer::Window window; |
202 window.id = 0; | 202 window.id = 0; |
203 window.title = "Test window"; | 203 window.title = "Test window"; |
204 list.push_back(window); | 204 list.push_back(window); |
205 window_capturer_->SetWindowList(list); | 205 window_capturer_->SetWindowList(list); |
206 | 206 |
207 { | 207 { |
208 testing::InSequence dummy; | 208 testing::InSequence dummy; |
209 EXPECT_CALL(observer_, OnSourceAdded(0)) | 209 EXPECT_CALL(observer_, OnSourceAdded(0)) |
210 .WillOnce(CheckListSize(model_.get(), 1)); | 210 .WillOnce(CheckListSize(model_.get(), 1)); |
211 EXPECT_CALL(observer_, OnSourceThumbnailChanged(0)) | 211 EXPECT_CALL(observer_, OnSourceThumbnailChanged(0)) |
212 .WillOnce(QuitMessageLoop(&message_loop_)); | 212 .WillOnce(QuitMessageLoop(&message_loop_)); |
213 } | 213 } |
214 model_->StartUpdating(&observer_); | 214 model_->StartUpdating(&observer_); |
215 | 215 |
216 message_loop_.Run(); | 216 message_loop_.Run(); |
217 | 217 |
218 EXPECT_EQ(model_->source(0).id.type, content::DesktopMediaID::TYPE_WINDOW); | 218 EXPECT_EQ(model_->source(0).id.type, content::DesktopMediaID::TYPE_WINDOW); |
219 } | 219 } |
220 | 220 |
221 TEST_F(DesktopMediaPickerModelTest, ScreenOnly) { | 221 TEST_F(DesktopMediaPickerModelTest, ScreenOnly) { |
222 model_.reset(new DesktopMediaPickerModel( | 222 model_.reset(new DesktopMediaPickerModelImpl( |
223 scoped_ptr<webrtc::ScreenCapturer>(new FakeScreenCapturer), | 223 scoped_ptr<webrtc::ScreenCapturer>(new FakeScreenCapturer), |
224 scoped_ptr<webrtc::WindowCapturer>())); | 224 scoped_ptr<webrtc::WindowCapturer>())); |
225 | 225 |
226 { | 226 { |
227 testing::InSequence dummy; | 227 testing::InSequence dummy; |
228 EXPECT_CALL(observer_, OnSourceAdded(0)) | 228 EXPECT_CALL(observer_, OnSourceAdded(0)) |
229 .WillOnce(CheckListSize(model_.get(), 1)); | 229 .WillOnce(CheckListSize(model_.get(), 1)); |
230 EXPECT_CALL(observer_, OnSourceThumbnailChanged(0)) | 230 EXPECT_CALL(observer_, OnSourceThumbnailChanged(0)) |
231 .WillOnce(QuitMessageLoop(&message_loop_)); | 231 .WillOnce(QuitMessageLoop(&message_loop_)); |
232 } | 232 } |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 EXPECT_CALL(observer_, OnSourceThumbnailChanged(1)) | 394 EXPECT_CALL(observer_, OnSourceThumbnailChanged(1)) |
395 .WillOnce(QuitMessageLoop(&message_loop_)); | 395 .WillOnce(QuitMessageLoop(&message_loop_)); |
396 | 396 |
397 // Update frame for the window and verify that we get notification about it. | 397 // Update frame for the window and verify that we get notification about it. |
398 window_capturer_->SetNextFrameValue(0, 1); | 398 window_capturer_->SetNextFrameValue(0, 1); |
399 | 399 |
400 message_loop_.Run(); | 400 message_loop_.Run(); |
401 } | 401 } |
402 | 402 |
403 } // namespace | 403 } // namespace |
OLD | NEW |