Commit f0655b36 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: Ide53b4613df407149c43cdfa68751be171db313f
Reviewed-on: https://chromium-review.googlesource.com/746995Reviewed-by: default avatarMike Baxley <baxley@chromium.org>
Commit-Queue: Eugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#513240}
parent 3a6caa20
......@@ -8,6 +8,7 @@
#include <vector>
#include "base/strings/sys_string_conversions.h"
#import "base/test/ios/wait_util.h"
#include "base/test/scoped_feature_list.h"
#include "components/bookmarks/browser/bookmark_model.h"
#include "components/prefs/pref_service.h"
......@@ -725,9 +726,9 @@ id<GREYMatcher> TappableBookmarkNodeWithLabel(NSString* label) {
performAction:grey_tap()];
// Wait so that the string is copied to clipboard.
testing::WaitUntilConditionOrTimeout(1, ^{
return false;
});
// TODO(crbug.com/780064): poll for pasteboard change instead.
base::test::ios::SpinRunLoopWithMinDelay(base::TimeDelta::FromSecondsD(1));
// Verify general pasteboard has the URL copied.
NSString* copiedString = [UIPasteboard generalPasteboard].string;
GREYAssert([copiedString containsString:@"www.a.fr"],
......
......@@ -16,8 +16,12 @@
#error "This file requires ARC support."
#endif
using testing::WaitUntilConditionOrTimeout;
using testing::kWaitForJSCompletionTimeout;
namespace chrome_test_util {
namespace {
// Synchronously returns the result of executed JavaScript.
id ExecuteScriptInStaticController(
StaticHtmlViewController* html_view_controller,
......@@ -31,12 +35,13 @@ id ExecuteScriptInStaticController(
}];
// If a timeout is reached, then return |result|, which should be nil;
testing::WaitUntilConditionOrTimeout(testing::kWaitForJSCompletionTimeout, ^{
bool completed = WaitUntilConditionOrTimeout(kWaitForJSCompletionTimeout, ^{
return did_finish;
});
return result;
return completed ? result : nil;
}
} // namespace
// Returns the StaticHtmlViewController for the given |web_state|. If none is
// found, it returns nil.
......
......@@ -64,8 +64,8 @@ BOOL SimulateTabsBackgrounding();
// Evicts the tabs associated with the non-current browser mode.
void EvictOtherTabModelTabs();
// Closes all incognito tabs.
void CloseAllIncognitoTabs();
// Closes all incognito tabs. Return YES on success.
BOOL CloseAllIncognitoTabs();
// Returns the number of main tabs currently evicted.
NSUInteger GetEvictedMainTabCount();
......
......@@ -25,6 +25,8 @@
#error "This file requires ARC support."
#endif
using testing::WaitUntilConditionOrTimeout;
namespace chrome_test_util {
namespace {
......@@ -154,7 +156,7 @@ void EvictOtherTabModelTabs() {
otherTabModel.webUsageEnabled = YES;
}
void CloseAllIncognitoTabs() {
BOOL CloseAllIncognitoTabs() {
MainController* main_controller = chrome_test_util::GetMainController();
DCHECK(main_controller);
TabModel* tabModel = [[main_controller browserViewInformation] otrTabModel];
......@@ -163,10 +165,11 @@ void CloseAllIncognitoTabs() {
if (!IsIPadIdiom()) {
// If the OTR BVC is active, wait until it isn't (since all of the
// tabs are now closed)
testing::WaitUntilConditionOrTimeout(testing::kWaitForUIElementTimeout, ^{
return WaitUntilConditionOrTimeout(testing::kWaitForUIElementTimeout, ^{
return !IsIncognitoMode();
});
}
return YES;
}
NSUInteger GetEvictedMainTabCount() {
......
......@@ -14,6 +14,7 @@
#endif
using testing::WaitUntilConditionOrTimeout;
using testing::kWaitForJSCompletionTimeout;
namespace ios_web_view {
namespace test {
......@@ -46,24 +47,24 @@ bool TapWebViewElementWithId(CWVWebView* web_view, NSString* element_id) {
}
id EvaluateJavaScript(CWVWebView* web_view, NSString* script, NSError** error) {
__block bool did_complete = false;
__block bool callback_called = false;
__block id evaluation_result = nil;
__block id evaluation_error = nil;
[web_view evaluateJavaScript:script
completionHandler:^(id local_result, NSError* local_error) {
did_complete = true;
callback_called = true;
evaluation_result = [local_result copy];
evaluation_error = [local_error copy];
}];
WaitUntilConditionOrTimeout(testing::kWaitForJSCompletionTimeout, ^{
return did_complete;
bool completed = WaitUntilConditionOrTimeout(kWaitForJSCompletionTimeout, ^{
return callback_called;
});
if (error)
*error = evaluation_error;
return evaluation_result;
return completed ? evaluation_result : nil;
}
bool WaitForWebViewContainingTextOrTimeout(CWVWebView* web_view,
......
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