From 1758e88fd909ea0ffd49621e8066ffad5627ffdf Mon Sep 17 00:00:00 2001 From: "brettw@chromium.org" Date: Mon, 1 Nov 2010 16:16:50 +0000 Subject: Move PPAPI into the Chrome repo. The old repo was http://ppapi.googlecode.com/ TEST=none BUG=none git-svn-id: svn://svn.chromium.org/chrome/trunk/src@64613 0039d316-1c4b-4281-b951-d872f2087c98 --- ppapi/tests/test_instance_deprecated.cc | 122 ++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 ppapi/tests/test_instance_deprecated.cc (limited to 'ppapi/tests/test_instance_deprecated.cc') diff --git a/ppapi/tests/test_instance_deprecated.cc b/ppapi/tests/test_instance_deprecated.cc new file mode 100644 index 0000000..74e929a --- /dev/null +++ b/ppapi/tests/test_instance_deprecated.cc @@ -0,0 +1,122 @@ +// Copyright (c) 2010 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_instance_deprecated.h" + +#include "ppapi/cpp/module.h" +#include "ppapi/cpp/dev/scriptable_object_deprecated.h" +#include "ppapi/tests/testing_instance.h" + +namespace { + +static const char kSetValueFunction[] = "SetValue"; +static const char kSetExceptionFunction[] = "SetException"; +static const char kReturnValueFunction[] = "ReturnValue"; + +// ScriptableObject used by instance. +class InstanceSO : public pp::deprecated::ScriptableObject { + public: + InstanceSO(TestInstance* i) : test_instance_(i) {} + + // pp::deprecated::ScriptableObject overrides. + bool HasMethod(const pp::Var& name, pp::Var* exception); + pp::Var Call(const pp::Var& name, + const std::vector& args, + pp::Var* exception); + + private: + TestInstance* test_instance_; +}; + +bool InstanceSO::HasMethod(const pp::Var& name, pp::Var* exception) { + if (!name.is_string()) + return false; + return name.AsString() == kSetValueFunction || + name.AsString() == kSetExceptionFunction || + name.AsString() == kReturnValueFunction; +} + +pp::Var InstanceSO::Call(const pp::Var& method_name, + const std::vector& args, + pp::Var* exception) { + if (!method_name.is_string()) + return false; + std::string name = method_name.AsString(); + + if (name == kSetValueFunction) { + if (args.size() != 1 || !args[0].is_string()) + *exception = pp::Var("Bad argument to SetValue()"); + else + test_instance_->set_string(args[0].AsString()); + } else if (name == kSetExceptionFunction) { + if (args.size() != 1 || !args[0].is_string()) + *exception = pp::Var("Bad argument to SetException()"); + else + *exception = args[0]; + } else if (name == kReturnValueFunction) { + if (args.size() != 1) + *exception = pp::Var("Need single arg to call ReturnValue"); + else + return args[0]; + } else { + *exception = pp::Var("Bad function call"); + } + + return pp::Var(); +} + +} // namespace + +REGISTER_TEST_CASE(Instance); + +TestInstance::TestInstance(TestingInstance* instance) : TestCase(instance) { +} + +bool TestInstance::Init() { + return true; +} + +void TestInstance::RunTest() { + RUN_TEST(ExecuteScript); +} + +pp::deprecated::ScriptableObject* TestInstance::CreateTestObject() { + return new InstanceSO(this); +} + +std::string TestInstance::TestExecuteScript() { + // Simple call back into the plugin. + pp::Var exception; + pp::Var ret = instance_->ExecuteScript( + "document.getElementById('plugin').SetValue('hello, world');", + &exception); + ASSERT_TRUE(ret.is_undefined()); + ASSERT_TRUE(exception.is_undefined()); + ASSERT_TRUE(string_ == "hello, world"); + + // Return values from the plugin should be returned. + ret = instance_->ExecuteScript( + "document.getElementById('plugin').ReturnValue('return value');", + &exception); + ASSERT_TRUE(ret.is_string() && ret.AsString() == "return value"); + ASSERT_TRUE(exception.is_undefined()); + + // Exception thrown by the plugin should be caught. + ret = instance_->ExecuteScript( + "document.getElementById('plugin').SetException('plugin exception');", + &exception); + ASSERT_TRUE(ret.is_undefined()); + ASSERT_TRUE(exception.is_string()); + // TODO(brettw) bug 54011: The TryCatch isn't working properly and + // doesn't actually pass the exception text up. + //ASSERT_TRUE(exception.AsString() == "plugin exception"); + + // Exception caused by string evaluation should be caught. + exception = pp::Var(); + ret = instance_->ExecuteScript("document.doesntExist()", &exception); + ASSERT_TRUE(ret.is_undefined()); + ASSERT_TRUE(exception.is_string()); // Don't know exactly what it will say. + + return std::string(); +} -- cgit v1.1