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

Side by Side Diff: media/audio/audio_output_controller_unittest.cc

Issue 9858007: Fix a couple of regressions that made it in before the weekend. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix media tests Created 8 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « media/audio/audio_output_controller.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/environment.h" 6 #include "base/environment.h"
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/message_loop.h"
9 #include "base/synchronization/waitable_event.h" 10 #include "base/synchronization/waitable_event.h"
10 #include "media/audio/audio_output_controller.h" 11 #include "media/audio/audio_output_controller.h"
11 #include "testing/gmock/include/gmock/gmock.h" 12 #include "testing/gmock/include/gmock/gmock.h"
12 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
13 14
14 // TODO(vrk): These tests need to be rewritten! (crbug.com/112500) 15 // TODO(vrk): These tests need to be rewritten! (crbug.com/112500)
15 16
16 using ::testing::_; 17 using ::testing::_;
17 using ::testing::AtLeast; 18 using ::testing::AtLeast;
18 using ::testing::DoAll; 19 using ::testing::DoAll;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 private: 59 private:
59 DISALLOW_COPY_AND_ASSIGN(MockAudioOutputControllerSyncReader); 60 DISALLOW_COPY_AND_ASSIGN(MockAudioOutputControllerSyncReader);
60 }; 61 };
61 62
62 ACTION_P(SignalEvent, event) { 63 ACTION_P(SignalEvent, event) {
63 event->Signal(); 64 event->Signal();
64 } 65 }
65 66
66 // Closes AudioOutputController synchronously. 67 // Closes AudioOutputController synchronously.
67 static void CloseAudioController(AudioOutputController* controller) { 68 static void CloseAudioController(AudioOutputController* controller) {
68 base::WaitableEvent closed_event(true, false); 69 controller->Close(MessageLoop::QuitClosure());
69 controller->Close(base::Bind(&base::WaitableEvent::Signal, 70 MessageLoop::current()->Run();
70 base::Unretained(&closed_event)));
71 closed_event.Wait();
72 } 71 }
73 72
74 TEST(AudioOutputControllerTest, CreateAndClose) { 73 class AudioOutputControllerTest : public testing::Test {
74 public:
75 AudioOutputControllerTest() {}
76 virtual ~AudioOutputControllerTest() {}
77
78 protected:
79 MessageLoopForIO message_loop_;
80
81 private:
82 DISALLOW_COPY_AND_ASSIGN(AudioOutputControllerTest);
83 };
84
85 TEST_F(AudioOutputControllerTest, CreateAndClose) {
75 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); 86 scoped_ptr<AudioManager> audio_manager(AudioManager::Create());
76 if (!audio_manager->HasAudioOutputDevices()) 87 if (!audio_manager->HasAudioOutputDevices())
77 return; 88 return;
78 89
79 MockAudioOutputControllerEventHandler event_handler; 90 MockAudioOutputControllerEventHandler event_handler;
80 91
81 EXPECT_CALL(event_handler, OnCreated(NotNull())) 92 EXPECT_CALL(event_handler, OnCreated(NotNull()))
82 .Times(1); 93 .Times(1);
83 94
84 MockAudioOutputControllerSyncReader sync_reader; 95 MockAudioOutputControllerSyncReader sync_reader;
85 EXPECT_CALL(sync_reader, Close()); 96 EXPECT_CALL(sync_reader, Close());
86 97
87 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, 98 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout,
88 kSampleRate, kBitsPerSample, kSamplesPerPacket); 99 kSampleRate, kBitsPerSample, kSamplesPerPacket);
89 scoped_refptr<AudioOutputController> controller = 100 scoped_refptr<AudioOutputController> controller =
90 AudioOutputController::Create( 101 AudioOutputController::Create(
91 audio_manager.get(), &event_handler, params, &sync_reader); 102 audio_manager.get(), &event_handler, params, &sync_reader);
92 ASSERT_TRUE(controller.get()); 103 ASSERT_TRUE(controller.get());
93 104
94 // Close the controller immediately. 105 // Close the controller immediately.
95 CloseAudioController(controller); 106 CloseAudioController(controller);
96 } 107 }
97 108
98 TEST(AudioOutputControllerTest, PlayPauseClose) { 109 TEST_F(AudioOutputControllerTest, PlayPauseClose) {
99 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); 110 scoped_ptr<AudioManager> audio_manager(AudioManager::Create());
100 if (!audio_manager->HasAudioOutputDevices()) 111 if (!audio_manager->HasAudioOutputDevices())
101 return; 112 return;
102 113
103 MockAudioOutputControllerEventHandler event_handler; 114 MockAudioOutputControllerEventHandler event_handler;
104 base::WaitableEvent event(false, false); 115 base::WaitableEvent event(false, false);
105 base::WaitableEvent pause_event(false, false); 116 base::WaitableEvent pause_event(false, false);
106 117
107 // If OnCreated is called then signal the event. 118 // If OnCreated is called then signal the event.
108 EXPECT_CALL(event_handler, OnCreated(NotNull())) 119 EXPECT_CALL(event_handler, OnCreated(NotNull()))
109 .WillOnce(InvokeWithoutArgs(&event, &base::WaitableEvent::Signal)); 120 .WillOnce(InvokeWithoutArgs(&event, &base::WaitableEvent::Signal));
110 121
111 // OnPlaying() will be called only once. 122 // OnPlaying() will be called only once.
112 EXPECT_CALL(event_handler, OnPlaying(NotNull())); 123 EXPECT_CALL(event_handler, OnPlaying(NotNull()));
113 124
114 MockAudioOutputControllerSyncReader sync_reader; 125 MockAudioOutputControllerSyncReader sync_reader;
115 EXPECT_CALL(sync_reader, UpdatePendingBytes(_)) 126 EXPECT_CALL(sync_reader, UpdatePendingBytes(_))
116 .Times(AtLeast(2)); 127 .Times(AtLeast(2));
117 EXPECT_CALL(sync_reader, Read(_, kHardwareBufferSize)) 128 EXPECT_CALL(sync_reader, Read(_, kHardwareBufferSize))
118 .WillRepeatedly(DoAll(SignalEvent(&event), 129 .WillRepeatedly(DoAll(SignalEvent(&event),
119 Return(4))); 130 Return(4)));
131 EXPECT_CALL(sync_reader, DataReady())
132 .WillRepeatedly(Return(true));
120 EXPECT_CALL(event_handler, OnPaused(NotNull())) 133 EXPECT_CALL(event_handler, OnPaused(NotNull()))
121 .WillOnce(InvokeWithoutArgs(&pause_event, &base::WaitableEvent::Signal)); 134 .WillOnce(InvokeWithoutArgs(&pause_event, &base::WaitableEvent::Signal));
122 EXPECT_CALL(sync_reader, Close()); 135 EXPECT_CALL(sync_reader, Close());
123 136
124 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, 137 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout,
125 kSampleRate, kBitsPerSample, kSamplesPerPacket); 138 kSampleRate, kBitsPerSample, kSamplesPerPacket);
126 scoped_refptr<AudioOutputController> controller = 139 scoped_refptr<AudioOutputController> controller =
127 AudioOutputController::Create( 140 AudioOutputController::Create(
128 audio_manager.get(), &event_handler, params, &sync_reader); 141 audio_manager.get(), &event_handler, params, &sync_reader);
129 ASSERT_TRUE(controller.get()); 142 ASSERT_TRUE(controller.get());
130 143
131 // Wait for OnCreated() to be called. 144 // Wait for OnCreated() to be called.
132 event.Wait(); 145 event.Wait();
133 146
134 ASSERT_FALSE(pause_event.IsSignaled()); 147 ASSERT_FALSE(pause_event.IsSignaled());
135 controller->Play(); 148 controller->Play();
136 controller->Pause(); 149 controller->Pause();
137 pause_event.Wait(); 150 pause_event.Wait();
138 151
139 // Now stop the controller. 152 // Now stop the controller.
140 CloseAudioController(controller); 153 CloseAudioController(controller);
141 } 154 }
142 155
143 156
144 TEST(AudioOutputControllerTest, HardwareBufferTooLarge) { 157 TEST_F(AudioOutputControllerTest, HardwareBufferTooLarge) {
145 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); 158 scoped_ptr<AudioManager> audio_manager(AudioManager::Create());
146 if (!audio_manager->HasAudioOutputDevices()) 159 if (!audio_manager->HasAudioOutputDevices())
147 return; 160 return;
148 161
149 // Create an audio device with a very large hardware buffer size. 162 // Create an audio device with a very large hardware buffer size.
150 MockAudioOutputControllerEventHandler event_handler; 163 MockAudioOutputControllerEventHandler event_handler;
151 164
152 MockAudioOutputControllerSyncReader sync_reader; 165 MockAudioOutputControllerSyncReader sync_reader;
153 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, 166 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout,
154 kSampleRate, kBitsPerSample, 167 kSampleRate, kBitsPerSample,
155 kSamplesPerPacket * 1000); 168 kSamplesPerPacket * 1000);
156 scoped_refptr<AudioOutputController> controller = 169 scoped_refptr<AudioOutputController> controller =
157 AudioOutputController::Create( 170 AudioOutputController::Create(
158 audio_manager.get(), &event_handler, params, &sync_reader); 171 audio_manager.get(), &event_handler, params, &sync_reader);
159 172
160 // Use assert because we don't stop the device and assume we can't 173 // Use assert because we don't stop the device and assume we can't
161 // create one. 174 // create one.
162 ASSERT_FALSE(controller); 175 ASSERT_FALSE(controller);
163 } 176 }
164 177
165 } // namespace media 178 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/audio_output_controller.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698