| 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/dom_ui/dom_ui_handler_browsertest.h" | 5 #include "chrome/browser/dom_ui/dom_ui_handler_browsertest.h" |
| 6 | 6 |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/browser/renderer_host/render_view_host.h" | 8 #include "chrome/browser/renderer_host/render_view_host.h" |
| 9 #include "chrome/test/ui_test_utils.h" | 9 #include "chrome/test/ui_test_utils.h" |
| 10 | 10 |
| 11 bool DOMUITestHandler::Execute(const std::string& js_test) { | 11 bool DOMUITestHandler::Execute(const std::string& js_test) { |
| 12 dom_ui_->GetRenderViewHost()->ExecuteJavascriptInWebFrame( | 12 dom_ui_->GetRenderViewHost()->ExecuteJavascriptInWebFrame( |
| 13 std::wstring(), UTF8ToWide(js_test)); | 13 string16(), UTF8ToUTF16(js_test)); |
| 14 return WaitForResult(); | 14 return WaitForResult(); |
| 15 } | 15 } |
| 16 | 16 |
| 17 void DOMUITestHandler::HandlePass(const ListValue* args) { | 17 void DOMUITestHandler::HandlePass(const ListValue* args) { |
| 18 test_succeeded_ = true; | 18 test_succeeded_ = true; |
| 19 if (is_waiting_) | 19 if (is_waiting_) |
| 20 MessageLoopForUI::current()->Quit(); | 20 MessageLoopForUI::current()->Quit(); |
| 21 } | 21 } |
| 22 | 22 |
| 23 void DOMUITestHandler::HandleFail(const ListValue* args) { | 23 void DOMUITestHandler::HandleFail(const ListValue* args) { |
| 24 test_succeeded_ = false; | 24 test_succeeded_ = false; |
| 25 if (is_waiting_) | 25 if (is_waiting_) |
| 26 MessageLoopForUI::current()->Quit(); | 26 MessageLoopForUI::current()->Quit(); |
| 27 } | 27 } |
| 28 | 28 |
| 29 void DOMUITestHandler::RegisterMessages() { | 29 void DOMUITestHandler::RegisterMessages() { |
| 30 dom_ui_->RegisterMessageCallback("Pass", | 30 dom_ui_->RegisterMessageCallback("Pass", |
| 31 NewCallback(this, &DOMUITestHandler::HandlePass)); | 31 NewCallback(this, &DOMUITestHandler::HandlePass)); |
| 32 dom_ui_->RegisterMessageCallback("Fail", | 32 dom_ui_->RegisterMessageCallback("Fail", |
| 33 NewCallback(this, &DOMUITestHandler::HandleFail)); | 33 NewCallback(this, &DOMUITestHandler::HandleFail)); |
| 34 } | 34 } |
| 35 | 35 |
| 36 bool DOMUITestHandler::WaitForResult() { | 36 bool DOMUITestHandler::WaitForResult() { |
| 37 is_waiting_ = true; | 37 is_waiting_ = true; |
| 38 ui_test_utils::RunMessageLoop(); | 38 ui_test_utils::RunMessageLoop(); |
| 39 is_waiting_ = false; | 39 is_waiting_ = false; |
| 40 return test_succeeded_; | 40 return test_succeeded_; |
| 41 } | 41 } |
| OLD | NEW |