Index: extensions/browser/api_test_utils.h |
diff --git a/extensions/browser/api_test_utils.h b/extensions/browser/api_test_utils.h |
index 81c36f42b4b31b704e8d7ffca71e2cd2025ad420..9ce78058db78db81b99f2abeaa9df4339ae80ec6 100644 |
--- a/extensions/browser/api_test_utils.h |
+++ b/extensions/browser/api_test_utils.h |
@@ -9,10 +9,10 @@ |
#include <string> |
#include "base/memory/ref_counted.h" |
+#include "base/run_loop.h" |
+#include "extensions/browser/extension_function.h" |
#include "extensions/common/manifest.h" |
-class UIThreadExtensionFunction; |
- |
namespace base { |
class DictionaryValue; |
class ListValue; |
@@ -34,6 +34,33 @@ class ExtensionFunctionDispatcher; |
// and migrate existing users to the new API. |
namespace api_test_utils { |
+// A helper class to handle waiting for a function response. |
+class SendResponseHelper { |
+ public: |
+ explicit SendResponseHelper(UIThreadExtensionFunction* function); |
+ ~SendResponseHelper(); |
+ |
+ bool has_response() { return response_.get() != nullptr; } |
+ |
+ // Asserts a response has been posted (has_response()) and returns the value. |
+ bool GetResponse(); |
+ |
+ // Waits until a response is posted. |
+ void WaitForResponse(); |
+ |
+ private: |
+ // Response handler. |
+ void OnResponse(ExtensionFunction::ResponseType response, |
+ const base::ListValue& results, |
+ const std::string& error, |
+ functions::HistogramValue histogram_value); |
+ |
+ base::RunLoop run_loop_; |
+ std::unique_ptr<bool> response_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(SendResponseHelper); |
+}; |
+ |
enum RunFunctionFlags { NONE = 0, INCLUDE_INCOGNITO = 1 << 0 }; |
// Parse JSON and return as the specified type, or NULL if the JSON is invalid |