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

Side by Side Diff: media/audio/audio_manager_factory_unittest.cc

Issue 1806313003: Pass task runners to AudioManager constructor. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: destroy AudioManagerPulse Created 4 years, 9 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 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/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "media/audio/audio_manager.h" 6 #include "media/audio/audio_manager.h"
7 #include "media/audio/audio_manager_factory.h" 7 #include "media/audio/audio_manager_factory.h"
8 #include "media/audio/audio_thread.h"
8 #include "media/audio/fake_audio_log_factory.h" 9 #include "media/audio/fake_audio_log_factory.h"
9 #include "media/audio/fake_audio_manager.h" 10 #include "media/audio/fake_audio_manager.h"
10 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
11 12
12 namespace media { 13 namespace media {
13 namespace { 14 namespace {
14 15
15 class FakeAudioManagerFactory : public AudioManagerFactory { 16 class FakeAudioManagerFactory : public AudioManagerFactory {
16 public: 17 public:
17 FakeAudioManagerFactory() {} 18 FakeAudioManagerFactory() {}
18 ~FakeAudioManagerFactory() override {} 19 ~FakeAudioManagerFactory() override {}
19 20
20 AudioManager* CreateInstance(AudioLogFactory* audio_log_factory) override { 21 AudioManager* CreateInstance(AudioLogFactory* audio_log_factory) override {
21 // |created_instance_| is used for verifying. Ownership is transferred to 22 // |created_instance_| is used for verifying. Ownership is transferred to
22 // caller. 23 // caller.
23 created_instance_ = new FakeAudioManager(audio_log_factory); 24 base::Thread* audio_thread = AudioThread::Get();
25 created_instance_ =
26 new FakeAudioManager(audio_thread->task_runner(),
27 audio_thread->task_runner(), audio_log_factory);
24 return created_instance_; 28 return created_instance_;
25 } 29 }
26 30
27 AudioManager* created_instance() { return created_instance_; } 31 AudioManager* created_instance() { return created_instance_; }
28 32
29 private: 33 private:
30 AudioManager* created_instance_; 34 AudioManager* created_instance_;
31 }; 35 };
32 36
33 } // namespace 37 } // namespace
34 38
35 // Verifies that SetFactory has the intended effect. 39 // Verifies that SetFactory has the intended effect.
36 TEST(AudioManagerFactoryTest, CreateInstance) { 40 TEST(AudioManagerFactoryTest, CreateInstance) {
37 // Create an audio manager and verify that it is not null. 41 // Create an audio manager and verify that it is not null.
38 scoped_ptr<AudioManager> manager(AudioManager::CreateForTesting()); 42 scoped_ptr<AudioManager> manager(AudioManager::CreateForTesting());
39 ASSERT_NE(nullptr, manager.get()); 43 ASSERT_NE(nullptr, manager.get());
40 manager.reset(); 44 AudioManager::Destroy(manager.release());
41 45
42 // Set the factory. Note that ownership of |factory| is transferred to 46 // Set the factory. Note that ownership of |factory| is transferred to
43 // AudioManager. 47 // AudioManager.
44 FakeAudioManagerFactory* factory = new FakeAudioManagerFactory(); 48 FakeAudioManagerFactory* factory = new FakeAudioManagerFactory();
45 AudioManager::SetFactory(factory); 49 AudioManager::SetFactory(factory);
46 50
47 // Create the AudioManager instance. Verify that it matches the instance 51 // Create the AudioManager instance. Verify that it matches the instance
48 // provided by the factory. 52 // provided by the factory.
49 manager.reset(AudioManager::CreateForTesting()); 53 manager.reset(AudioManager::CreateForTesting());
50 ASSERT_NE(nullptr, manager.get()); 54 ASSERT_NE(nullptr, manager.get());
51 ASSERT_EQ(factory->created_instance(), manager.get()); 55 ASSERT_EQ(factory->created_instance(), manager.get());
52 56
53 // Reset AudioManagerFactory to prevent factory from persisting to other 57 // Reset AudioManagerFactory to prevent factory from persisting to other
54 // tests on the same process. |manager| will reset when scope exits. 58 // tests on the same process.
55 AudioManager::ResetFactoryForTesting(); 59 AudioManager::ResetFactoryForTesting();
60 AudioManager::Destroy(manager.release());
56 } 61 }
57 62
58 } // namespace media 63 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698