Delete unused downloads page asset.
[chromium-blink-merge.git] / ppapi / tests / test_video_decoder.cc
bloba6b1ce98b5669579853e46348a0c18205c93dd6a
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.
5 #include "ppapi/tests/test_video_decoder.h"
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"
12 namespace {
14 // The maximum number of pictures that the client can pass in for
15 // min_picture_count, just as a sanity check on the argument.
16 // This should match the value of kMaximumPictureCount in
17 // video_decoder_resource.cc.
18 const uint32_t kMaximumPictureCount = 100;
20 } // namespace
22 REGISTER_TEST_CASE(VideoDecoder);
24 bool TestVideoDecoder::Init() {
25 const int width = 16;
26 const int height = 16;
27 const int32_t attribs[] = {PP_GRAPHICS3DATTRIB_WIDTH, width,
28 PP_GRAPHICS3DATTRIB_HEIGHT, height,
29 PP_GRAPHICS3DATTRIB_NONE};
30 graphics_3d_ = pp::Graphics3D(instance_, attribs);
31 return (pp::Module::Get()->GetBrowserInterface(PPB_VIDEODECODER_INTERFACE) &&
32 CheckTestingInterface());
35 void TestVideoDecoder::RunTests(const std::string& filter) {
36 RUN_CALLBACK_TEST(TestVideoDecoder, Create, filter);
39 std::string TestVideoDecoder::TestCreate() {
40 // Test that Initialize fails with a bad Graphics3D resource.
42 pp::VideoDecoder video_decoder(instance_);
43 ASSERT_FALSE(video_decoder.is_null());
45 TestCompletionCallback callback(instance_->pp_instance(), callback_type());
46 pp::Graphics3D null_graphics_3d;
47 callback.WaitForResult(
48 video_decoder.Initialize(null_graphics_3d,
49 PP_VIDEOPROFILE_VP8_ANY,
50 PP_HARDWAREACCELERATION_WITHFALLBACK,
52 callback.GetCallback()));
53 ASSERT_EQ(PP_ERROR_BADRESOURCE, callback.result());
55 // Test that Initialize fails with a bad profile enum value.
57 pp::VideoDecoder video_decoder(instance_);
58 TestCompletionCallback callback(instance_->pp_instance(), callback_type());
59 const PP_VideoProfile kInvalidProfile = static_cast<PP_VideoProfile>(-1);
60 callback.WaitForResult(
61 video_decoder.Initialize(graphics_3d_,
62 kInvalidProfile,
63 PP_HARDWAREACCELERATION_WITHFALLBACK,
65 callback.GetCallback()));
66 ASSERT_EQ(PP_ERROR_BADARGUMENT, callback.result());
68 // Test that Initialize succeeds if we can create a Graphics3D resources and
69 // if we allow software fallback to VP8, which should always be supported.
70 if (!graphics_3d_.is_null()) {
71 pp::VideoDecoder video_decoder(instance_);
72 TestCompletionCallback callback(instance_->pp_instance(), callback_type());
73 callback.WaitForResult(
74 video_decoder.Initialize(graphics_3d_,
75 PP_VIDEOPROFILE_VP8_ANY,
76 PP_HARDWAREACCELERATION_WITHFALLBACK,
78 callback.GetCallback()));
79 ASSERT_EQ(PP_OK, callback.result());
81 // Test that Initialize succeeds with a larger than normal number of requested
82 // picture buffers, if we can create a Graphics3D resource and if we allow
83 // software fallback to VP8, which should always be supported.
84 if (!graphics_3d_.is_null()) {
85 pp::VideoDecoder video_decoder(instance_);
86 TestCompletionCallback callback(instance_->pp_instance(), callback_type());
87 callback.WaitForResult(
88 video_decoder.Initialize(graphics_3d_,
89 PP_VIDEOPROFILE_VP8_ANY,
90 PP_HARDWAREACCELERATION_WITHFALLBACK,
91 kMaximumPictureCount,
92 callback.GetCallback()));
93 ASSERT_EQ(PP_OK, callback.result());
95 // Test that Initialize fails if we request an unreasonable number of picture
96 // buffers.
97 if (!graphics_3d_.is_null()) {
98 pp::VideoDecoder video_decoder(instance_);
99 TestCompletionCallback callback(instance_->pp_instance(), callback_type());
100 callback.WaitForResult(
101 video_decoder.Initialize(graphics_3d_,
102 PP_VIDEOPROFILE_VP8_ANY,
103 PP_HARDWAREACCELERATION_WITHFALLBACK,
104 kMaximumPictureCount + 1,
105 callback.GetCallback()));
106 ASSERT_EQ(PP_ERROR_BADARGUMENT, callback.result());
109 PASS();