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/message_loop.h" | 6 #include "base/message_loop.h" |
7 #include "base/time.h" | 7 #include "base/time.h" |
8 #include "media/audio/audio_buffers_state.h" | 8 #include "media/audio/audio_buffers_state.h" |
9 #include "media/audio/fake_audio_consumer.h" | 9 #include "media/audio/fake_audio_consumer.h" |
10 #include "media/audio/simple_sources.h" | 10 #include "media/audio/simple_sources.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 ASSERT_TRUE(message_loop_.message_loop_proxy()->BelongsToCurrentThread()); | 51 ASSERT_TRUE(message_loop_.message_loop_proxy()->BelongsToCurrentThread()); |
52 fake_consumer_.Stop(); | 52 fake_consumer_.Stop(); |
53 RunOnAudioThread(); | 53 RunOnAudioThread(); |
54 } | 54 } |
55 | 55 |
56 void TimeCallbacksOnAudioThread(int callbacks) { | 56 void TimeCallbacksOnAudioThread(int callbacks) { |
57 ASSERT_TRUE(message_loop_.message_loop_proxy()->BelongsToCurrentThread()); | 57 ASSERT_TRUE(message_loop_.message_loop_proxy()->BelongsToCurrentThread()); |
58 | 58 |
59 if (source_.callbacks() == 0) { | 59 if (source_.callbacks() == 0) { |
60 RunOnAudioThread(); | 60 RunOnAudioThread(); |
61 start_time_ = base::Time::Now(); | 61 start_time_ = base::TimeTicks::Now(); |
62 } | 62 } |
63 | 63 |
64 // Keep going until we've seen the requested number of callbacks. | 64 // Keep going until we've seen the requested number of callbacks. |
65 if (source_.callbacks() < callbacks) { | 65 if (source_.callbacks() < callbacks) { |
66 message_loop_.PostDelayedTask(FROM_HERE, base::Bind( | 66 message_loop_.PostDelayedTask(FROM_HERE, base::Bind( |
67 &FakeAudioConsumerTest::TimeCallbacksOnAudioThread, | 67 &FakeAudioConsumerTest::TimeCallbacksOnAudioThread, |
68 base::Unretained(this), callbacks), time_between_callbacks_ / 2); | 68 base::Unretained(this), callbacks), time_between_callbacks_ / 2); |
69 } else { | 69 } else { |
70 end_time_ = base::Time::Now(); | 70 end_time_ = base::TimeTicks::Now(); |
71 EndTest(callbacks); | 71 EndTest(callbacks); |
72 } | 72 } |
73 } | 73 } |
74 | 74 |
75 void EndTest(int callbacks) { | 75 void EndTest(int callbacks) { |
76 ASSERT_TRUE(message_loop_.message_loop_proxy()->BelongsToCurrentThread()); | 76 ASSERT_TRUE(message_loop_.message_loop_proxy()->BelongsToCurrentThread()); |
77 fake_consumer_.Stop(); | 77 fake_consumer_.Stop(); |
78 EXPECT_LE(callbacks, source_.callbacks()); | 78 EXPECT_LE(callbacks, source_.callbacks()); |
79 message_loop_.PostTask(FROM_HERE, base::MessageLoop::QuitClosure()); | 79 message_loop_.PostTask(FROM_HERE, base::MessageLoop::QuitClosure()); |
80 } | 80 } |
81 | 81 |
82 protected: | 82 protected: |
83 base::MessageLoop message_loop_; | 83 base::MessageLoop message_loop_; |
84 AudioParameters params_; | 84 AudioParameters params_; |
85 FakeAudioConsumer fake_consumer_; | 85 FakeAudioConsumer fake_consumer_; |
86 SineWaveAudioSource source_; | 86 SineWaveAudioSource source_; |
87 base::Time start_time_; | 87 base::TimeTicks start_time_; |
88 base::Time end_time_; | 88 base::TimeTicks end_time_; |
89 base::TimeDelta time_between_callbacks_; | 89 base::TimeDelta time_between_callbacks_; |
90 | 90 |
91 private: | 91 private: |
92 DISALLOW_COPY_AND_ASSIGN(FakeAudioConsumerTest); | 92 DISALLOW_COPY_AND_ASSIGN(FakeAudioConsumerTest); |
93 }; | 93 }; |
94 | 94 |
95 // Ensure the fake audio stream runs on the audio thread and handles fires | 95 // Ensure the fake audio stream runs on the audio thread and handles fires |
96 // callbacks to the AudioSourceCallback. | 96 // callbacks to the AudioSourceCallback. |
97 TEST_F(FakeAudioConsumerTest, FakeStreamBasicCallback) { | 97 TEST_F(FakeAudioConsumerTest, FakeStreamBasicCallback) { |
98 message_loop_.PostTask(FROM_HERE, base::Bind( | 98 message_loop_.PostTask(FROM_HERE, base::Bind( |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 // chance of catching the FakeAudioOutputStream doing the wrong thing. | 133 // chance of catching the FakeAudioOutputStream doing the wrong thing. |
134 message_loop_.PostDelayedTask(FROM_HERE, base::Bind( | 134 message_loop_.PostDelayedTask(FROM_HERE, base::Bind( |
135 &FakeAudioConsumerTest::StopStartOnAudioThread, | 135 &FakeAudioConsumerTest::StopStartOnAudioThread, |
136 base::Unretained(this)), time_between_callbacks_ / 2); | 136 base::Unretained(this)), time_between_callbacks_ / 2); |
137 | 137 |
138 // EndTest() will ensure the proper number of callbacks have occurred. | 138 // EndTest() will ensure the proper number of callbacks have occurred. |
139 message_loop_.Run(); | 139 message_loop_.Run(); |
140 } | 140 } |
141 | 141 |
142 } // namespace media | 142 } // namespace media |
OLD | NEW |