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

Side by Side Diff: ppapi/tests/test_message_handler.cc

Issue 600553002: PPAPI: Disallow blocking callbacks while handling a blocking message (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: try to improve comment Created 6 years, 2 months 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 unified diff | Download patch
« no previous file with comments | « ppapi/shared_impl/ppb_message_loop_shared.h ('k') | ppapi/thunk/enter.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ppapi/tests/test_message_handler.h" 5 #include "ppapi/tests/test_message_handler.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 #include <algorithm> 8 #include <algorithm>
9 #include <map> 9 #include <map>
10 #include <sstream> 10 #include <sstream>
11 11
12 #include "ppapi/c/pp_var.h" 12 #include "ppapi/c/pp_var.h"
13 #include "ppapi/c/ppb_file_io.h" 13 #include "ppapi/c/ppb_file_io.h"
14 #include "ppapi/c/ppb_messaging.h" 14 #include "ppapi/c/ppb_messaging.h"
15 #include "ppapi/c/ppp_message_handler.h" 15 #include "ppapi/c/ppp_message_handler.h"
16 #include "ppapi/cpp/completion_callback.h"
16 #include "ppapi/cpp/file_io.h" 17 #include "ppapi/cpp/file_io.h"
17 #include "ppapi/cpp/file_ref.h" 18 #include "ppapi/cpp/file_ref.h"
18 #include "ppapi/cpp/file_system.h" 19 #include "ppapi/cpp/file_system.h"
19 #include "ppapi/cpp/instance.h" 20 #include "ppapi/cpp/instance.h"
20 #include "ppapi/cpp/message_handler.h" 21 #include "ppapi/cpp/message_handler.h"
21 #include "ppapi/cpp/module_impl.h" 22 #include "ppapi/cpp/module_impl.h"
23 #include "ppapi/cpp/network_list.h"
24 #include "ppapi/cpp/network_monitor.h"
22 #include "ppapi/cpp/var.h" 25 #include "ppapi/cpp/var.h"
23 #include "ppapi/cpp/var_array.h" 26 #include "ppapi/cpp/var_array.h"
24 #include "ppapi/cpp/var_array_buffer.h" 27 #include "ppapi/cpp/var_array_buffer.h"
25 #include "ppapi/cpp/var_dictionary.h" 28 #include "ppapi/cpp/var_dictionary.h"
26 #include "ppapi/tests/pp_thread.h" 29 #include "ppapi/tests/pp_thread.h"
27 #include "ppapi/tests/test_utils.h" 30 #include "ppapi/tests/test_utils.h"
28 #include "ppapi/tests/testing_instance.h" 31 #include "ppapi/tests/testing_instance.h"
29 32
30 // Windows defines 'PostMessage', so we have to undef it. 33 // Windows defines 'PostMessage', so we have to undef it.
31 #ifdef PostMessage 34 #ifdef PostMessage
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 testing_instance_->PostMessage(var); 118 testing_instance_->PostMessage(var);
116 } 119 }
117 120
118 virtual pp::Var HandleBlockingMessage(pp::InstanceHandle instance, 121 virtual pp::Var HandleBlockingMessage(pp::InstanceHandle instance,
119 const pp::Var& var) { 122 const pp::Var& var) {
120 if (pp::MessageLoop::GetCurrent() != message_handler_loop_) 123 if (pp::MessageLoop::GetCurrent() != message_handler_loop_)
121 AddError("HandleBlockingMessage was called on the wrong thread!"); 124 AddError("HandleBlockingMessage was called on the wrong thread!");
122 if (instance.pp_instance() != testing_instance_->pp_instance()) 125 if (instance.pp_instance() != testing_instance_->pp_instance())
123 AddError("HandleBlockingMessage was passed the wrong instance!"); 126 AddError("HandleBlockingMessage was passed the wrong instance!");
124 127
128 // Attempt a blocking operation; make sure it's disallowed.
129 pp::NetworkMonitor monitor(instance);
130 PP_Resource out_param = 0;
131 pp::CompletionCallbackWithOutput<pp::NetworkList> blocking_callback(
132 &out_param);
133 int32_t error = monitor.UpdateNetworkList(blocking_callback);
134 if (error != PP_ERROR_WOULD_BLOCK_THREAD) {
135 AddError("HandleBlockingMessage was allowed to do a blocking call!");
136 pp::Module::Get()->core()->ReleaseResource(out_param);
137 }
138
125 return var; 139 return var;
126 } 140 }
127 141
128 virtual void WasUnregistered(pp::InstanceHandle instance) { 142 virtual void WasUnregistered(pp::InstanceHandle instance) {
129 if (pp::MessageLoop::GetCurrent() != message_handler_loop_) 143 if (pp::MessageLoop::GetCurrent() != message_handler_loop_)
130 AddError("Destroy was called on the wrong thread!"); 144 AddError("Destroy was called on the wrong thread!");
131 if (instance.pp_instance() != testing_instance_->pp_instance()) 145 if (instance.pp_instance() != testing_instance_->pp_instance())
132 AddError("Destroy was passed the wrong instance!"); 146 AddError("Destroy was passed the wrong instance!");
133 destroy_event_.Signal(); 147 destroy_event_.Signal();
134 } 148 }
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 // That should be fixed before this API goes to stable. See crbug.com/384528 273 // That should be fixed before this API goes to stable. See crbug.com/384528
260 js_code += "plugin.postMessage('FINISHED_TEST');\n"; 274 js_code += "plugin.postMessage('FINISHED_TEST');\n";
261 instance_->EvalScript(js_code); 275 instance_->EvalScript(js_code);
262 handler.WaitForTestFinishedMessage(); 276 handler.WaitForTestFinishedMessage();
263 handler.Unregister(); 277 handler.Unregister();
264 ASSERT_SUBTEST_SUCCESS(handler.WaitForDestroy()); 278 ASSERT_SUBTEST_SUCCESS(handler.WaitForDestroy());
265 279
266 PASS(); 280 PASS();
267 } 281 }
268 282
OLDNEW
« no previous file with comments | « ppapi/shared_impl/ppb_message_loop_shared.h ('k') | ppapi/thunk/enter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698