1 // Copyright 2014 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.
5 #include "base/command_line.h"
6 #include "chrome/browser/media/webrtc_browsertest_base.h"
7 #include "chrome/browser/media/webrtc_browsertest_common.h"
8 #include "chrome/common/channel_info.h"
9 #include "components/version_info/version_info.h"
10 #include "content/public/common/content_switches.h"
11 #include "media/base/media_switches.h"
12 #include "net/test/embedded_test_server/embedded_test_server.h"
14 static const char kMainWebrtcTestHtmlPage
[] =
15 "/webrtc/webrtc_jsep01_test.html";
17 // This tests the --disable-webrtc-encryption command line flag. Disabling
18 // encryption should only be possible on certain channels.
20 // NOTE: The test case for each channel will only be exercised when the browser
21 // is actually built for that channel. This is not ideal. One can test manually
22 // by e.g. faking the channel returned in chrome::GetChannel(). It's likely good
23 // to have the test anyway, even though a failure might not be detected until a
24 // branch has been promoted to another channel. The unit test for
25 // ChromeContentBrowserClient::MaybeCopyDisableWebRtcEncryptionSwitch tests for
26 // all channels however.
27 // TODO(grunell): Test the different channel cases for any build.
28 class WebRtcDisableEncryptionFlagBrowserTest
: public WebRtcTestBase
{
30 WebRtcDisableEncryptionFlagBrowserTest() {}
31 ~WebRtcDisableEncryptionFlagBrowserTest() override
{}
33 void SetUpInProcessBrowserTestFixture() override
{
34 DetectErrorsInJavaScript(); // Look for errors in our rather complex js.
37 void SetUpCommandLine(base::CommandLine
* command_line
) override
{
38 // This test should run with fake devices.
39 command_line
->AppendSwitch(switches::kUseFakeDeviceForMediaStream
);
41 // Disable encryption with the command line flag.
42 command_line
->AppendSwitch(switches::kDisableWebRtcEncryption
);
46 DISALLOW_COPY_AND_ASSIGN(WebRtcDisableEncryptionFlagBrowserTest
);
49 // Makes a call and checks that there's encryption or not in the SDP offer.
50 IN_PROC_BROWSER_TEST_F(WebRtcDisableEncryptionFlagBrowserTest
,
53 return; // Flaky timeout on a webrtc Win XP bot. http://crbug.com/368163.
55 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
57 content::WebContents
* left_tab
=
58 OpenTestPageAndGetUserMediaInNewTab(kMainWebrtcTestHtmlPage
);
59 content::WebContents
* right_tab
=
60 OpenTestPageAndGetUserMediaInNewTab(kMainWebrtcTestHtmlPage
);
62 SetupPeerconnectionWithLocalStream(left_tab
);
63 SetupPeerconnectionWithLocalStream(right_tab
);
65 NegotiateCall(left_tab
, right_tab
);
67 StartDetectingVideo(left_tab
, "remote-view");
68 StartDetectingVideo(right_tab
, "remote-view");
70 WaitForVideoToPlay(left_tab
);
71 WaitForVideoToPlay(right_tab
);
73 bool should_detect_encryption
= true;
74 version_info::Channel channel
= chrome::GetChannel();
75 if (channel
== version_info::Channel::UNKNOWN
||
76 channel
== version_info::Channel::CANARY
||
77 channel
== version_info::Channel::DEV
) {
78 should_detect_encryption
= false;
80 #if defined(OS_ANDROID)
81 if (channel
== version_info::Channel::BETA
)
82 should_detect_encryption
= false;
85 std::string expected_string
= should_detect_encryption
?
86 "crypto-seen" : "no-crypto-seen";
88 ASSERT_EQ(expected_string
,
89 ExecuteJavascript("hasSeenCryptoInSdp()", left_tab
));