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

Side by Side Diff: media/audio/android/audio_android_unittest.cc

Issue 2784433002: Ensures that audio tasks cannot run after AudioManager is deleted. (Closed)
Patch Set: rebase Created 3 years, 7 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
« no previous file with comments | « media/audio/alsa/audio_manager_alsa.cc ('k') | media/audio/android/audio_manager_android.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 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 <stdint.h> 5 #include <stdint.h>
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/android/build_info.h" 9 #include "base/android/build_info.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/files/file_util.h" 11 #include "base/files/file_util.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_loop.h"
14 #include "base/path_service.h" 14 #include "base/path_service.h"
15 #include "base/run_loop.h" 15 #include "base/run_loop.h"
16 #include "base/strings/stringprintf.h" 16 #include "base/strings/stringprintf.h"
17 #include "base/synchronization/lock.h" 17 #include "base/synchronization/lock.h"
18 #include "base/synchronization/waitable_event.h" 18 #include "base/synchronization/waitable_event.h"
19 #include "base/test/test_timeouts.h" 19 #include "base/test/test_timeouts.h"
20 #include "base/threading/thread_task_runner_handle.h" 20 #include "base/threading/thread_task_runner_handle.h"
21 #include "base/time/time.h" 21 #include "base/time/time.h"
22 #include "build/build_config.h" 22 #include "build/build_config.h"
23 #include "media/audio/android/audio_manager_android.h" 23 #include "media/audio/android/audio_manager_android.h"
24 #include "media/audio/audio_device_description.h" 24 #include "media/audio/audio_device_description.h"
25 #include "media/audio/audio_device_info_accessor_for_tests.h" 25 #include "media/audio/audio_device_info_accessor_for_tests.h"
26 #include "media/audio/audio_io.h" 26 #include "media/audio/audio_io.h"
27 #include "media/audio/audio_unittest_util.h" 27 #include "media/audio/audio_unittest_util.h"
28 #include "media/audio/mock_audio_source_callback.h" 28 #include "media/audio/mock_audio_source_callback.h"
29 #include "media/audio/test_audio_thread.h"
29 #include "media/base/decoder_buffer.h" 30 #include "media/base/decoder_buffer.h"
30 #include "media/base/seekable_buffer.h" 31 #include "media/base/seekable_buffer.h"
31 #include "media/base/test_data_util.h" 32 #include "media/base/test_data_util.h"
32 #include "testing/gmock/include/gmock/gmock.h" 33 #include "testing/gmock/include/gmock/gmock.h"
33 #include "testing/gtest/include/gtest/gtest.h" 34 #include "testing/gtest/include/gtest/gtest.h"
34 35
35 using ::testing::_; 36 using ::testing::_;
36 using ::testing::AtLeast; 37 using ::testing::AtLeast;
37 using ::testing::DoAll; 38 using ::testing::DoAll;
38 using ::testing::Invoke; 39 using ::testing::Invoke;
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 bool started_; 417 bool started_;
417 418
418 DISALLOW_COPY_AND_ASSIGN(FullDuplexAudioSinkSource); 419 DISALLOW_COPY_AND_ASSIGN(FullDuplexAudioSinkSource);
419 }; 420 };
420 421
421 // Test fixture class for tests which only exercise the output path. 422 // Test fixture class for tests which only exercise the output path.
422 class AudioAndroidOutputTest : public testing::Test { 423 class AudioAndroidOutputTest : public testing::Test {
423 public: 424 public:
424 AudioAndroidOutputTest() 425 AudioAndroidOutputTest()
425 : loop_(new base::MessageLoopForUI()), 426 : loop_(new base::MessageLoopForUI()),
426 audio_manager_(AudioManager::CreateForTesting(loop_->task_runner())), 427 audio_manager_(AudioManager::CreateForTesting(
428 base::MakeUnique<TestAudioThread>())),
427 audio_manager_device_info_(audio_manager_.get()), 429 audio_manager_device_info_(audio_manager_.get()),
428 audio_output_stream_(NULL) { 430 audio_output_stream_(NULL) {
429 // Flush the message loop to ensure that AudioManager is fully initialized. 431 // Flush the message loop to ensure that AudioManager is fully initialized.
430 base::RunLoop().RunUntilIdle(); 432 base::RunLoop().RunUntilIdle();
431 } 433 }
432 434
433 ~AudioAndroidOutputTest() override { 435 ~AudioAndroidOutputTest() override {
434 audio_manager_.reset(); 436 audio_manager_->Shutdown();
435 base::RunLoop().RunUntilIdle(); 437 base::RunLoop().RunUntilIdle();
436 } 438 }
437 439
438 protected: 440 protected:
439 AudioManager* audio_manager() { return audio_manager_.get(); } 441 AudioManager* audio_manager() { return audio_manager_.get(); }
440 AudioDeviceInfoAccessorForTests* audio_manager_device_info() { 442 AudioDeviceInfoAccessorForTests* audio_manager_device_info() {
441 return &audio_manager_device_info_; 443 return &audio_manager_device_info_;
442 } 444 }
443 const AudioParameters& audio_output_parameters() { 445 const AudioParameters& audio_output_parameters() {
444 return audio_output_parameters_; 446 return audio_output_parameters_;
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 } 577 }
576 578
577 void StopAndClose() { 579 void StopAndClose() {
578 DCHECK(audio_manager()->GetTaskRunner()->BelongsToCurrentThread()); 580 DCHECK(audio_manager()->GetTaskRunner()->BelongsToCurrentThread());
579 audio_output_stream_->Stop(); 581 audio_output_stream_->Stop();
580 audio_output_stream_->Close(); 582 audio_output_stream_->Close();
581 audio_output_stream_ = NULL; 583 audio_output_stream_ = NULL;
582 } 584 }
583 585
584 std::unique_ptr<base::MessageLoopForUI> loop_; 586 std::unique_ptr<base::MessageLoopForUI> loop_;
585 ScopedAudioManagerPtr audio_manager_; 587 std::unique_ptr<AudioManager> audio_manager_;
586 AudioDeviceInfoAccessorForTests audio_manager_device_info_; 588 AudioDeviceInfoAccessorForTests audio_manager_device_info_;
587 AudioParameters audio_output_parameters_; 589 AudioParameters audio_output_parameters_;
588 AudioOutputStream* audio_output_stream_; 590 AudioOutputStream* audio_output_stream_;
589 base::TimeTicks start_time_; 591 base::TimeTicks start_time_;
590 base::TimeTicks end_time_; 592 base::TimeTicks end_time_;
591 593
592 private: 594 private:
593 DISALLOW_COPY_AND_ASSIGN(AudioAndroidOutputTest); 595 DISALLOW_COPY_AND_ASSIGN(AudioAndroidOutputTest);
594 }; 596 };
595 597
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
975 printf("\n"); 977 printf("\n");
976 StopAndCloseAudioOutputStreamOnAudioThread(); 978 StopAndCloseAudioOutputStreamOnAudioThread();
977 StopAndCloseAudioInputStreamOnAudioThread(); 979 StopAndCloseAudioInputStreamOnAudioThread();
978 } 980 }
979 981
980 INSTANTIATE_TEST_CASE_P(AudioAndroidInputTest, 982 INSTANTIATE_TEST_CASE_P(AudioAndroidInputTest,
981 AudioAndroidInputTest, 983 AudioAndroidInputTest,
982 testing::Bool()); 984 testing::Bool());
983 985
984 } // namespace media 986 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/alsa/audio_manager_alsa.cc ('k') | media/audio/android/audio_manager_android.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698