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

Unified Diff: chrome/browser/ui/webui/web_ui_test_handler.cc

Issue 7576024: Provide ability for WebUIBrowserTests to run asynchronous tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Moved |errors| around and do errors.splice only when completing results. Created 9 years, 4 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 | « chrome/browser/ui/webui/web_ui_test_handler.h ('k') | chrome/test/data/webui/async.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/webui/web_ui_test_handler.cc
diff --git a/chrome/browser/ui/webui/web_ui_test_handler.cc b/chrome/browser/ui/webui/web_ui_test_handler.cc
index 14b407fa43b14fe7a8bdac81af2a560ec979c991..d5ef95d7fe0de2efdb1d5ffd7607c28b59d8dacd 100644
--- a/chrome/browser/ui/webui/web_ui_test_handler.cc
+++ b/chrome/browser/ui/webui/web_ui_test_handler.cc
@@ -12,6 +12,14 @@
#include "content/common/notification_details.h"
#include "content/common/notification_registrar.h"
+WebUITestHandler::WebUITestHandler()
Paweł Hajdan Jr. 2011/08/05 18:17:14 Have you considered sharing code with extension te
Sheridan Rawlins 2011/08/05 18:51:12 David considered this some time ago. I don't reca
+ : test_succeeded_(false),
+ is_waiting_(false),
+ test_done_async_(false),
+ test_succeeded_async_(false),
+ is_waiting_async_(false) {
+}
+
void WebUITestHandler::PreloadJavaScript(const string16& js_text,
RenderViewHost* preload_host) {
DCHECK(preload_host);
@@ -35,6 +43,44 @@ bool WebUITestHandler::RunJavaScriptTestWithResult(const string16& js_text) {
return WaitForResult();
}
+bool WebUITestHandler::WaitForAsyncResult() {
+ if (!test_done_async_) {
+ is_waiting_async_ = true;
+ ui_test_utils::RunMessageLoop();
+ is_waiting_async_ = false;
+ }
+ return test_succeeded_async_;
+};
+
+void WebUITestHandler::RegisterMessages() {
+ web_ui_->RegisterMessageCallback("asyncTestResult", NewCallback(
+ this, &WebUITestHandler::HandleAsyncTestResult));
+}
+
+void WebUITestHandler::HandleAsyncTestResult(const ListValue* test_result) {
+ // Quit the message loop if we were waiting so Waiting process can get result
+ // or error. To ensure this gets done, do this before ASSERT* calls.
+ if (is_waiting_async_)
+ MessageLoopForUI::current()->Quit();
+
+ EXPECT_FALSE(test_done_async_);
+ test_done_async_ = true;
+
+ SCOPED_TRACE("WebUITestHandler::HandleAsyncTestResult");
+ HandleTestResult(test_result, &test_succeeded_async_);
+}
+
+void WebUITestHandler::HandleTestResult(const ListValue* test_result,
+ bool* success) {
+ *success = false;
+ ASSERT_TRUE(test_result->GetBoolean(0, success));
+ if (!success) {
+ std::string message;
+ ASSERT_TRUE(test_result->GetString(1, &message));
+ LOG(ERROR) << message;
+ }
+}
+
void WebUITestHandler::Observe(int type,
const NotificationSource& source,
const NotificationDetails& details) {
@@ -45,14 +91,9 @@ void WebUITestHandler::Observe(int type,
SCOPED_TRACE("WebUITestHandler::Observe");
Value* value = Details<std::pair<int, Value*> >(details)->second;
- ListValue* list_value;
- ASSERT_TRUE(value->GetAsList(&list_value));
- ASSERT_TRUE(list_value->GetBoolean(0, &test_succeeded_));
- if (!test_succeeded_) {
- std::string message;
- ASSERT_TRUE(list_value->GetString(1, &message));
- LOG(ERROR) << message;
- }
+ ListValue* test_result;
+ ASSERT_TRUE(value->GetAsList(&test_result));
+ HandleTestResult(test_result, &test_succeeded_);
}
bool WebUITestHandler::WaitForResult() {
« no previous file with comments | « chrome/browser/ui/webui/web_ui_test_handler.h ('k') | chrome/test/data/webui/async.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698