Add ICU message format support
[chromium-blink-merge.git] / chrome / browser / media / desktop_media_list_ash_unittest.cc
blobd291dd2caaa94e42974f33bbbc956e6aaa398067
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/location.h"
9 #include "base/message_loop/message_loop.h"
10 #include "base/single_thread_task_runner.h"
11 #include "base/thread_task_runner_handle.h"
12 #include "chrome/browser/media/desktop_media_list_observer.h"
13 #include "testing/gmock/include/gmock/gmock.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "ui/aura/window.h"
17 int kThumbnailSize = 100;
19 using testing::AtLeast;
20 using testing::DoDefault;
22 class MockDesktopMediaListObserver : public DesktopMediaListObserver {
23 public:
24 MOCK_METHOD1(OnSourceAdded, void(int index));
25 MOCK_METHOD1(OnSourceRemoved, void(int index));
26 MOCK_METHOD2(OnSourceMoved, void(int old_index, int new_index));
27 MOCK_METHOD1(OnSourceNameChanged, void(int index));
28 MOCK_METHOD1(OnSourceThumbnailChanged, void(int index));
31 class DesktopMediaListAshTest : public ash::test::AshTestBase {
32 public:
33 DesktopMediaListAshTest() {}
34 ~DesktopMediaListAshTest() override {}
36 void CreateList(int source_types) {
37 list_.reset(new DesktopMediaListAsh(source_types));
38 list_->SetThumbnailSize(gfx::Size(kThumbnailSize, kThumbnailSize));
40 // Set update period to reduce the time it takes to run tests.
41 list_->SetUpdatePeriod(base::TimeDelta::FromMilliseconds(1));
44 protected:
45 MockDesktopMediaListObserver observer_;
46 scoped_ptr<DesktopMediaListAsh> list_;
47 DISALLOW_COPY_AND_ASSIGN(DesktopMediaListAshTest);
50 ACTION(QuitMessageLoop) {
51 base::ThreadTaskRunnerHandle::Get()->PostTask(
52 FROM_HERE, base::MessageLoop::QuitClosure());
55 TEST_F(DesktopMediaListAshTest, Screen) {
56 CreateList(DesktopMediaListAsh::SCREENS | DesktopMediaListAsh::WINDOWS);
58 EXPECT_CALL(observer_, OnSourceAdded(0));
59 EXPECT_CALL(observer_, OnSourceThumbnailChanged(0))
60 .WillOnce(QuitMessageLoop())
61 .WillRepeatedly(DoDefault());
62 list_->StartUpdating(&observer_);
63 base::MessageLoop::current()->Run();
66 TEST_F(DesktopMediaListAshTest, OneWindow) {
67 CreateList(DesktopMediaListAsh::SCREENS | DesktopMediaListAsh::WINDOWS);
69 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0));
71 EXPECT_CALL(observer_, OnSourceAdded(0));
72 EXPECT_CALL(observer_, OnSourceAdded(1));
73 EXPECT_CALL(observer_, OnSourceThumbnailChanged(0))
74 .Times(AtLeast(1));
75 EXPECT_CALL(observer_, OnSourceThumbnailChanged(1))
76 .WillOnce(QuitMessageLoop())
77 .WillRepeatedly(DoDefault());
78 EXPECT_CALL(observer_, OnSourceRemoved(1))
79 .WillOnce(QuitMessageLoop());
81 list_->StartUpdating(&observer_);
82 base::MessageLoop::current()->Run();
83 window.reset();
84 base::MessageLoop::current()->Run();
87 TEST_F(DesktopMediaListAshTest, ScreenOnly) {
88 CreateList(DesktopMediaListAsh::SCREENS);
90 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0));
92 EXPECT_CALL(observer_, OnSourceAdded(0));
93 EXPECT_CALL(observer_, OnSourceThumbnailChanged(0))
94 .WillOnce(QuitMessageLoop())
95 .WillRepeatedly(DoDefault());
97 list_->StartUpdating(&observer_);
98 base::MessageLoop::current()->Run();
101 // Times out on Win DrMemory bot. http://crbug.com/493187
102 #if defined(OS_WIN)
103 #define MAYBE_WindowOnly DISABLED_WindowOnly
104 #else
105 #define MAYBE_WindowOnly WindowOnly
106 #endif
108 TEST_F(DesktopMediaListAshTest, MAYBE_WindowOnly) {
109 CreateList(DesktopMediaListAsh::WINDOWS);
111 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0));
113 EXPECT_CALL(observer_, OnSourceAdded(0));
114 EXPECT_CALL(observer_, OnSourceThumbnailChanged(0))
115 .WillOnce(QuitMessageLoop())
116 .WillRepeatedly(DoDefault());
117 EXPECT_CALL(observer_, OnSourceRemoved(0))
118 .WillOnce(QuitMessageLoop());
120 list_->StartUpdating(&observer_);
121 base::MessageLoop::current()->Run();
122 window.reset();
123 base::MessageLoop::current()->Run();