| Index: content/browser/media/openh264_unittests.cc | 
| diff --git a/content/browser/media/openh264_unittests.cc b/content/browser/media/openh264_unittests.cc | 
| new file mode 100644 | 
| index 0000000000000000000000000000000000000000..01468c200244e2bf5b2f78cee5ea8208a15d21c3 | 
| --- /dev/null | 
| +++ b/content/browser/media/openh264_unittests.cc | 
| @@ -0,0 +1,66 @@ | 
| +// Copyright 2015 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 "testing/gtest/include/gtest/gtest.h" | 
| + | 
| +#include "third_party/openh264/testing/h264_codec_tester.h" | 
| +#include "third_party/openh264/testing/h264_decoder_impl.h" | 
| +#include "third_party/openh264/testing/h264_encoder_impl.h" | 
| +#include "third_party/openh264/testing/i420_utils.h" | 
| +#include "third_party/webrtc/common_video/libyuv/include/webrtc_libyuv.h" | 
| + | 
| +namespace openh264 { | 
| + | 
| +static const unsigned short kVideoWidth = 320; | 
| +static const unsigned short kVideoHeight = 240; | 
| + | 
| +static const size_t kNumSampleFrames = 10; | 
| + | 
| +class OpenH264Tests : public testing::Test { | 
| + protected: | 
| +  OpenH264Tests() { | 
| +    int shade = 0; | 
| +    for (size_t i = 0; i < kNumSampleFrames; ++i) { | 
| +      CreateRgbFrame(&sample_frames_[i], kVideoWidth, kVideoHeight, | 
| +                     shade, shade, shade); | 
| +      shade += 255 / kNumSampleFrames; | 
| +    } | 
| +  } | 
| +  ~OpenH264Tests() override {} | 
| + | 
| +  VideoFrame sample_frames_[kNumSampleFrames]; | 
| +  H264CodecTester codec_tester_; | 
| +}; | 
| + | 
| +TEST_F(OpenH264Tests, EncodeDecodeCompareFrames) { | 
| +  const int kNumFrames = 30; | 
| + | 
| +  ASSERT_TRUE(codec_tester_.Init(kVideoWidth, kVideoHeight)); | 
| +  double avg_ssim = 0.0; | 
| +  for (size_t i = 0; i < kNumFrames; ++i) { | 
| +    VideoFrame* original_frame = &sample_frames_[i % kNumSampleFrames]; | 
| +    ASSERT_TRUE(codec_tester_.Encode(*original_frame)); | 
| +    VideoFrame* decoded_frame = codec_tester_.Decode(); | 
| +    ASSERT_TRUE(decoded_frame != nullptr); | 
| + | 
| +    avg_ssim += webrtc::I420SSIM(original_frame, decoded_frame); | 
| +  } | 
| +  avg_ssim /= kNumFrames; | 
| + | 
| +  ASSERT_GE(avg_ssim, 0.9) << "Expected decoded frames to be more similar (on " | 
| +                           << "average) to the original frames (SSIM too low)"; | 
| +} | 
| + | 
| +#if defined(OS_CHROMEOS) | 
| +TEST_F(OpenH264Tests, BuildingWithOpenH264ShouldFail) { | 
| +  FAIL() << "Building with 'build_openh264==1' / defined(BUILD_OPENH264) makes " | 
| +            "this test fail. This is to ensure you do not accidentally land a " | 
| +            "CL that changes the default behavior. The default should be not " | 
| +            "to build it in Chromium due to licensing issues! However, you may " | 
| +            "have to temporarily change the default behavior in order for the " | 
| +            "trybots to run the OpenH264Tests test code."; | 
| +} | 
| +#endif | 
| + | 
| +}  // namespace openh264 | 
|  |