Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(356)

Unified Diff: ppapi/tests/test_message_handler.cc

Issue 605593002: PPAPI: Support sending browser-hosted resources synchronously Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix content_browsertests Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ppapi/tests/test_message_handler.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ppapi/tests/test_message_handler.cc
diff --git a/ppapi/tests/test_message_handler.cc b/ppapi/tests/test_message_handler.cc
index bfb3be3f57f29a647922b770bcdd80fe1d5b0623..acee8b70c427b09ec4c5c3a718fac1de37998c88 100644
--- a/ppapi/tests/test_message_handler.cc
+++ b/ppapi/tests/test_message_handler.cc
@@ -8,6 +8,7 @@
#include <algorithm>
#include <map>
#include <sstream>
+#include <vector>
#include "ppapi/c/pp_var.h"
#include "ppapi/c/ppb_file_io.h"
@@ -44,14 +45,13 @@ namespace {
// (Though it handles messages on the background thread).
class MyMessageHandler : public pp::MessageHandler {
public:
- explicit MyMessageHandler(TestingInstance* instance,
- const pp::MessageLoop& loop)
+ MyMessageHandler(TestingInstance* instance, const pp::MessageLoop& loop)
: testing_instance_(instance),
message_handler_loop_(loop),
is_registered_(false),
test_finished_event_(instance->pp_instance()),
destroy_event_(instance->pp_instance()),
- async_message_received_(instance->pp_instance()) {
+ finished_message_received_(instance->pp_instance()) {
AssertOnMainThread();
}
void Register() {
@@ -96,12 +96,10 @@ class MyMessageHandler : public pp::MessageHandler {
errors_.swap(temp_errors);
return temp_errors;
}
- pp::Var WaitForAsyncMessage() {
- async_message_received_.Wait();
- pp::Var var_to_return = last_async_message_received_;
- last_async_message_received_ = pp::Var();
- async_message_received_.Reset();
- return var_to_return;
+ void WaitForAsyncMessages(std::vector<pp::Var>* out_vec) {
+ finished_message_received_.Wait();
+ out_vec->swap(async_messages_received_);
+ finished_message_received_.Reset();
}
private:
static void AssertOnMainThread() {
@@ -122,12 +120,10 @@ class MyMessageHandler : public pp::MessageHandler {
AddError("HandleMessage was passed the wrong instance!");
if (var.is_string() && var.AsString() == "FINISHED_TEST") {
test_finished_event_.Signal();
+ } else if (var.is_string() && var.AsString() == "FINISHED_WAITING") {
+ finished_message_received_.Signal();
} else {
- // Any client causing a message to arrive must wait for the message
- // before continuing. See WaitForAsyncMessage().
- assert(last_async_message_received_.is_undefined());
- last_async_message_received_ = var;
- async_message_received_.Signal();
+ async_messages_received_.push_back(var);
}
}
@@ -178,8 +174,8 @@ class MyMessageHandler : public pp::MessageHandler {
NestedEvent test_finished_event_;
NestedEvent destroy_event_;
- pp::Var last_async_message_received_;
- NestedEvent async_message_received_;
+ std::vector<pp::Var> async_messages_received_;
+ NestedEvent finished_message_received_;
// Undefined & private to disallow copy and assign.
MyMessageHandler(const MyMessageHandler&);
@@ -220,6 +216,7 @@ void TestMessageHandler::RunTests(const std::string& filter) {
RUN_TEST(RegisterErrorConditions, filter);
RUN_TEST(PostMessageAndAwaitResponse, filter);
RUN_TEST(Exceptions, filter);
+ RUN_TEST(BrowserHostedResources, filter);
}
void TestMessageHandler::HandleMessage(const pp::Var& message_data) {
@@ -306,7 +303,7 @@ std::string TestMessageHandler::TestExceptions() {
MyMessageHandler handler(instance(),
handler_thread_.message_loop());
{
- // First, try sending a blocking message when there is no handler
+ // 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"
@@ -327,22 +324,63 @@ std::string TestMessageHandler::TestExceptions() {
}
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.
+ // Try passing different numbers of arguments; only 1 argument is allowed.
+ // Other numbers should throw an exception.
+ std::string js_code(
+ "var plugin = document.getElementById('plugin');\n"
+ "var caught_exception = false;\n"
+ "try {\n"
+ " plugin.postMessageAndAwaitResponse();\n"
+ "} catch (err) {\n"
+ " caught_exception = true;\n"
+ "}\n"
+ "plugin.postMessage(caught_exception ? 'SUCCESS' : 'FAIL');\n"
+ "try {\n"
+ " plugin.postMessageAndAwaitResponse('hello', 5);\n"
+ "} catch (err) {\n"
+ " caught_exception = true;\n"
+ "}\n"
+ "plugin.postMessage(caught_exception ? 'SUCCESS' : 'FAIL');\n"
+ "plugin.postMessage('FINISHED_WAITING');\n");
+ instance_->EvalScript(js_code);
+ std::vector<pp::Var> messages;
+ handler.WaitForAsyncMessages(&messages);
+ ASSERT_EQ(2u, messages.size());
+ ASSERT_EQ("SUCCESS", messages[0].AsString());
+ ASSERT_EQ("SUCCESS", messages[1].AsString());
+ }
+ handler.Unregister();
+ ASSERT_SUBTEST_SUCCESS(handler.WaitForDestroy());
+
+ PASS();
+}
+
+std::string TestMessageHandler::TestBrowserHostedResources() {
+ MyMessageHandler handler(instance(),
+ handler_thread_.message_loop());
+ handler.Register();
+ {
+ // Try requesting and sending a FileSystem. It should throw an exception.
+ // The file system is opened asynchronously. Once it opens successfully,
+ // then we send it via postMessage and postMessageAndAwaitResponse. We try
+ // both to make sure that the ordering is correct.
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"
+ " plugin.postMessage(fs);"
+ " plugin.postMessage(fs);"
+ " plugin.postMessage(fs);"
+ " plugin.postMessage(fs);"
+ " var result = plugin.postMessageAndAwaitResponse(fs);\n"
" } catch (err) {\n"
" caught_exception = true;\n"
- " }\n"
- " plugin.postMessage(caught_exception ? 'SUCCESS' : 'FAIL');\n"
+ " }\n" //TODO(dmichael): Really test that the filesystem is right
+ // ...and FileRef?
+ " plugin.postMessage(result.toString() == fs.toString() ?"
+ " 'SUCCESS' : result.toString());\n"
+ " plugin.postMessage('FINISHED_WAITING');\n"
"}\n"
"function fileSystemError() {\n"
" plugin.postMessage('Failed to open filesystem');\n"
@@ -350,9 +388,10 @@ std::string TestMessageHandler::TestExceptions() {
"window.webkitRequestFileSystem(\n"
" window.Temporary, 1024, gotFileSystem, fileSystemError)\n");
instance_->EvalScript(js_code);
- pp::Var msg = handler.WaitForAsyncMessage();
- ASSERT_EQ(PP_VARTYPE_STRING, msg.pp_var().type);
- ASSERT_EQ("SUCCESS", msg.AsString());
+ std::vector<pp::Var> messages;
+ handler.WaitForAsyncMessages(&messages);
+ ASSERT_EQ(5u, messages.size());
+ ASSERT_EQ("SUCCESS", messages.back().AsString());
}
handler.Unregister();
ASSERT_SUBTEST_SUCCESS(handler.WaitForDestroy());
@@ -360,6 +399,7 @@ std::string TestMessageHandler::TestExceptions() {
PASS();
}
+
pp::Var TestMessageHandler::WaitForMessage() {
message_received_.Wait();
pp::Var var_to_return = last_message_;
« no previous file with comments | « ppapi/tests/test_message_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698