summaryrefslogtreecommitdiffstats
path: root/ppapi
diff options
context:
space:
mode:
authordcheng <dcheng@chromium.org>2016-03-01 18:36:10 -0800
committerCommit bot <commit-bot@chromium.org>2016-03-02 02:37:35 +0000
commitc70b36ecb934e3b23769028495c4c13c9aa5e550 (patch)
tree301bf5c3fd2f91e2a2673209e00a3fd2e0b1d1ce /ppapi
parenta5e91c5d8f91db97acfe02fafbede56eaff3dbf2 (diff)
downloadchromium_src-c70b36ecb934e3b23769028495c4c13c9aa5e550.zip
chromium_src-c70b36ecb934e3b23769028495c4c13c9aa5e550.tar.gz
chromium_src-c70b36ecb934e3b23769028495c4c13c9aa5e550.tar.bz2
Implement a test plugin for testing deprecated/private PPAPI interfaces.
Unfortunately, there's still a few legacy consumers of these APIs. It's important to continue testing these to make sure there are no security or stability regressions. For now, only http/tests/plugins/cross-frame-object-access.html has been ported over to use the new plugin. BUG=474535 Review URL: https://codereview.chromium.org/1750783002 Cr-Commit-Position: refs/heads/master@{#378664}
Diffstat (limited to 'ppapi')
-rw-r--r--ppapi/BUILD.gn13
-rw-r--r--ppapi/ppapi_tests.gypi20
-rw-r--r--ppapi/tests/DEPS5
-rw-r--r--ppapi/tests/blink_deprecated_test_plugin.cc144
4 files changed, 182 insertions, 0 deletions
diff --git a/ppapi/BUILD.gn b/ppapi/BUILD.gn
index 6581390..f390d25 100644
--- a/ppapi/BUILD.gn
+++ b/ppapi/BUILD.gn
@@ -72,6 +72,19 @@ shared_library("power_saver_test_plugin") {
]
}
+loadable_module("blink_deprecated_test_plugin") {
+ sources = [
+ "tests/blink_deprecated_test_plugin.cc",
+ ]
+
+ deps = [
+ "//base",
+ "//build/config/sanitizers:deps",
+ "//ppapi/cpp",
+ "//ppapi/shared_impl",
+ ]
+}
+
loadable_module("blink_test_plugin") {
sources = [
"tests/blink_test_plugin.cc",
diff --git a/ppapi/ppapi_tests.gypi b/ppapi/ppapi_tests.gypi
index b168b11..1b98379 100644
--- a/ppapi/ppapi_tests.gypi
+++ b/ppapi/ppapi_tests.gypi
@@ -101,6 +101,26 @@
],
},
{
+ # GN version: //ppapi:blink_deprecated_test_plugin
+ 'target_name': 'blink_deprecated_test_plugin',
+ 'type': 'loadable_module',
+ 'sources': [
+ 'tests/blink_deprecated_test_plugin.cc',
+ ],
+ 'dependencies': [
+ '../base/base.gyp:base',
+ 'ppapi.gyp:ppapi_cpp',
+ 'ppapi_internal.gyp:ppapi_shared',
+ ],
+ 'conditions': [
+ ['OS=="mac"', {
+ 'mac_bundle': 1,
+ 'product_name': 'blink_deprecated_test_plugin',
+ 'product_extension': 'plugin',
+ }],
+ ],
+ },
+ {
# GN version: //ppapi:blink_test_plugin
'target_name': 'blink_test_plugin',
'type': 'loadable_module',
diff --git a/ppapi/tests/DEPS b/ppapi/tests/DEPS
index 27e5b57..2b50cb7 100644
--- a/ppapi/tests/DEPS
+++ b/ppapi/tests/DEPS
@@ -24,6 +24,11 @@ skip_child_includes = [
"clang",
]
specific_include_rules = {
+ # The Blink test plugins use //base.
+ "blink_deprecated_test_plugin\.cc": [
+ "+base",
+ ],
+
# extensions/packaged_app/test_packaged_app.cc uses kMaxDescriptorsPerMessage
# defined in ipc/ipc_message_attachment_set.h.
"test_packaged_app\.cc": [
diff --git a/ppapi/tests/blink_deprecated_test_plugin.cc b/ppapi/tests/blink_deprecated_test_plugin.cc
new file mode 100644
index 0000000..b11a37d
--- /dev/null
+++ b/ppapi/tests/blink_deprecated_test_plugin.cc
@@ -0,0 +1,144 @@
+// Copyright 2015 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.
+//
+// A simple C++ Pepper plugin for exercising deprecated PPAPI interfaces in
+// Blink layout tests.
+//
+// Most layout tests should prefer to use the normal Blink test plugin, with the
+// MIME type application/x-blink-test-plugin. For layout tests that absolutely
+// need to test deprecated synchronous scripting interfaces, this plugin can be
+// instantiated using the application/x-blink-deprecated-test-plugin MIME type.
+
+#include <stdint.h>
+
+#include <map>
+#include <sstream>
+#include <utility>
+
+#include "base/bind.h"
+#include "base/bind_helpers.h"
+#include "base/callback.h"
+#include "ppapi/cpp/dev/scriptable_object_deprecated.h"
+#include "ppapi/cpp/module.h"
+#include "ppapi/cpp/private/instance_private.h"
+#include "ppapi/cpp/private/var_private.h"
+#include "ppapi/cpp/var.h"
+
+namespace {
+
+class InstanceSO : public pp::deprecated::ScriptableObject {
+ public:
+ explicit InstanceSO(pp::InstancePrivate* instance) : instance_(instance) {
+ methods_.insert(std::make_pair(
+ "testExecuteScript",
+ base::Bind(&InstanceSO::TestExecuteScript, base::Unretained(this))));
+ methods_.insert(std::make_pair(
+ "testGetProperty",
+ base::Bind(&InstanceSO::TestGetProperty, base::Unretained(this))));
+ }
+
+ // pp::deprecated::ScriptableObject overrides:
+ bool HasMethod(const pp::Var& name, pp::Var* exception) {
+ return FindMethod(name) != methods_.end();
+ }
+
+ pp::Var Call(const pp::Var& method_name,
+ const std::vector<pp::Var>& args,
+ pp::Var* exception) override {
+ auto method = FindMethod(method_name);
+ if (method != methods_.end()) {
+ return method->second.Run(args, exception);
+ }
+
+ return ScriptableObject::Call(method_name, args, exception);
+ }
+
+ private:
+ using MethodMap =
+ std::map<std::string,
+ base::Callback<pp::Var(const std::vector<pp::Var>&, pp::Var*)>>;
+
+ MethodMap::iterator FindMethod(const pp::Var& name) {
+ if (!name.is_string())
+ return methods_.end();
+ return methods_.find(name.AsString());
+ }
+
+ // Requires one argument. The argument is passed through as-is to
+ // pp::InstancePrivate::ExecuteScript().
+ pp::Var TestExecuteScript(const std::vector<pp::Var>& args,
+ pp::Var* exception) {
+ if (args.size() != 1) {
+ *exception = pp::Var("testExecuteScript requires one argument");
+ return pp::Var();
+ }
+ return instance_->ExecuteScript(args[0], exception);
+ }
+
+ // Requires one or more arguments. Roughly analogous to NPN_GetProperty.
+ // The arguments are the chain of properties to traverse, starting with the
+ // global context.
+ pp::Var TestGetProperty(const std::vector<pp::Var>& args,
+ pp::Var* exception) {
+ if (args.size() < 1) {
+ *exception = pp::Var("testGetProperty requires at least one argument");
+ return pp::Var();
+ }
+ pp::VarPrivate object = instance_->GetWindowObject();
+ for (const auto& arg : args) {
+ if (!object.HasProperty(arg, exception))
+ return pp::Var();
+ object = object.GetProperty(arg, exception);
+ }
+ return object;
+ }
+
+ pp::InstancePrivate* const instance_;
+ MethodMap methods_;
+};
+
+class BlinkDeprecatedTestInstance : public pp::InstancePrivate {
+ public:
+ explicit BlinkDeprecatedTestInstance(PP_Instance instance)
+ : pp::InstancePrivate(instance) {}
+ ~BlinkDeprecatedTestInstance() override {}
+
+ bool Init(uint32_t argc, const char* argn[], const char* argv[]) {
+ return true;
+ }
+
+ // pp::InstancePrivate overrides:
+ pp::Var GetInstanceObject() override {
+ if (instance_var_.is_undefined()) {
+ instance_so_ = new InstanceSO(this);
+ instance_var_ = pp::VarPrivate(this, instance_so_);
+ }
+ return instance_var_;
+ }
+
+ private:
+ pp::VarPrivate instance_var_;
+ // Owned by |instance_var_|.
+ InstanceSO* instance_so_;
+};
+
+class BlinkDeprecatedTestModule : public pp::Module {
+ public:
+ BlinkDeprecatedTestModule() {}
+ ~BlinkDeprecatedTestModule() override {}
+
+ virtual pp::Instance* CreateInstance(PP_Instance instance) {
+ return new BlinkDeprecatedTestInstance(instance);
+ }
+};
+
+} // namespace
+
+namespace pp {
+
+Module* CreateModule() {
+ return new BlinkDeprecatedTestModule();
+}
+
+} // namespace pp