Commit ba2001fe authored by Eric Aleshire's avatar Eric Aleshire Committed by Commit Bot

Add "type" and "save password" actions to the ios autofill automation.

The type action allows for text to be typed into a field, enabling
more autofill scenarios, and additionally enabling for password
manager automation, which I am working on extending autofill
automation to support.

There are a great deal many more flows needed for
password automation compared to autofill (i.e. save password on login,
don't save password on login, update password on change, etc), and
"save password" is just the first of them - but this change lays
important groundwork by adding AX IDs to the confirm infobar so that
automation can tap them.

Change-Id: I5368fabfbc1a450341969b63936960dce2de6246
Reviewed-on: https://chromium-review.googlesource.com/c/1332008
Commit-Queue: ericale <ericale@chromium.org>
Reviewed-by: default avatarRohit Rao <rohitrao@chromium.org>
Reviewed-by: default avatarMoe Ahmadi <mahmadi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#607415}
parent 5ba4cd16
...@@ -21,6 +21,7 @@ source_set("eg_tests") { ...@@ -21,6 +21,7 @@ source_set("eg_tests") {
"//ios/chrome/app/strings", "//ios/chrome/app/strings",
"//ios/chrome/browser/autofill:autofill", "//ios/chrome/browser/autofill:autofill",
"//ios/chrome/browser/infobars", "//ios/chrome/browser/infobars",
"//ios/chrome/browser/ui/infobars:infobars_ui",
"//ios/chrome/browser/ui/infobars:test_support", "//ios/chrome/browser/ui/infobars:test_support",
"//ios/chrome/browser/ui/toolbar/buttons", "//ios/chrome/browser/ui/toolbar/buttons",
"//ios/chrome/browser/ui/toolbar/public", "//ios/chrome/browser/ui/toolbar/public",
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "components/autofill/core/browser/personal_data_manager.h" #include "components/autofill/core/browser/personal_data_manager.h"
#include "components/autofill/ios/browser/autofill_driver_ios.h" #include "components/autofill/ios/browser/autofill_driver_ios.h"
#import "ios/chrome/browser/autofill/form_suggestion_label.h" #import "ios/chrome/browser/autofill/form_suggestion_label.h"
#import "ios/chrome/browser/ui/infobars/infobar_constants.h"
#import "ios/chrome/test/app/chrome_test_util.h" #import "ios/chrome/test/app/chrome_test_util.h"
#import "ios/chrome/test/earl_grey/chrome_earl_grey.h" #import "ios/chrome/test/earl_grey/chrome_earl_grey.h"
#import "ios/web/public/test/earl_grey/web_view_actions.h" #import "ios/web/public/test/earl_grey/web_view_actions.h"
...@@ -124,6 +125,31 @@ using web::test::ElementSelector; ...@@ -124,6 +125,31 @@ using web::test::ElementSelector;
@interface AutomationActionLoadPage : AutomationAction @interface AutomationActionLoadPage : AutomationAction
@end @end
// An action that types the provided text in the specified field.
// This can be either of the "type" or "typePassword" type due to
// the two actions needing to be handled differently on desktop in order
// to ensure passwords are saved. They can be treated the same on iOS.
// We assume this action has a format resembling:
// {
// "type": "type" OR "typePassword",
// "selector": "//input[@autocapitalize=\"none\" and
// @name=\"session[password]\"]", "value": "mycoolpassword",
// }
@interface AutomationActionType : AutomationAction
@end
// An action that selects the affirmative option in an open confirmation dialog.
// One main use case is selecting "Save" from the "Save password?" dialog,
// but this action cannot tell the difference between different confirmation
// dialogs, so it is multi-purpose. This action assumes that this dialog is
// already open.
// We assume this action has a format resembling:
// {
// "type": "savePassword"
// }
@interface AutomationActionConfirmInfobar : AutomationAction
@end
@implementation AutomationAction @implementation AutomationAction
+ (instancetype)actionWithValueDictionary: + (instancetype)actionWithValueDictionary:
...@@ -147,6 +173,9 @@ using web::test::ElementSelector; ...@@ -147,6 +173,9 @@ using web::test::ElementSelector;
@"validateField" : [AutomationActionValidateField class], @"validateField" : [AutomationActionValidateField class],
@"select" : [AutomationActionSelectDropdown class], @"select" : [AutomationActionSelectDropdown class],
@"loadPage" : [AutomationActionLoadPage class], @"loadPage" : [AutomationActionLoadPage class],
@"type" : [AutomationActionType class],
@"typePassword" : [AutomationActionType class],
@"savePassword" : [AutomationActionConfirmInfobar class],
// More to come. // More to come.
}; };
...@@ -413,3 +442,29 @@ using web::test::ElementSelector; ...@@ -413,3 +442,29 @@ using web::test::ElementSelector;
} }
@end @end
@implementation AutomationActionType
- (void)execute {
web::test::ElementSelector selector = [self selectorForTarget];
std::string value = [self getStringFromDictionaryWithKey:"value"];
[self executeJavascript:
base::SysNSStringToUTF8([NSString
stringWithFormat:
@"__gCrWeb.fill.setInputElementValue(\"%s\", target);",
value.c_str()])
onTarget:selector];
}
@end
@implementation AutomationActionConfirmInfobar
- (void)execute {
[[EarlGrey
selectElementWithMatcher:
grey_accessibilityID(kConfirmInfobarButton1AccessibilityIdentifier)]
performAction:grey_tap()];
}
@end
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#import "ios/chrome/browser/ui/fancy_ui/bidi_container_view.h" #import "ios/chrome/browser/ui/fancy_ui/bidi_container_view.h"
// An inforbar with an optional message, icon, two action buttons, and a switch. // An infobar with an optional message, icon, two action buttons, and a switch.
@interface ConfirmInfoBarView : BidiContainerView @interface ConfirmInfoBarView : BidiContainerView
// Label text with links initialized with |stringAsLink:|. // Label text with links initialized with |stringAsLink:|.
......
...@@ -941,6 +941,8 @@ UIImage* InfoBarCloseImage() { ...@@ -941,6 +941,8 @@ UIImage* InfoBarCloseImage() {
tag:tag1 tag:tag1
target:target target:target
action:action]; action:action];
[button1_
setAccessibilityIdentifier:kConfirmInfobarButton1AccessibilityIdentifier];
[self addSubview:button1_]; [self addSubview:button1_];
button2_ = [self infoBarButton:title2 button2_ = [self infoBarButton:title2
...@@ -949,6 +951,8 @@ UIImage* InfoBarCloseImage() { ...@@ -949,6 +951,8 @@ UIImage* InfoBarCloseImage() {
tag:tag2 tag:tag2
target:target target:target
action:action]; action:action];
[button2_
setAccessibilityIdentifier:kConfirmInfobarButton2AccessibilityIdentifier];
[self addSubview:button2_]; [self addSubview:button2_];
} }
......
...@@ -5,6 +5,12 @@ ...@@ -5,6 +5,12 @@
#ifndef IOS_CHROME_BROWSER_UI_INFOBARS_INFOBAR_CONSTANTS_H_ #ifndef IOS_CHROME_BROWSER_UI_INFOBARS_INFOBAR_CONSTANTS_H_
#define IOS_CHROME_BROWSER_UI_INFOBARS_INFOBAR_CONSTANTS_H_ #define IOS_CHROME_BROWSER_UI_INFOBARS_INFOBAR_CONSTANTS_H_
#import <Foundation/Foundation.h>
extern const int kInfobarBackgroundColor; extern const int kInfobarBackgroundColor;
// a11y identifier so that automation can tap on either infobar button
extern NSString* const kConfirmInfobarButton1AccessibilityIdentifier;
extern NSString* const kConfirmInfobarButton2AccessibilityIdentifier;
#endif // IOS_CHROME_BROWSER_UI_INFOBARS_INFOBAR_CONSTANTS_H_ #endif // IOS_CHROME_BROWSER_UI_INFOBARS_INFOBAR_CONSTANTS_H_
...@@ -9,3 +9,9 @@ ...@@ -9,3 +9,9 @@
#endif #endif
const int kInfobarBackgroundColor = 0xfafafa; const int kInfobarBackgroundColor = 0xfafafa;
// a11y identifier so that automation can tap on either infobar button
NSString* const kConfirmInfobarButton1AccessibilityIdentifier =
@"confirmInfobarButton1AXID";
NSString* const kConfirmInfobarButton2AccessibilityIdentifier =
@"confirmInfobarButton2AXID";
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