This source file includes following definitions.
- MakeObjectVar
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
#include "ppapi/proxy/ppapi_proxy_test.h"
#include "ppapi/proxy/serialized_var.h"
#include "ppapi/shared_impl/proxy_lock.h"
namespace ppapi {
namespace proxy {
namespace {
PP_Var MakeObjectVar(int64_t object_id) {
PP_Var ret;
ret.type = PP_VARTYPE_OBJECT;
ret.value.as_id = object_id;
return ret;
}
class SerializedVarTest : public PluginProxyTest {
public:
SerializedVarTest() {}
};
}
TEST_F(SerializedVarTest, PluginSerializedVarInOutParam) {
ProxyAutoLock lock;
PP_Var host_object = MakeObjectVar(0x31337);
PP_Var plugin_object;
{
SerializedVarTestConstructor input(host_object);
SerializedVarReceiveInput receive_input(input);
plugin_object = receive_input.Get(plugin_dispatcher());
EXPECT_EQ(0, var_tracker().GetRefCountForObject(plugin_object));
EXPECT_EQ(0u, sink().message_count());
SerializedVar sv;
{
SerializedVarOutParam out_param(&sv);
var_tracker().AddRefVar(plugin_object);
EXPECT_EQ(1, var_tracker().GetRefCountForObject(plugin_object));
EXPECT_EQ(1u, sink().message_count());
*out_param.OutParam(plugin_dispatcher()) = plugin_object;
}
SerializedVarTestReader reader(sv);
EXPECT_EQ(host_object.value.as_id, reader.GetVar().value.as_id);
EXPECT_EQ(1, var_tracker().GetRefCountForObject(plugin_object));
EXPECT_EQ(1u, sink().message_count());
}
EXPECT_EQ(-1, var_tracker().GetRefCountForObject(plugin_object));
EXPECT_EQ(2u, sink().message_count());
}
TEST_F(SerializedVarTest, PluginSerializedStringVarInOutParam) {
ProxyAutoLock lock;
PP_Var plugin_string;
const std::string kTestString("elite");
{
SerializedVarTestConstructor input(kTestString);
SerializedVarReceiveInput receive_input(input);
plugin_string = receive_input.Get(plugin_dispatcher());
EXPECT_EQ(1, var_tracker().GetRefCountForObject(plugin_string));
EXPECT_EQ(0u, sink().message_count());
SerializedVar sv;
{
SerializedVarOutParam out_param(&sv);
var_tracker().AddRefVar(plugin_string);
EXPECT_EQ(2, var_tracker().GetRefCountForObject(plugin_string));
EXPECT_EQ(0u, sink().message_count());
*out_param.OutParam(plugin_dispatcher()) = plugin_string;
}
SerializedVarTestReader reader(sv);
EXPECT_EQ(2, var_tracker().GetRefCountForObject(plugin_string));
EXPECT_EQ(0u, sink().message_count());
}
EXPECT_EQ(-1, var_tracker().GetRefCountForObject(plugin_string));
EXPECT_EQ(0u, sink().message_count());
}
TEST_F(SerializedVarTest, PluginSerializedVarOutParam) {
ProxyAutoLock lock;
PP_Var host_object = MakeObjectVar(0x31337);
PP_Var plugin_object = var_tracker().ReceiveObjectPassRef(
host_object, plugin_dispatcher());
EXPECT_EQ(1, var_tracker().GetRefCountForObject(plugin_object));
{
SerializedVar sv;
{
SerializedVarOutParam out_param(&sv);
*out_param.OutParam(plugin_dispatcher()) = plugin_object;
}
SerializedVarTestReader reader(sv);
EXPECT_EQ(host_object.value.as_id, reader.GetVar().value.as_id);
EXPECT_EQ(1, var_tracker().GetRefCountForObject(plugin_object));
EXPECT_EQ(0u, sink().message_count());
}
EXPECT_EQ(-1, var_tracker().GetRefCountForObject(plugin_object));
EXPECT_EQ(1u, sink().message_count());
}
TEST_F(SerializedVarTest, PluginReceiveInput) {
ProxyAutoLock lock;
PP_Var host_object = MakeObjectVar(0x31337);
PP_Var plugin_object;
{
SerializedVarTestConstructor input1(host_object);
SerializedVarReceiveInput receive_input(input1);
plugin_object = receive_input.Get(plugin_dispatcher());
EXPECT_EQ(0, var_tracker().GetRefCountForObject(plugin_object));
EXPECT_EQ(0u, sink().message_count());
SerializedVarTestConstructor input2(host_object);
SerializedVarReceiveInput receive_input2(input2);
PP_Var plugin_object2 = receive_input2.Get(plugin_dispatcher());
EXPECT_EQ(plugin_object.value.as_id, plugin_object2.value.as_id);
EXPECT_EQ(0, var_tracker().GetRefCountForObject(plugin_object));
EXPECT_EQ(0u, sink().message_count());
var_tracker().AddRefVar(plugin_object);
EXPECT_EQ(1, var_tracker().GetRefCountForObject(plugin_object));
var_tracker().ReleaseVar(plugin_object);
EXPECT_EQ(0, var_tracker().GetRefCountForObject(plugin_object));
EXPECT_EQ(2u, sink().message_count());
}
EXPECT_EQ(-1, var_tracker().GetRefCountForObject(plugin_object));
}
TEST_F(SerializedVarTest, PluginVectorReceiveInput) {
ProxyAutoLock lock;
PP_Var host_object = MakeObjectVar(0x31337);
std::vector<PP_Var> plugin_objects;
std::vector<PP_Var> plugin_objects2;
{
std::vector<SerializedVar> input1;
input1.push_back(SerializedVarTestConstructor(host_object));
input1.push_back(SerializedVarTestConstructor("elite"));
SerializedVarVectorReceiveInput receive_input(input1);
uint32_t array_size = 0;
PP_Var* plugin_objects_array =
receive_input.Get(plugin_dispatcher(), &array_size);
plugin_objects.insert(plugin_objects.begin(), plugin_objects_array,
plugin_objects_array + array_size);
ASSERT_EQ(2u, array_size);
EXPECT_EQ(0, var_tracker().GetRefCountForObject(plugin_objects[0]));
EXPECT_EQ(1, var_tracker().GetRefCountForObject(plugin_objects[1]));
EXPECT_EQ(0u, sink().message_count());
std::vector<SerializedVar> input2;
input2.push_back(SerializedVarTestConstructor(host_object));
input2.push_back(SerializedVarTestConstructor("elite"));
SerializedVarVectorReceiveInput receive_input2(input2);
uint32_t array_size2 = 0;
PP_Var* plugin_objects_array2 =
receive_input2.Get(plugin_dispatcher(), &array_size2);
plugin_objects2.insert(plugin_objects2.begin(), plugin_objects_array2,
plugin_objects_array2 + array_size2);
ASSERT_EQ(2u, array_size2);
EXPECT_EQ(plugin_objects[0].value.as_id, plugin_objects2[0].value.as_id);
EXPECT_EQ(0, var_tracker().GetRefCountForObject(plugin_objects[0]));
EXPECT_NE(plugin_objects[1].value.as_id, plugin_objects2[1].value.as_id);
EXPECT_EQ(1, var_tracker().GetRefCountForObject(plugin_objects2[1]));
EXPECT_EQ(0u, sink().message_count());
var_tracker().AddRefVar(plugin_objects[0]);
EXPECT_EQ(1, var_tracker().GetRefCountForObject(plugin_objects[0]));
var_tracker().ReleaseVar(plugin_objects[0]);
EXPECT_EQ(0, var_tracker().GetRefCountForObject(plugin_objects[0]));
EXPECT_EQ(2u, sink().message_count());
uint32_t old_message_count = sink().message_count();
var_tracker().AddRefVar(plugin_objects[1]);
EXPECT_EQ(2, var_tracker().GetRefCountForObject(plugin_objects[1]));
var_tracker().ReleaseVar(plugin_objects[1]);
EXPECT_EQ(1, var_tracker().GetRefCountForObject(plugin_objects[1]));
EXPECT_EQ(old_message_count, sink().message_count());
}
EXPECT_EQ(-1, var_tracker().GetRefCountForObject(plugin_objects[0]));
EXPECT_EQ(-1, var_tracker().GetRefCountForObject(plugin_objects[1]));
EXPECT_EQ(-1, var_tracker().GetRefCountForObject(plugin_objects2[1]));
}
TEST_F(SerializedVarTest, PluginReceiveReturn) {
ProxyAutoLock lock;
PP_Var host_object = MakeObjectVar(0x31337);
PP_Var plugin_object;
{
SerializedVarTestConstructor input1(host_object);
ReceiveSerializedVarReturnValue receive_input(input1);
plugin_object = receive_input.Return(plugin_dispatcher());
EXPECT_EQ(1, var_tracker().GetRefCountForObject(plugin_object));
EXPECT_EQ(0u, sink().message_count());
SerializedVarTestConstructor input2(host_object);
ReceiveSerializedVarReturnValue receive_input2(input2);
PP_Var plugin_object2 = receive_input2.Return(plugin_dispatcher());
EXPECT_EQ(plugin_object.value.as_id, plugin_object2.value.as_id);
EXPECT_EQ(2, var_tracker().GetRefCountForObject(plugin_object));
EXPECT_EQ(1u, sink().message_count());
}
EXPECT_EQ(2, var_tracker().GetRefCountForObject(plugin_object));
EXPECT_EQ(1u, sink().message_count());
var_tracker().ReleaseVar(plugin_object);
EXPECT_EQ(1, var_tracker().GetRefCountForObject(plugin_object));
EXPECT_EQ(1u, sink().message_count());
var_tracker().ReleaseVar(plugin_object);
EXPECT_EQ(-1, var_tracker().GetRefCountForObject(plugin_object));
EXPECT_EQ(2u, sink().message_count());
}
TEST_F(SerializedVarTest, PluginReturnValue) {
ProxyAutoLock lock;
PP_Var host_object = MakeObjectVar(0x31337);
PP_Var plugin_object;
{
SerializedVarTestConstructor input1(host_object);
ReceiveSerializedVarReturnValue receive_input(input1);
plugin_object = receive_input.Return(plugin_dispatcher());
EXPECT_EQ(1, var_tracker().GetRefCountForObject(plugin_object));
EXPECT_EQ(0u, sink().message_count());
}
{
SerializedVar output;
SerializedVarReturnValue return_output(&output);
return_output.Return(plugin_dispatcher(), plugin_object);
EXPECT_EQ(1, var_tracker().GetRefCountForObject(plugin_object));
}
EXPECT_EQ(-1, var_tracker().GetRefCountForObject(plugin_object));
EXPECT_EQ(1u, sink().message_count());
}
}
}