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

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: addressed comments 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 "base/message_loop/message_loop.h"
6 #include "media/audio/audio_manager.h" 7 #include "media/audio/audio_manager.h"
7 #include "media/audio/audio_manager_factory.h" 8 #include "media/audio/audio_manager_factory.h"
8 #include "media/audio/fake_audio_log_factory.h"
9 #include "media/audio/fake_audio_manager.h" 9 #include "media/audio/fake_audio_manager.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 11
12 namespace media { 12 namespace media {
13 namespace { 13 namespace {
14 14
15 class FakeAudioManagerFactory : public AudioManagerFactory { 15 class FakeAudioManagerFactory : public AudioManagerFactory {
16 public: 16 public:
17 FakeAudioManagerFactory() {} 17 FakeAudioManagerFactory() {}
18 ~FakeAudioManagerFactory() override {} 18 ~FakeAudioManagerFactory() override {}
19 19
20 AudioManager* CreateInstance(AudioLogFactory* audio_log_factory) override { 20 ScopedAudioManagerPtr CreateInstance(
21 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
22 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner,
23 AudioLogFactory* audio_log_factory) override {
24 ScopedAudioManagerPtr instance(new FakeAudioManager(
25 task_runner, worker_task_runner, audio_log_factory));
21 // |created_instance_| is used for verifying. Ownership is transferred to 26 // |created_instance_| is used for verifying. Ownership is transferred to
22 // caller. 27 // caller.
23 created_instance_ = new FakeAudioManager(audio_log_factory); 28 created_instance_ = instance.get();
24 return created_instance_; 29 return instance;
25 } 30 }
26 31
27 AudioManager* created_instance() { return created_instance_; } 32 AudioManager* created_instance() { return created_instance_; }
28 33
29 private: 34 private:
30 AudioManager* created_instance_; 35 AudioManager* created_instance_;
31 }; 36 };
32 37
33 } // namespace 38 } // namespace
34 39
35 // Verifies that SetFactory has the intended effect. 40 // Verifies that SetFactory has the intended effect.
36 TEST(AudioManagerFactoryTest, CreateInstance) { 41 TEST(AudioManagerFactoryTest, CreateInstance) {
42 base::MessageLoop message_loop;
37 // Create an audio manager and verify that it is not null. 43 // Create an audio manager and verify that it is not null.
38 scoped_ptr<AudioManager> manager(AudioManager::CreateForTesting()); 44 ScopedAudioManagerPtr manager =
45 AudioManager::CreateForTesting(message_loop.task_runner());
39 ASSERT_NE(nullptr, manager.get()); 46 ASSERT_NE(nullptr, manager.get());
40 manager.reset(); 47 manager.reset();
41 48
42 // Set the factory. Note that ownership of |factory| is transferred to 49 // Set the factory. Note that ownership of |factory| is transferred to
43 // AudioManager. 50 // AudioManager.
44 FakeAudioManagerFactory* factory = new FakeAudioManagerFactory(); 51 FakeAudioManagerFactory* factory = new FakeAudioManagerFactory();
45 AudioManager::SetFactory(factory); 52 AudioManager::SetFactory(factory);
46 53
47 // Create the AudioManager instance. Verify that it matches the instance 54 // Create the AudioManager instance. Verify that it matches the instance
48 // provided by the factory. 55 // provided by the factory.
49 manager.reset(AudioManager::CreateForTesting()); 56 manager = AudioManager::CreateForTesting(message_loop.task_runner());
50 ASSERT_NE(nullptr, manager.get()); 57 ASSERT_NE(nullptr, manager.get());
51 ASSERT_EQ(factory->created_instance(), manager.get()); 58 ASSERT_EQ(factory->created_instance(), manager.get());
52 59
53 // Reset AudioManagerFactory to prevent factory from persisting to other 60 // Reset AudioManagerFactory to prevent factory from persisting to other
54 // tests on the same process. |manager| will reset when scope exits. 61 // tests on the same process.
55 AudioManager::ResetFactoryForTesting(); 62 AudioManager::ResetFactoryForTesting();
56 } 63 }
57 64
58 } // namespace media 65 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698