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

Side by Side Diff: ios/chrome/test/app/static_html_view_test_util.mm

Issue 2784943002: Remove matcher to wait for static HTML view. (Closed)
Patch Set: typo Created 3 years, 8 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
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #import "ios/chrome/test/app/static_html_view_test_util.h"
6
7 #import <Foundation/Foundation.h>
8
9 #include "base/mac/foundation_util.h"
10 #include "base/strings/sys_string_conversions.h"
11 #import "ios/chrome/browser/ui/static_content/static_html_view_controller.h"
12 #import "ios/chrome/test/app/chrome_test_util.h"
13 #import "ios/testing/wait_util.h"
14
15 namespace chrome_test_util {
16
17 // Synchronously returns the result of executed JavaScript.
18 id ExecuteScriptInStaticController(
19 StaticHtmlViewController* html_view_controller,
20 NSString* script) {
21 __block id result = nil;
22 __block bool did_finish = false;
23 [html_view_controller executeJavaScript:script
24 completionHandler:^(id script_result, NSError* error) {
25 result = [script_result copy];
26 did_finish = true;
27 }];
28
29 // If a timeout is reached, then return |result|, which should be nil;
30 testing::WaitUntilConditionOrTimeout(testing::kWaitForJSCompletionTimeout, ^{
31 return did_finish;
32 });
33
34 return [result autorelease];
35 }
36
37 // Returns the StaticHtmlViewController for the given |web_state|. If none is
38 // found, it returns nil.
39 StaticHtmlViewController* GetStaticHtmlView(web::WebState* web_state) {
40 // The WKWebView in a static HTML view isn't part of a
41 // webState, but it does have the StaticHtmlViewController
42 // as its navigation delegate. The WKWebView is the only child subview
43 // of the web state's view.
44 UIView* web_state_view = chrome_test_util::GetCurrentWebState()->GetView();
45 WKWebView* web_view =
46 base::mac::ObjCCast<WKWebView>(web_state_view.subviews.firstObject);
47 return base::mac::ObjCCast<StaticHtmlViewController>(
48 web_view.navigationDelegate);
49 }
50
51 bool StaticHtmlViewContainingText(web::WebState* web_state, std::string text) {
52 StaticHtmlViewController* html_view_controller = GetStaticHtmlView(web_state);
53 if (!html_view_controller) {
54 return false;
55 }
56
57 id body = ExecuteScriptInStaticController(
58 html_view_controller, @"document.body ? document.body.textContent : ''");
59 return [body containsString:base::SysUTF8ToNSString(text)];
60 return false;
61 }
62 } // namespace chrome_test_util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698