| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/combined_desktop_media_list.h" | 5 #include "chrome/browser/media/combined_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/run_loop.h" |
| 8 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/media/desktop_media_list_base.h" | 11 #include "chrome/browser/media/desktop_media_list_base.h" |
| 11 #include "chrome/browser/media/desktop_media_list_observer.h" | 12 #include "chrome/browser/media/desktop_media_list_observer.h" |
| 12 #include "content/public/test/test_browser_thread.h" | 13 #include "content/public/test/test_browser_thread.h" |
| 13 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "ui/gfx/image/image_skia.h" | 16 #include "ui/gfx/image/image_skia.h" |
| 16 | 17 |
| 17 using testing::DoAll; | 18 using testing::DoAll; |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 OnSourceThumbnailChanged(combined_list_.get(), i)); | 172 OnSourceThumbnailChanged(combined_list_.get(), i)); |
| 172 } | 173 } |
| 173 | 174 |
| 174 EXPECT_CALL(observer_, | 175 EXPECT_CALL(observer_, |
| 175 OnSourceThumbnailChanged(combined_list_.get(), | 176 OnSourceThumbnailChanged(combined_list_.get(), |
| 176 2 * kDefaultSourceCount - 1)) | 177 2 * kDefaultSourceCount - 1)) |
| 177 .WillOnce(QuitMessageLoop(&message_loop_)); | 178 .WillOnce(QuitMessageLoop(&message_loop_)); |
| 178 } | 179 } |
| 179 | 180 |
| 180 combined_list_->StartUpdating(&observer_); | 181 combined_list_->StartUpdating(&observer_); |
| 181 message_loop_.Run(); | 182 base::RunLoop().Run(); |
| 182 | 183 |
| 183 // list1_'s sources. | 184 // list1_'s sources. |
| 184 for (int i = 0; i < kDefaultSourceCount; ++i) { | 185 for (int i = 0; i < kDefaultSourceCount; ++i) { |
| 185 EXPECT_EQ(combined_list_->GetSource(i).id.type, | 186 EXPECT_EQ(combined_list_->GetSource(i).id.type, |
| 186 content::DesktopMediaID::TYPE_SCREEN); | 187 content::DesktopMediaID::TYPE_SCREEN); |
| 187 EXPECT_EQ(combined_list_->GetSource(i).id.id, i + 1); | 188 EXPECT_EQ(combined_list_->GetSource(i).id.id, i + 1); |
| 188 } | 189 } |
| 189 | 190 |
| 190 // list2_'s sources. | 191 // list2_'s sources. |
| 191 for (int i = kDefaultSourceCount; i < 2 * kDefaultSourceCount; i++) { | 192 for (int i = kDefaultSourceCount; i < 2 * kDefaultSourceCount; i++) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 217 int index = kDefaultSourceCount; | 218 int index = kDefaultSourceCount; |
| 218 list1_->AddFakeSource(index, base::UTF8ToUTF16("Test media"), index); | 219 list1_->AddFakeSource(index, base::UTF8ToUTF16("Test media"), index); |
| 219 | 220 |
| 220 EXPECT_CALL(observer_, OnSourceAdded(combined_list_.get(), index)) | 221 EXPECT_CALL(observer_, OnSourceAdded(combined_list_.get(), index)) |
| 221 .WillOnce( | 222 .WillOnce( |
| 222 CheckListSize(combined_list_.get(), 2 * kDefaultSourceCount + 1)); | 223 CheckListSize(combined_list_.get(), 2 * kDefaultSourceCount + 1)); |
| 223 EXPECT_CALL(observer_, OnSourceThumbnailChanged(combined_list_.get(), index)) | 224 EXPECT_CALL(observer_, OnSourceThumbnailChanged(combined_list_.get(), index)) |
| 224 .WillOnce(QuitMessageLoop(&message_loop_)); | 225 .WillOnce(QuitMessageLoop(&message_loop_)); |
| 225 | 226 |
| 226 list1_->Refresh(); | 227 list1_->Refresh(); |
| 227 message_loop_.Run(); | 228 base::RunLoop().Run(); |
| 228 | 229 |
| 229 list2_->AddFakeSource(index, base::UTF8ToUTF16("Test media"), index); | 230 list2_->AddFakeSource(index, base::UTF8ToUTF16("Test media"), index); |
| 230 | 231 |
| 231 EXPECT_CALL(observer_, | 232 EXPECT_CALL(observer_, |
| 232 OnSourceAdded(combined_list_.get(), 2 * kDefaultSourceCount + 1)) | 233 OnSourceAdded(combined_list_.get(), 2 * kDefaultSourceCount + 1)) |
| 233 .WillOnce( | 234 .WillOnce( |
| 234 CheckListSize(combined_list_.get(), 2 * kDefaultSourceCount + 2)); | 235 CheckListSize(combined_list_.get(), 2 * kDefaultSourceCount + 2)); |
| 235 EXPECT_CALL(observer_, OnSourceThumbnailChanged(combined_list_.get(), | 236 EXPECT_CALL(observer_, OnSourceThumbnailChanged(combined_list_.get(), |
| 236 2 * kDefaultSourceCount + 1)) | 237 2 * kDefaultSourceCount + 1)) |
| 237 .WillOnce(QuitMessageLoop(&message_loop_)); | 238 .WillOnce(QuitMessageLoop(&message_loop_)); |
| 238 | 239 |
| 239 list2_->Refresh(); | 240 list2_->Refresh(); |
| 240 message_loop_.Run(); | 241 base::RunLoop().Run(); |
| 241 | 242 |
| 242 // Verify last source for list1_ and first source for list2_. | 243 // Verify last source for list1_ and first source for list2_. |
| 243 EXPECT_EQ(combined_list_->GetSource(index).id.type, | 244 EXPECT_EQ(combined_list_->GetSource(index).id.type, |
| 244 content::DesktopMediaID::TYPE_SCREEN); | 245 content::DesktopMediaID::TYPE_SCREEN); |
| 245 EXPECT_EQ(combined_list_->GetSource(index).id.id, index + 1); | 246 EXPECT_EQ(combined_list_->GetSource(index).id.id, index + 1); |
| 246 EXPECT_EQ(combined_list_->GetSource(index + 1).id.type, | 247 EXPECT_EQ(combined_list_->GetSource(index + 1).id.type, |
| 247 content::DesktopMediaID::TYPE_WINDOW); | 248 content::DesktopMediaID::TYPE_WINDOW); |
| 248 EXPECT_EQ(combined_list_->GetSource(index + 1).id.id, 1); | 249 EXPECT_EQ(combined_list_->GetSource(index + 1).id.id, 1); |
| 249 } | 250 } |
| 250 | 251 |
| 251 TEST_F(CombinedDesktopMediaListTest, RemoveSource) { | 252 TEST_F(CombinedDesktopMediaListTest, RemoveSource) { |
| 252 InitializeAndVerify(); | 253 InitializeAndVerify(); |
| 253 | 254 |
| 254 int index = kDefaultSourceCount - 1; | 255 int index = kDefaultSourceCount - 1; |
| 255 list1_->RemoveFakeSource(index); | 256 list1_->RemoveFakeSource(index); |
| 256 | 257 |
| 257 EXPECT_CALL(observer_, OnSourceRemoved(combined_list_.get(), index)) | 258 EXPECT_CALL(observer_, OnSourceRemoved(combined_list_.get(), index)) |
| 258 .WillOnce(DoAll( | 259 .WillOnce(DoAll( |
| 259 CheckListSize(combined_list_.get(), 2 * kDefaultSourceCount - 1), | 260 CheckListSize(combined_list_.get(), 2 * kDefaultSourceCount - 1), |
| 260 QuitMessageLoop(&message_loop_))); | 261 QuitMessageLoop(&message_loop_))); |
| 261 | 262 |
| 262 list1_->Refresh(); | 263 list1_->Refresh(); |
| 263 message_loop_.Run(); | 264 base::RunLoop().Run(); |
| 264 | 265 |
| 265 list2_->RemoveFakeSource(index); | 266 list2_->RemoveFakeSource(index); |
| 266 | 267 |
| 267 EXPECT_CALL(observer_, OnSourceRemoved(combined_list_.get(), | 268 EXPECT_CALL(observer_, OnSourceRemoved(combined_list_.get(), |
| 268 2 * kDefaultSourceCount - 2)) | 269 2 * kDefaultSourceCount - 2)) |
| 269 .WillOnce(DoAll( | 270 .WillOnce(DoAll( |
| 270 CheckListSize(combined_list_.get(), 2 * kDefaultSourceCount - 2), | 271 CheckListSize(combined_list_.get(), 2 * kDefaultSourceCount - 2), |
| 271 QuitMessageLoop(&message_loop_))); | 272 QuitMessageLoop(&message_loop_))); |
| 272 | 273 |
| 273 list2_->Refresh(); | 274 list2_->Refresh(); |
| 274 message_loop_.Run(); | 275 base::RunLoop().Run(); |
| 275 | 276 |
| 276 // Verify last source for list1_ and first source for list2_. | 277 // Verify last source for list1_ and first source for list2_. |
| 277 EXPECT_EQ(combined_list_->GetSource(index - 1).id.type, | 278 EXPECT_EQ(combined_list_->GetSource(index - 1).id.type, |
| 278 content::DesktopMediaID::TYPE_SCREEN); | 279 content::DesktopMediaID::TYPE_SCREEN); |
| 279 EXPECT_EQ(combined_list_->GetSource(index - 1).id.id, index); | 280 EXPECT_EQ(combined_list_->GetSource(index - 1).id.id, index); |
| 280 EXPECT_EQ(combined_list_->GetSource(index).id.type, | 281 EXPECT_EQ(combined_list_->GetSource(index).id.type, |
| 281 content::DesktopMediaID::TYPE_WINDOW); | 282 content::DesktopMediaID::TYPE_WINDOW); |
| 282 EXPECT_EQ(combined_list_->GetSource(index).id.id, 1); | 283 EXPECT_EQ(combined_list_->GetSource(index).id.id, 1); |
| 283 } | 284 } |
| 284 | 285 |
| 285 TEST_F(CombinedDesktopMediaListTest, MoveSource) { | 286 TEST_F(CombinedDesktopMediaListTest, MoveSource) { |
| 286 InitializeAndVerify(); | 287 InitializeAndVerify(); |
| 287 | 288 |
| 288 // Swap sources. | 289 // Swap sources. |
| 289 list1_->RemoveFakeSource(kDefaultSourceCount - 1); | 290 list1_->RemoveFakeSource(kDefaultSourceCount - 1); |
| 290 list1_->RemoveFakeSource(kDefaultSourceCount - 2); | 291 list1_->RemoveFakeSource(kDefaultSourceCount - 2); |
| 291 list1_->AddFakeSource(kDefaultSourceCount - 1, | 292 list1_->AddFakeSource(kDefaultSourceCount - 1, |
| 292 base::UTF8ToUTF16("Test media"), | 293 base::UTF8ToUTF16("Test media"), |
| 293 kDefaultSourceCount - 1); | 294 kDefaultSourceCount - 1); |
| 294 list1_->AddFakeSource(kDefaultSourceCount - 2, | 295 list1_->AddFakeSource(kDefaultSourceCount - 2, |
| 295 base::UTF8ToUTF16("Test media"), | 296 base::UTF8ToUTF16("Test media"), |
| 296 kDefaultSourceCount - 2); | 297 kDefaultSourceCount - 2); |
| 297 | 298 |
| 298 EXPECT_CALL(observer_, | 299 EXPECT_CALL(observer_, |
| 299 OnSourceMoved(combined_list_.get(), kDefaultSourceCount - 1, | 300 OnSourceMoved(combined_list_.get(), kDefaultSourceCount - 1, |
| 300 kDefaultSourceCount - 2)) | 301 kDefaultSourceCount - 2)) |
| 301 .WillOnce(QuitMessageLoop(&message_loop_)); | 302 .WillOnce(QuitMessageLoop(&message_loop_)); |
| 302 | 303 |
| 303 list1_->Refresh(); | 304 list1_->Refresh(); |
| 304 message_loop_.Run(); | 305 base::RunLoop().Run(); |
| 305 | 306 |
| 306 // Swap sources. | 307 // Swap sources. |
| 307 list2_->RemoveFakeSource(kDefaultSourceCount - 1); | 308 list2_->RemoveFakeSource(kDefaultSourceCount - 1); |
| 308 list2_->RemoveFakeSource(kDefaultSourceCount - 2); | 309 list2_->RemoveFakeSource(kDefaultSourceCount - 2); |
| 309 list2_->AddFakeSource(kDefaultSourceCount - 1, | 310 list2_->AddFakeSource(kDefaultSourceCount - 1, |
| 310 base::UTF8ToUTF16("Test media"), | 311 base::UTF8ToUTF16("Test media"), |
| 311 kDefaultSourceCount - 1); | 312 kDefaultSourceCount - 1); |
| 312 list2_->AddFakeSource(kDefaultSourceCount - 2, | 313 list2_->AddFakeSource(kDefaultSourceCount - 2, |
| 313 base::UTF8ToUTF16("Test media"), | 314 base::UTF8ToUTF16("Test media"), |
| 314 kDefaultSourceCount - 2); | 315 kDefaultSourceCount - 2); |
| 315 | 316 |
| 316 EXPECT_CALL(observer_, | 317 EXPECT_CALL(observer_, |
| 317 OnSourceMoved(combined_list_.get(), 2 * kDefaultSourceCount - 1, | 318 OnSourceMoved(combined_list_.get(), 2 * kDefaultSourceCount - 1, |
| 318 2 * kDefaultSourceCount - 2)) | 319 2 * kDefaultSourceCount - 2)) |
| 319 .WillOnce(QuitMessageLoop(&message_loop_)); | 320 .WillOnce(QuitMessageLoop(&message_loop_)); |
| 320 | 321 |
| 321 list2_->Refresh(); | 322 list2_->Refresh(); |
| 322 message_loop_.Run(); | 323 base::RunLoop().Run(); |
| 323 } | 324 } |
| 324 | 325 |
| 325 TEST_F(CombinedDesktopMediaListTest, UpdateTitle) { | 326 TEST_F(CombinedDesktopMediaListTest, UpdateTitle) { |
| 326 InitializeAndVerify(); | 327 InitializeAndVerify(); |
| 327 | 328 |
| 328 // Change title. | 329 // Change title. |
| 329 list1_->RemoveFakeSource(kDefaultSourceCount - 1); | 330 list1_->RemoveFakeSource(kDefaultSourceCount - 1); |
| 330 list1_->AddFakeSource(kDefaultSourceCount - 1, | 331 list1_->AddFakeSource(kDefaultSourceCount - 1, |
| 331 base::UTF8ToUTF16("New test media"), | 332 base::UTF8ToUTF16("New test media"), |
| 332 kDefaultSourceCount - 1); | 333 kDefaultSourceCount - 1); |
| 333 | 334 |
| 334 EXPECT_CALL(observer_, OnSourceNameChanged(combined_list_.get(), | 335 EXPECT_CALL(observer_, OnSourceNameChanged(combined_list_.get(), |
| 335 kDefaultSourceCount - 1)) | 336 kDefaultSourceCount - 1)) |
| 336 .WillOnce(QuitMessageLoop(&message_loop_)); | 337 .WillOnce(QuitMessageLoop(&message_loop_)); |
| 337 | 338 |
| 338 list1_->Refresh(); | 339 list1_->Refresh(); |
| 339 message_loop_.Run(); | 340 base::RunLoop().Run(); |
| 340 | 341 |
| 341 // Change title. | 342 // Change title. |
| 342 list2_->RemoveFakeSource(kDefaultSourceCount - 1); | 343 list2_->RemoveFakeSource(kDefaultSourceCount - 1); |
| 343 list2_->AddFakeSource(kDefaultSourceCount - 1, | 344 list2_->AddFakeSource(kDefaultSourceCount - 1, |
| 344 base::UTF8ToUTF16("New test media"), | 345 base::UTF8ToUTF16("New test media"), |
| 345 kDefaultSourceCount - 1); | 346 kDefaultSourceCount - 1); |
| 346 | 347 |
| 347 EXPECT_CALL(observer_, OnSourceNameChanged(combined_list_.get(), | 348 EXPECT_CALL(observer_, OnSourceNameChanged(combined_list_.get(), |
| 348 2 * kDefaultSourceCount - 1)) | 349 2 * kDefaultSourceCount - 1)) |
| 349 .WillOnce(QuitMessageLoop(&message_loop_)); | 350 .WillOnce(QuitMessageLoop(&message_loop_)); |
| 350 | 351 |
| 351 list2_->Refresh(); | 352 list2_->Refresh(); |
| 352 message_loop_.Run(); | 353 base::RunLoop().Run(); |
| 353 | 354 |
| 354 EXPECT_EQ(combined_list_->GetSource(kDefaultSourceCount - 1).name, | 355 EXPECT_EQ(combined_list_->GetSource(kDefaultSourceCount - 1).name, |
| 355 base::UTF8ToUTF16("New test media")); | 356 base::UTF8ToUTF16("New test media")); |
| 356 EXPECT_EQ(combined_list_->GetSource(2 * kDefaultSourceCount - 1).name, | 357 EXPECT_EQ(combined_list_->GetSource(2 * kDefaultSourceCount - 1).name, |
| 357 base::UTF8ToUTF16("New test media")); | 358 base::UTF8ToUTF16("New test media")); |
| 358 } | 359 } |
| 359 | 360 |
| 360 TEST_F(CombinedDesktopMediaListTest, UpdateThumbnail) { | 361 TEST_F(CombinedDesktopMediaListTest, UpdateThumbnail) { |
| 361 InitializeAndVerify(); | 362 InitializeAndVerify(); |
| 362 | 363 |
| 363 // Change thumbnail. | 364 // Change thumbnail. |
| 364 list1_->RemoveFakeSource(kDefaultSourceCount - 1); | 365 list1_->RemoveFakeSource(kDefaultSourceCount - 1); |
| 365 list1_->AddFakeSource(kDefaultSourceCount - 1, | 366 list1_->AddFakeSource(kDefaultSourceCount - 1, |
| 366 base::UTF8ToUTF16("Test media"), 100); | 367 base::UTF8ToUTF16("Test media"), 100); |
| 367 | 368 |
| 368 EXPECT_CALL(observer_, OnSourceThumbnailChanged(combined_list_.get(), | 369 EXPECT_CALL(observer_, OnSourceThumbnailChanged(combined_list_.get(), |
| 369 kDefaultSourceCount - 1)) | 370 kDefaultSourceCount - 1)) |
| 370 .WillOnce(QuitMessageLoop(&message_loop_)); | 371 .WillOnce(QuitMessageLoop(&message_loop_)); |
| 371 | 372 |
| 372 list1_->Refresh(); | 373 list1_->Refresh(); |
| 373 message_loop_.Run(); | 374 base::RunLoop().Run(); |
| 374 | 375 |
| 375 // Change thumbnail. | 376 // Change thumbnail. |
| 376 list2_->RemoveFakeSource(kDefaultSourceCount - 1); | 377 list2_->RemoveFakeSource(kDefaultSourceCount - 1); |
| 377 list2_->AddFakeSource(kDefaultSourceCount - 1, | 378 list2_->AddFakeSource(kDefaultSourceCount - 1, |
| 378 base::UTF8ToUTF16("Test media"), 100); | 379 base::UTF8ToUTF16("Test media"), 100); |
| 379 | 380 |
| 380 EXPECT_CALL(observer_, OnSourceThumbnailChanged(combined_list_.get(), | 381 EXPECT_CALL(observer_, OnSourceThumbnailChanged(combined_list_.get(), |
| 381 2 * kDefaultSourceCount - 1)) | 382 2 * kDefaultSourceCount - 1)) |
| 382 .WillOnce(QuitMessageLoop(&message_loop_)); | 383 .WillOnce(QuitMessageLoop(&message_loop_)); |
| 383 | 384 |
| 384 list2_->Refresh(); | 385 list2_->Refresh(); |
| 385 message_loop_.Run(); | 386 base::RunLoop().Run(); |
| 386 } | 387 } |
| OLD | NEW |