| 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/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/macros.h" | 6 #include "base/macros.h" |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "base/synchronization/waitable_event.h" | 9 #include "base/synchronization/waitable_event.h" |
| 10 #include "base/test/test_timeouts.h" | 10 #include "base/test/test_timeouts.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 const std::string& message)); | 61 const std::string& message)); |
| 62 | 62 |
| 63 private: | 63 private: |
| 64 DISALLOW_COPY_AND_ASSIGN(MockAudioInputControllerEventHandler); | 64 DISALLOW_COPY_AND_ASSIGN(MockAudioInputControllerEventHandler); |
| 65 }; | 65 }; |
| 66 | 66 |
| 67 class MockSyncWriter : public AudioInputController::SyncWriter { | 67 class MockSyncWriter : public AudioInputController::SyncWriter { |
| 68 public: | 68 public: |
| 69 MockSyncWriter() {} | 69 MockSyncWriter() {} |
| 70 | 70 |
| 71 MOCK_METHOD4(Write, | 71 MOCK_METHOD5(Write, |
| 72 void(const AudioBus* data, | 72 void(const AudioBus* data, |
| 73 double volume, | 73 double volume, |
| 74 bool key_pressed, | 74 bool key_pressed, |
| 75 uint32_t hardware_delay_bytes)); | 75 base::TimeDelta delay, |
| 76 base::TimeTicks delay_timestamp)); |
| 76 MOCK_METHOD0(Close, void()); | 77 MOCK_METHOD0(Close, void()); |
| 77 }; | 78 }; |
| 78 | 79 |
| 79 // Test fixture. | 80 // Test fixture. |
| 80 class AudioInputControllerTest : public testing::Test { | 81 class AudioInputControllerTest : public testing::Test { |
| 81 public: | 82 public: |
| 82 AudioInputControllerTest() | 83 AudioInputControllerTest() |
| 83 : audio_thread_("AudioThread"), | 84 : audio_thread_("AudioThread"), |
| 84 suspend_event_(WaitableEvent::ResetPolicy::AUTOMATIC, | 85 suspend_event_(WaitableEvent::ResetPolicy::AUTOMATIC, |
| 85 WaitableEvent::InitialState::NOT_SIGNALED) { | 86 WaitableEvent::InitialState::NOT_SIGNALED) { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 TEST_F(AudioInputControllerTest, RecordAndClose) { | 151 TEST_F(AudioInputControllerTest, RecordAndClose) { |
| 151 MockAudioInputControllerEventHandler event_handler; | 152 MockAudioInputControllerEventHandler event_handler; |
| 152 MockSyncWriter sync_writer; | 153 MockSyncWriter sync_writer; |
| 153 int count = 0; | 154 int count = 0; |
| 154 | 155 |
| 155 // OnCreated() will be called once. | 156 // OnCreated() will be called once. |
| 156 EXPECT_CALL(event_handler, OnCreated(NotNull())) | 157 EXPECT_CALL(event_handler, OnCreated(NotNull())) |
| 157 .Times(Exactly(1)); | 158 .Times(Exactly(1)); |
| 158 | 159 |
| 159 // Write() should be called ten times. | 160 // Write() should be called ten times. |
| 160 EXPECT_CALL(sync_writer, Write(NotNull(), _, _, _)) | 161 EXPECT_CALL(sync_writer, Write(NotNull(), _, _, _, _)) |
| 161 .Times(AtLeast(10)) | 162 .Times(AtLeast(10)) |
| 162 .WillRepeatedly( | 163 .WillRepeatedly( |
| 163 CheckCountAndPostQuitTask(&count, 10, message_loop_.task_runner())); | 164 CheckCountAndPostQuitTask(&count, 10, message_loop_.task_runner())); |
| 164 | 165 |
| 165 EXPECT_CALL(event_handler, OnLog(_, _)).Times(AnyNumber()); | 166 EXPECT_CALL(event_handler, OnLog(_, _)).Times(AnyNumber()); |
| 166 EXPECT_CALL(sync_writer, Close()).Times(Exactly(1)); | 167 EXPECT_CALL(sync_writer, Close()).Times(Exactly(1)); |
| 167 | 168 |
| 168 AudioParameters params(AudioParameters::AUDIO_FAKE, kChannelLayout, | 169 AudioParameters params(AudioParameters::AUDIO_FAKE, kChannelLayout, |
| 169 kSampleRate, kBitsPerSample, kSamplesPerPacket); | 170 kSampleRate, kBitsPerSample, kSamplesPerPacket); |
| 170 | 171 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 controller->Record(); | 226 controller->Record(); |
| 226 | 227 |
| 227 controller->Close(base::MessageLoop::QuitWhenIdleClosure()); | 228 controller->Close(base::MessageLoop::QuitWhenIdleClosure()); |
| 228 base::RunLoop().Run(); | 229 base::RunLoop().Run(); |
| 229 | 230 |
| 230 controller->Close(base::MessageLoop::QuitWhenIdleClosure()); | 231 controller->Close(base::MessageLoop::QuitWhenIdleClosure()); |
| 231 base::RunLoop().Run(); | 232 base::RunLoop().Run(); |
| 232 } | 233 } |
| 233 | 234 |
| 234 } // namespace media | 235 } // namespace media |
| OLD | NEW |