Commit ac7891ec authored by Maksym Onufriienko's avatar Maksym Onufriienko Committed by Commit Bot

Converted tapWebStateElementWithID and tapWebStateElementInIFrameWithID to compile under EG2.

Bug: 922813
Change-Id: Icc342bcf95caba07ce12e72f1b2e7cadcd8684b7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1626515
Commit-Queue: Maksym Onufriienko <monufriienko@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#664994}
parent 37181175
...@@ -237,6 +237,20 @@ id ExecuteJavaScript(NSString* javascript, NSError* __autoreleasing* out_error); ...@@ -237,6 +237,20 @@ id ExecuteJavaScript(NSString* javascript, NSError* __autoreleasing* out_error);
#pragma mark - WebState Utilities (EG2) #pragma mark - WebState Utilities (EG2)
// Taps html element with |elementID| in the current web state.
// A GREYAssert is induced on failure.
// TODO(crbug.com/963613): Change return type to void when
// CHROME_EG_ASSERT_NO_ERROR is removed.
- (NSError*)tapWebStateElementWithID:(NSString*)elementID;
// Attempts to tap the element with |element_id| within window.frames[0] of the
// current WebState using a JavaScript click() event. This only works on
// same-origin iframes.
// A GREYAssert is induced on failure.
// TODO(crbug.com/963613): Change return type to void when
// CHROME_EG_ASSERT_NO_ERROR is removed.
- (NSError*)tapWebStateElementInIFrameWithID:(const std::string&)elementID;
// Waits for the current web state to contain an element matching |selector|. // Waits for the current web state to contain an element matching |selector|.
// If the condition is not met within a timeout a GREYAssert is induced. // If the condition is not met within a timeout a GREYAssert is induced.
// TODO(crbug.com/963613): Change return type to void when // TODO(crbug.com/963613): Change return type to void when
...@@ -303,17 +317,6 @@ id ExecuteJavaScript(NSString* javascript, NSError* __autoreleasing* out_error); ...@@ -303,17 +317,6 @@ id ExecuteJavaScript(NSString* javascript, NSError* __autoreleasing* out_error);
#pragma mark - WebState Utilities #pragma mark - WebState Utilities
// Taps html element with |elementID| in the current web state.
- (NSError*)tapWebStateElementWithID:(NSString*)elementID WARN_UNUSED_RESULT;
// Attempts to tap the element with |element_id| within window.frames[0] of the
// current WebState using a JavaScript click() event. This only works on
// same-origin iframes.
// If the condition did not succeeded returns an NSError indicating
// why the operation failed, otherwise nil.
- (NSError*)tapWebStateElementInIFrameWithID:(const std::string&)elementID
WARN_UNUSED_RESULT;
// Attempts to submit form with |formID| in the current WebState. // Attempts to submit form with |formID| in the current WebState.
- (NSError*)submitWebStateFormWithID:(const std::string&)formID - (NSError*)submitWebStateFormWithID:(const std::string&)formID
WARN_UNUSED_RESULT; WARN_UNUSED_RESULT;
......
...@@ -158,8 +158,8 @@ GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(ChromeEarlGreyAppInterface) ...@@ -158,8 +158,8 @@ GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(ChromeEarlGreyAppInterface)
} }
- (NSError*)closeAllIncognitoTabs { - (NSError*)closeAllIncognitoTabs {
EG_TEST_HELPER_ASSERT_TRUE([ChromeEarlGreyAppInterface closeAllIncognitoTabs], EG_TEST_HELPER_ASSERT_NO_ERROR(
@"Could not close all Incognito tabs"); [ChromeEarlGreyAppInterface closeAllIncognitoTabs]);
[[GREYUIThreadExecutor sharedInstance] drainUntilIdle]; [[GREYUIThreadExecutor sharedInstance] drainUntilIdle];
return nil; return nil;
...@@ -184,8 +184,8 @@ GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(ChromeEarlGreyAppInterface) ...@@ -184,8 +184,8 @@ GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(ChromeEarlGreyAppInterface)
- (NSError*)loadURL:(const GURL&)URL waitForCompletion:(BOOL)wait { - (NSError*)loadURL:(const GURL&)URL waitForCompletion:(BOOL)wait {
[ChromeEarlGreyAppInterface NSString* spec = base::SysUTF8ToNSString(URL.spec());
startLoadingURL:base::SysUTF8ToNSString(URL.spec())]; [ChromeEarlGreyAppInterface startLoadingURL:spec];
if (wait) { if (wait) {
[self waitForPageToFinishLoading]; [self waitForPageToFinishLoading];
EG_TEST_HELPER_ASSERT_TRUE( EG_TEST_HELPER_ASSERT_TRUE(
...@@ -254,6 +254,25 @@ GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(ChromeEarlGreyAppInterface) ...@@ -254,6 +254,25 @@ GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(ChromeEarlGreyAppInterface)
#pragma mark - WebState Utilities (EG2) #pragma mark - WebState Utilities (EG2)
- (NSError*)tapWebStateElementWithID:(NSString*)elementID {
NSError* error = nil;
bool success = [ChromeEarlGreyAppInterface tapWebStateElementWithID:elementID
error:error];
EG_TEST_HELPER_ASSERT_NO_ERROR(error);
NSString* description =
[NSString stringWithFormat:@"Failed to tap web state element with ID: %@",
elementID];
EG_TEST_HELPER_ASSERT_TRUE(success, description);
return nil;
}
- (NSError*)tapWebStateElementInIFrameWithID:(const std::string&)elementID {
NSString* NSElementID = base::SysUTF8ToNSString(elementID);
EG_TEST_HELPER_ASSERT_NO_ERROR([ChromeEarlGreyAppInterface
tapWebStateElementInIFrameWithID:NSElementID]);
return nil;
}
- (NSError*)waitForWebStateContainingElement:(ElementSelector*)selector { - (NSError*)waitForWebStateContainingElement:(ElementSelector*)selector {
EG_TEST_HELPER_ASSERT_NO_ERROR( EG_TEST_HELPER_ASSERT_NO_ERROR(
[ChromeEarlGreyAppInterface waitForWebStateContainingElement:selector]); [ChromeEarlGreyAppInterface waitForWebStateContainingElement:selector]);
...@@ -476,37 +495,6 @@ id ExecuteJavaScript(NSString* javascript, ...@@ -476,37 +495,6 @@ id ExecuteJavaScript(NSString* javascript,
#pragma mark - WebState Utilities #pragma mark - WebState Utilities
- (NSError*)tapWebStateElementWithID:(NSString*)elementID {
NSError* error = nil;
NSError* __autoreleasing tempError = error;
BOOL success = web::test::TapWebViewElementWithId(
chrome_test_util::GetCurrentWebState(),
base::SysNSStringToUTF8(elementID), &tempError);
error = tempError;
if (error != nil) {
return error;
}
if (!success) {
return testing::NSErrorWithLocalizedDescription([NSString
stringWithFormat:@"Failed to tap web state element with ID: %@",
elementID]);
}
return nil;
}
- (NSError*)tapWebStateElementInIFrameWithID:(const std::string&)elementID {
bool success = web::test::TapWebViewElementWithIdInIframe(
chrome_test_util::GetCurrentWebState(), elementID);
if (!success) {
return testing::NSErrorWithLocalizedDescription(
[NSString stringWithFormat:@"Failed to tap element with ID=%s",
elementID.c_str()]);
}
return nil;
}
- (NSError*)submitWebStateFormWithID:(const std::string&)formID { - (NSError*)submitWebStateFormWithID:(const std::string&)formID {
bool success = web::test::SubmitWebViewFormWithId( bool success = web::test::SubmitWebViewFormWithId(
chrome_test_util::GetCurrentWebState(), formID); chrome_test_util::GetCurrentWebState(), formID);
......
...@@ -90,8 +90,9 @@ ...@@ -90,8 +90,9 @@
// normal after closing all tabs. // normal after closing all tabs.
+ (void)closeAllTabsInCurrentMode; + (void)closeAllTabsInCurrentMode;
// Closes all incognito tabs. Return YES on success. // Closes all incognito tabs. If not succeed returns an NSError indicating why
+ (BOOL)closeAllIncognitoTabs; // the operation failed, otherwise nil.
+ (NSError*)closeAllIncognitoTabs;
// Closes all tabs in all modes (incognito and main (non-incognito)) and does // Closes all tabs in all modes (incognito and main (non-incognito)) and does
// not wait for the UI to complete. If current mode is Incognito, mode will be // not wait for the UI to complete. If current mode is Incognito, mode will be
...@@ -106,6 +107,16 @@ ...@@ -106,6 +107,16 @@
#pragma mark - WebState Utilities (EG2) #pragma mark - WebState Utilities (EG2)
// Attempts to tap the element with |element_id| within window.frames[0] of the
// current WebState using a JavaScript click() event. This only works on
// same-origin iframes. If not succeed returns an NSError indicating why the
// operation failed, otherwise nil.
+ (NSError*)tapWebStateElementInIFrameWithID:(NSString*)elementID;
// Taps html element with |elementID| in the current web state.
// On failure returns NO and |error| is set to include a message.
+ (BOOL)tapWebStateElementWithID:(NSString*)elementID error:(NSError*)error;
// Waits for the current web state to contain an element matching |selector|. // Waits for the current web state to contain an element matching |selector|.
// If not succeed returns an NSError indicating why the operation failed, // If not succeed returns an NSError indicating why the operation failed,
// otherwise nil. // otherwise nil.
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#import "ios/web/public/test/earl_grey/js_test_util.h" #import "ios/web/public/test/earl_grey/js_test_util.h"
#import "ios/web/public/test/element_selector.h" #import "ios/web/public/test/element_selector.h"
#import "ios/web/public/test/web_view_content_test_util.h" #import "ios/web/public/test/web_view_content_test_util.h"
#import "ios/web/public/test/web_view_interaction_test_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc) #if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support." #error "This file requires ARC support."
...@@ -133,8 +134,13 @@ using chrome_test_util::BrowserCommandDispatcherForMainBVC; ...@@ -133,8 +134,13 @@ using chrome_test_util::BrowserCommandDispatcherForMainBVC;
chrome_test_util::CloseAllTabsInCurrentMode(); chrome_test_util::CloseAllTabsInCurrentMode();
} }
+ (BOOL)closeAllIncognitoTabs { + (NSError*)closeAllIncognitoTabs {
return chrome_test_util::CloseAllIncognitoTabs(); bool success = chrome_test_util::CloseAllIncognitoTabs();
if (!success) {
return testing::NSErrorWithLocalizedDescription(
@"Could not close all Incognito tabs");
}
return nil;
} }
+ (void)closeAllTabs { + (void)closeAllTabs {
...@@ -151,6 +157,27 @@ using chrome_test_util::BrowserCommandDispatcherForMainBVC; ...@@ -151,6 +157,27 @@ using chrome_test_util::BrowserCommandDispatcherForMainBVC;
#pragma mark - WebState Utilities (EG2) #pragma mark - WebState Utilities (EG2)
+ (NSError*)tapWebStateElementInIFrameWithID:(NSString*)elementID {
bool success = web::test::TapWebViewElementWithIdInIframe(
chrome_test_util::GetCurrentWebState(),
base::SysNSStringToUTF8(elementID));
if (!success) {
return testing::NSErrorWithLocalizedDescription([NSString
stringWithFormat:@"Failed to tap element with ID=%@", elementID]);
}
return nil;
}
+ (BOOL)tapWebStateElementWithID:(NSString*)elementID error:(NSError*)error {
NSError* __autoreleasing autoreleasingError = nil;
bool success = web::test::TapWebViewElementWithId(
chrome_test_util::GetCurrentWebState(),
base::SysNSStringToUTF8(elementID), &autoreleasingError);
error = autoreleasingError;
return success;
}
+ (NSError*)waitForWebStateContainingElement:(ElementSelector*)selector { + (NSError*)waitForWebStateContainingElement:(ElementSelector*)selector {
bool success = WaitUntilConditionOrTimeout(kWaitForPageLoadTimeout, ^bool { bool success = WaitUntilConditionOrTimeout(kWaitForPageLoadTimeout, ^bool {
return web::test::IsWebViewContainingElement( return web::test::IsWebViewContainingElement(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment