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

Side by Side Diff: ppapi/tests/test_utils.h

Issue 10910099: PPAPI: Make CompletionCallbacks work right on background threads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add ppb_message_loop_shared.cc/.h Created 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #ifndef PPAPI_TESTS_TEST_UTILS_H_ 5 #ifndef PPAPI_TESTS_TEST_UTILS_H_
6 #define PPAPI_TESTS_TEST_UTILS_H_ 6 #define PPAPI_TESTS_TEST_UTILS_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "ppapi/c/dev/ppb_testing_dev.h" 10 #include "ppapi/c/dev/ppb_testing_dev.h"
11 #include "ppapi/c/pp_instance.h" 11 #include "ppapi/c/pp_instance.h"
12 #include "ppapi/c/pp_stdint.h" 12 #include "ppapi/c/pp_stdint.h"
13 #include "ppapi/cpp/completion_callback.h" 13 #include "ppapi/cpp/completion_callback.h"
14 #include "ppapi/cpp/dev/message_loop_dev.h"
14 #include "ppapi/utility/completion_callback_factory.h" 15 #include "ppapi/utility/completion_callback_factory.h"
15 16
16 // Timeout to wait for some action to complete. 17 // Timeout to wait for some action to complete.
17 extern const int kActionTimeoutMs; 18 extern const int kActionTimeoutMs;
18 19
19 const PPB_Testing_Dev* GetTestingInterface(); 20 const PPB_Testing_Dev* GetTestingInterface();
20 std::string ReportError(const char* method, int32_t error); 21 std::string ReportError(const char* method, int32_t error);
21 void PlatformSleep(int duration_ms); 22 void PlatformSleep(int duration_ms);
22 bool GetLocalHostPort(PP_Instance instance, std::string* host, uint16_t* port); 23 bool GetLocalHostPort(PP_Instance instance, std::string* host, uint16_t* port);
23 24
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 bool failed() { return !errors_.empty(); } 146 bool failed() { return !errors_.empty(); }
146 const std::string& errors() { return errors_; } 147 const std::string& errors() { return errors_; }
147 148
148 int32_t result() const { return result_; } 149 int32_t result() const { return result_; }
149 150
150 // Reset so that this callback can be used again. 151 // Reset so that this callback can be used again.
151 void Reset(); 152 void Reset();
152 153
153 private: 154 private:
154 static void Handler(void* user_data, int32_t result); 155 static void Handler(void* user_data, int32_t result);
156 void RunMessageLoop();
157 void QuitMessageLoop();
155 158
156 // Used to check that WaitForResult is only called once for each usage of the 159 // Used to check that WaitForResult is only called once for each usage of the
157 // callback. 160 // callback.
158 bool wait_for_result_called_; 161 bool wait_for_result_called_;
159 // Indicates whether we have already been invoked. 162 // Indicates whether we have already been invoked.
160 bool have_result_; 163 bool have_result_;
161 // The last result received (or PP_OK_COMPLETIONCALLBACK if none). 164 // The last result received (or PP_OK_COMPLETIONCALLBACK if none).
162 int32_t result_; 165 int32_t result_;
163 CallbackType callback_type_; 166 CallbackType callback_type_;
164 bool post_quit_task_; 167 bool post_quit_task_;
165 std::string errors_; 168 std::string errors_;
166 unsigned run_count_; 169 unsigned run_count_;
167 PP_Instance instance_; 170 PP_Instance instance_;
168 Delegate* delegate_; 171 Delegate* delegate_;
172 pp::MessageLoop_Dev target_loop_;
169 }; 173 };
170 174
171 // Verifies that the callback didn't record any errors. If the callback is run 175 // Verifies that the callback didn't record any errors. If the callback is run
172 // in an unexpected way (e.g., if it's invoked asynchronously when the call 176 // in an unexpected way (e.g., if it's invoked asynchronously when the call
173 // should have blocked), this returns an appropriate error string. 177 // should have blocked), this returns an appropriate error string.
174 #define CHECK_CALLBACK_BEHAVIOR(callback) \ 178 #define CHECK_CALLBACK_BEHAVIOR(callback) \
175 do { \ 179 do { \
176 if ((callback).failed()) \ 180 if ((callback).failed()) \
177 return (callback).errors(); \ 181 return (callback).errors(); \
178 } while (false) 182 } while (false)
(...skipping 22 matching lines...) Expand all
201 #error Please add support for your platform in ppapi/tests/test_utils.h 205 #error Please add support for your platform in ppapi/tests/test_utils.h
202 #endif 206 #endif
203 207
204 /* These are used to determine POSIX-like implementations vs Windows. */ 208 /* These are used to determine POSIX-like implementations vs Windows. */
205 #if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || \ 209 #if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || \
206 defined(__OpenBSD__) || defined(__sun) || defined(__native_client__) 210 defined(__OpenBSD__) || defined(__sun) || defined(__native_client__)
207 #define PPAPI_POSIX 1 211 #define PPAPI_POSIX 1
208 #endif 212 #endif
209 213
210 #endif // PPAPI_TESTS_TEST_UTILS_H_ 214 #endif // PPAPI_TESTS_TEST_UTILS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698