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

Side by Side Diff: ios/web/public/test/earl_grey/web_view_matchers.mm

Issue 2275303004: Context menu egtests, plus related utilities. (Closed)
Patch Set: Reviewable. Created 4 years, 3 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "ios/web/public/test/earl_grey/web_view_matchers.h" 5 #import "ios/web/public/test/earl_grey/web_view_matchers.h"
6 6
7 #include <memory>
8
9 #import <WebKit/WebKit.h> 7 #import <WebKit/WebKit.h>
10 8
9 #include "base/logging.h"
11 #include "base/mac/bind_objc_block.h" 10 #include "base/mac/bind_objc_block.h"
12 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
13 #include "base/strings/sys_string_conversions.h" 12 #include "base/strings/sys_string_conversions.h"
14 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
15 #include "base/test/ios/wait_util.h" 14 #include "base/test/ios/wait_util.h"
16 #include "base/values.h" 15 #include "base/values.h"
17 #include "ios/testing/earl_grey/wait_util.h" 16 #include "ios/testing/earl_grey/wait_util.h"
17 #import "ios/web/public/test/web_view_interaction_test_util.h"
Eugene But (OOO till 7-30) 2016/08/30 18:11:05 Do you need this include?
marq (ping after 24h) 2016/08/31 13:07:58 Yes, that's where ExecuteScript was moved to.
18 #include "ios/web/web_state/web_state_impl.h"
Eugene But (OOO till 7-30) 2016/08/30 18:11:05 Do you need to import web_state_impl? Maybe import
marq (ping after 24h) 2016/08/31 13:07:58 Correct, I needed it at one point but not now.
19
20 using web::test::ExecuteScript;
18 21
19 namespace { 22 namespace {
20 23
21 // Script that returns document.body as a string. 24 // Script that returns document.body as a string.
22 char kGetDocumentBodyJavaScript[] = 25 char kGetDocumentBodyJavaScript[] =
23 "document.body ? document.body.textContent : null"; 26 "document.body ? document.body.textContent : null";
24 // Script that tests presence of css selector. 27 // Script that tests presence of css selector.
25 char kTestCssSelectorJavaScriptTemplate[] = "!!document.querySelector(\"%s\");"; 28 char kTestCssSelectorJavaScriptTemplate[] = "!!document.querySelector(\"%s\");";
26 29
27 // Synchronously returns the result of executed JavaScript.
28 std::unique_ptr<base::Value> ExecuteScript(web::WebState* web_state,
29 const std::string& script) {
30 __block std::unique_ptr<base::Value> result;
31 __block bool did_finish = false;
32 web_state->ExecuteJavaScript(base::UTF8ToUTF16(script),
33 base::BindBlock(^(const base::Value* value) {
34 if (value)
35 result = value->CreateDeepCopy();
36 did_finish = true;
37 }));
38
39 testing::WaitUntilCondition(testing::kWaitForJSCompletionTimeout, ^{
40 return did_finish;
41 });
42
43 // As result is marked __block, this return call does a copy and not a move
44 // (marking the variable as __block mean it is allocated in the block object
45 // and not the stack). Since the "return std::move()" pattern is discouraged
46 // use a local variable.
47 //
48 // Fixes the following compilation failure:
49 // ../web_view_matchers.mm:ll:cc: error: call to implicitly-deleted copy
50 // constructor of 'std::unique_ptr<base::Value>'
51 std::unique_ptr<base::Value> stack_result = std::move(result);
52 return stack_result;
53 }
54
55 } // namespace 30 } // namespace
56 31
57 namespace web { 32 namespace web {
58 33
59 id<GREYMatcher> webViewInWebState(WebState* web_state) { 34 id<GREYMatcher> webViewInWebState(WebState* web_state) {
60 MatchesBlock matches = ^BOOL(UIView* view) { 35 MatchesBlock matches = ^BOOL(UIView* view) {
61 return [view isKindOfClass:[WKWebView class]] && 36 return [view isKindOfClass:[WKWebView class]] &&
62 [view isDescendantOfView:web_state->GetView()]; 37 [view isDescendantOfView:web_state->GetView()];
63 }; 38 };
64 39
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 DescribeToBlock describe = ^(id<GREYDescription> description) { 169 DescribeToBlock describe = ^(id<GREYDescription> description) {
195 [description appendText:@"web view scroll view"]; 170 [description appendText:@"web view scroll view"];
196 }; 171 };
197 172
198 return [[[GREYElementMatcherBlock alloc] initWithMatchesBlock:matches 173 return [[[GREYElementMatcherBlock alloc] initWithMatchesBlock:matches
199 descriptionBlock:describe] 174 descriptionBlock:describe]
200 autorelease]; 175 autorelease];
201 } 176 }
202 177
203 } // namespace web 178 } // namespace web
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698