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

Unified Diff: extensions/browser/api_test_utils.h

Issue 2348723002: [Extensions] Remove UIThreadExtensionFunction::DelegateForTests (Closed)
Patch Set: lazyboy's Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « extensions/browser/api/cast_channel/cast_channel_apitest.cc ('k') | extensions/browser/api_test_utils.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « extensions/browser/api/cast_channel/cast_channel_apitest.cc ('k') | extensions/browser/api_test_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698