Home | History | Annotate | Download | only in media
      1 // Copyright (c) 2013 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 "content/browser/media/media_browsertest.h"
      7 #include "content/public/common/content_switches.h"
      8 #if defined(OS_ANDROID)
      9 #include "base/android/build_info.h"
     10 #endif
     11 
     12 // Common media types.
     13 const char kWebMAudioOnly[] = "audio/webm; codecs=\"vorbis\"";
     14 const char kWebMVideoOnly[] = "video/webm; codecs=\"vp8\"";
     15 const char kWebMAudioVideo[] = "video/webm; codecs=\"vorbis, vp8\"";
     16 
     17 namespace content {
     18 
     19 // MSE is available on all desktop platforms and on Android 4.1 and later.
     20 static bool IsMSESupported() {
     21 #if defined(OS_ANDROID)
     22   if (base::android::BuildInfo::GetInstance()->sdk_int() < 16) {
     23     VLOG(0) << "MSE is only supported in Android 4.1 and later.";
     24     return false;
     25   }
     26 #endif  // defined(OS_ANDROID)
     27   return true;
     28 }
     29 
     30 class MediaSourceTest : public content::MediaBrowserTest {
     31  public:
     32   void TestSimplePlayback(const char* media_file, const char* media_type,
     33                           const char* expectation) {
     34     if (!IsMSESupported()) {
     35       VLOG(0) << "Skipping test - MSE not supported.";
     36       return;
     37     }
     38 
     39     std::vector<StringPair> query_params;
     40     query_params.push_back(std::make_pair("mediafile", media_file));
     41     query_params.push_back(std::make_pair("mediatype", media_type));
     42     RunMediaTestPage("media_source_player.html", &query_params, expectation,
     43                      true);
     44   }
     45 
     46 #if defined(OS_ANDROID)
     47   virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
     48     command_line->AppendSwitch(
     49         switches::kDisableGestureRequirementForMediaPlayback);
     50   }
     51 #endif
     52 };
     53 
     54 IN_PROC_BROWSER_TEST_F(MediaSourceTest, Playback_VideoAudio_WebM) {
     55   TestSimplePlayback("bear-320x240.webm", kWebMAudioVideo, kEnded);
     56 }
     57 
     58 IN_PROC_BROWSER_TEST_F(MediaSourceTest, Playback_VideoOnly_WebM) {
     59   TestSimplePlayback("bear-320x240-video-only.webm", kWebMVideoOnly, kEnded);
     60 }
     61 
     62 IN_PROC_BROWSER_TEST_F(MediaSourceTest, Playback_AudioOnly_WebM) {
     63   TestSimplePlayback("bear-320x240-audio-only.webm", kWebMAudioOnly, kEnded);
     64 }
     65 
     66 IN_PROC_BROWSER_TEST_F(MediaSourceTest, Playback_Type_Error) {
     67   TestSimplePlayback("bear-320x240-video-only.webm", kWebMAudioOnly, kError);
     68 }
     69 
     70 // Flaky test crbug.com/246308
     71 // Test changed to skip checks resulting in flakiness. Proper fix still needed.
     72 IN_PROC_BROWSER_TEST_F(MediaSourceTest, ConfigChangeVideo) {
     73   if (!IsMSESupported()) {
     74     VLOG(0) << "Skipping test - MSE not supported.";
     75     return;
     76   }
     77   RunMediaTestPage("mse_config_change.html", NULL, kEnded, true);
     78 }
     79 
     80 }  // namespace content
     81