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

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: Don't need to expose isAsyncTestDone. 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/test_api.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..4db910cfc24c4cd214937d901001400f2f559c43 100644
--- a/chrome/browser/ui/webui/web_ui_test_handler.cc
+++ b/chrome/browser/ui/webui/web_ui_test_handler.cc
@@ -35,6 +35,39 @@ bool WebUITestHandler::RunJavaScriptTestWithResult(const string16& js_text) {
return WaitForResult();
}
+bool WebUITestHandler::WaitForAsyncResult() {
+ is_waiting_async_ = true;
+ ui_test_utils::RunMessageLoop();
mmenke 2011/08/05 00:47:22 You need to check |test_done_async_| here, and not
Sheridan Rawlins 2011/08/05 01:15:48 Done.
+ 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) {
+ EXPECT_FALSE(test_done_async_);
+ test_done_async_ = true;
mmenke 2011/08/05 00:47:22 Neither this nor |is_waiting_async_| is ever initi
Sheridan Rawlins 2011/08/05 01:15:48 Done.
+
+ if (is_waiting_async_)
+ MessageLoopForUI::current()->Quit();
+
+ SCOPED_TRACE("WebUITestHandler::HandleAsyncTestResult");
+ HandleTestResult(test_result, &test_succeeded_async_);
+}
+
+void WebUITestHandler::HandleTestResult(const ListValue* test_result,
+ bool* success) {
+ ASSERT_TRUE(test_result->GetBoolean(0, success));
mmenke 2011/08/05 00:47:22 You should probably initialize success to false, b
Sheridan Rawlins 2011/08/05 01:15:48 Done.
+ 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 +78,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/test_api.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698