OLD | NEW |
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/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/bind.h" | 6 #include "base/bind.h" |
7 #include "base/environment.h" | 7 #include "base/environment.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 private: | 46 private: |
47 DISALLOW_COPY_AND_ASSIGN(MockAudioOutputControllerEventHandler); | 47 DISALLOW_COPY_AND_ASSIGN(MockAudioOutputControllerEventHandler); |
48 }; | 48 }; |
49 | 49 |
50 class MockAudioOutputControllerSyncReader | 50 class MockAudioOutputControllerSyncReader |
51 : public AudioOutputController::SyncReader { | 51 : public AudioOutputController::SyncReader { |
52 public: | 52 public: |
53 MockAudioOutputControllerSyncReader() {} | 53 MockAudioOutputControllerSyncReader() {} |
54 | 54 |
55 MOCK_METHOD1(UpdatePendingBytes, void(uint32 bytes)); | 55 MOCK_METHOD1(UpdatePendingBytes, void(uint32 bytes)); |
56 MOCK_METHOD2(Read, void(const AudioBus* source, AudioBus* dest)); | 56 MOCK_METHOD1(Read, void(AudioBus* dest)); |
57 MOCK_METHOD0(Close, void()); | 57 MOCK_METHOD0(Close, void()); |
58 | 58 |
59 private: | 59 private: |
60 DISALLOW_COPY_AND_ASSIGN(MockAudioOutputControllerSyncReader); | 60 DISALLOW_COPY_AND_ASSIGN(MockAudioOutputControllerSyncReader); |
61 }; | 61 }; |
62 | 62 |
63 class MockAudioOutputStream : public AudioOutputStream { | 63 class MockAudioOutputStream : public AudioOutputStream { |
64 public: | 64 public: |
65 MOCK_METHOD0(Open, bool()); | 65 MOCK_METHOD0(Open, bool()); |
66 MOCK_METHOD1(Start, void(AudioSourceCallback* callback)); | 66 MOCK_METHOD1(Start, void(AudioSourceCallback* callback)); |
67 MOCK_METHOD0(Stop, void()); | 67 MOCK_METHOD0(Stop, void()); |
68 MOCK_METHOD1(SetVolume, void(double volume)); | 68 MOCK_METHOD1(SetVolume, void(double volume)); |
69 MOCK_METHOD1(GetVolume, void(double* volume)); | 69 MOCK_METHOD1(GetVolume, void(double* volume)); |
70 MOCK_METHOD0(Close, void()); | 70 MOCK_METHOD0(Close, void()); |
71 | 71 |
72 // Set/get the callback passed to Start(). | 72 // Set/get the callback passed to Start(). |
73 AudioSourceCallback* callback() const { return callback_; } | 73 AudioSourceCallback* callback() const { return callback_; } |
74 void SetCallback(AudioSourceCallback* asc) { callback_ = asc; } | 74 void SetCallback(AudioSourceCallback* asc) { callback_ = asc; } |
75 | 75 |
76 private: | 76 private: |
77 AudioSourceCallback* callback_; | 77 AudioSourceCallback* callback_; |
78 }; | 78 }; |
79 | 79 |
80 ACTION_P(SignalEvent, event) { | 80 ACTION_P(SignalEvent, event) { |
81 event->Signal(); | 81 event->Signal(); |
82 } | 82 } |
83 | 83 |
84 static const float kBufferNonZeroData = 1.0f; | 84 static const float kBufferNonZeroData = 1.0f; |
85 ACTION(PopulateBuffer) { | 85 ACTION(PopulateBuffer) { |
86 arg1->Zero(); | 86 arg0->Zero(); |
87 // Note: To confirm the buffer will be populated in these tests, it's | 87 // Note: To confirm the buffer will be populated in these tests, it's |
88 // sufficient that only the first float in channel 0 is set to the value. | 88 // sufficient that only the first float in channel 0 is set to the value. |
89 arg1->channel(0)[0] = kBufferNonZeroData; | 89 arg0->channel(0)[0] = kBufferNonZeroData; |
90 } | 90 } |
91 | 91 |
92 class AudioOutputControllerTest : public testing::Test { | 92 class AudioOutputControllerTest : public testing::Test { |
93 public: | 93 public: |
94 AudioOutputControllerTest() | 94 AudioOutputControllerTest() |
95 : audio_manager_(AudioManager::CreateForTesting()), | 95 : audio_manager_(AudioManager::CreateForTesting()), |
96 create_event_(false, false), | 96 create_event_(false, false), |
97 play_event_(false, false), | 97 play_event_(false, false), |
98 read_event_(false, false), | 98 read_event_(false, false), |
99 pause_event_(false, false) { | 99 pause_event_(false, false) { |
(...skipping 29 matching lines...) Expand all Loading... |
129 | 129 |
130 void Play() { | 130 void Play() { |
131 // Expect the event handler to receive one OnPlaying() call. | 131 // Expect the event handler to receive one OnPlaying() call. |
132 EXPECT_CALL(mock_event_handler_, OnPlaying()) | 132 EXPECT_CALL(mock_event_handler_, OnPlaying()) |
133 .WillOnce(SignalEvent(&play_event_)); | 133 .WillOnce(SignalEvent(&play_event_)); |
134 | 134 |
135 // During playback, the mock pretends to provide audio data rendered and | 135 // During playback, the mock pretends to provide audio data rendered and |
136 // sent from the render process. | 136 // sent from the render process. |
137 EXPECT_CALL(mock_sync_reader_, UpdatePendingBytes(_)) | 137 EXPECT_CALL(mock_sync_reader_, UpdatePendingBytes(_)) |
138 .Times(AtLeast(1)); | 138 .Times(AtLeast(1)); |
139 EXPECT_CALL(mock_sync_reader_, Read(_, _)) | 139 EXPECT_CALL(mock_sync_reader_, Read(_)) |
140 .WillRepeatedly(DoAll(PopulateBuffer(), | 140 .WillRepeatedly(DoAll(PopulateBuffer(), |
141 SignalEvent(&read_event_))); | 141 SignalEvent(&read_event_))); |
142 controller_->Play(); | 142 controller_->Play(); |
143 } | 143 } |
144 | 144 |
145 void Pause() { | 145 void Pause() { |
146 // Expect the event handler to receive one OnPaused() call. | 146 // Expect the event handler to receive one OnPaused() call. |
147 EXPECT_CALL(mock_event_handler_, OnPaused()) | 147 EXPECT_CALL(mock_event_handler_, OnPaused()) |
148 .WillOnce(SignalEvent(&pause_event_)); | 148 .WillOnce(SignalEvent(&pause_event_)); |
149 | 149 |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 | 405 |
406 TEST_F(AudioOutputControllerTest, DivertRevertClose) { | 406 TEST_F(AudioOutputControllerTest, DivertRevertClose) { |
407 Create(kSamplesPerPacket); | 407 Create(kSamplesPerPacket); |
408 WaitForCreate(); | 408 WaitForCreate(); |
409 DivertNeverPlaying(); | 409 DivertNeverPlaying(); |
410 RevertWasNotPlaying(); | 410 RevertWasNotPlaying(); |
411 Close(); | 411 Close(); |
412 } | 412 } |
413 | 413 |
414 } // namespace media | 414 } // namespace media |
OLD | NEW |