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