| 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/tab_desktop_media_list.h" | 5 #include "chrome/browser/media/tab_desktop_media_list.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 | 217 |
| 218 for (int i = 0; i < kDefaultSourceCount - 1; i++) { | 218 for (int i = 0; i < kDefaultSourceCount - 1; i++) { |
| 219 EXPECT_CALL(observer_, OnSourceThumbnailChanged( | 219 EXPECT_CALL(observer_, OnSourceThumbnailChanged( |
| 220 list_.get(), kDefaultSourceCount - 1 - i)); | 220 list_.get(), kDefaultSourceCount - 1 - i)); |
| 221 } | 221 } |
| 222 EXPECT_CALL(observer_, OnSourceThumbnailChanged(list_.get(), 0)) | 222 EXPECT_CALL(observer_, OnSourceThumbnailChanged(list_.get(), 0)) |
| 223 .WillOnce(QuitMessageLoop()); | 223 .WillOnce(QuitMessageLoop()); |
| 224 } | 224 } |
| 225 | 225 |
| 226 list_->StartUpdating(&observer_); | 226 list_->StartUpdating(&observer_); |
| 227 base::MessageLoop::current()->Run(); | 227 base::RunLoop().Run(); |
| 228 | 228 |
| 229 for (int i = 0; i < kDefaultSourceCount; ++i) { | 229 for (int i = 0; i < kDefaultSourceCount; ++i) { |
| 230 EXPECT_EQ(list_->GetSource(i).id.type, | 230 EXPECT_EQ(list_->GetSource(i).id.type, |
| 231 content::DesktopMediaID::TYPE_WEB_CONTENTS); | 231 content::DesktopMediaID::TYPE_WEB_CONTENTS); |
| 232 } | 232 } |
| 233 | 233 |
| 234 observer_.VerifyAndClearExpectations(); | 234 observer_.VerifyAndClearExpectations(); |
| 235 } | 235 } |
| 236 | 236 |
| 237 // The path to temporary directory used to contain the test operations. | 237 // The path to temporary directory used to contain the test operations. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 261 TEST_F(TabDesktopMediaListTest, AddTab) { | 261 TEST_F(TabDesktopMediaListTest, AddTab) { |
| 262 InitializeAndVerify(); | 262 InitializeAndVerify(); |
| 263 | 263 |
| 264 AddWebcontents(10); | 264 AddWebcontents(10); |
| 265 | 265 |
| 266 EXPECT_CALL(observer_, OnSourceAdded(list_.get(), 0)) | 266 EXPECT_CALL(observer_, OnSourceAdded(list_.get(), 0)) |
| 267 .WillOnce(CheckListSize(list_.get(), kDefaultSourceCount + 1)); | 267 .WillOnce(CheckListSize(list_.get(), kDefaultSourceCount + 1)); |
| 268 EXPECT_CALL(observer_, OnSourceThumbnailChanged(list_.get(), 0)) | 268 EXPECT_CALL(observer_, OnSourceThumbnailChanged(list_.get(), 0)) |
| 269 .WillOnce(QuitMessageLoop()); | 269 .WillOnce(QuitMessageLoop()); |
| 270 | 270 |
| 271 base::MessageLoop::current()->Run(); | 271 base::RunLoop().Run(); |
| 272 | 272 |
| 273 list_.reset(); | 273 list_.reset(); |
| 274 } | 274 } |
| 275 | 275 |
| 276 TEST_F(TabDesktopMediaListTest, RemoveTab) { | 276 TEST_F(TabDesktopMediaListTest, RemoveTab) { |
| 277 InitializeAndVerify(); | 277 InitializeAndVerify(); |
| 278 | 278 |
| 279 TabStripModel* tab_strip_model = browser_->tab_strip_model(); | 279 TabStripModel* tab_strip_model = browser_->tab_strip_model(); |
| 280 ASSERT_TRUE(tab_strip_model); | 280 ASSERT_TRUE(tab_strip_model); |
| 281 tab_strip_model->DetachWebContentsAt(kDefaultSourceCount - 1); | 281 tab_strip_model->DetachWebContentsAt(kDefaultSourceCount - 1); |
| 282 | 282 |
| 283 EXPECT_CALL(observer_, OnSourceRemoved(list_.get(), 0)) | 283 EXPECT_CALL(observer_, OnSourceRemoved(list_.get(), 0)) |
| 284 .WillOnce( | 284 .WillOnce( |
| 285 testing::DoAll(CheckListSize(list_.get(), kDefaultSourceCount - 1), | 285 testing::DoAll(CheckListSize(list_.get(), kDefaultSourceCount - 1), |
| 286 QuitMessageLoop())); | 286 QuitMessageLoop())); |
| 287 | 287 |
| 288 base::MessageLoop::current()->Run(); | 288 base::RunLoop().Run(); |
| 289 | 289 |
| 290 list_.reset(); | 290 list_.reset(); |
| 291 } | 291 } |
| 292 | 292 |
| 293 TEST_F(TabDesktopMediaListTest, MoveTab) { | 293 TEST_F(TabDesktopMediaListTest, MoveTab) { |
| 294 InitializeAndVerify(); | 294 InitializeAndVerify(); |
| 295 | 295 |
| 296 // Swap the two media sources by swap their time stamps. | 296 // Swap the two media sources by swap their time stamps. |
| 297 TabStripModel* tab_strip_model = browser_->tab_strip_model(); | 297 TabStripModel* tab_strip_model = browser_->tab_strip_model(); |
| 298 ASSERT_TRUE(tab_strip_model); | 298 ASSERT_TRUE(tab_strip_model); |
| 299 | 299 |
| 300 WebContents* contents0 = tab_strip_model->GetWebContentsAt(0); | 300 WebContents* contents0 = tab_strip_model->GetWebContentsAt(0); |
| 301 ASSERT_TRUE(contents0); | 301 ASSERT_TRUE(contents0); |
| 302 base::TimeTicks t0 = contents0->GetLastActiveTime(); | 302 base::TimeTicks t0 = contents0->GetLastActiveTime(); |
| 303 WebContents* contents1 = tab_strip_model->GetWebContentsAt(1); | 303 WebContents* contents1 = tab_strip_model->GetWebContentsAt(1); |
| 304 ASSERT_TRUE(contents1); | 304 ASSERT_TRUE(contents1); |
| 305 base::TimeTicks t1 = contents1->GetLastActiveTime(); | 305 base::TimeTicks t1 = contents1->GetLastActiveTime(); |
| 306 | 306 |
| 307 contents0->SetLastActiveTime(t1); | 307 contents0->SetLastActiveTime(t1); |
| 308 contents1->SetLastActiveTime(t0); | 308 contents1->SetLastActiveTime(t0); |
| 309 | 309 |
| 310 EXPECT_CALL(observer_, OnSourceMoved(list_.get(), 1, 0)) | 310 EXPECT_CALL(observer_, OnSourceMoved(list_.get(), 1, 0)) |
| 311 .WillOnce(testing::DoAll(CheckListSize(list_.get(), kDefaultSourceCount), | 311 .WillOnce(testing::DoAll(CheckListSize(list_.get(), kDefaultSourceCount), |
| 312 QuitMessageLoop())); | 312 QuitMessageLoop())); |
| 313 | 313 |
| 314 base::MessageLoop::current()->Run(); | 314 base::RunLoop().Run(); |
| 315 | 315 |
| 316 list_.reset(); | 316 list_.reset(); |
| 317 } | 317 } |
| 318 | 318 |
| 319 TEST_F(TabDesktopMediaListTest, UpdateTitle) { | 319 TEST_F(TabDesktopMediaListTest, UpdateTitle) { |
| 320 InitializeAndVerify(); | 320 InitializeAndVerify(); |
| 321 | 321 |
| 322 // Change tab's title. | 322 // Change tab's title. |
| 323 TabStripModel* tab_strip_model = browser_->tab_strip_model(); | 323 TabStripModel* tab_strip_model = browser_->tab_strip_model(); |
| 324 ASSERT_TRUE(tab_strip_model); | 324 ASSERT_TRUE(tab_strip_model); |
| 325 WebContents* contents = | 325 WebContents* contents = |
| 326 tab_strip_model->GetWebContentsAt(kDefaultSourceCount - 1); | 326 tab_strip_model->GetWebContentsAt(kDefaultSourceCount - 1); |
| 327 ASSERT_TRUE(contents); | 327 ASSERT_TRUE(contents); |
| 328 contents->GetController().GetTransientEntry()->SetTitle( | 328 contents->GetController().GetTransientEntry()->SetTitle( |
| 329 base::UTF8ToUTF16("New test tab")); | 329 base::UTF8ToUTF16("New test tab")); |
| 330 | 330 |
| 331 EXPECT_CALL(observer_, OnSourceNameChanged(list_.get(), 0)) | 331 EXPECT_CALL(observer_, OnSourceNameChanged(list_.get(), 0)) |
| 332 .WillOnce(QuitMessageLoop()); | 332 .WillOnce(QuitMessageLoop()); |
| 333 | 333 |
| 334 base::MessageLoop::current()->Run(); | 334 base::RunLoop().Run(); |
| 335 | 335 |
| 336 EXPECT_EQ(list_->GetSource(0).name, base::UTF8ToUTF16("New test tab")); | 336 EXPECT_EQ(list_->GetSource(0).name, base::UTF8ToUTF16("New test tab")); |
| 337 | 337 |
| 338 list_.reset(); | 338 list_.reset(); |
| 339 } | 339 } |
| 340 | 340 |
| 341 TEST_F(TabDesktopMediaListTest, UpdateThumbnail) { | 341 TEST_F(TabDesktopMediaListTest, UpdateThumbnail) { |
| 342 InitializeAndVerify(); | 342 InitializeAndVerify(); |
| 343 | 343 |
| 344 // Change tab's favicon. | 344 // Change tab's favicon. |
| 345 TabStripModel* tab_strip_model = browser_->tab_strip_model(); | 345 TabStripModel* tab_strip_model = browser_->tab_strip_model(); |
| 346 ASSERT_TRUE(tab_strip_model); | 346 ASSERT_TRUE(tab_strip_model); |
| 347 WebContents* contents = | 347 WebContents* contents = |
| 348 tab_strip_model->GetWebContentsAt(kDefaultSourceCount - 1); | 348 tab_strip_model->GetWebContentsAt(kDefaultSourceCount - 1); |
| 349 ASSERT_TRUE(contents); | 349 ASSERT_TRUE(contents); |
| 350 | 350 |
| 351 content::FaviconStatus favicon_info; | 351 content::FaviconStatus favicon_info; |
| 352 favicon_info.image = CreateGrayscaleImage(gfx::Size(10, 10), 100); | 352 favicon_info.image = CreateGrayscaleImage(gfx::Size(10, 10), 100); |
| 353 contents->GetController().GetTransientEntry()->GetFavicon() = favicon_info; | 353 contents->GetController().GetTransientEntry()->GetFavicon() = favicon_info; |
| 354 | 354 |
| 355 EXPECT_CALL(observer_, OnSourceThumbnailChanged(list_.get(), 0)) | 355 EXPECT_CALL(observer_, OnSourceThumbnailChanged(list_.get(), 0)) |
| 356 .WillOnce(QuitMessageLoop()); | 356 .WillOnce(QuitMessageLoop()); |
| 357 | 357 |
| 358 base::MessageLoop::current()->Run(); | 358 base::RunLoop().Run(); |
| 359 | 359 |
| 360 list_.reset(); | 360 list_.reset(); |
| 361 } | 361 } |
| OLD | NEW |