1a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved.
2a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
3a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// found in the LICENSE file.
4a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
5a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "base/command_line.h"
6a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "chrome/browser/media/webrtc_browsertest_base.h"
7a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "chrome/browser/media/webrtc_browsertest_common.h"
8a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "chrome/common/chrome_version_info.h"
9a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "content/public/common/content_switches.h"
10cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "media/base/media_switches.h"
11a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "net/test/embedded_test_server/embedded_test_server.h"
12a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
13a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)static const char kMainWebrtcTestHtmlPage[] =
14a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    "/webrtc/webrtc_jsep01_test.html";
15a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
16a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)using chrome::VersionInfo;
17a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
18a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// This tests the --disable-webrtc-encryption command line flag. Disabling
19a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// encryption should only be possible on certain channels.
20a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
21a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// NOTE: The test case for each channel will only be exercised when the browser
22a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// is actually built for that channel. This is not ideal. One can test manually
23a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// by e.g. faking the channel returned in VersionInfo::GetChannel(). It's
24a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// likely good to have the test anyway, even though a failure might not be
25a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// detected until a branch has been promoted to another channel. The unit
26a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// test for ChromeContentBrowserClient::MaybeCopyDisableWebRtcEncryptionSwitch
27a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// tests for all channels however.
28a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// TODO(grunell): Test the different channel cases for any build.
29a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class WebRtcDisableEncryptionFlagBrowserTest : public WebRtcTestBase {
30a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) public:
31a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  WebRtcDisableEncryptionFlagBrowserTest() {}
32a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  virtual ~WebRtcDisableEncryptionFlagBrowserTest() {}
33a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
34a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
35a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    DetectErrorsInJavaScript();  // Look for errors in our rather complex js.
36a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  }
37a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
38a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
39a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    // This test should run with fake devices.
40a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    command_line->AppendSwitch(switches::kUseFakeDeviceForMediaStream);
41a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
42a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    // Disable encryption with the command line flag.
43a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    command_line->AppendSwitch(switches::kDisableWebRtcEncryption);
44a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  }
45a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
46a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) private:
47a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(WebRtcDisableEncryptionFlagBrowserTest);
48a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)};
49a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
50a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Makes a call and checks that there's encryption or not in the SDP offer.
51a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(WebRtcDisableEncryptionFlagBrowserTest,
52cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)                       VerifyEncryption) {
53cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  if (!OnWinXp())
54cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    return;  // Flaky timeout on a webrtc Win XP bot. http://crbug.com/368163.
555c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
56a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
57a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
58a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  content::WebContents* left_tab =
59a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      OpenTestPageAndGetUserMediaInNewTab(kMainWebrtcTestHtmlPage);
60a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  content::WebContents* right_tab =
61a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      OpenTestPageAndGetUserMediaInNewTab(kMainWebrtcTestHtmlPage);
62a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
63010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  SetupPeerconnectionWithLocalStream(left_tab);
64010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  SetupPeerconnectionWithLocalStream(right_tab);
65010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
66010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  NegotiateCall(left_tab, right_tab);
67a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
68a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  StartDetectingVideo(left_tab, "remote-view");
69a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  StartDetectingVideo(right_tab, "remote-view");
70a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
71a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  WaitForVideoToPlay(left_tab);
72a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  WaitForVideoToPlay(right_tab);
73a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
74a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  bool should_detect_encryption = true;
75a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  VersionInfo::Channel channel = VersionInfo::GetChannel();
76a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  if (channel == VersionInfo::CHANNEL_UNKNOWN ||
77a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      channel == VersionInfo::CHANNEL_CANARY ||
78a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      channel == VersionInfo::CHANNEL_DEV) {
79a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    should_detect_encryption = false;
80a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  }
81a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#if defined(OS_ANDROID)
82a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  if (channel == VersionInfo::CHANNEL_BETA)
83a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    should_detect_encryption = false;
84a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#endif
85a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
86a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  std::string expected_string = should_detect_encryption ?
87a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    "crypto-seen" : "no-crypto-seen";
88a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
89a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  ASSERT_EQ(expected_string,
90a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)            ExecuteJavascript("hasSeenCryptoInSdp()", left_tab));
91a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
92a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  HangUp(left_tab);
93cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  HangUp(right_tab);
94a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
95