Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: ppapi/tests/test_video_destination.cc

Issue 15039009: Add PPAPI tests for VideoSource and VideoDestination resources. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments on test code. Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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 // Tests PPB_VideoDestination_Private interface.
6
7 #include "ppapi/tests/test_video_destination.h"
8
9 #include <algorithm>
10 #include <limits>
11 #include <string>
12
13 #include "ppapi/c/dev/ppb_testing_dev.h"
14 #include "ppapi/cpp/completion_callback.h"
15 #include "ppapi/cpp/instance.h"
16 #include "ppapi/cpp/private/video_destination_private.h"
17 #include "ppapi/cpp/private/video_frame_private.h"
18 #include "ppapi/cpp/var.h"
19 #include "ppapi/tests/test_utils.h"
20 #include "ppapi/tests/testing_instance.h"
21
22 REGISTER_TEST_CASE(VideoDestination);
23
24 namespace {
25
26 const PP_Resource kInvalidResource = 0;
27 const PP_Instance kInvalidInstance = 0;
28
29 }
30
31 TestVideoDestination::TestVideoDestination(TestingInstance* instance)
32 : TestCase(instance),
33 ppb_video_destination_private_interface_(NULL),
34 ppb_core_interface_(NULL),
35 event_(instance_->pp_instance()) {
36 }
37
38 bool TestVideoDestination::Init() {
39 ppb_video_destination_private_interface_ =
40 static_cast<const PPB_VideoDestination_Private*>(
41 pp::Module::Get()->GetBrowserInterface(
42 PPB_VIDEODESTINATION_PRIVATE_INTERFACE));
palmer 2013/05/09 23:48:11 Style nit: I think the standard is to indent only
bbudge 2013/05/10 00:13:13 Yeah, I should switch to the clang format soon. Do
43 if (!ppb_video_destination_private_interface_)
44 instance_->AppendError(
45 "PPB_VideoDestination_Private interface not available");
46
47 ppb_core_interface_ = static_cast<const PPB_Core*>(
48 pp::Module::Get()->GetBrowserInterface(PPB_CORE_INTERFACE));
49 if (!ppb_core_interface_)
50 instance_->AppendError("PPB_Core interface not available");
51
52 return ppb_video_destination_private_interface_ && ppb_core_interface_;
53 }
54
55 TestVideoDestination::~TestVideoDestination() {
56 }
57
58 void TestVideoDestination::RunTests(const std::string& filter) {
59 RUN_TEST(Create, filter);
60 RUN_TEST(PutFrame, filter);
61 }
62
63 void TestVideoDestination::HandleMessage(const pp::Var& message_data) {
64 if (message_data.AsString().find("blob:") == 0) {
65 stream_url_ = message_data.AsString();
66 event_.Signal();
67 }
68 }
69
70 std::string TestVideoDestination::TestCreate() {
71 PP_Resource video_destination;
72 // Creating a destination from an invalid instance returns an invalid
73 // resource.
74 video_destination =
75 ppb_video_destination_private_interface_->Create(kInvalidInstance);
76 ASSERT_EQ(kInvalidResource, video_destination);
77 ASSERT_FALSE(
78 ppb_video_destination_private_interface_->IsVideoDestination(
79 video_destination));
80
81 // Creating a destination from a valid instance returns a valid resource.
82 video_destination =
83 ppb_video_destination_private_interface_->Create(
84 instance_->pp_instance());
85 ASSERT_NE(kInvalidResource, video_destination);
86 ASSERT_TRUE(
87 ppb_video_destination_private_interface_->IsVideoDestination(
88 video_destination));
89
90 ppb_core_interface_->ReleaseResource(video_destination);
91 // Once released, the resource shouldn't be a video destination.
92 ASSERT_FALSE(
93 ppb_video_destination_private_interface_->IsVideoDestination(
94 video_destination));
95
96 PASS();
97 }
98
99 std::string TestVideoDestination::TestPutFrame() {
100 std::string js_code;
101 js_code += "var test_stream = new webkitMediaStream([]);"
102 "var url = webkitURL.createObjectURL(test_stream);"
103 "var plugin = document.getElementById('plugin');"
104 "plugin.postMessage(url);";
105 instance_->EvalScript(js_code);
106 event_.Wait();
107
108 pp::VideoDestination_Private video_destination(instance_);
109 TestCompletionCallback cc1(instance_->pp_instance(), false);
110 cc1.WaitForResult(video_destination.Open(stream_url_, cc1.GetCallback()));
111 ASSERT_EQ(PP_OK, cc1.result());
112
113 pp::ImageData image_data(instance_,
114 PP_IMAGEDATAFORMAT_BGRA_PREMUL,
115 pp::Size(640, 480),
116 false /* init_to_zero */);
117 pp::VideoFrame_Private video_frame(image_data,
118 0.0 /* timestamp */);
119 ASSERT_EQ(PP_OK, video_destination.PutFrame(video_frame));
120
121 video_destination.Close();
122
123 PASS();
124 }
125
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698