| OLD | NEW |
| 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/chrome/test/earl_grey/chrome_earl_grey.h" | 5 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h" |
| 6 | 6 |
| 7 #import <Foundation/Foundation.h> | 7 #import <Foundation/Foundation.h> |
| 8 #import <WebKit/WebKit.h> | 8 #import <WebKit/WebKit.h> |
| 9 | 9 |
| 10 #include "base/mac/foundation_util.h" | 10 #include "base/mac/foundation_util.h" |
| 11 #include "base/strings/sys_string_conversions.h" | 11 #include "base/strings/sys_string_conversions.h" |
| 12 #import "base/test/ios/wait_util.h" |
| 13 #include "components/strings/grit/components_strings.h" |
| 14 #import "ios/chrome/browser/ui/static_content/static_html_view_controller.h" |
| 12 #import "ios/chrome/test/app/chrome_test_util.h" | 15 #import "ios/chrome/test/app/chrome_test_util.h" |
| 13 #import "ios/chrome/test/app/history_test_util.h" | 16 #import "ios/chrome/test/app/history_test_util.h" |
| 14 #include "ios/chrome/test/app/navigation_test_util.h" | 17 #include "ios/chrome/test/app/navigation_test_util.h" |
| 18 #import "ios/chrome/test/app/static_html_view_test_util.h" |
| 15 #import "ios/testing/wait_util.h" | 19 #import "ios/testing/wait_util.h" |
| 16 #import "ios/web/public/test/earl_grey/js_test_util.h" | 20 #import "ios/web/public/test/earl_grey/js_test_util.h" |
| 17 #import "ios/web/public/test/web_view_interaction_test_util.h" | 21 #import "ios/web/public/test/web_view_interaction_test_util.h" |
| 18 #import "ios/web/public/web_state/js/crw_js_injection_receiver.h" | 22 #import "ios/web/public/web_state/js/crw_js_injection_receiver.h" |
| 19 #import "ios/web/public/web_state/web_state.h" | 23 #import "ios/web/public/web_state/web_state.h" |
| 24 #include "ui/base/l10n/l10n_util.h" |
| 20 | 25 |
| 21 #if !defined(__has_feature) || !__has_feature(objc_arc) | 26 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 22 #error "This file requires ARC support." | 27 #error "This file requires ARC support." |
| 23 #endif | 28 #endif |
| 24 | 29 |
| 25 namespace chrome_test_util { | 30 namespace chrome_test_util { |
| 26 | 31 |
| 27 id ExecuteJavaScript(NSString* javascript, | 32 id ExecuteJavaScript(NSString* javascript, |
| 28 NSError* __unsafe_unretained* out_error) { | 33 NSError* __unsafe_unretained* out_error) { |
| 29 __block bool did_complete = false; | 34 __block bool did_complete = false; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 } | 123 } |
| 119 | 124 |
| 120 + (void)tapWebViewElementWithID:(NSString*)elementID { | 125 + (void)tapWebViewElementWithID:(NSString*)elementID { |
| 121 BOOL success = | 126 BOOL success = |
| 122 web::test::TapWebViewElementWithId(chrome_test_util::GetCurrentWebState(), | 127 web::test::TapWebViewElementWithId(chrome_test_util::GetCurrentWebState(), |
| 123 base::SysNSStringToUTF8(elementID)); | 128 base::SysNSStringToUTF8(elementID)); |
| 124 GREYAssertTrue(success, @"Failed to tap web view element with ID: %@", | 129 GREYAssertTrue(success, @"Failed to tap web view element with ID: %@", |
| 125 elementID); | 130 elementID); |
| 126 } | 131 } |
| 127 | 132 |
| 133 + (void)waitForErrorPage { |
| 134 NSString* const kInternetDisconnectedError = |
| 135 l10n_util::GetNSString(IDS_ERRORPAGES_HEADING_NOT_AVAILABLE); |
| 136 [self waitForStaticHTMLViewContainingText:kInternetDisconnectedError |
| 137 isTextPresent:YES]; |
| 138 } |
| 139 |
| 140 + (void)waitForStaticHTMLViewContainingText:(NSString*)text |
| 141 isTextPresent:(BOOL)present { |
| 142 GREYCondition* condition = [GREYCondition |
| 143 conditionWithName:@"Wait for page to complete loading." |
| 144 block:^BOOL { |
| 145 return present == |
| 146 chrome_test_util::StaticHtmlViewContainingText( |
| 147 chrome_test_util::GetCurrentWebState(), |
| 148 base::SysNSStringToUTF8(text)); |
| 149 }]; |
| 150 GREYAssert([condition waitWithTimeout:testing::kWaitForUIElementTimeout], |
| 151 @"Failed to find static html view %@containing %@", |
| 152 present ? @"" : @"not ", text); |
| 153 } |
| 154 |
| 128 @end | 155 @end |
| OLD | NEW |