Chromium Code Reviews| 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() |
| + : 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() { |
|
David Tseng
2011/08/05 13:45:40
This looks virtually identical to WaitForResult. I
Sheridan Rawlins
2011/08/05 15:41:59
The distinction is that our "normal" RunJavascript
|
| + 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_) |
|
David Tseng
2011/08/05 13:45:40
Why do we need separate *async versions of these b
Sheridan Rawlins
2011/08/05 15:41:59
We need separate booleans because the messages are
|
| + MessageLoopForUI::current()->Quit(); |
| + |
| + EXPECT_FALSE(test_done_async_); |
| + test_done_async_ = true; |
|
David Tseng
2011/08/05 13:45:40
What's the difference between test_done_async and
mmenke
2011/08/05 13:54:18
The async result could theoretically be reported b
Sheridan Rawlins
2011/08/05 15:41:59
I like duplicating the booleans to be explicit abo
|
| + |
| + 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() { |