Plugin Power Saver: Fix a nullptr crash with plugin placeholder resize.
[chromium-blink-merge.git] / media / audio / audio_manager_factory_unittest.cc
blob1d13c2e0269751ce48c34b9ad754823f0145a42f
1 // Copyright 2015 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 "base/memory/scoped_ptr.h"
6 #include "media/audio/audio_manager.h"
7 #include "media/audio/audio_manager_factory.h"
8 #include "media/audio/fake_audio_log_factory.h"
9 #include "media/audio/fake_audio_manager.h"
10 #include "testing/gtest/include/gtest/gtest.h"
12 namespace media {
13 namespace {
15 class FakeAudioManagerFactory : public AudioManagerFactory {
16 public:
17 FakeAudioManagerFactory() {}
18 ~FakeAudioManagerFactory() override {}
20 AudioManager* CreateInstance(AudioLogFactory* audio_log_factory) override {
21 // |created_instance_| is used for verifying. Ownership is transferred to
22 // caller.
23 created_instance_ = new FakeAudioManager(audio_log_factory);
24 return created_instance_;
27 AudioManager* created_instance() { return created_instance_; }
29 private:
30 AudioManager* created_instance_;
33 } // namespace
35 // Verifies that SetFactory has the intended effect.
36 TEST(AudioManagerFactoryTest, CreateInstance) {
37 // Create an audio manager and verify that it is not null.
38 scoped_ptr<AudioManager> manager(AudioManager::CreateForTesting());
39 ASSERT_NE(nullptr, manager.get());
40 manager.reset();
42 // Set the factory. Note that ownership of |factory| is transferred to
43 // AudioManager.
44 FakeAudioManagerFactory* factory = new FakeAudioManagerFactory();
45 AudioManager::SetFactory(factory);
47 // Create the AudioManager instance. Verify that it matches the instance
48 // provided by the factory.
49 manager.reset(AudioManager::CreateForTesting());
50 ASSERT_NE(nullptr, manager.get());
51 ASSERT_EQ(factory->created_instance(), manager.get());
53 // Reset AudioManagerFactory to prevent factory from persisting to other
54 // tests on the same process. |manager| will reset when scope exits.
55 AudioManager::ResetFactoryForTesting();
58 } // namespace media