summaryrefslogtreecommitdiff
path: root/chromium/content/browser/webrtc/webrtc_audio_browsertest.cc
blob: 31692059d2424959e055e957c349bce794091ed7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
// Copyright (c) 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/command_line.h"
#include "base/files/file_util.h"
#include "base/test/scoped_feature_list.h"
#include "base/threading/platform_thread.h"
#include "build/build_config.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/browser/webrtc/webrtc_content_browsertest_base.h"
#include "content/public/common/content_features.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/content_browser_test_utils.h"
#include "content/public/test/test_utils.h"
#include "media/base/media_switches.h"
#include "media/webrtc/webrtc_switches.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "third_party/blink/public/common/peerconnection/webrtc_ip_handling_policy.h"

const char kAudioConstraints[] = "audio: {echoCancellation: {exact: false}}";
const char kVideoConstraints[] = "video:true";

namespace content {

// This class tests the scenario when permission to access mic or camera is
// granted.
class WebRtcAudioBrowserTest : public WebRtcContentBrowserTestBase {
 public:
  ~WebRtcAudioBrowserTest() override {}

  void SetUpCommandLine(base::CommandLine* command_line) override {
    WebRtcContentBrowserTestBase::SetUpCommandLine(command_line);
    // Automatically grant device permission.
    AppendUseFakeUIForMediaStreamFlag();
  }

 protected:
  // Convenience method for making calls that detect if audio os playing (which
  // has some special prerequisites, such that there needs to be an audio output
  // device on the executing machine).
  void MakeAudioDetectingPeerConnectionCall(const std::string& javascript) {
    if (!HasAudioOutputDevices()) {
      // Bots with no output devices will force the audio code into a state
      // where it doesn't manage to set either the low or high latency path.
      // This test will compute useless values in that case, so skip running on
      // such bots (see crbug.com/326338).
      LOG(INFO) << "Missing output devices: skipping test...";
      return;
    }

    ASSERT_TRUE(base::CommandLine::ForCurrentProcess()->HasSwitch(
        switches::kUseFakeDeviceForMediaStream))
        << "Must run with fake devices since the test will explicitly look "
        << "for the fake device signal.";

    MakeTypicalCall(javascript, "/media/peerconnection-call-audio.html");
  }

  std::string BuildConstraints(const char* audio, const char* video) {
    DCHECK(audio);
    DCHECK(video);

    std::string audio_str(audio);
    std::string video_str(video);
    if (!audio_str.empty() && !video_str.empty())
      return "{" + audio_str + "," + video_str + "}";
    if (!audio_str.empty())
      return "{" + audio_str + "}";

    return "{" + video_str + "}";
  }

 private:
  base::test::ScopedFeatureList audio_service_features_;
};

#if defined(OS_MACOSX)

// Flaky on MacOS: http://crbug.com/982421
#define MAYBE_CanMakeVideoCallAndThenRenegotiateToAudio \
  DISABLED_CanMakeVideoCallAndThenRenegotiateToAudio
#define MAYBE_EstablishAudioVideoCallAndEnsureAudioIsPlaying \
  DISABLED_EstablishAudioVideoCallAndEnsureAudioIsPlaying
#define MAYBE_EstablishAudioOnlyCallAndEnsureAudioIsPlaying \
  DISABLED_EstablishAudioOnlyCallAndEnsureAudioIsPlaying
#define MAYBE_EstablishIsac16KCallAndEnsureAudioIsPlaying \
  DISABLED_EstablishIsac16KCallAndEnsureAudioIsPlaying
#define MAYBE_EnsureLocalVideoMuteDoesntMuteAudio \
  DISABLED_EnsureLocalVideoMuteDoesntMuteAudio
#define MAYBE_EnsureRemoteVideoMuteDoesntMuteAudio \
  DISABLED_EnsureRemoteVideoMuteDoesntMuteAudio
#define MAYBE_EstablishAudioVideoCallAndVerifyUnmutingWorks \
  DISABLED_EstablishAudioVideoCallAndVerifyUnmutingWorks
#define MAYBE_EstablishAudioOnlyCallAndVerifyGetSynchronizationSourcesWorks \
  DISABLED_EstablishAudioOnlyCallAndVerifyGetSynchronizationSourcesWorks

#else

#define MAYBE_CanMakeVideoCallAndThenRenegotiateToAudio \
  CanMakeVideoCallAndThenRenegotiateToAudio
#define MAYBE_EstablishAudioVideoCallAndEnsureAudioIsPlaying \
  EstablishAudioVideoCallAndEnsureAudioIsPlaying
#define MAYBE_EstablishAudioOnlyCallAndEnsureAudioIsPlaying \
  EstablishAudioOnlyCallAndEnsureAudioIsPlaying
#define MAYBE_EstablishIsac16KCallAndEnsureAudioIsPlaying \
  EstablishIsac16KCallAndEnsureAudioIsPlaying
#define MAYBE_EnsureLocalVideoMuteDoesntMuteAudio \
  EnsureLocalVideoMuteDoesntMuteAudio
#define MAYBE_EnsureRemoteVideoMuteDoesntMuteAudio \
  EnsureRemoteVideoMuteDoesntMuteAudio
#define MAYBE_EstablishAudioVideoCallAndVerifyUnmutingWorks \
  EstablishAudioVideoCallAndVerifyUnmutingWorks
#define MAYBE_EstablishAudioOnlyCallAndVerifyGetSynchronizationSourcesWorks \
  EstablishAudioOnlyCallAndVerifyGetSynchronizationSourcesWorks

#endif  // defined(OS_MACOSX)

IN_PROC_BROWSER_TEST_F(WebRtcAudioBrowserTest,
                       MAYBE_CanMakeVideoCallAndThenRenegotiateToAudio) {
  std::string constraints =
      BuildConstraints(kAudioConstraints, kVideoConstraints);
  std::string audio_only_constraints = BuildConstraints(kAudioConstraints, "");
  MakeAudioDetectingPeerConnectionCall("callAndRenegotiateToAudio(" +
                                       constraints + ", " +
                                       audio_only_constraints + ");");
}

IN_PROC_BROWSER_TEST_F(WebRtcAudioBrowserTest,
                       MAYBE_EstablishAudioVideoCallAndEnsureAudioIsPlaying) {
  std::string constraints =
      BuildConstraints(kAudioConstraints, kVideoConstraints);
  MakeAudioDetectingPeerConnectionCall("callAndEnsureAudioIsPlaying(" +
                                       constraints + ");");
}

IN_PROC_BROWSER_TEST_F(WebRtcAudioBrowserTest,
                       MAYBE_EstablishAudioOnlyCallAndEnsureAudioIsPlaying) {
  std::string constraints =
      BuildConstraints(kAudioConstraints, kVideoConstraints);
  MakeAudioDetectingPeerConnectionCall("callAndEnsureAudioIsPlaying(" +
                                       constraints + ");");
}

IN_PROC_BROWSER_TEST_F(WebRtcAudioBrowserTest,
                       MAYBE_EstablishIsac16KCallAndEnsureAudioIsPlaying) {
  std::string constraints =
      BuildConstraints(kAudioConstraints, kVideoConstraints);
  MakeAudioDetectingPeerConnectionCall(
      "callWithIsac16KAndEnsureAudioIsPlaying(" + constraints + ");");
}

IN_PROC_BROWSER_TEST_F(WebRtcAudioBrowserTest,
                       EstablishAudioVideoCallAndVerifyRemoteMutingWorks) {
  std::string constraints =
      BuildConstraints(kAudioConstraints, kVideoConstraints);
  MakeAudioDetectingPeerConnectionCall(
      "callAndEnsureRemoteAudioTrackMutingWorks(" + constraints + ");");
}

IN_PROC_BROWSER_TEST_F(WebRtcAudioBrowserTest,
                       EstablishAudioVideoCallAndVerifyLocalMutingWorks) {
  std::string constraints =
      BuildConstraints(kAudioConstraints, kVideoConstraints);
  MakeAudioDetectingPeerConnectionCall(
      "callAndEnsureLocalAudioTrackMutingWorks(" + constraints + ");");
}

IN_PROC_BROWSER_TEST_F(WebRtcAudioBrowserTest,
                       MAYBE_EnsureLocalVideoMuteDoesntMuteAudio) {
  std::string constraints =
      BuildConstraints(kAudioConstraints, kVideoConstraints);
  MakeAudioDetectingPeerConnectionCall(
      "callAndEnsureLocalVideoMutingDoesntMuteAudio(" + constraints + ");");
}

IN_PROC_BROWSER_TEST_F(WebRtcAudioBrowserTest,
                       MAYBE_EnsureRemoteVideoMuteDoesntMuteAudio) {
  std::string constraints =
      BuildConstraints(kAudioConstraints, kVideoConstraints);
  MakeAudioDetectingPeerConnectionCall(
      "callAndEnsureRemoteVideoMutingDoesntMuteAudio(" + constraints + ");");
}

IN_PROC_BROWSER_TEST_F(WebRtcAudioBrowserTest,
                       MAYBE_EstablishAudioVideoCallAndVerifyUnmutingWorks) {
  std::string constraints =
      BuildConstraints(kAudioConstraints, kVideoConstraints);
  MakeAudioDetectingPeerConnectionCall("callAndEnsureAudioTrackUnmutingWorks(" +
                                       constraints + ");");
}

// TODO(crbug.com/988432): This test is a temporary replacement for:
// external/wpt/webrtc/RTCRtpReceiver-getSynchronizationSources.https.html
IN_PROC_BROWSER_TEST_F(
    WebRtcAudioBrowserTest,
    MAYBE_EstablishAudioOnlyCallAndVerifyGetSynchronizationSourcesWorks) {
  MakeAudioDetectingPeerConnectionCall(
      "testEstablishAudioOnlyCallAndVerifyGetSynchronizationSourcesWorks();");
}

}  // namespace content