OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/media/ash_desktop_media_list.h" |
| 6 |
| 7 #include "ash/test/ash_test_base.h" |
| 8 #include "base/message_loop/message_loop.h" |
| 9 #include "chrome/browser/media/desktop_media_list_observer.h" |
| 10 #include "testing/gmock/include/gmock/gmock.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "ui/aura/window.h" |
| 13 #include "ui/compositor/test/test_context_factory.h" |
| 14 |
| 15 int kThumbnailSize = 100; |
| 16 |
| 17 class MockDesktopMediaListObserver : public DesktopMediaListObserver { |
| 18 public: |
| 19 MOCK_METHOD1(OnSourceAdded, void(int index)); |
| 20 MOCK_METHOD1(OnSourceRemoved, void(int index)); |
| 21 MOCK_METHOD1(OnSourceNameChanged, void(int index)); |
| 22 MOCK_METHOD1(OnSourceThumbnailChanged, void(int index)); |
| 23 }; |
| 24 |
| 25 |
| 26 class AshDesktopMediaListTest : public ash::test::AshTestBase { |
| 27 public: |
| 28 AshDesktopMediaListTest() {} |
| 29 virtual ~AshDesktopMediaListTest() {} |
| 30 |
| 31 void CreateList(int source_types) { |
| 32 list_.reset(new AshDesktopMediaList(source_types)); |
| 33 list_->SetUpdatePeriod(base::TimeDelta::FromMilliseconds(0)); |
| 34 list_->SetThumbnailSize(gfx::Size(kThumbnailSize, kThumbnailSize)); |
| 35 } |
| 36 |
| 37 protected: |
| 38 MockDesktopMediaListObserver observer_; |
| 39 scoped_ptr<AshDesktopMediaList> list_; |
| 40 DISALLOW_COPY_AND_ASSIGN(AshDesktopMediaListTest); |
| 41 }; |
| 42 |
| 43 ACTION(QuitMessageLoop) { |
| 44 base::MessageLoop::current()->PostTask( |
| 45 FROM_HERE, base::MessageLoop::QuitClosure()); |
| 46 } |
| 47 |
| 48 TEST_F(AshDesktopMediaListTest, Screen) { |
| 49 CreateList(AshDesktopMediaList::SCREENS | AshDesktopMediaList::WINDOWS); |
| 50 |
| 51 EXPECT_CALL(observer_, OnSourceAdded(0)) |
| 52 .WillOnce(QuitMessageLoop()); |
| 53 list_->StartUpdating(&observer_); |
| 54 base::MessageLoop::current()->Run(); |
| 55 } |
| 56 |
| 57 TEST_F(AshDesktopMediaListTest, OneWindow) { |
| 58 CreateList(AshDesktopMediaList::SCREENS | AshDesktopMediaList::WINDOWS); |
| 59 |
| 60 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); |
| 61 |
| 62 EXPECT_CALL(observer_, OnSourceAdded(0)); |
| 63 EXPECT_CALL(observer_, OnSourceAdded(1)) |
| 64 .WillOnce(QuitMessageLoop()); |
| 65 EXPECT_CALL(observer_, OnSourceRemoved(1)) |
| 66 .WillOnce(QuitMessageLoop()); |
| 67 |
| 68 list_->StartUpdating(&observer_); |
| 69 base::MessageLoop::current()->Run(); |
| 70 window.reset(); |
| 71 base::MessageLoop::current()->Run(); |
| 72 } |
| 73 |
| 74 TEST_F(AshDesktopMediaListTest, ScreenOnly) { |
| 75 CreateList(AshDesktopMediaList::SCREENS | AshDesktopMediaList::WINDOWS); |
| 76 |
| 77 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); |
| 78 |
| 79 EXPECT_CALL(observer_, OnSourceAdded(0)) |
| 80 .WillOnce(QuitMessageLoop()); |
| 81 |
| 82 list_->StartUpdating(&observer_); |
| 83 base::MessageLoop::current()->Run(); |
| 84 } |
| 85 |
| 86 TEST_F(AshDesktopMediaListTest, WindowOnly) { |
| 87 CreateList(AshDesktopMediaList::WINDOWS); |
| 88 |
| 89 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); |
| 90 |
| 91 EXPECT_CALL(observer_, OnSourceAdded(0)) |
| 92 .WillOnce(QuitMessageLoop()); |
| 93 EXPECT_CALL(observer_, OnSourceRemoved(0)) |
| 94 .WillOnce(QuitMessageLoop()); |
| 95 |
| 96 list_->StartUpdating(&observer_); |
| 97 base::MessageLoop::current()->Run(); |
| 98 window.reset(); |
| 99 base::MessageLoop::current()->Run(); |
| 100 } |
OLD | NEW |