Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 <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.
| |
| 10 #include <algorithm> | |
| 11 #include <limits> | |
| 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)); | |
| 43 ppb_core_interface_ = static_cast<const PPB_Core*>( | |
| 44 pp::Module::Get()->GetBrowserInterface(PPB_CORE_INTERFACE)); | |
| 45 if (!ppb_video_destination_private_interface_) | |
| 46 instance_->AppendError( | |
| 47 "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.
| |
| 48 if (!ppb_core_interface_) | |
| 49 instance_->AppendError("PPB_Core interface not available"); | |
| 50 | |
| 51 return true; | |
| 52 } | |
| 53 | |
| 54 TestVideoDestination::~TestVideoDestination() { | |
| 55 } | |
| 56 | |
| 57 void TestVideoDestination::RunTests(const std::string& filter) { | |
| 58 RUN_TEST(Create, filter); | |
| 59 RUN_TEST(PutFrame, filter); | |
| 60 } | |
| 61 | |
| 62 void TestVideoDestination::HandleMessage(const pp::Var& message_data) { | |
| 63 if (message_data.AsString().find("blob:") == 0) { | |
| 64 stream_url_ = message_data.AsString(); | |
| 65 event_.Signal(); | |
| 66 } | |
| 67 } | |
| 68 | |
| 69 std::string TestVideoDestination::TestCreate() { | |
| 70 PP_Resource video_destination; | |
| 71 // Creating a destination from an invalid instance returns an invalid | |
| 72 // resource. | |
| 73 video_destination = | |
| 74 ppb_video_destination_private_interface_->Create(kInvalidInstance); | |
| 75 ASSERT_EQ(kInvalidResource, video_destination); | |
| 76 ASSERT_FALSE( | |
| 77 ppb_video_destination_private_interface_->IsVideoDestination( | |
| 78 video_destination)); | |
| 79 | |
| 80 // Creating a destination from a valid instance returns a valid resource. | |
| 81 video_destination = | |
| 82 ppb_video_destination_private_interface_->Create( | |
| 83 instance_->pp_instance()); | |
| 84 ASSERT_NE(kInvalidResource, video_destination); | |
| 85 ASSERT_TRUE( | |
| 86 ppb_video_destination_private_interface_->IsVideoDestination( | |
| 87 video_destination)); | |
| 88 | |
| 89 ppb_core_interface_->ReleaseResource(video_destination); | |
| 90 // Once released, the resource shouldn't be a video destination. | |
| 91 ASSERT_FALSE( | |
| 92 ppb_video_destination_private_interface_->IsVideoDestination( | |
| 93 video_destination)); | |
| 94 | |
| 95 PASS(); | |
| 96 } | |
| 97 | |
| 98 std::string TestVideoDestination::TestPutFrame() { | |
| 99 { | |
|
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
| |
| 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 | |
| 124 PASS(); | |
| 125 } | |
| 126 | |
| OLD | NEW |