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 "ppapi/tests/test_video_decoder.h"
6
7#include "ppapi/c/pp_errors.h"
8#include "ppapi/cpp/video_decoder.h"
9#include "ppapi/lib/gl/gles2/gl2ext_ppapi.h"
10#include "ppapi/tests/testing_instance.h"
11
12REGISTER_TEST_CASE(VideoDecoder);
13
14bool TestVideoDecoder::Init() {
15  video_decoder_interface_ = static_cast<const PPB_VideoDecoder_0_1*>(
16      pp::Module::Get()->GetBrowserInterface(PPB_VIDEODECODER_INTERFACE_0_1));
17  const int width = 16;
18  const int height = 16;
19  const int32_t attribs[] = {PP_GRAPHICS3DATTRIB_WIDTH, width,
20                             PP_GRAPHICS3DATTRIB_HEIGHT, height,
21                             PP_GRAPHICS3DATTRIB_NONE};
22  graphics_3d_ = pp::Graphics3D(instance_, attribs);
23  return video_decoder_interface_ && CheckTestingInterface();
24}
25
26void TestVideoDecoder::RunTests(const std::string& filter) {
27  RUN_CALLBACK_TEST(TestVideoDecoder, Create, filter);
28}
29
30std::string TestVideoDecoder::TestCreate() {
31  // Test that Initialize fails with a bad Graphics3D resource.
32  {
33    pp::VideoDecoder video_decoder(instance_);
34    ASSERT_FALSE(video_decoder.is_null());
35
36    TestCompletionCallback callback(instance_->pp_instance(), callback_type());
37    pp::Graphics3D null_graphics_3d;
38    callback.WaitForResult(
39        video_decoder.Initialize(null_graphics_3d,
40                                 PP_VIDEOPROFILE_VP8_ANY,
41                                 PP_HARDWAREACCELERATION_WITHFALLBACK,
42                                 callback.GetCallback()));
43    ASSERT_EQ(PP_ERROR_BADRESOURCE, callback.result());
44  }
45  // Test that Initialize fails with a bad profile enum value.
46  {
47    pp::VideoDecoder video_decoder(instance_);
48    TestCompletionCallback callback(instance_->pp_instance(), callback_type());
49    const PP_VideoProfile kInvalidProfile = static_cast<PP_VideoProfile>(-1);
50    callback.WaitForResult(
51        video_decoder.Initialize(graphics_3d_,
52                                 kInvalidProfile,
53                                 PP_HARDWAREACCELERATION_WITHFALLBACK,
54                                 callback.GetCallback()));
55    ASSERT_EQ(PP_ERROR_BADARGUMENT, callback.result());
56  }
57  // Test that Initialize succeeds if we can create a Graphics3D resources and
58  // if we allow software fallback to VP8, which should always be supported.
59  if (!graphics_3d_.is_null()) {
60    pp::VideoDecoder video_decoder(instance_);
61    TestCompletionCallback callback(instance_->pp_instance(), callback_type());
62    callback.WaitForResult(
63        video_decoder.Initialize(graphics_3d_,
64                                 PP_VIDEOPROFILE_VP8_ANY,
65                                 PP_HARDWAREACCELERATION_WITHFALLBACK,
66                                 callback.GetCallback()));
67    ASSERT_EQ(PP_OK, callback.result());
68  }
69
70  PASS();
71}
72