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

Unified 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: Fix proxy so basic tests pass. 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 side-by-side diff with in-line comments
Download patch
Index: ppapi/tests/test_video_destination.cc
diff --git a/ppapi/tests/test_video_destination.cc b/ppapi/tests/test_video_destination.cc
new file mode 100644
index 0000000000000000000000000000000000000000..56ce6b2b88f38bf778fd7d8110e21e4da3f3409b
--- /dev/null
+++ b/ppapi/tests/test_video_destination.cc
@@ -0,0 +1,126 @@
+// Copyright (c) 2013 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.
+//
+// Tests PPB_VideoDestination_Private interface.
+
+#include "ppapi/tests/test_video_destination.h"
+
+#include <string.h>
Ronghua Wu (Left Chromium) 2013/05/09 22:22:52 do we want string.h instead of string?
bbudge 2013/05/09 22:35:35 Done.
+#include <algorithm>
+#include <limits>
+
+#include "ppapi/c/dev/ppb_testing_dev.h"
+#include "ppapi/cpp/completion_callback.h"
+#include "ppapi/cpp/instance.h"
+#include "ppapi/cpp/private/video_destination_private.h"
+#include "ppapi/cpp/private/video_frame_private.h"
+#include "ppapi/cpp/var.h"
+#include "ppapi/tests/test_utils.h"
+#include "ppapi/tests/testing_instance.h"
+
+REGISTER_TEST_CASE(VideoDestination);
+
+namespace {
+
+const PP_Resource kInvalidResource = 0;
+const PP_Instance kInvalidInstance = 0;
+
+}
+
+TestVideoDestination::TestVideoDestination(TestingInstance* instance)
+ : TestCase(instance),
+ ppb_video_destination_private_interface_(NULL),
+ ppb_core_interface_(NULL),
+ event_(instance_->pp_instance()) {
+}
+
+bool TestVideoDestination::Init() {
+ ppb_video_destination_private_interface_ =
+ static_cast<const PPB_VideoDestination_Private*>(
+ pp::Module::Get()->GetBrowserInterface(
+ PPB_VIDEODESTINATION_PRIVATE_INTERFACE));
+ ppb_core_interface_ = static_cast<const PPB_Core*>(
+ pp::Module::Get()->GetBrowserInterface(PPB_CORE_INTERFACE));
+ if (!ppb_video_destination_private_interface_)
+ instance_->AppendError(
+ "PPB_VideoDestination_Private interface not available");
Ronghua Wu (Left Chromium) 2013/05/09 22:22:52 do we need to return false here?
bbudge 2013/05/09 22:35:35 Done.
+ if (!ppb_core_interface_)
+ instance_->AppendError("PPB_Core interface not available");
+
+ return true;
+}
+
+TestVideoDestination::~TestVideoDestination() {
+}
+
+void TestVideoDestination::RunTests(const std::string& filter) {
+ RUN_TEST(Create, filter);
+ RUN_TEST(PutFrame, filter);
+}
+
+void TestVideoDestination::HandleMessage(const pp::Var& message_data) {
+ if (message_data.AsString().find("blob:") == 0) {
+ stream_url_ = message_data.AsString();
+ event_.Signal();
+ }
+}
+
+std::string TestVideoDestination::TestCreate() {
+ PP_Resource video_destination;
+ // Creating a destination from an invalid instance returns an invalid
+ // resource.
+ video_destination =
+ ppb_video_destination_private_interface_->Create(kInvalidInstance);
+ ASSERT_EQ(kInvalidResource, video_destination);
+ ASSERT_FALSE(
+ ppb_video_destination_private_interface_->IsVideoDestination(
+ video_destination));
+
+ // Creating a destination from a valid instance returns a valid resource.
+ video_destination =
+ ppb_video_destination_private_interface_->Create(
+ instance_->pp_instance());
+ ASSERT_NE(kInvalidResource, video_destination);
+ ASSERT_TRUE(
+ ppb_video_destination_private_interface_->IsVideoDestination(
+ video_destination));
+
+ ppb_core_interface_->ReleaseResource(video_destination);
+ // Once released, the resource shouldn't be a video destination.
+ ASSERT_FALSE(
+ ppb_video_destination_private_interface_->IsVideoDestination(
+ video_destination));
+
+ PASS();
+}
+
+std::string TestVideoDestination::TestPutFrame() {
+ {
Ronghua Wu (Left Chromium) 2013/05/09 22:22:52 just curious, why do we need a { } here?
bbudge 2013/05/09 22:35:35 That makes it easier to add later tests, since we
+ std::string js_code;
+ js_code += "var test_stream = new webkitMediaStream([]);"
+ "var url = webkitURL.createObjectURL(test_stream);"
+ "var plugin = document.getElementById('plugin');"
+ "plugin.postMessage(url);";
+ instance_->EvalScript(js_code);
+ event_.Wait();
+
+ pp::VideoDestination_Private video_destination(instance_);
+ TestCompletionCallback cc1(instance_->pp_instance(), false);
+ cc1.WaitForResult(video_destination.Open(stream_url_, cc1.GetCallback()));
+ ASSERT_EQ(PP_OK, cc1.result());
+
+ pp::ImageData image_data(instance_,
+ PP_IMAGEDATAFORMAT_BGRA_PREMUL,
+ pp::Size(640, 480),
+ false /* init_to_zero */);
+ pp::VideoFrame_Private video_frame(image_data,
+ 0.0 /* timestamp */);
+ ASSERT_EQ(PP_OK, video_destination.PutFrame(video_frame));
+
+ video_destination.Close();
+ }
+
+ PASS();
+}
+

Powered by Google App Engine
This is Rietveld 408576698