Chromium Code Reviews| Index: ppapi/tests/blink_deprecated_test_plugin.cc |
| diff --git a/ppapi/tests/blink_deprecated_test_plugin.cc b/ppapi/tests/blink_deprecated_test_plugin.cc |
| index e179bc7800555b84ae4f1b8258e1efccbc7af3a6..d9e2e75e362cb6d8ed9300a77473365ab69205e1 100644 |
| --- a/ppapi/tests/blink_deprecated_test_plugin.cc |
| +++ b/ppapi/tests/blink_deprecated_test_plugin.cc |
| @@ -14,6 +14,7 @@ |
| #include <map> |
| #include <sstream> |
| +#include <unordered_map> |
| #include <utility> |
| #include "base/bind.h" |
| @@ -21,6 +22,7 @@ |
| #include "base/callback.h" |
| #include "base/strings/stringprintf.h" |
| #include "ppapi/cpp/dev/scriptable_object_deprecated.h" |
| +#include "ppapi/cpp/input_event.h" |
| #include "ppapi/cpp/module.h" |
| #include "ppapi/cpp/private/instance_private.h" |
| #include "ppapi/cpp/private/var_private.h" |
| @@ -126,6 +128,15 @@ class InstanceSO : public ScriptableBase { |
| explicit InstanceSO(pp::InstancePrivate* instance) |
| : ScriptableBase(instance) { |
| methods_.insert(std::make_pair( |
| + "normalize", |
|
dcheng
2016/03/22 18:03:05
Can we add add documentation about the various att
piman
2016/03/23 05:30:24
Done.
|
| + base::Bind(&InstanceSO::Normalize, base::Unretained(this)))); |
| + methods_.insert(std::make_pair( |
| + "remember", |
| + base::Bind(&InstanceSO::Remember, base::Unretained(this)))); |
| + methods_.insert(std::make_pair( |
| + "testCloneObject", |
| + base::Bind(&InstanceSO::TestCloneObject, base::Unretained(this)))); |
| + methods_.insert(std::make_pair( |
| "testExecuteScript", |
| base::Bind(&InstanceSO::TestExecuteScript, base::Unretained(this)))); |
| methods_.insert(std::make_pair( |
| @@ -134,6 +145,13 @@ class InstanceSO : public ScriptableBase { |
| methods_.insert(std::make_pair( |
| "testPassTestObject", |
| base::Bind(&InstanceSO::TestPassTestObject, base::Unretained(this)))); |
| + // Note: the semantics of testScriptObjectInvoke are identical to the |
| + // semantics of testPassTestObject: call args[0] with args[1] as a |
| + // parameter. |
| + methods_.insert( |
| + std::make_pair("testScriptObjectInvoke", |
| + base::Bind(&InstanceSO::TestPassTestObject, |
| + base::Unretained(this)))); |
| properties_.insert(std::make_pair( |
| "testObject", base::Bind(&InstanceSO::TestObjectAccessor, |
| base::Unretained(this)))); |
| @@ -141,6 +159,28 @@ class InstanceSO : public ScriptableBase { |
| ~InstanceSO() override {} |
| private: |
| + // Requires no argument. |
| + pp::Var Normalize(const std::vector<pp::Var>& args, pp::Var* exception) { |
| + pp::VarPrivate object = instance_->GetWindowObject(); |
| + return object.Call(pp::Var("pluginCallback"), exception); |
| + } |
| + |
| + // Requires 1 argument. The argument is retained into remembered_ |
| + pp::Var Remember(const std::vector<pp::Var>& args, pp::Var* exception) { |
| + if (args.size() != 1) { |
| + *exception = pp::Var("remember requires one argument"); |
| + return pp::Var(); |
| + } |
| + remembered_ = args[0]; |
| + return pp::Var(); |
| + } |
| + |
| + // Requires no argument. |
| + pp::Var TestCloneObject(const std::vector<pp::Var>& args, |
| + pp::Var* exception) { |
| + return pp::VarPrivate(instance_, new InstanceSO(instance_)); |
| + } |
| + |
| // Requires one argument. The argument is passed through as-is to |
| // pp::InstancePrivate::ExecuteScript(). |
| pp::Var TestExecuteScript(const std::vector<pp::Var>& args, |
| @@ -191,6 +231,7 @@ class InstanceSO : public ScriptableBase { |
| } |
| pp::VarPrivate test_object_; |
| + pp::Var remembered_; |
| }; |
| class BlinkDeprecatedTestInstance : public pp::InstancePrivate { |
| @@ -201,10 +242,45 @@ class BlinkDeprecatedTestInstance : public pp::InstancePrivate { |
| LogMessage("%s", "Destroying"); |
| } |
| - bool Init(uint32_t argc, const char* argn[], const char* argv[]) { |
| + // pp::Instance overrides |
| + bool Init(uint32_t argc, const char* argn[], const char* argv[]) override { |
| + for (uint32_t i = 0; i < argc; ++i) |
| + attributes_[argn[i]] = argv[i]; |
| + |
| + if (HasAttribute("onnew")) |
| + ExecuteScript(attributes_["onnew"]); |
| + |
| + if (HasAttribute("loginit")) |
| + LogMessage("%s", "Initializing"); |
| + |
| + if (HasAttribute("testwindowopen")) |
| + return TestWindowOpen(); |
| + |
| + uint32_t event_classes = 0; |
| + if (HasAttribute("keydownscript")) |
| + event_classes |= PP_INPUTEVENT_CLASS_KEYBOARD; |
| + if (HasAttribute("mousedownscript")) |
| + event_classes |= PP_INPUTEVENT_CLASS_MOUSE; |
| + RequestFilteringInputEvents(event_classes); |
| + |
| return true; |
| } |
| + virtual bool HandleInputEvent(const pp::InputEvent& event) override { |
| + switch (event.GetType()) { |
| + case PP_INPUTEVENT_TYPE_MOUSEDOWN: |
| + if (HasAttribute("mousedownscript")) |
| + ExecuteScript(attributes_["mousedownscript"]); |
| + return true; |
| + case PP_INPUTEVENT_TYPE_KEYDOWN: |
| + if (HasAttribute("keydownscript")) |
| + ExecuteScript(attributes_["keydownscript"]); |
| + return true; |
| + default: |
| + return false; |
| + } |
| + } |
| + |
| // pp::InstancePrivate overrides: |
| pp::Var GetInstanceObject() override { |
| if (instance_var_.is_undefined()) { |
| @@ -214,6 +290,19 @@ class BlinkDeprecatedTestInstance : public pp::InstancePrivate { |
| return instance_var_; |
| } |
| + void NotifyTestCompletion() { |
| + ExecuteScript("window.testRunner.notifyDone()"); |
| + } |
| + |
| + bool TestWindowOpen() { |
| + pp::Var result = GetWindowObject().Call( |
| + pp::Var("open"), pp::Var("about:blank"), pp::Var("_blank")); |
| + if (result.is_object()) |
| + LogMessage("PLUGIN: WINDOW OPEN SUCCESS"); |
| + NotifyTestCompletion(); |
| + return true; |
| + } |
| + |
| void LogMessage(const char* format...) { |
| va_list args; |
| va_start(args, format); |
| @@ -224,6 +313,10 @@ class BlinkDeprecatedTestInstance : public pp::InstancePrivate { |
| } |
| private: |
| + bool HasAttribute(const std::string& name) { |
| + return attributes_.find(name) != attributes_.end(); |
| + } |
|
dcheng
2016/03/22 18:03:05
Nit: newline.
piman
2016/03/23 05:30:24
Done.
|
| + std::unordered_map<std::string, std::string> attributes_; |
| pp::VarPrivate instance_var_; |
| // Owned by |instance_var_|. |
| InstanceSO* instance_so_; |