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/bind.h" 6 #include "base/test/launcher/unit_test_launcher.h" 7 #include "base/test/test_suite.h" 8 #include "build/build_config.h" 9 #include "media/base/media.h" 10 #include "third_party/WebKit/public/web/WebKit.h" 11 12 #if defined(OS_ANDROID) 13 #include "base/android/jni_android.h" 14 #include "media/base/android/media_jni_registrar.h" 15 #include "ui/gl/android/gl_jni_registrar.h" 16 #endif 17 18 class TestBlinkPlatformSupport : NON_EXPORTED_BASE(public blink::Platform) { 19 public: 20 virtual ~TestBlinkPlatformSupport(); 21 22 virtual void cryptographicallyRandomValues(unsigned char* buffer, 23 size_t length) OVERRIDE; 24 virtual const unsigned char* getTraceCategoryEnabledFlag( 25 const char* categoryName) OVERRIDE; 26 }; 27 28 TestBlinkPlatformSupport::~TestBlinkPlatformSupport() {} 29 30 void TestBlinkPlatformSupport::cryptographicallyRandomValues( 31 unsigned char* buffer, 32 size_t length) { 33 } 34 35 const unsigned char* TestBlinkPlatformSupport::getTraceCategoryEnabledFlag( 36 const char* categoryName) { 37 static const unsigned char tracingIsDisabled = 0; 38 return &tracingIsDisabled; 39 } 40 41 class BlinkMediaTestSuite : public base::TestSuite { 42 public: 43 BlinkMediaTestSuite(int argc, char** argv); 44 virtual ~BlinkMediaTestSuite(); 45 46 protected: 47 virtual void Initialize() OVERRIDE; 48 49 private: 50 scoped_ptr<TestBlinkPlatformSupport> blink_platform_support_; 51 }; 52 53 BlinkMediaTestSuite::BlinkMediaTestSuite(int argc, char** argv) 54 : TestSuite(argc, argv), 55 blink_platform_support_(new TestBlinkPlatformSupport()) { 56 } 57 58 BlinkMediaTestSuite::~BlinkMediaTestSuite() {} 59 60 void BlinkMediaTestSuite::Initialize() { 61 // Run TestSuite::Initialize first so that logging is initialized. 62 base::TestSuite::Initialize(); 63 64 #if defined(OS_ANDROID) 65 // Register JNI bindings for android. 66 JNIEnv* env = base::android::AttachCurrentThread(); 67 // Needed for surface texture support. 68 ui::gl::android::RegisterJni(env); 69 media::RegisterJni(env); 70 #endif 71 72 // Run this here instead of main() to ensure an AtExitManager is already 73 // present. 74 media::InitializeMediaLibraryForTesting(); 75 76 blink::initialize(blink_platform_support_.get()); 77 } 78 79 int main(int argc, char** argv) { 80 BlinkMediaTestSuite test_suite(argc, argv); 81 82 return base::LaunchUnitTests( 83 argc, argv, base::Bind(&BlinkMediaTestSuite::Run, 84 base::Unretained(&test_suite))); 85 } 86