Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(813)

Side by Side Diff: chrome/browser/media/desktop_media_list_ash_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698