summaryrefslogtreecommitdiffstats
path: root/ppapi
diff options
context:
space:
mode:
authordmichael <dmichael@chromium.org>2014-09-26 13:34:38 -0700
committerCommit bot <commit-bot@chromium.org>2014-09-26 20:35:32 +0000
commite5ac6335b792a683c7022f753068751c97374664 (patch)
treea1041b66e99270776f1dc8271037a8678a17bae8 /ppapi
parentf8831db369da6c5c334a0defae6f22358760cce2 (diff)
downloadchromium_src-e5ac6335b792a683c7022f753068751c97374664.zip
chromium_src-e5ac6335b792a683c7022f753068751c97374664.tar.gz
chromium_src-e5ac6335b792a683c7022f753068751c97374664.tar.bz2
PPAPI: Add more error testing for postMessageAndAwaitResponse
Add a test that tries using postMessageAndAwaitResponse in ways that should throw an exception, and makes sure it actually throws. BUG=367896 Review URL: https://codereview.chromium.org/608843002 Cr-Commit-Position: refs/heads/master@{#297024}
Diffstat (limited to 'ppapi')
-rw-r--r--ppapi/tests/test_message_handler.cc72
-rw-r--r--ppapi/tests/test_message_handler.h6
-rw-r--r--ppapi/tests/testing_instance.cc4
-rw-r--r--ppapi/tests/testing_instance.h3
4 files changed, 82 insertions, 3 deletions
diff --git a/ppapi/tests/test_message_handler.cc b/ppapi/tests/test_message_handler.cc
index c8132e6..7dc933d 100644
--- a/ppapi/tests/test_message_handler.cc
+++ b/ppapi/tests/test_message_handler.cc
@@ -184,7 +184,8 @@ void FakeDestroy(PP_Instance instance, void* user_data) {}
TestMessageHandler::TestMessageHandler(TestingInstance* instance)
: TestCase(instance),
ppb_messaging_if_(NULL),
- handler_thread_(instance) {
+ handler_thread_(instance),
+ message_received_(instance->pp_instance()) {
}
TestMessageHandler::~TestMessageHandler() {
@@ -202,11 +203,22 @@ bool TestMessageHandler::Init() {
void TestMessageHandler::RunTests(const std::string& filter) {
RUN_TEST(RegisterErrorConditions, filter);
RUN_TEST(PostMessageAndAwaitResponse, filter);
+ RUN_TEST(Exceptions, filter);
}
void TestMessageHandler::HandleMessage(const pp::Var& message_data) {
- // All messages should go to the background thread message handler.
- assert(false);
+ if (instance()->current_test_name() == "Exceptions") {
+ // For TestPostMessageAndAwaitResponse(), all messages should go to the
+ // background thread message handler.
+ assert(false);
+ } else {
+ if (message_data.is_string()) {
+ last_message_ = message_data.AsString();
+ } else {
+ last_message_ = "message_data was not a string!";
+ }
+ message_received_.Signal();
+ }
}
std::string TestMessageHandler::TestRegisterErrorConditions() {
@@ -244,6 +256,7 @@ std::string TestMessageHandler::TestRegisterErrorConditions() {
std::string TestMessageHandler::TestPostMessageAndAwaitResponse() {
EchoingMessageHandler handler(instance(),
handler_thread_.message_loop());
+ // Test doing a sync call before the handler is registered.
handler.Register();
std::string js_code("var plugin = document.getElementById('plugin');\n");
js_code += "var result = undefined;\n";
@@ -275,3 +288,56 @@ std::string TestMessageHandler::TestPostMessageAndAwaitResponse() {
PASS();
}
+std::string TestMessageHandler::TestExceptions() {
+ EchoingMessageHandler handler(instance(),
+ handler_thread_.message_loop());
+ {
+ // First, try sending a blocking message when there is no handler
+ // registered. It should throw an exception.
+ std::string js_code(
+ "var plugin = document.getElementById('plugin');\n"
+ "var caught_exception = false;\n"
+ "try {\n"
+ " plugin.postMessageAndAwaitResponse('Hello!');\n"
+ "} catch (err) {\n"
+ " caught_exception = true;\n"
+ "}\n"
+ "plugin.postMessage(caught_exception ? 'SUCCESS' : 'FAIL');\n");
+ instance_->EvalScript(js_code);
+ message_received_.Wait();
+ ASSERT_EQ("SUCCESS", last_message_);
+ }
+ handler.Register();
+ {
+ // Now that a handler is registered, try requesting and sending a
+ // FileSystem. It should throw an exception. The file system is opened
+ // asynchronously. What *should* happen is that it opens successfully, then
+ // we try to send it via postMessageAndAwaitResponse, which fails with an
+ // exception. The test could fail either because the filesystem doesn't
+ // open or because postMessageAndAwaitResponse doesn't throw an exception.
+ std::string js_code(
+ "var plugin = document.getElementById('plugin');\n"
+ "function gotFileSystem(fs) {\n"
+ " var caught_exception = false;\n"
+ " try {\n"
+ " plugin.postMessageAndAwaitResponse(fs);\n"
+ " } catch (err) {\n"
+ " caught_exception = true;\n"
+ " }\n"
+ " plugin.postMessage(caught_exception ? 'SUCCESS' : 'FAIL');\n"
+ "}\n"
+ "function fileSystemError() {\n"
+ " plugin.postMessage('Failed to open filesystem');\n"
+ "}\n"
+ "window.webkitRequestFileSystem(\n"
+ " window.Temporary, 1024, gotFileSystem, fileSystemError)\n");
+ instance_->EvalScript(js_code);
+ message_received_.Wait();
+ ASSERT_EQ("SUCCESS", last_message_);
+ }
+ handler.Unregister();
+ ASSERT_SUBTEST_SUCCESS(handler.WaitForDestroy());
+
+ PASS();
+}
+
diff --git a/ppapi/tests/test_message_handler.h b/ppapi/tests/test_message_handler.h
index 70e6a2f..d64314e 100644
--- a/ppapi/tests/test_message_handler.h
+++ b/ppapi/tests/test_message_handler.h
@@ -10,6 +10,7 @@
#include "ppapi/c/ppb_messaging.h"
#include "ppapi/tests/test_case.h"
+#include "ppapi/tests/test_utils.h"
#include "ppapi/utility/threading/simple_thread.h"
class TestMessageHandler : public TestCase {
@@ -25,9 +26,14 @@ class TestMessageHandler : public TestCase {
std::string TestRegisterErrorConditions();
std::string TestPostMessageAndAwaitResponse();
+ std::string TestExceptions();
const PPB_Messaging_1_2* ppb_messaging_if_;
pp::SimpleThread handler_thread_;
+
+ // For TestExceptions():
+ NestedEvent message_received_;
+ std::string last_message_;
};
#endif // PPAPI_TESTS_TEST_MESSAGE_HANDLER_H_
diff --git a/ppapi/tests/testing_instance.cc b/ppapi/tests/testing_instance.cc
index 043ef02..b1eaae46 100644
--- a/ppapi/tests/testing_instance.cc
+++ b/ppapi/tests/testing_instance.cc
@@ -124,6 +124,8 @@ void TestingInstance::SetCookie(const std::string& name,
void TestingInstance::LogTest(const std::string& test_name,
const std::string& error_message,
PP_TimeTicks start_time) {
+ current_test_name_ = test_name;
+
// Compute the time to run the test and save it in a string for logging:
PP_TimeTicks end_time(pp::Module::Get()->core()->GetTimeTicks());
std::ostringstream number_stream;
@@ -164,6 +166,8 @@ void TestingInstance::LogTest(const std::string& test_name,
test_time.append(time_string);
test_time.append(" seconds.");
LogTestTime(test_time);
+
+ current_test_name_.clear();
}
void TestingInstance::AppendError(const std::string& message) {
diff --git a/ppapi/tests/testing_instance.h b/ppapi/tests/testing_instance.h
index 96d6254..2b306a5 100644
--- a/ppapi/tests/testing_instance.h
+++ b/ppapi/tests/testing_instance.h
@@ -87,6 +87,7 @@ pp::InstancePrivate {
void LogTest(const std::string& test_name,
const std::string& error_message,
PP_TimeTicks start_time);
+ const std::string& current_test_name() { return current_test_name_; }
// Appends an error message to the log.
void AppendError(const std::string& message);
@@ -150,6 +151,8 @@ pp::InstancePrivate {
// Owning pointer to the current test case. Valid after Init has been called.
TestCase* current_case_;
+ std::string current_test_name_;
+
// A filter to use when running tests. This is passed to 'RunTests', which
// runs only tests whose name contains test_filter_ as a substring.
std::string test_filter_;