diff options
author | bbudge@chromium.org <bbudge@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-17 14:24:30 +0000 |
---|---|---|
committer | bbudge@chromium.org <bbudge@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-17 14:24:30 +0000 |
commit | 08610101320e903c398cea854bd8ad66e361aebc (patch) | |
tree | 38bb90bf10119a519a68a1a6f0955d0c8910c1f9 /ppapi | |
parent | 5ccea8893320e6b6ccf422179ec50cee08f15a7f (diff) | |
download | chromium_src-08610101320e903c398cea854bd8ad66e361aebc.zip chromium_src-08610101320e903c398cea854bd8ad66e361aebc.tar.gz chromium_src-08610101320e903c398cea854bd8ad66e361aebc.tar.bz2 |
Add TestingInstance::ExecuteScript method which posts a message that the test page
can eval(). Change InputEvent and PostMessage tests to use this.
Add proxy for PPB_Testing_Dev::SimulateInputEvent function.
BUG=NONE
TEST=ui_tests
Review URL: http://codereview.chromium.org/8920005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@114924 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi')
-rw-r--r-- | ppapi/native_client/src/shared/ppapi_proxy/browser_ppb_testing_rpc_server.cc | 15 | ||||
-rw-r--r-- | ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_testing.cc | 15 | ||||
-rw-r--r-- | ppapi/native_client/src/shared/ppapi_proxy/ppb_rpc_client.cc | 21 | ||||
-rw-r--r-- | ppapi/native_client/src/shared/ppapi_proxy/ppb_rpc_server.cc | 16 | ||||
-rw-r--r-- | ppapi/native_client/src/shared/ppapi_proxy/ppb_testing.srpc | 7 | ||||
-rw-r--r-- | ppapi/native_client/src/shared/ppapi_proxy/trusted/srpcgen/ppb_rpc.h | 5 | ||||
-rw-r--r-- | ppapi/native_client/src/shared/ppapi_proxy/untrusted/srpcgen/ppb_rpc.h | 4 | ||||
-rw-r--r-- | ppapi/ppapi_sources.gypi | 2 | ||||
-rw-r--r-- | ppapi/tests/test_case.html | 10 | ||||
-rw-r--r-- | ppapi/tests/test_input_event.cc | 7 | ||||
-rw-r--r-- | ppapi/tests/test_post_message.cc | 28 | ||||
-rw-r--r-- | ppapi/tests/testing_instance.cc | 6 | ||||
-rw-r--r-- | ppapi/tests/testing_instance.h | 3 |
13 files changed, 115 insertions, 24 deletions
diff --git a/ppapi/native_client/src/shared/ppapi_proxy/browser_ppb_testing_rpc_server.cc b/ppapi/native_client/src/shared/ppapi_proxy/browser_ppb_testing_rpc_server.cc index 69b04a0..8288036 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/browser_ppb_testing_rpc_server.cc +++ b/ppapi/native_client/src/shared/ppapi_proxy/browser_ppb_testing_rpc_server.cc @@ -91,6 +91,21 @@ void PpbTestingRpcServer::PPB_Testing_GetLiveObjectsForInstance( rpc->result = NACL_SRPC_RESULT_OK; } +void PpbTestingRpcServer::PPB_Testing_SimulateInputEvent( + NaClSrpcRpc* rpc, + NaClSrpcClosure* done, + PP_Instance instance, + PP_Resource input_event) { + NaClSrpcClosureRunner runner(done); + rpc->result = NACL_SRPC_RESULT_APP_ERROR; + + PPBTestingInterface()->SimulateInputEvent(instance, input_event); + + DebugPrintf("PPB_Testing::SimulateInputEvent: instance=%"NACL_PRIu32"\n", + instance); + rpc->result = NACL_SRPC_RESULT_OK; +} + void PpbTestingRpcServer::PPB_Testing_GetDocumentURL( NaClSrpcRpc* rpc, NaClSrpcClosure* done, diff --git a/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_testing.cc b/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_testing.cc index 6b928ec..8b93846 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_testing.cc +++ b/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_testing.cc @@ -102,6 +102,19 @@ PP_Bool IsOutOfProcess() { return PP_FALSE; } +void SimulateInputEvent(PP_Instance instance, PP_Resource input_event) { + DebugPrintf("PPB_Testing::SimulateInputEvent: instance=%"NACL_PRId32", " + "input_event=%"NACL_PRId32"\n", + instance, input_event); + + NaClSrpcError srpc_result = + PpbTestingRpcClient::PPB_Testing_SimulateInputEvent(GetMainSrpcChannel(), + instance, + input_event); + DebugPrintf("PPB_Testing::SimulateInputEvent: %s\n", + NaClSrpcErrorString(srpc_result)); +} + struct PP_Var GetDocumentURL(PP_Instance instance, struct PP_URLComponents_Dev* components) { DebugPrintf("PPB_Testing::GetDocumentURL: " @@ -140,7 +153,7 @@ const PPB_Testing_Dev* PluginTesting::GetInterface() { QuitMessageLoop, GetLiveObjectsForInstance, IsOutOfProcess, - NULL, + SimulateInputEvent, GetDocumentURL }; return &testing_interface; diff --git a/ppapi/native_client/src/shared/ppapi_proxy/ppb_rpc_client.cc b/ppapi/native_client/src/shared/ppapi_proxy/ppb_rpc_client.cc index 97f0155..d438ac1 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/ppb_rpc_client.cc +++ b/ppapi/native_client/src/shared/ppapi_proxy/ppb_rpc_client.cc @@ -1452,7 +1452,7 @@ NaClSrpcError PpbGraphics3DRpcClient::PPB_Graphics3DTrusted_InitCommandBuffer( NaClSrpcError PpbGraphics3DRpcClient::PPB_Graphics3DTrusted_SetGetBuffer( NaClSrpcChannel* channel, PP_Resource resource_id, - int32_t transfer_buffer_id) { + int32_t shm_id) { VCHECK(ppapi_proxy::PPBCoreInterface()->IsMainThread(), ("%s: PPAPI calls are not supported off the main thread\n", __FUNCTION__)); @@ -1461,7 +1461,7 @@ NaClSrpcError PpbGraphics3DRpcClient::PPB_Graphics3DTrusted_SetGetBuffer( channel, "PPB_Graphics3DTrusted_SetGetBuffer:ii:", resource_id, - transfer_buffer_id + shm_id ); return retval; } @@ -2553,6 +2553,23 @@ NaClSrpcError PpbTestingRpcClient::PPB_Testing_GetLiveObjectsForInstance( return retval; } +NaClSrpcError PpbTestingRpcClient::PPB_Testing_SimulateInputEvent( + NaClSrpcChannel* channel, + PP_Instance instance, + PP_Resource input_event) { + VCHECK(ppapi_proxy::PPBCoreInterface()->IsMainThread(), + ("%s: PPAPI calls are not supported off the main thread\n", + __FUNCTION__)); + NaClSrpcError retval; + retval = NaClSrpcInvokeBySignature( + channel, + "PPB_Testing_SimulateInputEvent:ii:", + instance, + input_event + ); + return retval; +} + NaClSrpcError PpbTestingRpcClient::PPB_Testing_GetDocumentURL( NaClSrpcChannel* channel, PP_Instance instance, diff --git a/ppapi/native_client/src/shared/ppapi_proxy/ppb_rpc_server.cc b/ppapi/native_client/src/shared/ppapi_proxy/ppb_rpc_server.cc index 60936f0..11c3b3a 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/ppb_rpc_server.cc +++ b/ppapi/native_client/src/shared/ppapi_proxy/ppb_rpc_server.cc @@ -2056,6 +2056,21 @@ static void PPB_Testing_GetLiveObjectsForInstanceDispatcher( ); } +static void PPB_Testing_SimulateInputEventDispatcher( + NaClSrpcRpc* rpc, + NaClSrpcArg** inputs, + NaClSrpcArg** outputs, + NaClSrpcClosure* done +) { + UNREFERENCED_PARAMETER(outputs); + PpbTestingRpcServer::PPB_Testing_SimulateInputEvent( + rpc, + done, + inputs[0]->u.ival, + inputs[1]->u.ival + ); +} + static void PPB_Testing_GetDocumentURLDispatcher( NaClSrpcRpc* rpc, NaClSrpcArg** inputs, @@ -2692,6 +2707,7 @@ NaClSrpcHandlerDesc PpbRpcs::srpc_methods[] = { { "PPB_Testing_RunMessageLoop:i:", PPB_Testing_RunMessageLoopDispatcher }, { "PPB_Testing_QuitMessageLoop:i:", PPB_Testing_QuitMessageLoopDispatcher }, { "PPB_Testing_GetLiveObjectsForInstance:i:i", PPB_Testing_GetLiveObjectsForInstanceDispatcher }, + { "PPB_Testing_SimulateInputEvent:ii:", PPB_Testing_SimulateInputEventDispatcher }, { "PPB_Testing_GetDocumentURL:i:CC", PPB_Testing_GetDocumentURLDispatcher }, { "PPB_UDPSocket_Private_Create:i:i", PPB_UDPSocket_Private_CreateDispatcher }, { "PPB_UDPSocket_Private_IsUDPSocket:i:i", PPB_UDPSocket_Private_IsUDPSocketDispatcher }, diff --git a/ppapi/native_client/src/shared/ppapi_proxy/ppb_testing.srpc b/ppapi/native_client/src/shared/ppapi_proxy/ppb_testing.srpc index ceb62f7..10482be 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/ppb_testing.srpc +++ b/ppapi/native_client/src/shared/ppapi_proxy/ppb_testing.srpc @@ -33,6 +33,13 @@ 'outputs': [['live_object_count', 'int32_t'], # uint32_t ] }, + {'name': 'PPB_Testing_SimulateInputEvent', + 'inputs': [['instance', 'PP_Instance'], + ['input_event', 'PP_Resource'], + ], + 'outputs': [ + ] + }, {'name': 'PPB_Testing_GetDocumentURL', 'inputs': [['instance', 'PP_Instance'], ], diff --git a/ppapi/native_client/src/shared/ppapi_proxy/trusted/srpcgen/ppb_rpc.h b/ppapi/native_client/src/shared/ppapi_proxy/trusted/srpcgen/ppb_rpc.h index 97cd7b3..aca8ace 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/trusted/srpcgen/ppb_rpc.h +++ b/ppapi/native_client/src/shared/ppapi_proxy/trusted/srpcgen/ppb_rpc.h @@ -1021,6 +1021,11 @@ class PpbTestingRpcServer { NaClSrpcClosure* done, PP_Instance instance, int32_t* live_object_count); + static void PPB_Testing_SimulateInputEvent( + NaClSrpcRpc* rpc, + NaClSrpcClosure* done, + PP_Instance instance, + PP_Resource input_event); static void PPB_Testing_GetDocumentURL( NaClSrpcRpc* rpc, NaClSrpcClosure* done, diff --git a/ppapi/native_client/src/shared/ppapi_proxy/untrusted/srpcgen/ppb_rpc.h b/ppapi/native_client/src/shared/ppapi_proxy/untrusted/srpcgen/ppb_rpc.h index 6085308..e7d04f1 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/untrusted/srpcgen/ppb_rpc.h +++ b/ppapi/native_client/src/shared/ppapi_proxy/untrusted/srpcgen/ppb_rpc.h @@ -888,6 +888,10 @@ class PpbTestingRpcClient { NaClSrpcChannel* channel, PP_Instance instance, int32_t* live_object_count); + static NaClSrpcError PPB_Testing_SimulateInputEvent( + NaClSrpcChannel* channel, + PP_Instance instance, + PP_Resource input_event); static NaClSrpcError PPB_Testing_GetDocumentURL( NaClSrpcChannel* channel, PP_Instance instance, diff --git a/ppapi/ppapi_sources.gypi b/ppapi/ppapi_sources.gypi index 49e74fd..5ebe710 100644 --- a/ppapi/ppapi_sources.gypi +++ b/ppapi/ppapi_sources.gypi @@ -286,10 +286,12 @@ 'tests/test_file_io.cc', 'tests/test_file_ref.cc', 'tests/test_file_system.cc', + 'tests/test_input_event.cc', 'tests/test_memory.cc', 'tests/test_graphics_2d.cc', 'tests/test_image_data.cc', 'tests/test_paint_aggregator.cc', + 'tests/test_post_message.cc', 'tests/test_scrollbar.cc', 'tests/test_url_loader.cc', 'tests/test_var.cc', diff --git a/ppapi/tests/test_case.html b/ppapi/tests/test_case.html index 43b24a5..7e8630e 100644 --- a/ppapi/tests/test_case.html +++ b/ppapi/tests/test_case.html @@ -78,6 +78,7 @@ function ExtractSearchParameter(name) { // - DidExecuteTests // - LogHTML // - SetCookie +// - EvalScript // The second item is the verbatim message_contents. function ParseTestingMessage(message_data) { if (typeof(message_data)!='string') @@ -107,6 +108,13 @@ function SetCookie(key_value_string) { window.document.cookie = key_value_string + "; path=/"; } +function EvalScript(script) { + try { + eval(script); + } catch(ex) { + } +} + function IsTestingMessage(message_data) { return (ParseTestingMessage(message_data) != undefined); } @@ -124,6 +132,8 @@ function handleTestingMessage(message_event) { LogHTML(contents); else if (type === "SetCookie") SetCookie(contents); + else if (type === "EvalScript") + EvalScript(contents); } } diff --git a/ppapi/tests/test_input_event.cc b/ppapi/tests/test_input_event.cc index 49526db..cdd4939 100644 --- a/ppapi/tests/test_input_event.cc +++ b/ppapi/tests/test_input_event.cc @@ -52,8 +52,7 @@ TestInputEvent::~TestInputEvent() { "plugin.removeEventListener('message'," " plugin.wait_for_messages_handler);" "delete plugin.wait_for_messages_handler;"; - pp::Var exception; - instance_->ExecuteScript(js_code, &exception); + instance_->EvalScript(js_code); } bool TestInputEvent::Init() { @@ -94,9 +93,7 @@ bool TestInputEvent::Init() { "plugin.addEventListener('message', wait_for_messages_handler);" // Stash it on the plugin so we can remove it in the destructor. "plugin.wait_for_messages_handler = wait_for_messages_handler;"; - pp::Var exception; - instance_->ExecuteScript(js_code, &exception); - success = success && exception.is_undefined(); + instance_->EvalScript(js_code); return success; } diff --git a/ppapi/tests/test_post_message.cc b/ppapi/tests/test_post_message.cc index a86f310..665dad7 100644 --- a/ppapi/tests/test_post_message.cc +++ b/ppapi/tests/test_post_message.cc @@ -65,8 +65,7 @@ TestPostMessage::~TestPostMessage() { "plugin.removeEventListener('message'," " plugin.wait_for_messages_handler);" "delete plugin.wait_for_messages_handler;"; - pp::Var exception; - instance_->ExecuteScript(js_code, &exception); + instance_->EvalScript(js_code); } bool TestPostMessage::Init() { @@ -90,9 +89,7 @@ bool TestPostMessage::Init() { "plugin.addEventListener('message', wait_for_messages_handler);" // Stash it on the plugin so we can remove it in the destructor. "plugin.wait_for_messages_handler = wait_for_messages_handler;"; - pp::Var exception; - instance_->ExecuteScript(js_code, &exception); - success = success && exception.is_undefined(); + instance_->EvalScript(js_code); // Set up the JavaScript message event listener to echo the data part of the // message event back to us. @@ -149,20 +146,19 @@ bool TestPostMessage::AddEchoingListener(const std::string& expression) { // ClearListeners()). "if (!plugin.eventListeners) plugin.eventListeners = [];" "plugin.eventListeners.push(message_handler);"; - pp::Var exception; - instance_->ExecuteScript(js_code, &exception); - return exception.is_undefined(); + instance_->EvalScript(js_code); + return true; } bool TestPostMessage::ClearListeners() { - std::string js_code( - "var plugin = document.getElementById('plugin');" - "while (plugin.eventListeners.length) {" - " plugin.removeEventListener('message', plugin.eventListeners.pop());" - "}"); - pp::Var exception; - instance_->ExecuteScript(js_code, &exception); - return(exception.is_undefined()); + std::string js_code; + js_code += "var plugin = document.getElementById('plugin');" + "while (plugin.eventListeners.length) {" + " plugin.removeEventListener('message'," + " plugin.eventListeners.pop());" + "}"; + instance_->EvalScript(js_code); + return true; } int TestPostMessage::WaitForMessages() { diff --git a/ppapi/tests/testing_instance.cc b/ppapi/tests/testing_instance.cc index 056477d..88ef424 100644 --- a/ppapi/tests/testing_instance.cc +++ b/ppapi/tests/testing_instance.cc @@ -101,6 +101,12 @@ bool TestingInstance::HandleInputEvent(const pp::InputEvent& event) { return false; } +void TestingInstance::EvalScript(const std::string& script) { + std::string message("TESTING_MESSAGE:EvalScript:"); + message.append(script); + PostMessage(pp::Var(message)); +} + void TestingInstance::LogTest(const std::string& test_name, const std::string& error_message) { // Tell the browser we're still working. diff --git a/ppapi/tests/testing_instance.h b/ppapi/tests/testing_instance.h index 8f6b7b1..397c1c7 100644 --- a/ppapi/tests/testing_instance.h +++ b/ppapi/tests/testing_instance.h @@ -83,6 +83,9 @@ pp::InstancePrivate { return protocol_; } + // Posts a message to the test page to eval() the script. + void EvalScript(const std::string& script); + private: void ExecuteTests(int32_t unused); |