Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Side by Side Diff: webkit/renderer/media/webaudiosourceprovider_impl_unittest.cc

Issue 16155009: Update webkit/ to use scoped_refptr<T>::get() rather than implicit "operator T*" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "media/audio/audio_parameters.h" 5 #include "media/audio/audio_parameters.h"
6 #include "media/base/fake_audio_render_callback.h" 6 #include "media/base/fake_audio_render_callback.h"
7 #include "media/base/mock_audio_renderer_sink.h" 7 #include "media/base/mock_audio_renderer_sink.h"
8 #include "testing/gmock/include/gmock/gmock.h" 8 #include "testing/gmock/include/gmock/gmock.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAudioSourceProvide rClient.h" 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAudioSourceProvide rClient.h"
(...skipping 15 matching lines...) Expand all
26 fake_callback_(0.1), 26 fake_callback_(0.1),
27 mock_sink_(new media::MockAudioRendererSink()), 27 mock_sink_(new media::MockAudioRendererSink()),
28 wasp_impl_(new WebAudioSourceProviderImpl(mock_sink_)) { 28 wasp_impl_(new WebAudioSourceProviderImpl(mock_sink_)) {
29 } 29 }
30 30
31 virtual ~WebAudioSourceProviderImplTest() {} 31 virtual ~WebAudioSourceProviderImplTest() {}
32 32
33 void CallAllSinkMethodsAndVerify(bool verify) { 33 void CallAllSinkMethodsAndVerify(bool verify) {
34 testing::InSequence s; 34 testing::InSequence s;
35 35
36 EXPECT_CALL(*mock_sink_, Start()).Times(verify); 36 EXPECT_CALL(*mock_sink_.get(), Start()).Times(verify);
37 wasp_impl_->Start(); 37 wasp_impl_->Start();
38 38
39 EXPECT_CALL(*mock_sink_, Play()).Times(verify); 39 EXPECT_CALL(*mock_sink_.get(), Play()).Times(verify);
40 wasp_impl_->Play(); 40 wasp_impl_->Play();
41 41
42 EXPECT_CALL(*mock_sink_, Pause()).Times(verify); 42 EXPECT_CALL(*mock_sink_.get(), Pause()).Times(verify);
43 wasp_impl_->Pause(); 43 wasp_impl_->Pause();
44 44
45 EXPECT_CALL(*mock_sink_, SetVolume(kTestVolume)).Times(verify); 45 EXPECT_CALL(*mock_sink_.get(), SetVolume(kTestVolume)).Times(verify);
46 wasp_impl_->SetVolume(kTestVolume); 46 wasp_impl_->SetVolume(kTestVolume);
47 47
48 EXPECT_CALL(*mock_sink_, Stop()).Times(verify); 48 EXPECT_CALL(*mock_sink_.get(), Stop()).Times(verify);
49 wasp_impl_->Stop(); 49 wasp_impl_->Stop();
50 50
51 testing::Mock::VerifyAndClear(mock_sink_); 51 testing::Mock::VerifyAndClear(mock_sink_.get());
52 } 52 }
53 53
54 void SetClient(WebKit::WebAudioSourceProviderClient* client) { 54 void SetClient(WebKit::WebAudioSourceProviderClient* client) {
55 testing::InSequence s; 55 testing::InSequence s;
56 56
57 if (client) { 57 if (client) {
58 EXPECT_CALL(*mock_sink_, Stop()); 58 EXPECT_CALL(*mock_sink_.get(), Stop());
59 EXPECT_CALL(*this, setFormat(params_.channels(), params_.sample_rate())); 59 EXPECT_CALL(*this, setFormat(params_.channels(), params_.sample_rate()));
60 } 60 }
61 wasp_impl_->setClient(client); 61 wasp_impl_->setClient(client);
62 62
63 testing::Mock::VerifyAndClear(mock_sink_); 63 testing::Mock::VerifyAndClear(mock_sink_.get());
64 testing::Mock::VerifyAndClear(this); 64 testing::Mock::VerifyAndClear(this);
65 } 65 }
66 66
67 bool CompareBusses(const media::AudioBus* bus1, const media::AudioBus* bus2) { 67 bool CompareBusses(const media::AudioBus* bus1, const media::AudioBus* bus2) {
68 EXPECT_EQ(bus1->channels(), bus2->channels()); 68 EXPECT_EQ(bus1->channels(), bus2->channels());
69 EXPECT_EQ(bus1->frames(), bus2->frames()); 69 EXPECT_EQ(bus1->frames(), bus2->frames());
70 for (int ch = 0; ch < bus1->channels(); ++ch) { 70 for (int ch = 0; ch < bus1->channels(); ++ch) {
71 if (memcmp(bus1->channel(ch), bus2->channel(ch), 71 if (memcmp(bus1->channel(ch), bus2->channel(ch),
72 sizeof(*bus1->channel(ch)) * bus1->frames()) != 0) { 72 sizeof(*bus1->channel(ch)) * bus1->frames()) != 0) {
73 return false; 73 return false;
(...skipping 11 matching lines...) Expand all
85 scoped_refptr<media::MockAudioRendererSink> mock_sink_; 85 scoped_refptr<media::MockAudioRendererSink> mock_sink_;
86 scoped_refptr<WebAudioSourceProviderImpl> wasp_impl_; 86 scoped_refptr<WebAudioSourceProviderImpl> wasp_impl_;
87 87
88 DISALLOW_COPY_AND_ASSIGN(WebAudioSourceProviderImplTest); 88 DISALLOW_COPY_AND_ASSIGN(WebAudioSourceProviderImplTest);
89 }; 89 };
90 90
91 TEST_F(WebAudioSourceProviderImplTest, SetClientBeforeInitialize) { 91 TEST_F(WebAudioSourceProviderImplTest, SetClientBeforeInitialize) {
92 // setClient() with a NULL client should do nothing if no client is set. 92 // setClient() with a NULL client should do nothing if no client is set.
93 wasp_impl_->setClient(NULL); 93 wasp_impl_->setClient(NULL);
94 94
95 EXPECT_CALL(*mock_sink_, Stop()); 95 EXPECT_CALL(*mock_sink_.get(), Stop());
96 wasp_impl_->setClient(this); 96 wasp_impl_->setClient(this);
97 97
98 // When Initialize() is called after setClient(), the params should propagate 98 // When Initialize() is called after setClient(), the params should propagate
99 // to the client via setFormat() during the call. 99 // to the client via setFormat() during the call.
100 EXPECT_CALL(*this, setFormat(params_.channels(), params_.sample_rate())); 100 EXPECT_CALL(*this, setFormat(params_.channels(), params_.sample_rate()));
101 wasp_impl_->Initialize(params_, &fake_callback_); 101 wasp_impl_->Initialize(params_, &fake_callback_);
102 102
103 // setClient() with the same client should do nothing. 103 // setClient() with the same client should do nothing.
104 wasp_impl_->setClient(this); 104 wasp_impl_->setClient(this);
105 } 105 }
106 106
107 // Verify AudioRendererSink functionality w/ and w/o a client. 107 // Verify AudioRendererSink functionality w/ and w/o a client.
108 TEST_F(WebAudioSourceProviderImplTest, SinkMethods) { 108 TEST_F(WebAudioSourceProviderImplTest, SinkMethods) {
109 wasp_impl_->Initialize(params_, &fake_callback_); 109 wasp_impl_->Initialize(params_, &fake_callback_);
110 ASSERT_EQ(mock_sink_->callback(), &fake_callback_); 110 ASSERT_EQ(mock_sink_->callback(), &fake_callback_);
111 111
112 // Without a client all WASP calls should fall through to the underlying sink. 112 // Without a client all WASP calls should fall through to the underlying sink.
113 CallAllSinkMethodsAndVerify(true); 113 CallAllSinkMethodsAndVerify(true);
114 114
115 // With a client no calls should reach the Stop()'d sink. Also, setClient() 115 // With a client no calls should reach the Stop()'d sink. Also, setClient()
116 // should propagate the params provided during Initialize() at call time. 116 // should propagate the params provided during Initialize() at call time.
117 SetClient(this); 117 SetClient(this);
118 CallAllSinkMethodsAndVerify(false); 118 CallAllSinkMethodsAndVerify(false);
119 119
120 // Removing the client should cause WASP to revert to the underlying sink. 120 // Removing the client should cause WASP to revert to the underlying sink.
121 EXPECT_CALL(*mock_sink_, SetVolume(kTestVolume)); 121 EXPECT_CALL(*mock_sink_.get(), SetVolume(kTestVolume));
122 SetClient(NULL); 122 SetClient(NULL);
123 CallAllSinkMethodsAndVerify(true); 123 CallAllSinkMethodsAndVerify(true);
124 } 124 }
125 125
126 // Verify underlying sink state is restored after client removal. 126 // Verify underlying sink state is restored after client removal.
127 TEST_F(WebAudioSourceProviderImplTest, SinkStateRestored) { 127 TEST_F(WebAudioSourceProviderImplTest, SinkStateRestored) {
128 wasp_impl_->Initialize(params_, &fake_callback_); 128 wasp_impl_->Initialize(params_, &fake_callback_);
129 129
130 // Verify state set before the client is set propagates back afterward. 130 // Verify state set before the client is set propagates back afterward.
131 EXPECT_CALL(*mock_sink_, Start()); 131 EXPECT_CALL(*mock_sink_.get(), Start());
132 wasp_impl_->Start(); 132 wasp_impl_->Start();
133 SetClient(this); 133 SetClient(this);
134 134
135 EXPECT_CALL(*mock_sink_, SetVolume(1.0)); 135 EXPECT_CALL(*mock_sink_.get(), SetVolume(1.0));
136 EXPECT_CALL(*mock_sink_, Start()); 136 EXPECT_CALL(*mock_sink_.get(), Start());
137 SetClient(NULL); 137 SetClient(NULL);
138 138
139 // Verify state set while the client was attached propagates back afterward. 139 // Verify state set while the client was attached propagates back afterward.
140 SetClient(this); 140 SetClient(this);
141 wasp_impl_->Play(); 141 wasp_impl_->Play();
142 wasp_impl_->SetVolume(kTestVolume); 142 wasp_impl_->SetVolume(kTestVolume);
143 143
144 EXPECT_CALL(*mock_sink_, SetVolume(kTestVolume)); 144 EXPECT_CALL(*mock_sink_.get(), SetVolume(kTestVolume));
145 EXPECT_CALL(*mock_sink_, Start()); 145 EXPECT_CALL(*mock_sink_.get(), Start());
146 EXPECT_CALL(*mock_sink_, Play()); 146 EXPECT_CALL(*mock_sink_.get(), Play());
147 SetClient(NULL); 147 SetClient(NULL);
148 } 148 }
149 149
150 // Test the AudioRendererSink state machine and its effects on provideInput(). 150 // Test the AudioRendererSink state machine and its effects on provideInput().
151 TEST_F(WebAudioSourceProviderImplTest, ProvideInput) { 151 TEST_F(WebAudioSourceProviderImplTest, ProvideInput) {
152 scoped_ptr<media::AudioBus> bus1 = media::AudioBus::Create(params_); 152 scoped_ptr<media::AudioBus> bus1 = media::AudioBus::Create(params_);
153 scoped_ptr<media::AudioBus> bus2 = media::AudioBus::Create(params_); 153 scoped_ptr<media::AudioBus> bus2 = media::AudioBus::Create(params_);
154 154
155 // Point the WebVector into memory owned by |bus1|. 155 // Point the WebVector into memory owned by |bus1|.
156 WebKit::WebVector<float*> audio_data(static_cast<size_t>(bus1->channels())); 156 WebKit::WebVector<float*> audio_data(static_cast<size_t>(bus1->channels()));
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 ASSERT_FALSE(CompareBusses(bus1.get(), bus2.get())); 212 ASSERT_FALSE(CompareBusses(bus1.get(), bus2.get()));
213 213
214 // Stop() should return silence. 214 // Stop() should return silence.
215 wasp_impl_->Stop(); 215 wasp_impl_->Stop();
216 bus1->channel(0)[0] = 1; 216 bus1->channel(0)[0] = 1;
217 wasp_impl_->provideInput(audio_data, params_.frames_per_buffer()); 217 wasp_impl_->provideInput(audio_data, params_.frames_per_buffer());
218 ASSERT_TRUE(CompareBusses(bus1.get(), bus2.get())); 218 ASSERT_TRUE(CompareBusses(bus1.get(), bus2.get()));
219 } 219 }
220 220
221 } // namespace webkit_media 221 } // namespace webkit_media
OLDNEW
« no previous file with comments | « webkit/renderer/media/crypto/proxy_decryptor.cc ('k') | webkit/renderer/media/webmediaplayer_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698