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.
5 #include "chrome/browser/media/desktop_media_list_ash.h"
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"
14 int kThumbnailSize
= 100;
16 using testing::AtLeast
;
17 using testing::DoDefault
;
19 class MockDesktopMediaListObserver
: public DesktopMediaListObserver
{
21 MOCK_METHOD1(OnSourceAdded
, void(int index
));
22 MOCK_METHOD1(OnSourceRemoved
, void(int index
));
23 MOCK_METHOD2(OnSourceMoved
, void(int old_index
, int new_index
));
24 MOCK_METHOD1(OnSourceNameChanged
, void(int index
));
25 MOCK_METHOD1(OnSourceThumbnailChanged
, void(int index
));
28 class DesktopMediaListAshTest
: public ash::test::AshTestBase
{
30 DesktopMediaListAshTest() {}
31 ~DesktopMediaListAshTest() override
{}
33 void CreateList(int source_types
) {
34 list_
.reset(new DesktopMediaListAsh(source_types
));
35 list_
->SetThumbnailSize(gfx::Size(kThumbnailSize
, kThumbnailSize
));
37 // Set update period to reduce the time it takes to run tests.
38 list_
->SetUpdatePeriod(base::TimeDelta::FromMilliseconds(1));
42 MockDesktopMediaListObserver observer_
;
43 scoped_ptr
<DesktopMediaListAsh
> list_
;
44 DISALLOW_COPY_AND_ASSIGN(DesktopMediaListAshTest
);
47 ACTION(QuitMessageLoop
) {
48 base::MessageLoop::current()->PostTask(
49 FROM_HERE
, base::MessageLoop::QuitClosure());
52 TEST_F(DesktopMediaListAshTest
, Screen
) {
53 CreateList(DesktopMediaListAsh::SCREENS
| DesktopMediaListAsh::WINDOWS
);
55 EXPECT_CALL(observer_
, OnSourceAdded(0));
56 EXPECT_CALL(observer_
, OnSourceThumbnailChanged(0))
57 .WillOnce(QuitMessageLoop())
58 .WillRepeatedly(DoDefault());
59 list_
->StartUpdating(&observer_
);
60 base::MessageLoop::current()->Run();
63 TEST_F(DesktopMediaListAshTest
, OneWindow
) {
64 CreateList(DesktopMediaListAsh::SCREENS
| DesktopMediaListAsh::WINDOWS
);
66 scoped_ptr
<aura::Window
> window(CreateTestWindowInShellWithId(0));
68 EXPECT_CALL(observer_
, OnSourceAdded(0));
69 EXPECT_CALL(observer_
, OnSourceAdded(1));
70 EXPECT_CALL(observer_
, OnSourceThumbnailChanged(0))
72 EXPECT_CALL(observer_
, OnSourceThumbnailChanged(1))
73 .WillOnce(QuitMessageLoop())
74 .WillRepeatedly(DoDefault());
75 EXPECT_CALL(observer_
, OnSourceRemoved(1))
76 .WillOnce(QuitMessageLoop());
78 list_
->StartUpdating(&observer_
);
79 base::MessageLoop::current()->Run();
81 base::MessageLoop::current()->Run();
84 TEST_F(DesktopMediaListAshTest
, ScreenOnly
) {
85 CreateList(DesktopMediaListAsh::SCREENS
);
87 scoped_ptr
<aura::Window
> window(CreateTestWindowInShellWithId(0));
89 EXPECT_CALL(observer_
, OnSourceAdded(0));
90 EXPECT_CALL(observer_
, OnSourceThumbnailChanged(0))
91 .WillOnce(QuitMessageLoop())
92 .WillRepeatedly(DoDefault());
94 list_
->StartUpdating(&observer_
);
95 base::MessageLoop::current()->Run();
98 TEST_F(DesktopMediaListAshTest
, WindowOnly
) {
99 CreateList(DesktopMediaListAsh::WINDOWS
);
101 scoped_ptr
<aura::Window
> window(CreateTestWindowInShellWithId(0));
103 EXPECT_CALL(observer_
, OnSourceAdded(0));
104 EXPECT_CALL(observer_
, OnSourceThumbnailChanged(0))
105 .WillOnce(QuitMessageLoop())
106 .WillRepeatedly(DoDefault());
107 EXPECT_CALL(observer_
, OnSourceRemoved(0))
108 .WillOnce(QuitMessageLoop());
110 list_
->StartUpdating(&observer_
);
111 base::MessageLoop::current()->Run();
113 base::MessageLoop::current()->Run();