| 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/desktop_media_list_ash.h" | |
| 6 | |
| 7 #include "ash/test/ash_test_base.h" | |
| 8 #include "base/location.h" | |
| 9 #include "base/macros.h" | |
| 10 #include "base/message_loop/message_loop.h" | |
| 11 #include "base/single_thread_task_runner.h" | |
| 12 #include "base/threading/thread_task_runner_handle.h" | |
| 13 #include "build/build_config.h" | |
| 14 #include "chrome/browser/media/desktop_media_list_observer.h" | |
| 15 #include "testing/gmock/include/gmock/gmock.h" | |
| 16 #include "testing/gtest/include/gtest/gtest.h" | |
| 17 #include "ui/aura/window.h" | |
| 18 | |
| 19 int kThumbnailSize = 100; | |
| 20 | |
| 21 using testing::AtLeast; | |
| 22 using testing::DoDefault; | |
| 23 | |
| 24 class MockDesktopMediaListObserver : public DesktopMediaListObserver { | |
| 25 public: | |
| 26 MOCK_METHOD2(OnSourceAdded, void(DesktopMediaList* list, int index)); | |
| 27 MOCK_METHOD2(OnSourceRemoved, void(DesktopMediaList* list, int index)); | |
| 28 MOCK_METHOD3(OnSourceMoved, | |
| 29 void(DesktopMediaList* list, int old_index, int new_index)); | |
| 30 MOCK_METHOD2(OnSourceNameChanged, void(DesktopMediaList* list, int index)); | |
| 31 MOCK_METHOD2(OnSourceThumbnailChanged, | |
| 32 void(DesktopMediaList* list, int index)); | |
| 33 }; | |
| 34 | |
| 35 class DesktopMediaListAshTest : public ash::test::AshTestBase { | |
| 36 public: | |
| 37 DesktopMediaListAshTest() {} | |
| 38 ~DesktopMediaListAshTest() override {} | |
| 39 | |
| 40 void CreateList(int source_types) { | |
| 41 list_.reset(new DesktopMediaListAsh(source_types)); | |
| 42 list_->SetThumbnailSize(gfx::Size(kThumbnailSize, kThumbnailSize)); | |
| 43 | |
| 44 // Set update period to reduce the time it takes to run tests. | |
| 45 list_->SetUpdatePeriod(base::TimeDelta::FromMilliseconds(1)); | |
| 46 } | |
| 47 | |
| 48 protected: | |
| 49 MockDesktopMediaListObserver observer_; | |
| 50 std::unique_ptr<DesktopMediaListAsh> list_; | |
| 51 DISALLOW_COPY_AND_ASSIGN(DesktopMediaListAshTest); | |
| 52 }; | |
| 53 | |
| 54 ACTION(QuitMessageLoop) { | |
| 55 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
| 56 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); | |
| 57 } | |
| 58 | |
| 59 TEST_F(DesktopMediaListAshTest, Screen) { | |
| 60 CreateList(DesktopMediaListAsh::SCREENS | DesktopMediaListAsh::WINDOWS); | |
| 61 | |
| 62 EXPECT_CALL(observer_, OnSourceAdded(list_.get(), 0)); | |
| 63 EXPECT_CALL(observer_, OnSourceThumbnailChanged(list_.get(), 0)) | |
| 64 .WillOnce(QuitMessageLoop()) | |
| 65 .WillRepeatedly(DoDefault()); | |
| 66 list_->StartUpdating(&observer_); | |
| 67 base::MessageLoop::current()->Run(); | |
| 68 } | |
| 69 | |
| 70 TEST_F(DesktopMediaListAshTest, OneWindow) { | |
| 71 CreateList(DesktopMediaListAsh::SCREENS | DesktopMediaListAsh::WINDOWS); | |
| 72 | |
| 73 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); | |
| 74 | |
| 75 EXPECT_CALL(observer_, OnSourceAdded(list_.get(), 0)); | |
| 76 EXPECT_CALL(observer_, OnSourceAdded(list_.get(), 1)); | |
| 77 EXPECT_CALL(observer_, OnSourceThumbnailChanged(list_.get(), 0)) | |
| 78 .Times(AtLeast(1)); | |
| 79 EXPECT_CALL(observer_, OnSourceThumbnailChanged(list_.get(), 1)) | |
| 80 .WillOnce(QuitMessageLoop()) | |
| 81 .WillRepeatedly(DoDefault()); | |
| 82 EXPECT_CALL(observer_, OnSourceRemoved(list_.get(), 1)) | |
| 83 .WillOnce(QuitMessageLoop()); | |
| 84 | |
| 85 list_->StartUpdating(&observer_); | |
| 86 base::MessageLoop::current()->Run(); | |
| 87 window.reset(); | |
| 88 base::MessageLoop::current()->Run(); | |
| 89 } | |
| 90 | |
| 91 TEST_F(DesktopMediaListAshTest, ScreenOnly) { | |
| 92 CreateList(DesktopMediaListAsh::SCREENS); | |
| 93 | |
| 94 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); | |
| 95 | |
| 96 EXPECT_CALL(observer_, OnSourceAdded(list_.get(), 0)); | |
| 97 EXPECT_CALL(observer_, OnSourceThumbnailChanged(list_.get(), 0)) | |
| 98 .WillOnce(QuitMessageLoop()) | |
| 99 .WillRepeatedly(DoDefault()); | |
| 100 | |
| 101 list_->StartUpdating(&observer_); | |
| 102 base::MessageLoop::current()->Run(); | |
| 103 } | |
| 104 | |
| 105 // Times out on Win DrMemory bot. http://crbug.com/493187 | |
| 106 #if defined(OS_WIN) | |
| 107 #define MAYBE_WindowOnly DISABLED_WindowOnly | |
| 108 #else | |
| 109 #define MAYBE_WindowOnly WindowOnly | |
| 110 #endif | |
| 111 | |
| 112 TEST_F(DesktopMediaListAshTest, MAYBE_WindowOnly) { | |
| 113 CreateList(DesktopMediaListAsh::WINDOWS); | |
| 114 | |
| 115 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); | |
| 116 | |
| 117 EXPECT_CALL(observer_, OnSourceAdded(list_.get(), 0)); | |
| 118 EXPECT_CALL(observer_, OnSourceThumbnailChanged(list_.get(), 0)) | |
| 119 .WillOnce(QuitMessageLoop()) | |
| 120 .WillRepeatedly(DoDefault()); | |
| 121 EXPECT_CALL(observer_, OnSourceRemoved(list_.get(), 0)) | |
| 122 .WillOnce(QuitMessageLoop()); | |
| 123 | |
| 124 list_->StartUpdating(&observer_); | |
| 125 base::MessageLoop::current()->Run(); | |
| 126 window.reset(); | |
| 127 base::MessageLoop::current()->Run(); | |
| 128 } | |
| OLD | NEW |