summaryrefslogtreecommitdiffstats
path: root/ppapi/tests/test_instance_deprecated.cc
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-01 16:16:50 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-01 16:16:50 +0000
commit1758e88fd909ea0ffd49621e8066ffad5627ffdf (patch)
treec304a5eed047cae5665f5af1739d84655fb5815d /ppapi/tests/test_instance_deprecated.cc
parente7d8b51953b7d3b2b8a0aba46132305b32f3efce (diff)
downloadchromium_src-1758e88fd909ea0ffd49621e8066ffad5627ffdf.zip
chromium_src-1758e88fd909ea0ffd49621e8066ffad5627ffdf.tar.gz
chromium_src-1758e88fd909ea0ffd49621e8066ffad5627ffdf.tar.bz2
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
Diffstat (limited to 'ppapi/tests/test_instance_deprecated.cc')
-rw-r--r--ppapi/tests/test_instance_deprecated.cc122
1 files changed, 122 insertions, 0 deletions
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<pp::Var>& 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<pp::Var>& 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(<string>)");
+ 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(<string>)");
+ 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();
+}