OLD | NEW |
| (Empty) |
1 // Copyright 2016 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. | |
4 | |
5 #include "media/remoting/remoting_controller.h" | |
6 | |
7 #include "base/callback.h" | |
8 #include "base/message_loop/message_loop.h" | |
9 #include "base/run_loop.h" | |
10 #include "media/base/audio_decoder_config.h" | |
11 #include "media/base/limits.h" | |
12 #include "media/base/media_util.h" | |
13 #include "media/base/video_decoder_config.h" | |
14 #include "media/remoting/fake_remoting_controller.h" | |
15 #include "mojo/public/cpp/bindings/strong_binding.h" | |
16 #include "testing/gtest/include/gtest/gtest.h" | |
17 | |
18 namespace media { | |
19 namespace { | |
20 | |
21 constexpr gfx::Size kCodedSize(320, 240); | |
22 constexpr gfx::Rect kVisibleRect(320, 240); | |
23 constexpr gfx::Size kNaturalSize(320, 240); | |
24 | |
25 PipelineMetadata defaultMetadata() { | |
26 PipelineMetadata data; | |
27 data.has_audio = true; | |
28 data.has_video = true; | |
29 data.video_decoder_config = VideoDecoderConfig( | |
30 kCodecVP8, VP8PROFILE_ANY, VideoPixelFormat::PIXEL_FORMAT_I420, | |
31 ColorSpace::COLOR_SPACE_SD_REC601, kCodedSize, kVisibleRect, kNaturalSize, | |
32 EmptyExtraData(), Unencrypted()); | |
33 data.audio_decoder_config = AudioDecoderConfig( | |
34 kCodecOpus, SampleFormat::kSampleFormatU8, | |
35 ChannelLayout::CHANNEL_LAYOUT_MONO, limits::kMinSampleRate, | |
36 EmptyExtraData(), Unencrypted()); | |
37 return data; | |
38 } | |
39 | |
40 } // namespace | |
41 | |
42 class RemotingControllerTest : public ::testing::Test { | |
43 public: | |
44 RemotingControllerTest() | |
45 : remoting_controller_(CreateRemotingController(false)), | |
46 is_remoting_(false) { | |
47 remoting_controller_->SetSwitchRendererCallback(base::Bind( | |
48 &RemotingControllerTest::ToggleRenderer, base::Unretained(this))); | |
49 } | |
50 ~RemotingControllerTest() override {} | |
51 | |
52 void TearDown() final { RunUntilIdle(); } | |
53 | |
54 static void RunUntilIdle() { base::RunLoop().RunUntilIdle(); } | |
55 | |
56 void ToggleRenderer() { is_remoting_ = remoting_controller_->is_remoting(); } | |
57 | |
58 base::MessageLoop message_loop_; | |
59 | |
60 protected: | |
61 std::unique_ptr<RemotingController> remoting_controller_; | |
62 bool is_remoting_; | |
63 | |
64 private: | |
65 DISALLOW_COPY_AND_ASSIGN(RemotingControllerTest); | |
66 }; | |
67 | |
68 TEST_F(RemotingControllerTest, ToggleRenderer) { | |
69 EXPECT_FALSE(is_remoting_); | |
70 remoting_controller_->OnSinkAvailable(); | |
71 remoting_controller_->OnEnteredFullscreen(); | |
72 EXPECT_FALSE(is_remoting_); | |
73 remoting_controller_->OnMetadataChanged(defaultMetadata()); | |
74 RunUntilIdle(); | |
75 EXPECT_TRUE(is_remoting_); | |
76 remoting_controller_->OnExitedFullscreen(); | |
77 RunUntilIdle(); | |
78 EXPECT_FALSE(is_remoting_); | |
79 } | |
80 | |
81 TEST_F(RemotingControllerTest, StartFailed) { | |
82 EXPECT_FALSE(is_remoting_); | |
83 remoting_controller_ = CreateRemotingController(true); | |
84 remoting_controller_->SetSwitchRendererCallback(base::Bind( | |
85 &RemotingControllerTest::ToggleRenderer, base::Unretained(this))); | |
86 remoting_controller_->OnSinkAvailable(); | |
87 remoting_controller_->OnEnteredFullscreen(); | |
88 remoting_controller_->OnMetadataChanged(defaultMetadata()); | |
89 RunUntilIdle(); | |
90 EXPECT_FALSE(is_remoting_); | |
91 } | |
92 | |
93 } // namespace media | |
OLD | NEW |