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