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

Unified Diff: ios/web/shell/test/web_view_matchers.mm

Issue 1890333002: Web shell test to go back and forward. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: s/include/import Created 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ios/web/shell/test/web_view_matchers.h ('k') | ios/web/shell/view_controller.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/web/shell/test/web_view_matchers.mm
diff --git a/ios/web/shell/test/web_view_matchers.mm b/ios/web/shell/test/web_view_matchers.mm
new file mode 100644
index 0000000000000000000000000000000000000000..a3fb1d1208a51caa1eb4781cb5938957fa7ed370
--- /dev/null
+++ b/ios/web/shell/test/web_view_matchers.mm
@@ -0,0 +1,82 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "ios/web/shell/test/web_view_matchers.h"
+
+#import <WebKit/WebKit.h>
+
+#include "base/mac/bind_objc_block.h"
+#include "base/strings/sys_string_conversions.h"
+#include "base/strings/utf_string_conversions.h"
+#include "base/test/ios/wait_util.h"
+#include "base/values.h"
+#include "ios/web/public/web_state/web_state.h"
+#include "ios/web/shell/test/navigation_test_util.h"
+#include "ios/web/shell/test/web_shell_test_util.h"
+
+namespace {
+
+// Constant for UI wait loop in seconds.
+const NSTimeInterval kSpinDelaySeconds = 0.01;
+
+// Constant for timeout in seconds while waiting for web element.
+const NSTimeInterval kWaitForWebElementTimeout = 4.0;
+
+// Script that returns document.body as a string.
+char kGetDocumentBodyJavaScript[] =
+ "document.body ? document.body.textContent : null";
+}
+
+@implementation GREYMatchers (WebViewAdditions)
+
++ (id<GREYMatcher>)matcherForWebViewContainingText:(NSString*)text {
+ MatchesBlock matches = ^BOOL(UIView* view) {
+ if (![view isKindOfClass:[WKWebView class]]) {
+ return NO;
+ }
+
+ ViewController* viewController =
+ web::web_shell_test_util::GetCurrentViewController();
+ web::WebState* webState = [viewController webState];
+
+ __block BOOL didSucceed = NO;
+ NSDate* deadline =
+ [NSDate dateWithTimeIntervalSinceNow:kWaitForWebElementTimeout];
+ while (([[NSDate date] compare:deadline] != NSOrderedDescending) &&
+ !didSucceed) {
+ webState->ExecuteJavaScript(
+ base::UTF8ToUTF16(kGetDocumentBodyJavaScript),
+ base::BindBlock(^(const base::Value* value) {
+ std::string response;
+ if (value && value->IsType(base::Value::TYPE_STRING) &&
+ value->GetAsString(&response)) {
+ didSucceed = response.find(base::SysNSStringToUTF8(text)) !=
+ std::string::npos;
+ }
+ }));
+ base::test::ios::SpinRunLoopWithMaxDelay(
+ base::TimeDelta::FromSecondsD(kSpinDelaySeconds));
+ }
+ return didSucceed;
+ };
+
+ DescribeToBlock describe = ^(id<GREYDescription> description) {
+ [description
+ appendText:[NSString stringWithFormat:@"web view containing %@", text]];
+ };
+
+ return [[[GREYElementMatcherBlock alloc] initWithMatchesBlock:matches
+ descriptionBlock:describe]
+ autorelease];
+}
+
+@end
+
+#if !(GREY_DISABLE_SHORTHAND)
+
+id<GREYMatcher> shell_webViewContainingText(NSString* text) {
+ return [GREYMatchers matcherForWebViewContainingText:text];
+}
+
+#endif
« no previous file with comments | « ios/web/shell/test/web_view_matchers.h ('k') | ios/web/shell/view_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698