diff options
author | mgiuca@chromium.org <mgiuca@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-19 15:58:08 +0000 |
---|---|---|
committer | mgiuca@chromium.org <mgiuca@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-19 15:58:08 +0000 |
commit | 81216b5e1666b1c72c1db208b9d871a0869c740b (patch) | |
tree | dcf8c0c1de2851c63d272bb09bbc8854b74dc90b /ppapi/tests | |
parent | 779dd28c4bf2b8b47ef012c2f76d64e07e8340aa (diff) | |
download | chromium_src-81216b5e1666b1c72c1db208b9d871a0869c740b.zip chromium_src-81216b5e1666b1c72c1db208b9d871a0869c740b.tar.gz chromium_src-81216b5e1666b1c72c1db208b9d871a0869c740b.tar.bz2 |
[PPAPI] Added new Pepper interface PPB_VarResource_Dev.
This interface allows the plugin to create resource vars from PP_Resource, and
also to extract the PP_Resource from a resource var. This facilitates sending
and receiving resources through the JavaScript messaging interface.
Currently only available to plugins with DEV permission.
BUG=177017
Review URL: https://codereview.chromium.org/26464002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@229574 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/tests')
-rw-r--r-- | ppapi/tests/test_var_resource.cc | 135 | ||||
-rw-r--r-- | ppapi/tests/test_var_resource.h | 35 |
2 files changed, 170 insertions, 0 deletions
diff --git a/ppapi/tests/test_var_resource.cc b/ppapi/tests/test_var_resource.cc new file mode 100644 index 0000000..bf5c02e --- /dev/null +++ b/ppapi/tests/test_var_resource.cc @@ -0,0 +1,135 @@ +// Copyright 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. + +#include "ppapi/tests/test_var_resource.h" + +#include "ppapi/c/pp_resource.h" +#include "ppapi/c/pp_var.h" +#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/module.h" +#include "ppapi/tests/testing_instance.h" + +REGISTER_TEST_CASE(VarResource); + +bool TestVarResource::Init() { + core_interface_ = static_cast<const PPB_Core*>( + pp::Module::Get()->GetBrowserInterface(PPB_CORE_INTERFACE)); + file_system_interface_ = static_cast<const PPB_FileSystem*>( + pp::Module::Get()->GetBrowserInterface(PPB_FILESYSTEM_INTERFACE)); + var_interface_ = static_cast<const PPB_Var*>( + pp::Module::Get()->GetBrowserInterface(PPB_VAR_INTERFACE)); + var_resource_interface_ = static_cast<const PPB_VarResource_Dev*>( + pp::Module::Get()->GetBrowserInterface(PPB_VAR_RESOURCE_DEV_INTERFACE)); + return core_interface_ && file_system_interface_ && var_interface_ && + var_resource_interface_ && CheckTestingInterface(); +} + +void TestVarResource::RunTests(const std::string& filter) { + RUN_TEST(BasicResource, filter); + RUN_TEST(InvalidAndEmpty, filter); + RUN_TEST(WrongType, filter); +} + +std::string TestVarResource::TestBasicResource() { + uint32_t before_object = testing_interface_->GetLiveObjectsForInstance( + instance_->pp_instance()); + { + // Create an unopened FileSystem resource. + PP_Resource file_system = file_system_interface_->Create( + instance_->pp_instance(), PP_FILESYSTEMTYPE_LOCALTEMPORARY); + ASSERT_NE(0, file_system); + + // Build a var to wrap the resource. + PP_Var var = var_resource_interface_->VarFromResource(file_system); + ASSERT_EQ(PP_VARTYPE_RESOURCE, var.type); + + // Reading back the resource should work. This will increment the reference + // on the resource, so we must release it afterwards. + PP_Resource result = var_resource_interface_->VarToResource(var); + ASSERT_EQ(file_system, result); + core_interface_->ReleaseResource(result); + + // Destroy the var, readback should now fail. + var_interface_->Release(var); + result = var_resource_interface_->VarToResource(var); + ASSERT_EQ(0, result); + + // Release the resource. There should be no more references to it. + core_interface_->ReleaseResource(file_system); + } + + // Make sure nothing leaked. This checks for both var and resource leaks. + ASSERT_EQ( + before_object, + testing_interface_->GetLiveObjectsForInstance(instance_->pp_instance())); + + PASS(); +} + +std::string TestVarResource::TestInvalidAndEmpty() { + uint32_t before_object = testing_interface_->GetLiveObjectsForInstance( + instance_->pp_instance()); + { + PP_Var invalid_resource; + invalid_resource.type = PP_VARTYPE_RESOURCE; + invalid_resource.value.as_id = 31415926; + + // Invalid resource vars should give 0 as the return value. + PP_Resource result = + var_resource_interface_->VarToResource(invalid_resource); + ASSERT_EQ(0, result); + + // Test writing and reading a non-existant resource. + PP_Resource fake_resource = 27182818; + PP_Var var = var_resource_interface_->VarFromResource(fake_resource); + if (testing_interface()->IsOutOfProcess()) { + // An out-of-process plugin is expected to generate null in this case. + ASSERT_EQ(PP_VARTYPE_NULL, var.type); + result = var_resource_interface_->VarToResource(var); + ASSERT_EQ(0, result); + } else { + // An in-process plugin is expected to generate a valid resource var + // (because it does not validate the resource). + ASSERT_EQ(PP_VARTYPE_RESOURCE, var.type); + result = var_resource_interface_->VarToResource(var); + ASSERT_EQ(fake_resource, result); + var_interface_->Release(var); + } + // Note: Not necessary to release the resource, since it does not exist. + + // Write the resource 0; expect a valid resource var with 0. + var = var_resource_interface_->VarFromResource(0); + ASSERT_EQ(PP_VARTYPE_RESOURCE, var.type); + result = var_resource_interface_->VarToResource(var); + ASSERT_EQ(0, result); + var_interface_->Release(var); + } + + // Make sure nothing leaked. This checks for both var and resource leaks. + ASSERT_EQ( + before_object, + testing_interface_->GetLiveObjectsForInstance(instance_->pp_instance())); + + PASS(); +} + +std::string TestVarResource::TestWrongType() { + PP_Resource result = + var_resource_interface_->VarToResource(PP_MakeUndefined()); + ASSERT_EQ(0, result); + + result = var_resource_interface_->VarToResource(PP_MakeNull()); + ASSERT_EQ(0, result); + + result = var_resource_interface_->VarToResource(PP_MakeBool(PP_TRUE)); + ASSERT_EQ(0, result); + + result = var_resource_interface_->VarToResource(PP_MakeInt32(42)); + ASSERT_EQ(0, result); + + result = var_resource_interface_->VarToResource(PP_MakeDouble(1.0)); + ASSERT_EQ(0, result); + + PASS(); +} diff --git a/ppapi/tests/test_var_resource.h b/ppapi/tests/test_var_resource.h new file mode 100644 index 0000000..73645e5 --- /dev/null +++ b/ppapi/tests/test_var_resource.h @@ -0,0 +1,35 @@ +// Copyright 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. + +#ifndef PPAPI_TEST_TEST_VAR_RESOURCE_H_ +#define PPAPI_TEST_TEST_VAR_RESOURCE_H_ + +#include <string> + +#include "ppapi/c/dev/ppb_var_resource_dev.h" +#include "ppapi/c/ppb_file_system.h" +#include "ppapi/c/ppb_var.h" +#include "ppapi/tests/test_case.h" + +class TestVarResource : public TestCase { + public: + explicit TestVarResource(TestingInstance* instance) : TestCase(instance) {} + + private: + // TestCase implementation. + virtual bool Init(); + virtual void RunTests(const std::string& filter); + + std::string TestBasicResource(); + std::string TestInvalidAndEmpty(); + std::string TestWrongType(); + + // Used by the tests that access the C APIs directly. + const PPB_Core* core_interface_; + const PPB_FileSystem* file_system_interface_; + const PPB_Var* var_interface_; + const PPB_VarResource_Dev* var_resource_interface_; +}; + +#endif // PPAPI_TEST_TEST_VAR_RESOURCE_H_ |