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

Side by Side Diff: media/audio/sounds/audio_stream_handler_unittest.cc

Issue 1453233002: Improve input handling for WaveAudioHandler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Address comments Created 5 years, 1 month 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
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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/bind_helpers.h" 7 #include "base/bind_helpers.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 base::MessageLoop message_loop_; 56 base::MessageLoop message_loop_;
57 }; 57 };
58 58
59 TEST_F(AudioStreamHandlerTest, Play) { 59 TEST_F(AudioStreamHandlerTest, Play) {
60 base::RunLoop run_loop; 60 base::RunLoop run_loop;
61 TestObserver observer(run_loop.QuitClosure()); 61 TestObserver observer(run_loop.QuitClosure());
62 62
63 SetObserverForTesting(&observer); 63 SetObserverForTesting(&observer);
64 64
65 ASSERT_TRUE(audio_stream_handler()->IsInitialized()); 65 ASSERT_TRUE(audio_stream_handler()->IsInitialized());
66 EXPECT_EQ(base::TimeDelta::FromMicroseconds(20u),
67 audio_stream_handler()->duration());
68
66 ASSERT_TRUE(audio_stream_handler()->Play()); 69 ASSERT_TRUE(audio_stream_handler()->Play());
67 70
68 run_loop.Run(); 71 run_loop.Run();
69 72
70 SetObserverForTesting(NULL); 73 SetObserverForTesting(NULL);
71 74
72 ASSERT_EQ(1, observer.num_play_requests()); 75 ASSERT_EQ(1, observer.num_play_requests());
73 ASSERT_EQ(1, observer.num_stop_requests()); 76 ASSERT_EQ(1, observer.num_stop_requests());
74 ASSERT_EQ(4, observer.cursor()); 77 ASSERT_EQ(4, observer.cursor());
75 } 78 }
76 79
77 TEST_F(AudioStreamHandlerTest, ConsecutivePlayRequests) { 80 TEST_F(AudioStreamHandlerTest, ConsecutivePlayRequests) {
78 base::RunLoop run_loop; 81 base::RunLoop run_loop;
79 TestObserver observer(run_loop.QuitClosure()); 82 TestObserver observer(run_loop.QuitClosure());
80 SineWaveAudioSource source(CHANNEL_LAYOUT_STEREO, 200.0, 8000); 83 SineWaveAudioSource source(CHANNEL_LAYOUT_STEREO, 200.0, 8000);
81 84
82 SetObserverForTesting(&observer); 85 SetObserverForTesting(&observer);
83 SetAudioSourceForTesting(&source); 86 SetAudioSourceForTesting(&source);
84 87
85 ASSERT_TRUE(audio_stream_handler()->IsInitialized()); 88 ASSERT_TRUE(audio_stream_handler()->IsInitialized());
89 EXPECT_EQ(base::TimeDelta::FromMicroseconds(20u),
90 audio_stream_handler()->duration());
86 91
87 ASSERT_TRUE(audio_stream_handler()->Play()); 92 ASSERT_TRUE(audio_stream_handler()->Play());
88 base::MessageLoop::current()->PostDelayedTask( 93 base::MessageLoop::current()->PostDelayedTask(
89 FROM_HERE, 94 FROM_HERE,
90 base::Bind(base::IgnoreResult(&AudioStreamHandler::Play), 95 base::Bind(base::IgnoreResult(&AudioStreamHandler::Play),
91 base::Unretained(audio_stream_handler())), 96 base::Unretained(audio_stream_handler())),
92 base::TimeDelta::FromSeconds(1)); 97 base::TimeDelta::FromSeconds(1));
93 base::MessageLoop::current()->PostDelayedTask( 98 base::MessageLoop::current()->PostDelayedTask(
94 FROM_HERE, 99 FROM_HERE,
95 base::Bind(&AudioStreamHandler::Stop, 100 base::Bind(&AudioStreamHandler::Stop,
96 base::Unretained(audio_stream_handler())), 101 base::Unretained(audio_stream_handler())),
97 base::TimeDelta::FromSeconds(2)); 102 base::TimeDelta::FromSeconds(2));
98 103
99 run_loop.Run(); 104 run_loop.Run();
100 105
101 SetObserverForTesting(NULL); 106 SetObserverForTesting(NULL);
102 SetAudioSourceForTesting(NULL); 107 SetAudioSourceForTesting(NULL);
103 108
104 ASSERT_EQ(1, observer.num_play_requests()); 109 ASSERT_EQ(1, observer.num_play_requests());
105 ASSERT_EQ(1, observer.num_stop_requests()); 110 ASSERT_EQ(1, observer.num_stop_requests());
106 } 111 }
107 112
113 TEST_F(AudioStreamHandlerTest, BadWavDataDoesNotInitialize) {
114 // The class members and SetUp() will be ignored for this test. Create a
115 // handler on the stack with some bad WAV data.
116 AudioStreamHandler handler("RIFF1234WAVEjunkjunkjunkjunk");
117 EXPECT_FALSE(handler.IsInitialized());
118 EXPECT_FALSE(handler.Play());
119 EXPECT_EQ(base::TimeDelta(), handler.duration());
120
121 // Call Stop() to ensure that there is no crash.
122 handler.Stop();
123 }
124
108 } // namespace media 125 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698