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

Side by Side Diff: chromeos/audio/cras_audio_handler_unittest.cc

Issue 2845973003: Use ScopedTaskEnvironment instead of MessageLoopForUI in chromeos tests. (Closed)
Patch Set: CR 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 | « no previous file | chromeos/cryptohome/system_salt_getter_unittest.cc » ('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 (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "chromeos/audio/cras_audio_handler.h" 5 #include "chromeos/audio/cras_audio_handler.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/message_loop/message_loop.h"
16 #include "base/run_loop.h" 15 #include "base/run_loop.h"
16 #include "base/test/scoped_task_environment.h"
17 #include "base/threading/thread_task_runner_handle.h" 17 #include "base/threading/thread_task_runner_handle.h"
18 #include "base/values.h" 18 #include "base/values.h"
19 #include "chromeos/audio/audio_devices_pref_handler.h" 19 #include "chromeos/audio/audio_devices_pref_handler.h"
20 #include "chromeos/audio/audio_devices_pref_handler_stub.h" 20 #include "chromeos/audio/audio_devices_pref_handler_stub.h"
21 #include "chromeos/dbus/audio_node.h" 21 #include "chromeos/dbus/audio_node.h"
22 #include "chromeos/dbus/dbus_thread_manager.h" 22 #include "chromeos/dbus/dbus_thread_manager.h"
23 #include "chromeos/dbus/fake_cras_audio_client.h" 23 #include "chromeos/dbus/fake_cras_audio_client.h"
24 #include "media/base/video_facing.h" 24 #include "media/base/video_facing.h"
25 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
26 26
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 private: 244 private:
245 base::ObserverList<media::VideoCaptureObserver> observers_; 245 base::ObserverList<media::VideoCaptureObserver> observers_;
246 DISALLOW_COPY_AND_ASSIGN(FakeVideoCaptureManager); 246 DISALLOW_COPY_AND_ASSIGN(FakeVideoCaptureManager);
247 }; 247 };
248 248
249 } // namespace 249 } // namespace
250 250
251 // Test param is the version of stabel device id used by audio node. 251 // Test param is the version of stabel device id used by audio node.
252 class CrasAudioHandlerTest : public testing::TestWithParam<int> { 252 class CrasAudioHandlerTest : public testing::TestWithParam<int> {
253 public: 253 public:
254 CrasAudioHandlerTest() {} 254 CrasAudioHandlerTest()
255 : scoped_task_environment_(
256 base::test::ScopedTaskEnvironment::MainThreadType::UI) {}
255 ~CrasAudioHandlerTest() override {} 257 ~CrasAudioHandlerTest() override {}
256 258
257 void SetUp() override { 259 void SetUp() override {
258 video_capture_manager_.reset(new FakeVideoCaptureManager); 260 video_capture_manager_.reset(new FakeVideoCaptureManager);
259 } 261 }
260 262
261 void TearDown() override { 263 void TearDown() override {
262 cras_audio_handler_->RemoveAudioObserver(test_observer_.get()); 264 cras_audio_handler_->RemoveAudioObserver(test_observer_.get());
263 test_observer_.reset(); 265 test_observer_.reset();
264 video_capture_manager_->RemoveAllObservers(); 266 video_capture_manager_->RemoveAllObservers();
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 video_capture_manager_->NotifyVideoCaptureStarted( 404 video_capture_manager_->NotifyVideoCaptureStarted(
403 media::MEDIA_VIDEO_FACING_ENVIRONMENT); 405 media::MEDIA_VIDEO_FACING_ENVIRONMENT);
404 } 406 }
405 407
406 void StopRearFacingCamera() { 408 void StopRearFacingCamera() {
407 video_capture_manager_->NotifyVideoCaptureStopped( 409 video_capture_manager_->NotifyVideoCaptureStopped(
408 media::MEDIA_VIDEO_FACING_ENVIRONMENT); 410 media::MEDIA_VIDEO_FACING_ENVIRONMENT);
409 } 411 }
410 412
411 protected: 413 protected:
412 base::MessageLoopForUI message_loop_; 414 base::test::ScopedTaskEnvironment scoped_task_environment_;
413 CrasAudioHandler* cras_audio_handler_ = nullptr; // Not owned. 415 CrasAudioHandler* cras_audio_handler_ = nullptr; // Not owned.
414 FakeCrasAudioClient* fake_cras_audio_client_ = nullptr; // Not owned. 416 FakeCrasAudioClient* fake_cras_audio_client_ = nullptr; // Not owned.
415 std::unique_ptr<TestObserver> test_observer_; 417 std::unique_ptr<TestObserver> test_observer_;
416 scoped_refptr<AudioDevicesPrefHandlerStub> audio_pref_handler_; 418 scoped_refptr<AudioDevicesPrefHandlerStub> audio_pref_handler_;
417 std::unique_ptr<FakeVideoCaptureManager> video_capture_manager_; 419 std::unique_ptr<FakeVideoCaptureManager> video_capture_manager_;
418 420
419 private: 421 private:
420 DISALLOW_COPY_AND_ASSIGN(CrasAudioHandlerTest); 422 DISALLOW_COPY_AND_ASSIGN(CrasAudioHandlerTest);
421 }; 423 };
422 424
(...skipping 3553 matching lines...) Expand 10 before | Expand all | Expand 10 after
3976 // Verity the active mic does not change when there is still camera on. 3978 // Verity the active mic does not change when there is still camera on.
3977 EXPECT_EQ(kRearMicId, cras_audio_handler_->GetPrimaryActiveInputNode()); 3979 EXPECT_EQ(kRearMicId, cras_audio_handler_->GetPrimaryActiveInputNode());
3978 3980
3979 // Stop the rear mic. 3981 // Stop the rear mic.
3980 StopRearFacingCamera(); 3982 StopRearFacingCamera();
3981 // Verify the actice mic changes to front mic after both cameras stop. 3983 // Verify the actice mic changes to front mic after both cameras stop.
3982 EXPECT_EQ(kFrontMicId, cras_audio_handler_->GetPrimaryActiveInputNode()); 3984 EXPECT_EQ(kFrontMicId, cras_audio_handler_->GetPrimaryActiveInputNode());
3983 } 3985 }
3984 3986
3985 } // namespace chromeos 3987 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | chromeos/cryptohome/system_salt_getter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698