Files.app: Remove wait for startup animation.
[chromium-blink-merge.git] / media / audio / sounds / sounds_manager_unittest.cc
blob9741e6ef02906bd51c0e973667492b248e420b0a
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.
5 #include <vector>
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"
19 namespace media {
21 class SoundsManagerTest : public testing::Test {
22 public:
23 SoundsManagerTest() {}
24 ~SoundsManagerTest() override {}
26 void SetUp() override {
27 audio_manager_.reset(AudioManager::CreateForTesting());
28 SoundsManager::Create();
31 void TearDown() override {
32 SoundsManager::Shutdown();
33 audio_manager_.reset();
36 void SetObserverForTesting(AudioStreamHandler::TestObserver* observer) {
37 AudioStreamHandler::SetObserverForTesting(observer);
40 private:
41 scoped_ptr<AudioManager> audio_manager_;
43 base::MessageLoop message_loop_;
46 TEST_F(SoundsManagerTest, Play) {
47 ASSERT_TRUE(SoundsManager::Get());
49 base::RunLoop run_loop;
50 TestObserver observer(run_loop.QuitClosure());
52 SetObserverForTesting(&observer);
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();
62 ASSERT_EQ(1, observer.num_play_requests());
63 ASSERT_EQ(1, observer.num_stop_requests());
64 ASSERT_EQ(4, observer.cursor());
66 SetObserverForTesting(NULL);
69 } // namespace media