| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 | 54 |
| 55 void WebUITestHandler::RegisterMessages() { | 55 void WebUITestHandler::RegisterMessages() { |
| 56 web_ui()->RegisterMessageCallback("testResult", | 56 web_ui()->RegisterMessageCallback("testResult", |
| 57 base::Bind(&WebUITestHandler::HandleTestResult, base::Unretained(this))); | 57 base::Bind(&WebUITestHandler::HandleTestResult, base::Unretained(this))); |
| 58 } | 58 } |
| 59 | 59 |
| 60 void WebUITestHandler::HandleTestResult(const base::ListValue* test_result) { | 60 void WebUITestHandler::HandleTestResult(const base::ListValue* test_result) { |
| 61 // Quit the message loop if |is_waiting_| so waiting process can get result or | 61 // Quit the message loop if |is_waiting_| so waiting process can get result or |
| 62 // error. To ensure this gets done, do this before ASSERT* calls. | 62 // error. To ensure this gets done, do this before ASSERT* calls. |
| 63 if (is_waiting_) | 63 if (is_waiting_) |
| 64 base::MessageLoopForUI::current()->Quit(); | 64 base::MessageLoopForUI::current()->QuitWhenIdle(); |
| 65 | 65 |
| 66 SCOPED_TRACE("WebUITestHandler::HandleTestResult"); | 66 SCOPED_TRACE("WebUITestHandler::HandleTestResult"); |
| 67 | 67 |
| 68 EXPECT_FALSE(test_done_); | 68 EXPECT_FALSE(test_done_); |
| 69 test_done_ = true; | 69 test_done_ = true; |
| 70 test_succeeded_ = false; | 70 test_succeeded_ = false; |
| 71 | 71 |
| 72 ASSERT_TRUE(test_result->GetBoolean(0, &test_succeeded_)); | 72 ASSERT_TRUE(test_result->GetBoolean(0, &test_succeeded_)); |
| 73 if (!test_succeeded_) { | 73 if (!test_succeeded_) { |
| 74 std::string message; | 74 std::string message; |
| 75 ASSERT_TRUE(test_result->GetString(1, &message)); | 75 ASSERT_TRUE(test_result->GetString(1, &message)); |
| 76 LOG(ERROR) << message; | 76 LOG(ERROR) << message; |
| 77 } | 77 } |
| 78 } | 78 } |
| 79 | 79 |
| 80 void WebUITestHandler::JavaScriptComplete(const base::Value* result) { | 80 void WebUITestHandler::JavaScriptComplete(const base::Value* result) { |
| 81 // Quit the message loop if |is_waiting_| so waiting process can get result or | 81 // Quit the message loop if |is_waiting_| so waiting process can get result or |
| 82 // error. To ensure this gets done, do this before ASSERT* calls. | 82 // error. To ensure this gets done, do this before ASSERT* calls. |
| 83 if (is_waiting_) | 83 if (is_waiting_) |
| 84 base::MessageLoopForUI::current()->Quit(); | 84 base::MessageLoopForUI::current()->QuitWhenIdle(); |
| 85 | 85 |
| 86 SCOPED_TRACE("WebUITestHandler::JavaScriptComplete"); | 86 SCOPED_TRACE("WebUITestHandler::JavaScriptComplete"); |
| 87 | 87 |
| 88 EXPECT_FALSE(run_test_done_); | 88 EXPECT_FALSE(run_test_done_); |
| 89 run_test_done_ = true; | 89 run_test_done_ = true; |
| 90 run_test_succeeded_ = false; | 90 run_test_succeeded_ = false; |
| 91 | 91 |
| 92 ASSERT_TRUE(result->GetAsBoolean(&run_test_succeeded_)); | 92 ASSERT_TRUE(result->GetAsBoolean(&run_test_succeeded_)); |
| 93 } | 93 } |
| 94 | 94 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 107 // complete. | 107 // complete. |
| 108 if (!run_test_done_ || (run_test_succeeded_ && !test_done_)) { | 108 if (!run_test_done_ || (run_test_succeeded_ && !test_done_)) { |
| 109 content::RunMessageLoop(); | 109 content::RunMessageLoop(); |
| 110 } | 110 } |
| 111 | 111 |
| 112 is_waiting_ = false; | 112 is_waiting_ = false; |
| 113 | 113 |
| 114 // To succeed the test must execute as well as pass the test. | 114 // To succeed the test must execute as well as pass the test. |
| 115 return run_test_succeeded_ && test_succeeded_; | 115 return run_test_succeeded_ && test_succeeded_; |
| 116 } | 116 } |
| OLD | NEW |