Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/webui/web_ui_test_handler.h" | 5 #include "chrome/browser/ui/webui/web_ui_test_handler.h" |
| 6 | 6 |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "chrome/common/render_messages.h" | 9 #include "chrome/common/render_messages.h" |
| 10 #include "chrome/test/base/ui_test_utils.h" | 10 #include "chrome/test/base/ui_test_utils.h" |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 bool WebUITestHandler::RunJavaScriptTestWithResult(const string16& js_text) { | 28 bool WebUITestHandler::RunJavaScriptTestWithResult(const string16& js_text) { |
| 29 NotificationRegistrar notification_registrar; | 29 NotificationRegistrar notification_registrar; |
| 30 notification_registrar.Add( | 30 notification_registrar.Add( |
| 31 this, content::NOTIFICATION_EXECUTE_JAVASCRIPT_RESULT, | 31 this, content::NOTIFICATION_EXECUTE_JAVASCRIPT_RESULT, |
| 32 Source<RenderViewHost>(web_ui_->GetRenderViewHost())); | 32 Source<RenderViewHost>(web_ui_->GetRenderViewHost())); |
| 33 web_ui_->GetRenderViewHost()->ExecuteJavascriptInWebFrameNotifyResult( | 33 web_ui_->GetRenderViewHost()->ExecuteJavascriptInWebFrameNotifyResult( |
| 34 string16(), js_text); | 34 string16(), js_text); |
| 35 return WaitForResult(); | 35 return WaitForResult(); |
| 36 } | 36 } |
| 37 | 37 |
| 38 bool WebUITestHandler::WaitForAsyncResult() { | |
| 39 is_waiting_async_ = true; | |
| 40 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.
| |
| 41 is_waiting_async_ = false; | |
| 42 return test_succeeded_async_; | |
| 43 }; | |
| 44 | |
| 45 void WebUITestHandler::RegisterMessages() { | |
| 46 web_ui_->RegisterMessageCallback("asyncTestResult", NewCallback( | |
| 47 this, &WebUITestHandler::HandleAsyncTestResult)); | |
| 48 } | |
| 49 | |
| 50 void WebUITestHandler::HandleAsyncTestResult(const ListValue* test_result) { | |
| 51 EXPECT_FALSE(test_done_async_); | |
| 52 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.
| |
| 53 | |
| 54 if (is_waiting_async_) | |
| 55 MessageLoopForUI::current()->Quit(); | |
| 56 | |
| 57 SCOPED_TRACE("WebUITestHandler::HandleAsyncTestResult"); | |
| 58 HandleTestResult(test_result, &test_succeeded_async_); | |
| 59 } | |
| 60 | |
| 61 void WebUITestHandler::HandleTestResult(const ListValue* test_result, | |
| 62 bool* success) { | |
| 63 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.
| |
| 64 if (!success) { | |
| 65 std::string message; | |
| 66 ASSERT_TRUE(test_result->GetString(1, &message)); | |
| 67 LOG(ERROR) << message; | |
| 68 } | |
| 69 } | |
| 70 | |
| 38 void WebUITestHandler::Observe(int type, | 71 void WebUITestHandler::Observe(int type, |
| 39 const NotificationSource& source, | 72 const NotificationSource& source, |
| 40 const NotificationDetails& details) { | 73 const NotificationDetails& details) { |
| 41 // Quit the message loop if we were waiting so Waiting process can get result | 74 // Quit the message loop if we were waiting so Waiting process can get result |
| 42 // or error. To ensure this gets done, do this before ASSERT* calls. | 75 // or error. To ensure this gets done, do this before ASSERT* calls. |
| 43 if (is_waiting_) | 76 if (is_waiting_) |
| 44 MessageLoopForUI::current()->Quit(); | 77 MessageLoopForUI::current()->Quit(); |
| 45 | 78 |
| 46 SCOPED_TRACE("WebUITestHandler::Observe"); | 79 SCOPED_TRACE("WebUITestHandler::Observe"); |
| 47 Value* value = Details<std::pair<int, Value*> >(details)->second; | 80 Value* value = Details<std::pair<int, Value*> >(details)->second; |
| 48 ListValue* list_value; | 81 ListValue* test_result; |
| 49 ASSERT_TRUE(value->GetAsList(&list_value)); | 82 ASSERT_TRUE(value->GetAsList(&test_result)); |
| 50 ASSERT_TRUE(list_value->GetBoolean(0, &test_succeeded_)); | 83 HandleTestResult(test_result, &test_succeeded_); |
| 51 if (!test_succeeded_) { | |
| 52 std::string message; | |
| 53 ASSERT_TRUE(list_value->GetString(1, &message)); | |
| 54 LOG(ERROR) << message; | |
| 55 } | |
| 56 } | 84 } |
| 57 | 85 |
| 58 bool WebUITestHandler::WaitForResult() { | 86 bool WebUITestHandler::WaitForResult() { |
| 59 is_waiting_ = true; | 87 is_waiting_ = true; |
| 60 ui_test_utils::RunMessageLoop(); | 88 ui_test_utils::RunMessageLoop(); |
| 61 is_waiting_ = false; | 89 is_waiting_ = false; |
| 62 return test_succeeded_; | 90 return test_succeeded_; |
| 63 } | 91 } |
| OLD | NEW |