<commit_before>// Copyright (c) 2012 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/basictypes.h"
#include "base/command_line.h"
#include "base/file_util.h"
#include "base/path_service.h"
#include "base/string16.h"
#include "base/string_util.h"
#include "base/stringprintf.h"
#include "base/utf_string_conversions.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/browser_test_utils.h"
#include "content/shell/shell.h"
#include "content/test/content_browser_test.h"
#include "content/test/content_browser_test_utils.h"
#include "googleurl/src/gurl.h"
#include "media/base/media_switches.h"
#include "webkit/media/crypto/key_systems.h"

// Platform-specific filename relative to the chrome executable.
#if defined(OS_WIN)
static const wchar_t kLibraryName[] = L"clearkeycdmplugin.dll";
#elif defined(OS_MACOSX)
static const char kLibraryName[] = "clearkeycdmplugin.plugin";
#elif defined(OS_POSIX)
static const char kLibraryName[] = "libclearkeycdmplugin.so";
#endif

// Available key systems.
static const char kClearKeyKeySystem[] = "webkit-org.w3.clearkey";
static const char kExternalClearKeyKeySystem[] =
    "org.chromium.externalclearkey";

static const char kWebMAudioOnly[] = "audio/webm; codecs=\"vorbis\"";
static const char kWebMVideoOnly[] = "video/webm; codecs=\"vp8\"";
static const char kWebMAudioVideo[] = "video/webm; codecs=\"vorbis, vp8\"";

namespace content {

class EncryptedMediaTest : public testing::WithParamInterface<const char*>,
                           public ContentBrowserTest {
 public:
  void TestSimplePlayback(const char* encrypted_media, const char* media_type,
                          const char* key_system, const string16 expectation) {
    PlayEncryptedMedia("encrypted_media_player.html", encrypted_media,
                       media_type, key_system, expectation);
  }

  void TestFrameSizeChange(const char* key_system, const string16 expectation) {
    PlayEncryptedMedia("encrypted_frame_size_change.html",
                       "frame_size_change-av-enc-v.webm", kWebMAudioVideo,
                       key_system, expectation);
  }

  void PlayEncryptedMedia(const char* html_page, const char* media_file,
                          const char* media_type, const char* key_system,
                          const string16 expectation) {
    // TODO(shadi): Add non-HTTP tests once src is supported for EME.
    ASSERT_TRUE(test_server()->Start());

    const string16 kError = ASCIIToUTF16("ERROR");
    const string16 kFailed = ASCIIToUTF16("FAILED");
    GURL player_gurl = test_server()->GetURL(base::StringPrintf(
        "files/media/%s?keysystem=%s&mediafile=%s&mediatype=%s", html_page,
        key_system, media_file, media_type));
    TitleWatcher title_watcher(shell()->web_contents(), expectation);
    title_watcher.AlsoWaitForTitle(kError);
    title_watcher.AlsoWaitForTitle(kFailed);

    NavigateToURL(shell(), player_gurl);

    string16 final_title = title_watcher.WaitAndGetTitle();
    EXPECT_EQ(expectation, final_title);

    if (final_title == kFailed) {
      std::string fail_message;
      EXPECT_TRUE(ExecuteScriptAndExtractString(
          shell()->web_contents(),
          "window.domAutomationController.send(failMessage);",
          &fail_message));
      LOG(INFO) << "Test failed: " << fail_message;
    }
  }

 protected:
  // Registers any CDM plugins not registered by default.
  virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
    command_line->AppendSwitch(switches::kDisableAudio);
    command_line->AppendSwitch(switches::kPpapiOutOfProcess);

    // Append the switch to register the Clear Key CDM plugin.
    FilePath plugin_dir;
    EXPECT_TRUE(PathService::Get(base::DIR_MODULE, &plugin_dir));
    FilePath plugin_lib = plugin_dir.Append(kLibraryName);
    EXPECT_TRUE(file_util::PathExists(plugin_lib));
    FilePath::StringType pepper_plugin = plugin_lib.value();
    pepper_plugin.append(FILE_PATH_LITERAL(
        "#Clear Key CDM#Clear Key CDM 0.1.0.0#0.1.0.0;"));
#if defined(OS_WIN)
      pepper_plugin.append(ASCIIToWide(
          webkit_media::GetPluginType(kExternalClearKeyKeySystem)));
#else
      pepper_plugin.append(
          webkit_media::GetPluginType(kExternalClearKeyKeySystem));
#endif
    command_line->AppendSwitchNative(switches::kRegisterPepperPlugins,
                                     pepper_plugin);
  }
};

INSTANTIATE_TEST_CASE_P(ClearKey, EncryptedMediaTest,
                        ::testing::Values(kClearKeyKeySystem));

INSTANTIATE_TEST_CASE_P(ExternalClearKey, EncryptedMediaTest,
                        ::testing::Values(kExternalClearKeyKeySystem));

IN_PROC_BROWSER_TEST_F(EncryptedMediaTest, InvalidKeySystem) {
  const string16 kExpected = ASCIIToUTF16(
      StringToUpperASCII(std::string("GenerateKeyRequestException")));
  ASSERT_NO_FATAL_FAILURE(
      TestSimplePlayback("bear-320x240-av-enc_av.webm", kWebMAudioVideo,
                         "com.example.invalid", kExpected));
}

IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, BasicPlayback_AudioOnly) {
  const string16 kExpected = ASCIIToUTF16("ENDED");
  ASSERT_NO_FATAL_FAILURE(
      TestSimplePlayback("bear-a-enc_a.webm", kWebMAudioOnly,
                         GetParam(), kExpected));
}

IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, BasicPlayback_AudioClearVideo) {
  const string16 kExpected = ASCIIToUTF16("ENDED");
  ASSERT_NO_FATAL_FAILURE(
      TestSimplePlayback("bear-320x240-av-enc_a.webm", kWebMAudioVideo,
                         GetParam(), kExpected));
}

IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, BasicPlayback_VideoAudio) {
  const string16 kExpected = ASCIIToUTF16("ENDED");
  ASSERT_NO_FATAL_FAILURE(
      TestSimplePlayback("bear-320x240-av-enc_av.webm", kWebMAudioVideo,
                         GetParam(), kExpected));
}

IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, BasicPlayback_VideoOnly) {
  const string16 kExpected = ASCIIToUTF16("ENDED");
  ASSERT_NO_FATAL_FAILURE(
      TestSimplePlayback("bear-320x240-v-enc_v.webm", kWebMVideoOnly,
                         GetParam(), kExpected));
}

IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, BasicPlayback_VideoClearAudio) {
  const string16 kExpected = ASCIIToUTF16("ENDED");
  ASSERT_NO_FATAL_FAILURE(
      TestSimplePlayback("bear-320x240-av-enc_v.webm", kWebMAudioVideo,
                         GetParam(), kExpected));<commit_msg>Disable some EncryptedMediaTests<commit_after>// Copyright (c) 2012 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/basictypes.h"
#include "base/command_line.h"
#include "base/file_util.h"
#include "base/path_service.h"
#include "base/string16.h"
#include "base/string_util.h"
#include "base/stringprintf.h"
#include "base/utf_string_conversions.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/browser_test_utils.h"
#include "content/shell/shell.h"
#include "content/test/content_browser_test.h"
#include "content/test/content_browser_test_utils.h"
#include "googleurl/src/gurl.h"
#include "media/base/media_switches.h"
#include "webkit/media/crypto/key_systems.h"

// Platform-specific filename relative to the chrome executable.
#if defined(OS_WIN)
static const wchar_t kLibraryName[] = L"clearkeycdmplugin.dll";
#elif defined(OS_MACOSX)
static const char kLibraryName[] = "clearkeycdmplugin.plugin";
#elif defined(OS_POSIX)
static const char kLibraryName[] = "libclearkeycdmplugin.so";
#endif

// Available key systems.
static const char kClearKeyKeySystem[] = "webkit-org.w3.clearkey";
static const char kExternalClearKeyKeySystem[] =
    "org.chromium.externalclearkey";

static const char kWebMAudioOnly[] = "audio/webm; codecs=\"vorbis\"";
static const char kWebMVideoOnly[] = "video/webm; codecs=\"vp8\"";
static const char kWebMAudioVideo[] = "video/webm; codecs=\"vorbis, vp8\"";

namespace content {

class EncryptedMediaTest : public testing::WithParamInterface<const char*>,
                           public ContentBrowserTest {
 public:
  void TestSimplePlayback(const char* encrypted_media, const char* media_type,
                          const char* key_system, const string16 expectation) {
    PlayEncryptedMedia("encrypted_media_player.html", encrypted_media,
                       media_type, key_system, expectation);
  }

  void TestFrameSizeChange(const char* key_system, const string16 expectation) {
    PlayEncryptedMedia("encrypted_frame_size_change.html",
                       "frame_size_change-av-enc-v.webm", kWebMAudioVideo,
                       key_system, expectation);
  }

  void PlayEncryptedMedia(const char* html_page, const char* media_file,
                          const char* media_type, const char* key_system,
                          const string16 expectation) {
    // TODO(shadi): Add non-HTTP tests once src is supported for EME.
    ASSERT_TRUE(test_server()->Start());

    const string16 kError = ASCIIToUTF16("ERROR");
    const string16 kFailed = ASCIIToUTF16("FAILED");
    GURL player_gurl = test_server()->GetURL(base::StringPrintf(
        "files/media/%s?keysystem=%s&mediafile=%s&mediatype=%s", html_page,
        key_system, media_file, media_type));
    TitleWatcher title_watcher(shell()->web_contents(), expectation);
    title_watcher.AlsoWaitForTitle(kError);
    title_watcher.AlsoWaitForTitle(kFailed);

    NavigateToURL(shell(), player_gurl);

    string16 final_title = title_watcher.WaitAndGetTitle();
    EXPECT_EQ(expectation, final_title);

    if (final_title == kFailed) {
      std::string fail_message;
      EXPECT_TRUE(ExecuteScriptAndExtractString(
          shell()->web_contents(),
          "window.domAutomationController.send(failMessage);",
          &fail_message));
      LOG(INFO) << "Test failed: " << fail_message;
    }
  }

 protected:
  // Registers any CDM plugins not registered by default.
  virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
    command_line->AppendSwitch(switches::kDisableAudio);
    command_line->AppendSwitch(switches::kPpapiOutOfProcess);

    // Append the switch to register the Clear Key CDM plugin.
    FilePath plugin_dir;
    EXPECT_TRUE(PathService::Get(base::DIR_MODULE, &plugin_dir));
    FilePath plugin_lib = plugin_dir.Append(kLibraryName);
    EXPECT_TRUE(file_util::PathExists(plugin_lib));
    FilePath::StringType pepper_plugin = plugin_lib.value();
    pepper_plugin.append(FILE_PATH_LITERAL(
        "#Clear Key CDM#Clear Key CDM 0.1.0.0#0.1.0.0;"));
#if defined(OS_WIN)
      pepper_plugin.append(ASCIIToWide(
          webkit_media::GetPluginType(kExternalClearKeyKeySystem)));
#else
      pepper_plugin.append(
          webkit_media::GetPluginType(kExternalClearKeyKeySystem));
#endif
    command_line->AppendSwitchNative(switches::kRegisterPepperPlugins,
                                     pepper_plugin);
  }
};

INSTANTIATE_TEST_CASE_P(ClearKey, EncryptedMediaTest,
                        ::testing::Values(kClearKeyKeySystem));

INSTANTIATE_TEST_CASE_P(ExternalClearKey, EncryptedMediaTest,
                        ::testing::Values(kExternalClearKeyKeySystem));

IN_PROC_BROWSER_TEST_F(EncryptedMediaTest, InvalidKeySystem) {
  const string16 kExpected = ASCIIToUTF16(
      StringToUpperASCII(std::string("GenerateKeyRequestException")));
  ASSERT_NO_FATAL_FAILURE(
      TestSimplePlayback("bear-320x240-av-enc_av.webm", kWebMAudioVideo,
                         "com.example.invalid", kExpected));
}

#if defined(OS_LINUX) && !defined(NDEBUG)
// http://crbug.com/174294; not using MAYBE_ because IN_PROC_BROWSER_TEST_P does
// not expand the test name macro correctly, TODO(vabr, bauerb)
IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, DISABLED_BasicPlayback_AudioOnly) {
#else
IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, BasicPlayback_AudioOnly) {
#endif
  const string16 kExpected = ASCIIToUTF16("ENDED");
  ASSERT_NO_FATAL_FAILURE(
      TestSimplePlayback("bear-a-enc_a.webm", kWebMAudioOnly,
                         GetParam(), kExpected));
}

#if defined(OS_LINUX) && !defined(NDEBUG)
// http://crbug.com/174294; not using MAYBE_ because IN_PROC_BROWSER_TEST_P does
// not expand the test name macro correctly, TODO(vabr, bauerb)
IN_PROC_BROWSER_TEST_P(EncryptedMediaTest,
                       DISABLED_BasicPlayback_AudioClearVideo) {
#else
IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, BasicPlayback_AudioClearVideo) {
#endif
  const string16 kExpected = ASCIIToUTF16("ENDED");
  ASSERT_NO_FATAL_FAILURE(
      TestSimplePlayback("bear-320x240-av-enc_a.webm", kWebMAudioVideo,
                         GetParam(), kExpected));
}

#if defined(OS_LINUX) && !defined(NDEBUG)
// http://crbug.com/174294; not using MAYBE_ because IN_PROC_BROWSER_TEST_P does
// not expand the test name macro correctly, TODO(vabr, bauerb)
IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, DISABLED_BasicPlayback_VideoAudio) {
#else
IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, BasicPlayback_VideoAudio) {
#endif
  const string16 kExpected = ASCIIToUTF16("ENDED");
  ASSERT_NO_FATAL_FAILURE(
      TestSimplePlayback("bear-320x240-av-enc_av.webm", kWebMAudioVideo,
                         GetParam(), kExpected));
}

#if defined(OS_LINUX) && !defined(NDEBUG)
// http://crbug.com/174294; not using MAYBE_ because IN_PROC_BROWSER_TEST_P does
// not expand the test name macro correctly, TODO(vabr, bauerb)
IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, DISABLED_BasicPlayback_VideoOnly) {
#else
IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, BasicPlayback_VideoOnly) {
#endif
  const string16 kExpected = ASCIIToUTF16("ENDED");
  ASSERT_NO_FATAL_FAILURE(
      TestSimplePlayback("bear-320x240-v-enc_v.webm", kWebMVideoOnly,
                         GetParam(), kExpected));
}

#if defined(OS_LINUX) && !defined(NDEBUG)
// http://crbug.com/174294; not using MAYBE_ because IN_PROC_BROWSER_TEST_P does
// not expand the test name macro correctly, TODO(vabr, bauerb)
IN_PROC_BROWSER_TEST_P(EncryptedMediaTest,
                       DISABLED_BasicPlayback_VideoClearAudio) {
#else
IN_PROC_BROWSER_TEST_P(EncryptedMediaTest, BasicPlayback_VideoClearAudio) {
#endif
  const string16 kExpected = ASCIIToUTF16("ENDED");
  ASSERT_NO_FATAL_FAILURE(
      TestSimplePlayback("bear-320x240-av-enc_v.webm", kWebMAudioVideo,
                         GetParam(), kExpected));
{'fraction_non_alphanumeric': 0.10588477648836092, 'fraction_numerical': 0.014008102726086658, 'mean_word_length': 4.208869814020028, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '410648', 'n_tokens_mistral': 4832, 'n_tokens_neox': 4654, 'n_words': 834}