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 @@
#endif
using web::NavigationManager;
using testing::WaitUntilConditionOrTimeout;
using testing::kWaitForUIElementTimeout;
using testing::kWaitForJSCompletionTimeout;
namespace web {
namespace test {
......@@ -40,10 +43,9 @@ std::unique_ptr<base::Value> ExecuteJavaScript(web::WebState* web_state,
did_finish = true;
}));
bool completed = testing::WaitUntilConditionOrTimeout(
testing::kWaitForJSCompletionTimeout, ^{
return did_finish;
});
bool completed = WaitUntilConditionOrTimeout(kWaitForJSCompletionTimeout, ^{
return did_finish;
});
if (!completed) {
return nullptr;
}
......@@ -86,22 +88,21 @@ CGRect GetBoundingRectOfElementWithId(web::WebState* web_state,
__block base::DictionaryValue const* rect = nullptr;
bool found =
testing::WaitUntilConditionOrTimeout(testing::kWaitForUIElementTimeout, ^{
std::unique_ptr<base::Value> value =
ExecuteJavaScript(web_state, kGetBoundsScript);
base::DictionaryValue* dictionary = nullptr;
if (value && value->GetAsDictionary(&dictionary)) {
std::string error;
if (dictionary->GetString("error", &error)) {
DLOG(ERROR) << "Error getting rect: " << error << ", retrying..";
} else {
rect = dictionary->DeepCopy();
return true;
}
}
return false;
});
bool found = WaitUntilConditionOrTimeout(kWaitForUIElementTimeout, ^{
std::unique_ptr<base::Value> value =
ExecuteJavaScript(web_state, kGetBoundsScript);
base::DictionaryValue* dictionary = nullptr;
if (value && value->GetAsDictionary(&dictionary)) {
std::string error;
if (dictionary->GetString("error", &error)) {
DLOG(ERROR) << "Error getting rect: " << error << ", retrying..";
} else {
rect = dictionary->DeepCopy();
return true;
}
}
return false;
});
if (!found)
return CGRectNull;
......@@ -159,11 +160,11 @@ bool RunActionOnWebViewElementWithId(web::WebState* web_state,
element_found = [result boolValue];
}];
testing::WaitUntilConditionOrTimeout(testing::kWaitForJSCompletionTimeout, ^{
bool js_finished = WaitUntilConditionOrTimeout(kWaitForJSCompletionTimeout, ^{
return did_complete;
});
return element_found;
return js_finished && element_found;
}
bool TapWebViewElementWithId(web::WebState* web_state,
......
......@@ -21,6 +21,9 @@
#error "This file requires ARC support."
#endif
using testing::WaitUntilConditionOrTimeout;
using testing::kWaitForJSCompletionTimeout;
namespace {
// Synchronously checks |cache| for the specified cert and returns the judgment.
web::CertPolicy::Judgment GetJudgmenet(
......@@ -31,17 +34,15 @@ web::CertPolicy::Judgment GetJudgmenet(
// Post a task to the IO thread and wait for a reply
__block web::CertPolicy::Judgment judgement =
web::CertPolicy::Judgment::UNKNOWN;
__block bool io_thread_has_run = false;
web::WebThread::PostTaskAndReply(
web::WebThread::IO, FROM_HERE, base::BindBlockArc(^{
judgement = cache->QueryPolicy(cert.get(), host, status);
}),
base::BindBlockArc(^{
io_thread_has_run = true;
}));
testing::WaitUntilConditionOrTimeout(testing::kWaitForJSCompletionTimeout, ^{
return io_thread_has_run;
});
__block bool completed = false;
web::WebThread::PostTask(web::WebThread::IO, FROM_HERE, base::BindBlockArc(^{
completed = true;
judgement =
cache->QueryPolicy(cert.get(), host, status);
}));
EXPECT_TRUE(WaitUntilConditionOrTimeout(1.0, ^{
return completed;
}));
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