Index: content/test/content_browser_test_utils.cc |
diff --git a/content/test/content_browser_test_utils.cc b/content/test/content_browser_test_utils.cc |
index 1e92c7faf1a62b90f664bfe7f07c4de7e66a6968..cf5139051308b0b55742b67b091b765d9db3d1a0 100644 |
--- a/content/test/content_browser_test_utils.cc |
+++ b/content/test/content_browser_test_utils.cc |
@@ -8,8 +8,11 @@ |
#include "base/file_path.h" |
#include "base/path_service.h" |
#include "base/run_loop.h" |
+#include "content/public/browser/dom_operation_notification_details.h" |
#include "content/public/browser/navigation_controller.h" |
#include "content/public/browser/notification_source.h" |
+#include "content/public/browser/notification_types.h" |
+#include "content/public/browser/notification_service.h" |
#include "content/public/browser/web_contents.h" |
#include "content/public/common/content_paths.h" |
#include "content/public/test/browser_test_utils.h" |
@@ -89,4 +92,42 @@ void ShellAddedObserver::ShellCreated(Shell* shell) { |
runner_->QuitClosure().Run(); |
} |
+DOMMessageQueue::DOMMessageQueue() : waiting_for_message_(false) { |
+ registrar_.Add(this, content::NOTIFICATION_DOM_OPERATION_RESPONSE, |
+ content::NotificationService::AllSources()); |
+} |
+ |
+DOMMessageQueue::~DOMMessageQueue() {} |
+ |
+void DOMMessageQueue::Observe(int type, |
+ const content::NotificationSource& source, |
+ const content::NotificationDetails& details) { |
+ content::Details<DomOperationNotificationDetails> dom_op_details(details); |
+ content::Source<RenderViewHost> sender(source); |
+ message_queue_.push(dom_op_details->json); |
+ if (waiting_for_message_) { |
+ waiting_for_message_ = false; |
+ message_loop_runner_->Quit(); |
+ } |
+} |
+ |
+void DOMMessageQueue::ClearQueue() { |
+ message_queue_ = std::queue<std::string>(); |
+} |
+ |
+bool DOMMessageQueue::WaitForMessage(std::string* message) { |
+ if (message_queue_.empty()) { |
+ waiting_for_message_ = true; |
+ // This will be quit when a new message comes in. |
+ message_loop_runner_ = new content::MessageLoopRunner; |
+ message_loop_runner_->Run(); |
+ } |
+ // The queue should not be empty, unless we were quit because of a timeout. |
+ if (message_queue_.empty()) |
+ return false; |
+ if (message) |
+ *message = message_queue_.front(); |
+ return true; |
+} |
+ |
} // namespace content |