Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(360)

Unified Diff: ios/web/public/test/earl_grey/web_view_matchers.mm

Issue 2275303004: Context menu egtests, plus related utilities. (Closed)
Patch Set: Review feedback plus some fixes and tweaks. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ios/web/public/test/earl_grey/web_view_matchers.mm
diff --git a/ios/web/public/test/earl_grey/web_view_matchers.mm b/ios/web/public/test/earl_grey/web_view_matchers.mm
index 24504095af9b1001ec0e0f6e5796bf116f43ac1f..116dde759392b543582665393df321f738245f6c 100644
--- a/ios/web/public/test/earl_grey/web_view_matchers.mm
+++ b/ios/web/public/test/earl_grey/web_view_matchers.mm
@@ -4,8 +4,6 @@
#import "ios/web/public/test/earl_grey/web_view_matchers.h"
-#include <memory>
-
#import <WebKit/WebKit.h>
#include "base/mac/bind_objc_block.h"
@@ -15,6 +13,9 @@
#include "base/test/ios/wait_util.h"
#include "base/values.h"
#include "ios/testing/earl_grey/wait_util.h"
+#import "ios/web/public/test/web_view_interaction_test_util.h"
+
+using web::test::ExecuteJavaScript;
namespace {
@@ -24,34 +25,6 @@ char kGetDocumentBodyJavaScript[] =
// Script that tests presence of css selector.
char kTestCssSelectorJavaScriptTemplate[] = "!!document.querySelector(\"%s\");";
-// Synchronously returns the result of executed JavaScript.
-std::unique_ptr<base::Value> ExecuteScript(web::WebState* web_state,
- const std::string& script) {
- __block std::unique_ptr<base::Value> result;
- __block bool did_finish = false;
- web_state->ExecuteJavaScript(base::UTF8ToUTF16(script),
- base::BindBlock(^(const base::Value* value) {
- if (value)
- result = value->CreateDeepCopy();
- did_finish = true;
- }));
-
- testing::WaitUntilCondition(testing::kWaitForJSCompletionTimeout, ^{
- return did_finish;
- });
-
- // As result is marked __block, this return call does a copy and not a move
- // (marking the variable as __block mean it is allocated in the block object
- // and not the stack). Since the "return std::move()" pattern is discouraged
- // use a local variable.
- //
- // Fixes the following compilation failure:
- // ../web_view_matchers.mm:ll:cc: error: call to implicitly-deleted copy
- // constructor of 'std::unique_ptr<base::Value>'
- std::unique_ptr<base::Value> stack_result = std::move(result);
- return stack_result;
-}
-
} // namespace
namespace web {
@@ -71,7 +44,8 @@ id<GREYMatcher> webViewInWebState(WebState* web_state) {
autorelease];
}
-id<GREYMatcher> webViewContainingText(std::string text, WebState* web_state) {
+id<GREYMatcher> webViewContainingText(const std::string& text,
Eugene But (OOO till 7-30) 2016/08/31 15:27:59 This should be string by value or local variable (
+ WebState* web_state) {
MatchesBlock matches = ^BOOL(WKWebView*) {
__block BOOL did_succeed = NO;
NSDate* deadline =
@@ -79,7 +53,7 @@ id<GREYMatcher> webViewContainingText(std::string text, WebState* web_state) {
while (([[NSDate date] compare:deadline] != NSOrderedDescending) &&
!did_succeed) {
std::unique_ptr<base::Value> value =
- ExecuteScript(web_state, kGetDocumentBodyJavaScript);
+ ExecuteJavaScript(web_state, kGetDocumentBodyJavaScript);
std::string body;
if (value && value->GetAsString(&body)) {
did_succeed = body.find(text) != std::string::npos;
@@ -102,7 +76,7 @@ id<GREYMatcher> webViewContainingText(std::string text, WebState* web_state) {
nil);
}
-id<GREYMatcher> webViewContainingBlockedImage(std::string image_id,
+id<GREYMatcher> webViewContainingBlockedImage(const std::string& image_id,
Eugene But (OOO till 7-30) 2016/08/31 15:27:59 ditto
CGSize expected_size,
WebState* web_state) {
MatchesBlock matches = ^BOOL(WKWebView*) {
@@ -120,7 +94,7 @@ id<GREYMatcher> webViewContainingBlockedImage(std::string image_id,
@" width:imageWidth"
@"});",
base::SysUTF8ToNSString(image_id)];
- std::unique_ptr<base::Value> value = ExecuteScript(
+ std::unique_ptr<base::Value> value = ExecuteJavaScript(
web_state, base::SysNSStringToUTF8(kGetElementAttributesScript));
std::string result;
if (value && value->GetAsString(&result)) {
@@ -154,7 +128,8 @@ id<GREYMatcher> webViewContainingBlockedImage(std::string image_id,
nil);
}
-id<GREYMatcher> webViewCssSelector(std::string selector, WebState* web_state) {
+id<GREYMatcher> webViewCssSelector(const std::string& selector,
Eugene But (OOO till 7-30) 2016/08/31 15:27:59 ditto
+ WebState* web_state) {
MatchesBlock matches = ^BOOL(WKWebView*) {
std::string script = base::StringPrintf(kTestCssSelectorJavaScriptTemplate,
selector.c_str());
@@ -163,7 +138,7 @@ id<GREYMatcher> webViewCssSelector(std::string selector, WebState* web_state) {
[NSDate dateWithTimeIntervalSinceNow:testing::kWaitForUIElementTimeout];
while (([[NSDate date] compare:deadline] != NSOrderedDescending) &&
!did_succeed) {
- std::unique_ptr<base::Value> value = ExecuteScript(web_state, script);
+ std::unique_ptr<base::Value> value = ExecuteJavaScript(web_state, script);
if (value)
value->GetAsBoolean(&did_succeed);
base::test::ios::SpinRunLoopWithMaxDelay(

Powered by Google App Engine
This is Rietveld 408576698