| 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/message_loop.h" | 6 #include "base/message_loop/message_loop.h" |
| 7 #include "base/time/time.h" | 7 #include "base/time/time.h" |
| 8 #include "media/audio/audio_parameters.h" | 8 #include "media/audio/audio_parameters.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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 message_loop_.PostTask(FROM_HERE, base::Bind( | 106 message_loop_.PostTask(FROM_HERE, base::Bind( |
| 107 &FakeAudioConsumerTest::TimeCallbacksOnAudioThread, | 107 &FakeAudioConsumerTest::TimeCallbacksOnAudioThread, |
| 108 base::Unretained(this), kTestCallbacks)); | 108 base::Unretained(this), kTestCallbacks)); |
| 109 message_loop_.Run(); | 109 message_loop_.Run(); |
| 110 | 110 |
| 111 // There are only (kTestCallbacks - 1) intervals between kTestCallbacks. | 111 // There are only (kTestCallbacks - 1) intervals between kTestCallbacks. |
| 112 base::TimeDelta actual_time_between_callbacks = | 112 base::TimeDelta actual_time_between_callbacks = |
| 113 (end_time_ - start_time_) / (source_.callbacks() - 1); | 113 (end_time_ - start_time_) / (source_.callbacks() - 1); |
| 114 | 114 |
| 115 // Ensure callback time is no faster than the expected time between callbacks. | 115 // Ensure callback time is no faster than the expected time between callbacks. |
| 116 EXPECT_TRUE(actual_time_between_callbacks >= time_between_callbacks_); | 116 EXPECT_GE(actual_time_between_callbacks, time_between_callbacks_); |
| 117 | 117 |
| 118 // Softly check if the callback time is no slower than twice the expected time | 118 // Softly check if the callback time is no slower than twice the expected time |
| 119 // between callbacks. Since this test runs on the bots we can't be too strict | 119 // between callbacks. Since this test runs on the bots we can't be too strict |
| 120 // with the bounds. | 120 // with the bounds. |
| 121 if (actual_time_between_callbacks > 2 * time_between_callbacks_) | 121 if (actual_time_between_callbacks > 2 * time_between_callbacks_) |
| 122 LOG(ERROR) << "Time between fake audio callbacks is too large!"; | 122 LOG(ERROR) << "Time between fake audio callbacks is too large!"; |
| 123 } | 123 } |
| 124 | 124 |
| 125 // Ensure Start()/Stop() on the stream doesn't generate too many callbacks. See | 125 // Ensure Start()/Stop() on the stream doesn't generate too many callbacks. See |
| 126 // http://crbug.com/159049 | 126 // http://crbug.com/159049 |
| 127 TEST_F(FakeAudioConsumerTest, StartStopClearsCallbacks) { | 127 TEST_F(FakeAudioConsumerTest, StartStopClearsCallbacks) { |
| 128 message_loop_.PostTask(FROM_HERE, base::Bind( | 128 message_loop_.PostTask(FROM_HERE, base::Bind( |
| 129 &FakeAudioConsumerTest::TimeCallbacksOnAudioThread, | 129 &FakeAudioConsumerTest::TimeCallbacksOnAudioThread, |
| 130 base::Unretained(this), kTestCallbacks)); | 130 base::Unretained(this), kTestCallbacks)); |
| 131 | 131 |
| 132 // Issue a Stop() / Start() in between expected callbacks to maximize the | 132 // Issue a Stop() / Start() in between expected callbacks to maximize the |
| 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 |