OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/message_loop.h" | 5 #include "base/message_loop.h" |
6 #include "base/process_util.h" | 6 #include "base/process_util.h" |
7 #include "base/scoped_ptr.h" | 7 #include "base/scoped_ptr.h" |
| 8 #include "chrome/browser/chrome_thread.h" |
8 #include "chrome/browser/renderer_host/audio_renderer_host.h" | 9 #include "chrome/browser/renderer_host/audio_renderer_host.h" |
9 #include "chrome/common/render_messages.h" | 10 #include "chrome/common/render_messages.h" |
10 #include "testing/gmock/include/gmock/gmock.h" | 11 #include "testing/gmock/include/gmock/gmock.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
12 | 13 |
13 using ::testing::_; | 14 using ::testing::_; |
14 using ::testing::DoAll; | 15 using ::testing::DoAll; |
15 using ::testing::InSequence; | 16 using ::testing::InSequence; |
16 using ::testing::Return; | 17 using ::testing::Return; |
17 using ::testing::SaveArg; | 18 using ::testing::SaveArg; |
18 using ::testing::SetArgumentPointee; | 19 using ::testing::SetArgumentPointee; |
19 | 20 |
20 namespace { | 21 namespace { |
21 | 22 |
22 const int kInvalidId = -1; | 23 const int kInvalidId = -1; |
23 const int kProcessId = 100; | 24 const int kProcessId = 100; |
24 const int kRouteId = 200; | 25 const int kRouteId = 200; |
25 const int kBufferCapacity = 65536; | 26 const int kBufferCapacity = 65536; |
26 const int kPacketSize = 16384; | 27 const int kPacketSize = 16384; |
27 | 28 |
28 } // namespace | 29 } // namespace |
29 | 30 |
30 class MockAudioRendererHost : public AudioRendererHost { | 31 class MockAudioRendererHost : public AudioRendererHost { |
31 public: | 32 public: |
32 MockAudioRendererHost(MessageLoop* loop) | 33 MockAudioRendererHost() |
33 : AudioRendererHost(loop) { | 34 : AudioRendererHost() { |
34 } | 35 } |
35 | 36 |
36 virtual ~MockAudioRendererHost() { | 37 virtual ~MockAudioRendererHost() { |
37 } | 38 } |
38 | 39 |
39 // A list of mock methods. | 40 // A list of mock methods. |
40 MOCK_METHOD4(OnRequestPacket, | 41 MOCK_METHOD4(OnRequestPacket, |
41 void(int routing_id, int stream_id, | 42 void(int routing_id, int stream_id, |
42 size_t bytes_in_buffer, int64 message_timestamp)); | 43 size_t bytes_in_buffer, int64 message_timestamp)); |
43 | 44 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 class AudioRendererHostTest : public testing::Test { | 114 class AudioRendererHostTest : public testing::Test { |
114 public: | 115 public: |
115 AudioRendererHostTest() | 116 AudioRendererHostTest() |
116 : current_stream_id_(0) { | 117 : current_stream_id_(0) { |
117 } | 118 } |
118 | 119 |
119 protected: | 120 protected: |
120 virtual void SetUp() { | 121 virtual void SetUp() { |
121 // Create a message loop so AudioRendererHost can use it. | 122 // Create a message loop so AudioRendererHost can use it. |
122 message_loop_.reset(new MessageLoop(MessageLoop::TYPE_IO)); | 123 message_loop_.reset(new MessageLoop(MessageLoop::TYPE_IO)); |
123 host_ = new MockAudioRendererHost(message_loop_.get()); | 124 io_thread_.reset(new ChromeThread(ChromeThread::IO, message_loop_.get())); |
| 125 host_ = new MockAudioRendererHost(); |
124 } | 126 } |
125 | 127 |
126 virtual void TearDown() { | 128 virtual void TearDown() { |
127 // This task post a task to message_loop_ to do internal destruction on | 129 // This task post a task to message_loop_ to do internal destruction on |
128 // message_loop_. | 130 // message_loop_. |
129 host_->Destroy(); | 131 host_->Destroy(); |
130 | 132 |
| 133 // Release the reference to the mock object. |
| 134 host_ = NULL; |
| 135 |
131 // We need to continue running message_loop_ to complete all destructions. | 136 // We need to continue running message_loop_ to complete all destructions. |
132 message_loop_->RunAllPending(); | 137 message_loop_->RunAllPending(); |
133 | 138 |
134 // Release the reference to the mock object. | 139 io_thread_.reset(); |
135 host_ = NULL; | |
136 } | 140 } |
137 | 141 |
138 AudioRendererHost::IPCAudioSource* CreateAudioStream( | 142 AudioRendererHost::IPCAudioSource* CreateAudioStream( |
139 AudioManager::Format format) { | 143 AudioManager::Format format) { |
140 InSequence s; | 144 InSequence s; |
141 | 145 |
142 // 1. We will first receive a OnStreamCreated() signal. | 146 // 1. We will first receive a OnStreamCreated() signal. |
143 EXPECT_CALL(*host_, | 147 EXPECT_CALL(*host_, |
144 OnStreamCreated(kRouteId, current_stream_id_, kPacketSize)); | 148 OnStreamCreated(kRouteId, current_stream_id_, kPacketSize)); |
145 | 149 |
(...skipping 27 matching lines...) Expand all Loading... |
173 | 177 |
174 AudioRendererHost::IPCAudioSource* CreateMockStream() { | 178 AudioRendererHost::IPCAudioSource* CreateMockStream() { |
175 return CreateAudioStream(AudioManager::AUDIO_MOCK); | 179 return CreateAudioStream(AudioManager::AUDIO_MOCK); |
176 } | 180 } |
177 | 181 |
178 int current_stream_id_; | 182 int current_stream_id_; |
179 scoped_refptr<MockAudioRendererHost> host_; | 183 scoped_refptr<MockAudioRendererHost> host_; |
180 scoped_ptr<MessageLoop> message_loop_; | 184 scoped_ptr<MessageLoop> message_loop_; |
181 | 185 |
182 private: | 186 private: |
| 187 scoped_ptr<ChromeThread> io_thread_; |
183 DISALLOW_COPY_AND_ASSIGN(AudioRendererHostTest); | 188 DISALLOW_COPY_AND_ASSIGN(AudioRendererHostTest); |
184 }; | 189 }; |
185 | 190 |
186 TEST_F(AudioRendererHostTest, MockStreamDataConversation) { | 191 TEST_F(AudioRendererHostTest, MockStreamDataConversation) { |
187 scoped_ptr<AudioRendererHost::IPCAudioSource> source(CreateMockStream()); | 192 scoped_ptr<AudioRendererHost::IPCAudioSource> source(CreateMockStream()); |
188 | 193 |
189 // We will receive packet requests until the buffer is full. We first send | 194 // We will receive packet requests until the buffer is full. We first send |
190 // three packets of 16KB, then we send packets of 1KB until the buffer is | 195 // three packets of 16KB, then we send packets of 1KB until the buffer is |
191 // full. Then there will no more packet requests. | 196 // full. Then there will no more packet requests. |
192 InSequence s; | 197 InSequence s; |
(...skipping 21 matching lines...) Expand all Loading... |
214 source->NotifyPacketReady(kPacketSize); | 219 source->NotifyPacketReady(kPacketSize); |
215 source->NotifyPacketReady(kPacketSize); | 220 source->NotifyPacketReady(kPacketSize); |
216 source->NotifyPacketReady(kStep); | 221 source->NotifyPacketReady(kStep); |
217 source->NotifyPacketReady(kStep); | 222 source->NotifyPacketReady(kStep); |
218 source->NotifyPacketReady(kStep); | 223 source->NotifyPacketReady(kStep); |
219 source->NotifyPacketReady(kStep); | 224 source->NotifyPacketReady(kStep); |
220 source->Play(); | 225 source->Play(); |
221 EXPECT_EQ(ViewMsg_AudioStreamState::kPlaying, state.state); | 226 EXPECT_EQ(ViewMsg_AudioStreamState::kPlaying, state.state); |
222 source->Close(); | 227 source->Close(); |
223 } | 228 } |
OLD | NEW |