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 3 // found in the LICENSE file. 4 5 #include <vector> 6 7 #include "base/compiler_specific.h" 8 #include "base/logging.h" 9 #include "base/memory/scoped_ptr.h" 10 #include "base/message_loop/message_loop.h" 11 #include "base/run_loop.h" 12 #include "base/strings/string_piece.h" 13 #include "media/audio/audio_manager.h" 14 #include "media/audio/sounds/audio_stream_handler.h" 15 #include "media/audio/sounds/sounds_manager.h" 16 #include "media/audio/sounds/test_data.h" 17 #include "testing/gtest/include/gtest/gtest.h" 18 19 namespace media { 20 21 class SoundsManagerTest : public testing::Test { 22 public: SoundsManagerTest()23 SoundsManagerTest() {} ~SoundsManagerTest()24 virtual ~SoundsManagerTest() {} 25 SetUp()26 virtual void SetUp() OVERRIDE { 27 audio_manager_.reset(AudioManager::CreateForTesting()); 28 SoundsManager::Create(); 29 } 30 TearDown()31 virtual void TearDown() OVERRIDE { 32 SoundsManager::Shutdown(); 33 audio_manager_.reset(); 34 } 35 SetObserverForTesting(AudioStreamHandler::TestObserver * observer)36 void SetObserverForTesting(AudioStreamHandler::TestObserver* observer) { 37 AudioStreamHandler::SetObserverForTesting(observer); 38 } 39 40 private: 41 scoped_ptr<AudioManager> audio_manager_; 42 43 base::MessageLoop message_loop_; 44 }; 45 TEST_F(SoundsManagerTest,Play)46TEST_F(SoundsManagerTest, Play) { 47 ASSERT_TRUE(SoundsManager::Get()); 48 49 base::RunLoop run_loop; 50 TestObserver observer(run_loop.QuitClosure()); 51 52 SetObserverForTesting(&observer); 53 54 ASSERT_TRUE(SoundsManager::Get()->Initialize( 55 kTestAudioKey, 56 base::StringPiece(kTestAudioData, arraysize(kTestAudioData)))); 57 ASSERT_EQ(20, 58 SoundsManager::Get()->GetDuration(kTestAudioKey).InMicroseconds()); 59 ASSERT_TRUE(SoundsManager::Get()->Play(kTestAudioKey)); 60 run_loop.Run(); 61 62 ASSERT_EQ(1, observer.num_play_requests()); 63 ASSERT_EQ(1, observer.num_stop_requests()); 64 ASSERT_EQ(4, observer.cursor()); 65 66 SetObserverForTesting(NULL); 67 } 68 69 } // namespace media 70