Commit bcdcbc98 authored by Eugene But's avatar Eugene But Committed by Commit Bot

Do not ignore result of WaitUntilConditionOrTimeout.

Ignoring the result of WaitUntilConditionOrTimeout call is incorrect in
many cases. So WaitUntilConditionOrTimeout will have WARN_UNUSED_RESULT
annotation to force callers to do the checks. This CL prepares ios/web
for WaitUntilConditionOrTimeout changes.

Bug: 780062
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: Id6dbc3f21da5c3c4c907eca5009964dfc67ab510
Reviewed-on: https://chromium-review.googlesource.com/747066Reviewed-by: default avatarMike Baxley <baxley@chromium.org>
Commit-Queue: Eugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#512939}
parent f381a3d8
...@@ -19,6 +19,9 @@ ...@@ -19,6 +19,9 @@
#endif #endif
using web::NavigationManager; using web::NavigationManager;
using testing::WaitUntilConditionOrTimeout;
using testing::kWaitForUIElementTimeout;
using testing::kWaitForJSCompletionTimeout;
namespace web { namespace web {
namespace test { namespace test {
...@@ -40,10 +43,9 @@ std::unique_ptr<base::Value> ExecuteJavaScript(web::WebState* web_state, ...@@ -40,10 +43,9 @@ std::unique_ptr<base::Value> ExecuteJavaScript(web::WebState* web_state,
did_finish = true; did_finish = true;
})); }));
bool completed = testing::WaitUntilConditionOrTimeout( bool completed = WaitUntilConditionOrTimeout(kWaitForJSCompletionTimeout, ^{
testing::kWaitForJSCompletionTimeout, ^{ return did_finish;
return did_finish; });
});
if (!completed) { if (!completed) {
return nullptr; return nullptr;
} }
...@@ -86,22 +88,21 @@ CGRect GetBoundingRectOfElementWithId(web::WebState* web_state, ...@@ -86,22 +88,21 @@ CGRect GetBoundingRectOfElementWithId(web::WebState* web_state,
__block base::DictionaryValue const* rect = nullptr; __block base::DictionaryValue const* rect = nullptr;
bool found = bool found = WaitUntilConditionOrTimeout(kWaitForUIElementTimeout, ^{
testing::WaitUntilConditionOrTimeout(testing::kWaitForUIElementTimeout, ^{ std::unique_ptr<base::Value> value =
std::unique_ptr<base::Value> value = ExecuteJavaScript(web_state, kGetBoundsScript);
ExecuteJavaScript(web_state, kGetBoundsScript); base::DictionaryValue* dictionary = nullptr;
base::DictionaryValue* dictionary = nullptr; if (value && value->GetAsDictionary(&dictionary)) {
if (value && value->GetAsDictionary(&dictionary)) { std::string error;
std::string error; if (dictionary->GetString("error", &error)) {
if (dictionary->GetString("error", &error)) { DLOG(ERROR) << "Error getting rect: " << error << ", retrying..";
DLOG(ERROR) << "Error getting rect: " << error << ", retrying.."; } else {
} else { rect = dictionary->DeepCopy();
rect = dictionary->DeepCopy(); return true;
return true; }
} }
} return false;
return false; });
});
if (!found) if (!found)
return CGRectNull; return CGRectNull;
...@@ -159,11 +160,11 @@ bool RunActionOnWebViewElementWithId(web::WebState* web_state, ...@@ -159,11 +160,11 @@ bool RunActionOnWebViewElementWithId(web::WebState* web_state,
element_found = [result boolValue]; element_found = [result boolValue];
}]; }];
testing::WaitUntilConditionOrTimeout(testing::kWaitForJSCompletionTimeout, ^{ bool js_finished = WaitUntilConditionOrTimeout(kWaitForJSCompletionTimeout, ^{
return did_complete; return did_complete;
}); });
return element_found; return js_finished && element_found;
} }
bool TapWebViewElementWithId(web::WebState* web_state, bool TapWebViewElementWithId(web::WebState* web_state,
......
...@@ -21,6 +21,9 @@ ...@@ -21,6 +21,9 @@
#error "This file requires ARC support." #error "This file requires ARC support."
#endif #endif
using testing::WaitUntilConditionOrTimeout;
using testing::kWaitForJSCompletionTimeout;
namespace { namespace {
// Synchronously checks |cache| for the specified cert and returns the judgment. // Synchronously checks |cache| for the specified cert and returns the judgment.
web::CertPolicy::Judgment GetJudgmenet( web::CertPolicy::Judgment GetJudgmenet(
...@@ -31,17 +34,15 @@ web::CertPolicy::Judgment GetJudgmenet( ...@@ -31,17 +34,15 @@ web::CertPolicy::Judgment GetJudgmenet(
// Post a task to the IO thread and wait for a reply // Post a task to the IO thread and wait for a reply
__block web::CertPolicy::Judgment judgement = __block web::CertPolicy::Judgment judgement =
web::CertPolicy::Judgment::UNKNOWN; web::CertPolicy::Judgment::UNKNOWN;
__block bool io_thread_has_run = false; __block bool completed = false;
web::WebThread::PostTaskAndReply( web::WebThread::PostTask(web::WebThread::IO, FROM_HERE, base::BindBlockArc(^{
web::WebThread::IO, FROM_HERE, base::BindBlockArc(^{ completed = true;
judgement = cache->QueryPolicy(cert.get(), host, status); judgement =
}), cache->QueryPolicy(cert.get(), host, status);
base::BindBlockArc(^{ }));
io_thread_has_run = true; EXPECT_TRUE(WaitUntilConditionOrTimeout(1.0, ^{
})); return completed;
testing::WaitUntilConditionOrTimeout(testing::kWaitForJSCompletionTimeout, ^{ }));
return io_thread_has_run;
});
return judgement; return judgement;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment