Commit 919aab84 authored by Javier Ernesto Flores Robles's avatar Javier Ernesto Flores Robles Committed by Commit Bot

[iOS][MF][EG2] Migrate credit card tests

Consolidate Manual Fallback matchers in one place.
Consolidate credit card Autofill helpers in the respective app
interface.

TBR= eugenebut@chromium.org

Bug: 1017685, 1016367
Change-Id: Ib91e2baba9e72f6e065e8ebf08fdd5f5d3c0c9bb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1878197
Commit-Queue: Javier Ernesto Flores Robles <javierrobles@chromium.org>
Reviewed-by: default avatarStepan Khapugin <stkhapugin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#709020}
parent 8d8965d2
...@@ -30,6 +30,15 @@ ...@@ -30,6 +30,15 @@
// Resturns the name of the sample profile. // Resturns the name of the sample profile.
+ (NSString*)exampleProfileName; + (NSString*)exampleProfileName;
// Removes the stored credit cards.
+ (void)clearCreditCardStore;
// Saves a local credit card that doesn't require CVC to be used.
+ (void)saveLocalCreditCard;
// Saves a masked credit card that requires CVC to be used.
+ (void)saveMaskedCreditCard;
@end @end
#endif // IOS_CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_APP_INTERFACE_H_ #endif // IOS_CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_APP_INTERFACE_H_
...@@ -189,6 +189,41 @@ void AddAutofillProfile(autofill::PersonalDataManager* personalDataManager) { ...@@ -189,6 +189,41 @@ void AddAutofillProfile(autofill::PersonalDataManager* personalDataManager) {
return base::SysUTF16ToNSString(name); return base::SysUTF16ToNSString(name);
} }
+ (void)clearCreditCardStore {
autofill::PersonalDataManager* personalDataManager =
[self personalDataManager];
for (const auto* creditCard : personalDataManager->GetCreditCards()) {
personalDataManager->RemoveByGUID(creditCard->guid());
}
}
+ (void)saveLocalCreditCard {
autofill::PersonalDataManager* personalDataManager =
[self personalDataManager];
autofill::CreditCard card = autofill::test::GetCreditCard();
size_t card_count = personalDataManager->GetCreditCards().size();
personalDataManager->AddCreditCard(card);
ConditionBlock conditionBlock = ^bool {
return card_count < personalDataManager->GetCreditCards().size();
};
base::test::ios::TimeUntilCondition(
nil, conditionBlock, false,
base::TimeDelta::FromSeconds(
base::test::ios::kWaitForFileOperationTimeout));
personalDataManager->NotifyPersonalDataObserver();
}
+ (void)saveMaskedCreditCard {
autofill::PersonalDataManager* personalDataManager =
[self personalDataManager];
autofill::CreditCard card = autofill::test::GetMaskedServerCard();
DCHECK(card.record_type() != autofill::CreditCard::LOCAL_CARD);
personalDataManager->AddServerCreditCardForTest(
std::make_unique<autofill::CreditCard>(card));
personalDataManager->NotifyPersonalDataObserver();
}
#pragma mark - Private #pragma mark - Private
// The PersonalDataManager instance for the current browser state. // The PersonalDataManager instance for the current browser state.
......
...@@ -236,6 +236,7 @@ source_set("eg2_tests") { ...@@ -236,6 +236,7 @@ source_set("eg2_tests") {
] ]
testonly = true testonly = true
sources = [ sources = [
"card_view_controller_egtest.mm",
"fallback_coordinator_egtest.mm", "fallback_coordinator_egtest.mm",
"password_view_controller_egtest.mm", "password_view_controller_egtest.mm",
] ]
...@@ -244,6 +245,7 @@ source_set("eg2_tests") { ...@@ -244,6 +245,7 @@ source_set("eg2_tests") {
"//base/test:test_support", "//base/test:test_support",
"//ios/chrome/app/strings:ios_strings_grit", "//ios/chrome/app/strings:ios_strings_grit",
"//ios/chrome/browser/ui/autofill:eg_test_support+eg2", "//ios/chrome/browser/ui/autofill:eg_test_support+eg2",
"//ios/chrome/browser/ui/settings/autofill:feature_flags",
"//ios/chrome/test/earl_grey:eg_test_support+eg2", "//ios/chrome/test/earl_grey:eg_test_support+eg2",
"//ios/testing/earl_grey:eg_test_support+eg2", "//ios/testing/earl_grey:eg_test_support+eg2",
"//ios/third_party/earl_grey2:test_lib", "//ios/third_party/earl_grey2:test_lib",
......
...@@ -2,35 +2,18 @@ ...@@ -2,35 +2,18 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#import <EarlGrey/EarlGrey.h>
#import <EarlGrey/GREYKeyboard.h>
#include "base/ios/ios_util.h" #include "base/ios/ios_util.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "base/strings/utf_string_conversions.h"
#import "base/test/ios/wait_util.h" #import "base/test/ios/wait_util.h"
#include "base/test/scoped_feature_list.h" #import "ios/chrome/browser/ui/autofill/autofill_app_interface.h"
#include "components/autofill/core/browser/autofill_test_utils.h"
#include "components/autofill/core/browser/data_model/credit_card.h"
#include "components/autofill/core/browser/personal_data_manager.h"
#include "components/autofill/core/common/autofill_features.h"
#include "components/keyed_service/core/service_access_type.h"
#import "ios/chrome/browser/autofill/form_suggestion_constants.h"
#include "ios/chrome/browser/autofill/personal_data_manager_factory.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/card_coordinator.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/card_mediator.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/card_view_controller.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/manual_fill_accessory_view_controller.h"
#import "ios/chrome/browser/ui/settings/autofill/autofill_credit_card_table_view_controller.h"
#import "ios/chrome/browser/ui/settings/autofill/features.h" #import "ios/chrome/browser/ui/settings/autofill/features.h"
#import "ios/chrome/browser/ui/util/ui_util.h"
#include "ios/chrome/grit/ios_strings.h" #include "ios/chrome/grit/ios_strings.h"
#import "ios/chrome/test/app/chrome_test_util.h"
#import "ios/chrome/test/earl_grey/chrome_actions.h" #import "ios/chrome/test/earl_grey/chrome_actions.h"
#import "ios/chrome/test/earl_grey/chrome_earl_grey.h" #import "ios/chrome/test/earl_grey/chrome_earl_grey.h"
#import "ios/chrome/test/earl_grey/chrome_matchers.h" #import "ios/chrome/test/earl_grey/chrome_matchers.h"
#import "ios/chrome/test/earl_grey/chrome_test_case.h" #import "ios/chrome/test/earl_grey/chrome_test_case.h"
#import "ios/web/public/test/earl_grey/web_view_matchers.h" #import "ios/testing/earl_grey/app_launch_manager.h"
#import "ios/testing/earl_grey/earl_grey_test.h"
#include "ios/web/public/test/element_selector.h" #include "ios/web/public/test/element_selector.h"
#include "net/test/embedded_test_server/embedded_test_server.h" #include "net/test/embedded_test_server/embedded_test_server.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -39,7 +22,17 @@ ...@@ -39,7 +22,17 @@
#error "This file requires ARC support." #error "This file requires ARC support."
#endif #endif
using base::test::ios::kWaitForActionTimeout;
using chrome_test_util::CancelButton; using chrome_test_util::CancelButton;
using chrome_test_util::ManualFallbackAddCreditCardsMatcher;
using chrome_test_util::ManualFallbackCreditCardIconMatcher;
using chrome_test_util::ManualFallbackCreditCardTableViewMatcher;
using chrome_test_util::ManualFallbackCreditCardTableViewWindowMatcher;
using chrome_test_util::ManualFallbackFormSuggestionViewMatcher;
using chrome_test_util::ManualFallbackKeyboardIconMatcher;
using chrome_test_util::ManualFallbackManageCreditCardsMatcher;
using chrome_test_util::NavigationBarCancelButton;
using chrome_test_util::SettingsCreditCardMatcher;
using chrome_test_util::StaticTextWithAccessibilityLabelId; using chrome_test_util::StaticTextWithAccessibilityLabelId;
using chrome_test_util::TapWebElementWithId; using chrome_test_util::TapWebElementWithId;
...@@ -57,10 +50,12 @@ NSString* kLocalCardExpirationYear = @"22"; ...@@ -57,10 +50,12 @@ NSString* kLocalCardExpirationYear = @"22";
// - 0x0020 - Space. // - 0x0020 - Space.
// - 0x2060 - WORD-JOINER (makes string undivisible). // - 0x2060 - WORD-JOINER (makes string undivisible).
constexpr base::char16 separator[] = {0x2060, 0x0020, 0}; constexpr base::char16 separator[] = {0x2060, 0x0020, 0};
constexpr base::char16 kMidlineEllipsis[] = {
0x2022, 0x2060, 0x2006, 0x2060, 0x2022, 0x2060, 0x2006, 0x2060, 0x2022,
0x2060, 0x2006, 0x2060, 0x2022, 0x2060, 0x2006, 0x2060, 0};
NSString* kObfuscatedNumberPrefix = base::SysUTF16ToNSString( NSString* kObfuscatedNumberPrefix = base::SysUTF16ToNSString(
autofill::kMidlineEllipsis + base::string16(separator) + kMidlineEllipsis + base::string16(separator) + kMidlineEllipsis +
autofill::kMidlineEllipsis + base::string16(separator) + base::string16(separator) + kMidlineEllipsis + base::string16(separator));
autofill::kMidlineEllipsis + base::string16(separator));
NSString* kLocalNumberObfuscated = NSString* kLocalNumberObfuscated =
[NSString stringWithFormat:@"%@1111", kObfuscatedNumberPrefix]; [NSString stringWithFormat:@"%@1111", kObfuscatedNumberPrefix];
...@@ -70,70 +65,15 @@ NSString* kServerNumberObfuscated = ...@@ -70,70 +65,15 @@ NSString* kServerNumberObfuscated =
const char kFormHTMLFile[] = "/multi_field_form.html"; const char kFormHTMLFile[] = "/multi_field_form.html";
// Timeout in seconds while waiting for a profile or a credit to be added to the // TODO(crbug.com/1016367): Remove the guard once ExecuteJavaScript is updated
// PersonalDataManager. // to compile on EG2.
const NSTimeInterval kPDMMaxDelaySeconds = 10.0; #if defined(CHROME_EARL_GREY_1)
// Returns a matcher for the scroll view in keyboard accessory bar.
id<GREYMatcher> FormSuggestionViewMatcher() {
return grey_accessibilityID(kFormSuggestionsViewAccessibilityIdentifier);
}
// Returns a matcher for the credit card icon in the keyboard accessory bar.
id<GREYMatcher> CreditCardIconMatcher() {
return grey_accessibilityID(
manual_fill::AccessoryCreditCardAccessibilityIdentifier);
}
id<GREYMatcher> KeyboardIconMatcher() {
return grey_accessibilityID(
manual_fill::AccessoryKeyboardAccessibilityIdentifier);
}
// Returns a matcher for the credit card table view in manual fallback.
id<GREYMatcher> CreditCardTableViewMatcher() {
return grey_accessibilityID(
manual_fill::CardTableViewAccessibilityIdentifier);
}
// Returns a matcher for the button to open password settings in manual
// fallback.
id<GREYMatcher> ManageCreditCardsMatcher() {
return grey_accessibilityID(manual_fill::ManageCardsAccessibilityIdentifier);
}
// Returns a matcher for the button to add credit cards settings in manual
// fallback.
id<GREYMatcher> AddCreditCardsMatcher() {
return grey_accessibilityID(
manual_fill::kAddCreditCardsAccessibilityIdentifier);
}
// Returns a matcher for the credit card settings collection view.
id<GREYMatcher> CreditCardSettingsMatcher() {
return grey_accessibilityID(kAutofillCreditCardTableViewId);
}
// Matcher for the not secure website alert. // Matcher for the not secure website alert.
id<GREYMatcher> NotSecureWebsiteAlert() { id<GREYMatcher> NotSecureWebsiteAlert() {
return StaticTextWithAccessibilityLabelId( return StaticTextWithAccessibilityLabelId(
IDS_IOS_MANUAL_FALLBACK_NOT_SECURE_TITLE); IDS_IOS_MANUAL_FALLBACK_NOT_SECURE_TITLE);
} }
// Returns a matcher for the CreditCardTableView window.
id<GREYMatcher> CreditCardTableViewWindowMatcher() {
id<GREYMatcher> classMatcher = grey_kindOfClass([UIWindow class]);
id<GREYMatcher> parentMatcher = grey_descendant(CreditCardTableViewMatcher());
return grey_allOf(classMatcher, parentMatcher, nil);
}
// Returns the matcher for an enabled cancel button in a navigation bar.
id<GREYMatcher> NavigationBarCancelMatcher() {
return grey_allOf(
grey_ancestor(grey_kindOfClass([UINavigationBar class])), CancelButton(),
grey_not(grey_accessibilityTrait(UIAccessibilityTraitNotEnabled)), nil);
}
// Polls the JavaScript query |java_script_condition| until the returned // Polls the JavaScript query |java_script_condition| until the returned
// |boolValue| is YES with a kWaitForActionTimeout timeout. // |boolValue| is YES with a kWaitForActionTimeout timeout.
BOOL WaitForJavaScriptCondition(NSString* java_script_condition) { BOOL WaitForJavaScriptCondition(NSString* java_script_condition) {
...@@ -148,92 +88,48 @@ BOOL WaitForJavaScriptCondition(NSString* java_script_condition) { ...@@ -148,92 +88,48 @@ BOOL WaitForJavaScriptCondition(NSString* java_script_condition) {
block:verify_block]; block:verify_block];
return [condition waitWithTimeout:timeout]; return [condition waitWithTimeout:timeout];
} }
#endif
// Waits for the keyboard to appear. Returns NO on timeout.
BOOL WaitForKeyboardToAppear() {
GREYCondition* waitForKeyboard = [GREYCondition
conditionWithName:@"Wait for keyboard"
block:^BOOL {
return [ChromeEarlGrey isKeyboardShownWithError:nil];
}];
return [waitForKeyboard waitWithTimeout:kWaitForActionTimeout];
}
} // namespace } // namespace
// Integration Tests for Manual Fallback credit cards View Controller. // Integration Tests for Manual Fallback credit cards View Controller.
@interface CreditCardViewControllerTestCase : ChromeTestCase { @interface CreditCardViewControllerTestCase : ChromeTestCase
// The PersonalDataManager instance for the current browser state.
autofill::PersonalDataManager* _personalDataManager;
// Credit Cards added to the PersonalDataManager.
std::vector<autofill::CreditCard> _cards;
}
@end @end
@implementation CreditCardViewControllerTestCase @implementation CreditCardViewControllerTestCase
- (void)setUp { - (void)setUp {
[super setUp]; [super setUp];
[[AppLaunchManager sharedManager]
ensureAppLaunchedWithFeaturesEnabled:{kSettingsAddPaymentMethod,
kCreditCardScanner}
disabled:{}
forceRestart:NO];
GREYAssertTrue(self.testServer->Start(), @"Test server failed to start."); GREYAssertTrue(self.testServer->Start(), @"Test server failed to start.");
const GURL URL = self.testServer->GetURL(kFormHTMLFile); const GURL URL = self.testServer->GetURL(kFormHTMLFile);
[ChromeEarlGrey loadURL:URL]; [ChromeEarlGrey loadURL:URL];
[ChromeEarlGrey waitForWebStateContainingText:"hello!"]; [ChromeEarlGrey waitForWebStateContainingText:"hello!"];
[AutofillAppInterface clearCreditCardStore];
_personalDataManager =
autofill::PersonalDataManagerFactory::GetForBrowserState(
chrome_test_util::GetOriginalBrowserState());
_personalDataManager->SetSyncingForTest(true);
for (autofill::CreditCard* card :
_personalDataManager->GetLocalCreditCards()) {
_personalDataManager->RemoveByGUID(card->guid());
}
GREYAssert(base::test::ios::WaitUntilConditionOrTimeout(
kPDMMaxDelaySeconds,
^bool() {
return _personalDataManager->GetLocalCreditCards().size() ==
0;
}),
@"Failed to remove local credit cards.");
} }
- (void)tearDown { - (void)tearDown {
for (const auto& card : _cards) { [AutofillAppInterface clearCreditCardStore];
_personalDataManager->RemoveByGUID(card.guid()); [ChromeEarlGrey rotateDeviceToOrientation:UIDeviceOrientationPortrait
} error:nil];
_cards.clear();
[EarlGrey rotateDeviceToOrientation:UIDeviceOrientationPortrait
errorOrNil:nil];
[super tearDown]; [super tearDown];
} }
#pragma mark - Helpers
// Adds a local credit card, one that doesn't need CVC unlocking.
- (void)addCreditCard:(const autofill::CreditCard&)card {
_cards.push_back(card);
size_t card_count = _personalDataManager->GetCreditCards().size();
_personalDataManager->AddCreditCard(card);
GREYAssert(base::test::ios::WaitUntilConditionOrTimeout(
kPDMMaxDelaySeconds,
^bool() {
return card_count <
_personalDataManager->GetCreditCards().size();
}),
@"Failed to add credit card.");
_personalDataManager->NotifyPersonalDataObserver();
}
// Adds a server credit card, one that needs CVC unlocking.
- (void)addServerCreditCard:(const autofill::CreditCard&)card {
DCHECK(card.record_type() != autofill::CreditCard::LOCAL_CARD);
_personalDataManager->AddServerCreditCardForTest(
std::make_unique<autofill::CreditCard>(card));
_personalDataManager->NotifyPersonalDataObserver();
}
- (void)saveLocalCreditCard {
autofill::CreditCard card = autofill::test::GetCreditCard();
[self addCreditCard:card];
}
- (void)saveMaskedCreditCard {
autofill::CreditCard card = autofill::test::GetMaskedServerCard();
[self addServerCreditCard:card];
}
#pragma mark - Tests #pragma mark - Tests
// Tests that the credit card view butotn is absent when there are no cards // Tests that the credit card view butotn is absent when there are no cards
...@@ -244,141 +140,145 @@ BOOL WaitForJavaScriptCondition(NSString* java_script_condition) { ...@@ -244,141 +140,145 @@ BOOL WaitForJavaScriptCondition(NSString* java_script_condition) {
performAction:TapWebElementWithId(kFormElementUsername)]; performAction:TapWebElementWithId(kFormElementUsername)];
// Verify there's no credit card icon. // Verify there's no credit card icon.
[[EarlGrey selectElementWithMatcher:CreditCardIconMatcher()] [[EarlGrey selectElementWithMatcher:ManualFallbackCreditCardIconMatcher()]
assertWithMatcher:grey_notVisible()]; assertWithMatcher:grey_notVisible()];
} }
// Tests that the credit card view controller appears on screen. // Tests that the credit card view controller appears on screen.
- (void)testCreditCardsViewControllerIsPresented { - (void)testCreditCardsViewControllerIsPresented {
[self saveLocalCreditCard]; [AutofillAppInterface saveLocalCreditCard];
// Bring up the keyboard. // Bring up the keyboard.
[[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewMatcher()] [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewMatcher()]
performAction:TapWebElementWithId(kFormElementUsername)]; performAction:TapWebElementWithId(kFormElementUsername)];
// Tap on the credit card icon. // Tap on the credit card icon.
[[EarlGrey selectElementWithMatcher:CreditCardIconMatcher()] [[EarlGrey selectElementWithMatcher:ManualFallbackCreditCardIconMatcher()]
performAction:grey_tap()]; performAction:grey_tap()];
// Verify the credit cards controller table view is visible. // Verify the credit cards controller table view is visible.
[[EarlGrey selectElementWithMatcher:CreditCardTableViewMatcher()] [[EarlGrey
selectElementWithMatcher:ManualFallbackCreditCardTableViewMatcher()]
assertWithMatcher:grey_sufficientlyVisible()]; assertWithMatcher:grey_sufficientlyVisible()];
} }
// Tests that the credit cards view controller contains the "Manage Credit // Tests that the credit cards view controller contains the "Manage Credit
// Cards..." action. // Cards..." action.
- (void)testCreditCardsViewControllerContainsManageCreditCardsAction { - (void)testCreditCardsViewControllerContainsManageCreditCardsAction {
[self saveLocalCreditCard]; [AutofillAppInterface saveLocalCreditCard];
// Bring up the keyboard. // Bring up the keyboard.
[[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewMatcher()] [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewMatcher()]
performAction:TapWebElementWithId(kFormElementUsername)]; performAction:TapWebElementWithId(kFormElementUsername)];
// Tap on the credit card icon. // Tap on the credit card icon.
[[EarlGrey selectElementWithMatcher:CreditCardIconMatcher()] [[EarlGrey selectElementWithMatcher:ManualFallbackCreditCardIconMatcher()]
performAction:grey_tap()]; performAction:grey_tap()];
// Try to scroll. // Try to scroll.
[[EarlGrey selectElementWithMatcher:CreditCardTableViewMatcher()] [[EarlGrey
selectElementWithMatcher:ManualFallbackCreditCardTableViewMatcher()]
performAction:grey_scrollToContentEdge(kGREYContentEdgeBottom)]; performAction:grey_scrollToContentEdge(kGREYContentEdgeBottom)];
// Verify the credit cards controller contains the "Manage Credit Cards..." // Verify the credit cards controller contains the "Manage Credit Cards..."
// action. // action.
[[EarlGrey selectElementWithMatcher:ManageCreditCardsMatcher()] [[EarlGrey selectElementWithMatcher:ManualFallbackManageCreditCardsMatcher()]
assertWithMatcher:grey_interactable()]; assertWithMatcher:grey_interactable()];
} }
// Tests that the "Manage Credit Cards..." action works. // Tests that the "Manage Credit Cards..." action works.
- (void)testManageCreditCardsActionOpensCreditCardSettings { - (void)testManageCreditCardsActionOpensCreditCardSettings {
[self saveLocalCreditCard]; [AutofillAppInterface saveLocalCreditCard];
// Bring up the keyboard. // Bring up the keyboard.
[[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewMatcher()] [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewMatcher()]
performAction:TapWebElementWithId(kFormElementUsername)]; performAction:TapWebElementWithId(kFormElementUsername)];
// Tap on the credit card icon. // Tap on the credit card icon.
[[EarlGrey selectElementWithMatcher:CreditCardIconMatcher()] [[EarlGrey selectElementWithMatcher:ManualFallbackCreditCardIconMatcher()]
performAction:grey_tap()]; performAction:grey_tap()];
// Try to scroll. // Try to scroll.
[[EarlGrey selectElementWithMatcher:CreditCardTableViewMatcher()] [[EarlGrey
selectElementWithMatcher:ManualFallbackCreditCardTableViewMatcher()]
performAction:grey_scrollToContentEdge(kGREYContentEdgeBottom)]; performAction:grey_scrollToContentEdge(kGREYContentEdgeBottom)];
// Tap the "Manage Credit Cards..." action. // Tap the "Manage Credit Cards..." action.
[[EarlGrey selectElementWithMatcher:ManageCreditCardsMatcher()] [[EarlGrey selectElementWithMatcher:ManualFallbackManageCreditCardsMatcher()]
performAction:grey_tap()]; performAction:grey_tap()];
// Verify the credit cards settings opened. // Verify the credit cards settings opened.
[[EarlGrey selectElementWithMatcher:CreditCardSettingsMatcher()] [[EarlGrey selectElementWithMatcher:SettingsCreditCardMatcher()]
assertWithMatcher:grey_sufficientlyVisible()]; assertWithMatcher:grey_sufficientlyVisible()];
} }
// Tests that the manual fallback view and icon is not highlighted after // Tests that the manual fallback view and icon is not highlighted after
// presenting the manage credit cards view. // presenting the manage credit cards view.
- (void)testCreditCardsStateAfterPresentingCreditCardSettings { - (void)testCreditCardsStateAfterPresentingCreditCardSettings {
[self saveLocalCreditCard]; [AutofillAppInterface saveLocalCreditCard];
// Bring up the keyboard. // Bring up the keyboard.
[[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewMatcher()] [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewMatcher()]
performAction:TapWebElementWithId(kFormElementUsername)]; performAction:TapWebElementWithId(kFormElementUsername)];
// Scroll to the right. // Scroll to the right.
[[EarlGrey selectElementWithMatcher:FormSuggestionViewMatcher()] [[EarlGrey selectElementWithMatcher:ManualFallbackFormSuggestionViewMatcher()]
performAction:grey_scrollToContentEdge(kGREYContentEdgeRight)]; performAction:grey_scrollToContentEdge(kGREYContentEdgeRight)];
// Tap on the credit card icon. // Tap on the credit card icon.
[[EarlGrey selectElementWithMatcher:CreditCardIconMatcher()] [[EarlGrey selectElementWithMatcher:ManualFallbackCreditCardIconMatcher()]
performAction:grey_tap()]; performAction:grey_tap()];
// Verify the status of the icon. // Verify the status of the icon.
[[EarlGrey selectElementWithMatcher:CreditCardIconMatcher()] [[EarlGrey selectElementWithMatcher:ManualFallbackCreditCardIconMatcher()]
assertWithMatcher:grey_not(grey_userInteractionEnabled())]; assertWithMatcher:grey_not(grey_userInteractionEnabled())];
// Try to scroll. // Try to scroll.
[[EarlGrey selectElementWithMatcher:CreditCardTableViewMatcher()] [[EarlGrey
selectElementWithMatcher:ManualFallbackCreditCardTableViewMatcher()]
performAction:grey_scrollToContentEdge(kGREYContentEdgeBottom)]; performAction:grey_scrollToContentEdge(kGREYContentEdgeBottom)];
// Tap the "Manage Credit Cards..." action. // Tap the "Manage Credit Cards..." action.
[[EarlGrey selectElementWithMatcher:ManageCreditCardsMatcher()] [[EarlGrey selectElementWithMatcher:ManualFallbackManageCreditCardsMatcher()]
performAction:grey_tap()]; performAction:grey_tap()];
// Tap Cancel Button. // Tap Cancel Button.
[[EarlGrey selectElementWithMatcher:NavigationBarCancelMatcher()] [[EarlGrey selectElementWithMatcher:NavigationBarCancelButton()]
performAction:grey_tap()]; performAction:grey_tap()];
// Verify the status of the icons. // Verify the status of the icons.
[[EarlGrey selectElementWithMatcher:CreditCardIconMatcher()] [[EarlGrey selectElementWithMatcher:ManualFallbackCreditCardIconMatcher()]
assertWithMatcher:grey_sufficientlyVisible()]; assertWithMatcher:grey_sufficientlyVisible()];
[[EarlGrey selectElementWithMatcher:CreditCardIconMatcher()] [[EarlGrey selectElementWithMatcher:ManualFallbackCreditCardIconMatcher()]
assertWithMatcher:grey_userInteractionEnabled()]; assertWithMatcher:grey_userInteractionEnabled()];
[[EarlGrey selectElementWithMatcher:KeyboardIconMatcher()] [[EarlGrey selectElementWithMatcher:ManualFallbackKeyboardIconMatcher()]
assertWithMatcher:grey_not(grey_sufficientlyVisible())]; assertWithMatcher:grey_not(grey_sufficientlyVisible())];
// Verify the keyboard is not cover by the cards view. // Verify the keyboard is not cover by the cards view.
[[EarlGrey selectElementWithMatcher:CreditCardTableViewMatcher()] [[EarlGrey
selectElementWithMatcher:ManualFallbackCreditCardTableViewMatcher()]
assertWithMatcher:grey_notVisible()]; assertWithMatcher:grey_notVisible()];
} }
// Tests that the "Add Credit Cards..." action works. // Tests that the "Add Credit Cards..." action works.
- (void)testAddCreditCardsActionOpensAddCreditCardSettings { - (void)testAddCreditCardsActionOpensAddCreditCardSettings {
base::test::ScopedFeatureList featureList; [AutofillAppInterface saveLocalCreditCard];
featureList.InitAndEnableFeature(kSettingsAddPaymentMethod);
[self saveLocalCreditCard];
// Bring up the keyboard. // Bring up the keyboard.
[[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewMatcher()] [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewMatcher()]
performAction:TapWebElementWithId(kFormElementUsername)]; performAction:TapWebElementWithId(kFormElementUsername)];
// Tap on the credit card icon. // Tap on the credit card icon.
[[EarlGrey selectElementWithMatcher:CreditCardIconMatcher()] [[EarlGrey selectElementWithMatcher:ManualFallbackCreditCardIconMatcher()]
performAction:grey_tap()]; performAction:grey_tap()];
// Try to scroll. // Try to scroll.
[[EarlGrey selectElementWithMatcher:CreditCardTableViewMatcher()] [[EarlGrey
selectElementWithMatcher:ManualFallbackCreditCardTableViewMatcher()]
performAction:grey_scrollToContentEdge(kGREYContentEdgeBottom)]; performAction:grey_scrollToContentEdge(kGREYContentEdgeBottom)];
// Tap the "Add Credit Cards..." action. // Tap the "Add Credit Cards..." action.
[[EarlGrey selectElementWithMatcher:AddCreditCardsMatcher()] [[EarlGrey selectElementWithMatcher:ManualFallbackAddCreditCardsMatcher()]
performAction:grey_tap()]; performAction:grey_tap()];
// Verify the credit cards settings opened. // Verify the credit cards settings opened.
...@@ -388,9 +288,7 @@ BOOL WaitForJavaScriptCondition(NSString* java_script_condition) { ...@@ -388,9 +288,7 @@ BOOL WaitForJavaScriptCondition(NSString* java_script_condition) {
// Tests that the "Add Credit Cards..." action works on OTR. // Tests that the "Add Credit Cards..." action works on OTR.
- (void)testOTRAddCreditCardsActionOpensAddCreditCardSettings { - (void)testOTRAddCreditCardsActionOpensAddCreditCardSettings {
base::test::ScopedFeatureList featureList; [AutofillAppInterface saveLocalCreditCard];
featureList.InitAndEnableFeature(kSettingsAddPaymentMethod);
[self saveLocalCreditCard];
// Open a tab in incognito. // Open a tab in incognito.
[ChromeEarlGrey openNewIncognitoTab]; [ChromeEarlGrey openNewIncognitoTab];
...@@ -403,15 +301,16 @@ BOOL WaitForJavaScriptCondition(NSString* java_script_condition) { ...@@ -403,15 +301,16 @@ BOOL WaitForJavaScriptCondition(NSString* java_script_condition) {
performAction:TapWebElementWithId(kFormElementUsername)]; performAction:TapWebElementWithId(kFormElementUsername)];
// Tap on the credit card icon. // Tap on the credit card icon.
[[EarlGrey selectElementWithMatcher:CreditCardIconMatcher()] [[EarlGrey selectElementWithMatcher:ManualFallbackCreditCardIconMatcher()]
performAction:grey_tap()]; performAction:grey_tap()];
// Try to scroll. // Try to scroll.
[[EarlGrey selectElementWithMatcher:CreditCardTableViewMatcher()] [[EarlGrey
selectElementWithMatcher:ManualFallbackCreditCardTableViewMatcher()]
performAction:grey_scrollToContentEdge(kGREYContentEdgeBottom)]; performAction:grey_scrollToContentEdge(kGREYContentEdgeBottom)];
// Tap the "Add Credit Cards..." action. // Tap the "Add Credit Cards..." action.
[[EarlGrey selectElementWithMatcher:AddCreditCardsMatcher()] [[EarlGrey selectElementWithMatcher:ManualFallbackAddCreditCardsMatcher()]
performAction:grey_tap()]; performAction:grey_tap()];
// Verify the credit cards settings opened. // Verify the credit cards settings opened.
...@@ -422,48 +321,48 @@ BOOL WaitForJavaScriptCondition(NSString* java_script_condition) { ...@@ -422,48 +321,48 @@ BOOL WaitForJavaScriptCondition(NSString* java_script_condition) {
// Tests that the manual fallback view icon is not highlighted after presenting // Tests that the manual fallback view icon is not highlighted after presenting
// the add credit card view. // the add credit card view.
- (void)testCreditCardsButtonStateAfterPresentingAddCreditCard { - (void)testCreditCardsButtonStateAfterPresentingAddCreditCard {
base::test::ScopedFeatureList featureList; [AutofillAppInterface saveLocalCreditCard];
featureList.InitAndEnableFeature(kSettingsAddPaymentMethod);
[self saveLocalCreditCard];
// Bring up the keyboard. // Bring up the keyboard.
[[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewMatcher()] [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewMatcher()]
performAction:TapWebElementWithId(kFormElementUsername)]; performAction:TapWebElementWithId(kFormElementUsername)];
// Scroll to the right. // Scroll to the right.
[[EarlGrey selectElementWithMatcher:FormSuggestionViewMatcher()] [[EarlGrey selectElementWithMatcher:ManualFallbackFormSuggestionViewMatcher()]
performAction:grey_scrollToContentEdge(kGREYContentEdgeRight)]; performAction:grey_scrollToContentEdge(kGREYContentEdgeRight)];
// Tap on the credit card icon. // Tap on the credit card icon.
[[EarlGrey selectElementWithMatcher:CreditCardIconMatcher()] [[EarlGrey selectElementWithMatcher:ManualFallbackCreditCardIconMatcher()]
performAction:grey_tap()]; performAction:grey_tap()];
// Verify the status of the icon. // Verify the status of the icon.
[[EarlGrey selectElementWithMatcher:CreditCardIconMatcher()] [[EarlGrey selectElementWithMatcher:ManualFallbackCreditCardIconMatcher()]
assertWithMatcher:grey_not(grey_userInteractionEnabled())]; assertWithMatcher:grey_not(grey_userInteractionEnabled())];
// Try to scroll. // Try to scroll.
[[EarlGrey selectElementWithMatcher:CreditCardTableViewMatcher()] [[EarlGrey
selectElementWithMatcher:ManualFallbackCreditCardTableViewMatcher()]
performAction:grey_scrollToContentEdge(kGREYContentEdgeBottom)]; performAction:grey_scrollToContentEdge(kGREYContentEdgeBottom)];
// Tap the "Add Credit Cards..." action. // Tap the "Add Credit Cards..." action.
[[EarlGrey selectElementWithMatcher:AddCreditCardsMatcher()] [[EarlGrey selectElementWithMatcher:ManualFallbackAddCreditCardsMatcher()]
performAction:grey_tap()]; performAction:grey_tap()];
// Tap Cancel Button. // Tap Cancel Button.
[[EarlGrey selectElementWithMatcher:NavigationBarCancelMatcher()] [[EarlGrey selectElementWithMatcher:NavigationBarCancelButton()]
performAction:grey_tap()]; performAction:grey_tap()];
// Verify the status of the icons. // Verify the status of the icons.
[[EarlGrey selectElementWithMatcher:CreditCardIconMatcher()] [[EarlGrey selectElementWithMatcher:ManualFallbackCreditCardIconMatcher()]
assertWithMatcher:grey_sufficientlyVisible()]; assertWithMatcher:grey_sufficientlyVisible()];
[[EarlGrey selectElementWithMatcher:CreditCardIconMatcher()] [[EarlGrey selectElementWithMatcher:ManualFallbackCreditCardIconMatcher()]
assertWithMatcher:grey_userInteractionEnabled()]; assertWithMatcher:grey_userInteractionEnabled()];
[[EarlGrey selectElementWithMatcher:KeyboardIconMatcher()] [[EarlGrey selectElementWithMatcher:ManualFallbackKeyboardIconMatcher()]
assertWithMatcher:grey_not(grey_sufficientlyVisible())]; assertWithMatcher:grey_not(grey_sufficientlyVisible())];
// Verify the keyboard is not cover by the cards view. // Verify the keyboard is not cover by the cards view.
[[EarlGrey selectElementWithMatcher:CreditCardTableViewMatcher()] [[EarlGrey
selectElementWithMatcher:ManualFallbackCreditCardTableViewMatcher()]
assertWithMatcher:grey_notVisible()]; assertWithMatcher:grey_notVisible()];
} }
...@@ -474,29 +373,31 @@ BOOL WaitForJavaScriptCondition(NSString* java_script_condition) { ...@@ -474,29 +373,31 @@ BOOL WaitForJavaScriptCondition(NSString* java_script_condition) {
// The keyboard icon is never present in iPads. // The keyboard icon is never present in iPads.
return; return;
} }
[self saveLocalCreditCard]; [AutofillAppInterface saveLocalCreditCard];
// Bring up the keyboard. // Bring up the keyboard.
[[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewMatcher()] [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewMatcher()]
performAction:TapWebElementWithId(kFormElementUsername)]; performAction:TapWebElementWithId(kFormElementUsername)];
// Tap on the credit cards icon. // Tap on the credit cards icon.
[[EarlGrey selectElementWithMatcher:CreditCardIconMatcher()] [[EarlGrey selectElementWithMatcher:ManualFallbackCreditCardIconMatcher()]
performAction:grey_tap()]; performAction:grey_tap()];
// Verify the credit card controller table view is visible. // Verify the credit card controller table view is visible.
[[EarlGrey selectElementWithMatcher:CreditCardTableViewMatcher()] [[EarlGrey
selectElementWithMatcher:ManualFallbackCreditCardTableViewMatcher()]
assertWithMatcher:grey_sufficientlyVisible()]; assertWithMatcher:grey_sufficientlyVisible()];
// Tap on the keyboard icon. // Tap on the keyboard icon.
[[EarlGrey selectElementWithMatcher:KeyboardIconMatcher()] [[EarlGrey selectElementWithMatcher:ManualFallbackKeyboardIconMatcher()]
performAction:grey_tap()]; performAction:grey_tap()];
// Verify the credit card controller table view and the credit card icon is // Verify the credit card controller table view and the credit card icon is
// NOT visible. // NOT visible.
[[EarlGrey selectElementWithMatcher:CreditCardTableViewMatcher()] [[EarlGrey
selectElementWithMatcher:ManualFallbackCreditCardTableViewMatcher()]
assertWithMatcher:grey_notVisible()]; assertWithMatcher:grey_notVisible()];
[[EarlGrey selectElementWithMatcher:KeyboardIconMatcher()] [[EarlGrey selectElementWithMatcher:ManualFallbackKeyboardIconMatcher()]
assertWithMatcher:grey_notVisible()]; assertWithMatcher:grey_notVisible()];
} }
...@@ -506,31 +407,34 @@ BOOL WaitForJavaScriptCondition(NSString* java_script_condition) { ...@@ -506,31 +407,34 @@ BOOL WaitForJavaScriptCondition(NSString* java_script_condition) {
if (![ChromeEarlGrey isIPadIdiom]) { if (![ChromeEarlGrey isIPadIdiom]) {
return; return;
} }
[self saveLocalCreditCard]; [AutofillAppInterface saveLocalCreditCard];
// Bring up the keyboard. // Bring up the keyboard.
[[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewMatcher()] [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewMatcher()]
performAction:TapWebElementWithId(kFormElementUsername)]; performAction:TapWebElementWithId(kFormElementUsername)];
// Tap on the credit cards icon. // Tap on the credit cards icon.
[[EarlGrey selectElementWithMatcher:CreditCardIconMatcher()] [[EarlGrey selectElementWithMatcher:ManualFallbackCreditCardIconMatcher()]
performAction:grey_tap()]; performAction:grey_tap()];
// Verify the credit card controller table view is visible. // Verify the credit card controller table view is visible.
[[EarlGrey selectElementWithMatcher:CreditCardTableViewMatcher()] [[EarlGrey
selectElementWithMatcher:ManualFallbackCreditCardTableViewMatcher()]
assertWithMatcher:grey_sufficientlyVisible()]; assertWithMatcher:grey_sufficientlyVisible()];
// Tap on a point outside of the popover. // Tap on a point outside of the popover.
// The way EarlGrey taps doesn't go through the window hierarchy. Because of // The way EarlGrey taps doesn't go through the window hierarchy. Because of
// this, the tap needs to be done in the same window as the popover. // this, the tap needs to be done in the same window as the popover.
[[EarlGrey selectElementWithMatcher:CreditCardTableViewWindowMatcher()] [[EarlGrey
selectElementWithMatcher:ManualFallbackCreditCardTableViewWindowMatcher()]
performAction:grey_tapAtPoint(CGPointMake(0, 0))]; performAction:grey_tapAtPoint(CGPointMake(0, 0))];
// Verify the credit card controller table view and the credit card icon is // Verify the credit card controller table view and the credit card icon is
// NOT visible. // NOT visible.
[[EarlGrey selectElementWithMatcher:CreditCardTableViewMatcher()] [[EarlGrey
selectElementWithMatcher:ManualFallbackCreditCardTableViewMatcher()]
assertWithMatcher:grey_notVisible()]; assertWithMatcher:grey_notVisible()];
[[EarlGrey selectElementWithMatcher:KeyboardIconMatcher()] [[EarlGrey selectElementWithMatcher:ManualFallbackKeyboardIconMatcher()]
assertWithMatcher:grey_notVisible()]; assertWithMatcher:grey_notVisible()];
} }
...@@ -541,42 +445,45 @@ BOOL WaitForJavaScriptCondition(NSString* java_script_condition) { ...@@ -541,42 +445,45 @@ BOOL WaitForJavaScriptCondition(NSString* java_script_condition) {
if (![ChromeEarlGrey isIPadIdiom]) { if (![ChromeEarlGrey isIPadIdiom]) {
return; return;
} }
[self saveLocalCreditCard]; [AutofillAppInterface saveLocalCreditCard];
// Bring up the keyboard. // Bring up the keyboard.
[[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewMatcher()] [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewMatcher()]
performAction:TapWebElementWithId(kFormElementUsername)]; performAction:TapWebElementWithId(kFormElementUsername)];
// Tap on the credit cards icon. // Tap on the credit cards icon.
[[EarlGrey selectElementWithMatcher:CreditCardIconMatcher()] [[EarlGrey selectElementWithMatcher:ManualFallbackCreditCardIconMatcher()]
performAction:grey_tap()]; performAction:grey_tap()];
// Verify the credit card controller table view is visible. // Verify the credit card controller table view is visible.
[[EarlGrey selectElementWithMatcher:CreditCardTableViewMatcher()] [[EarlGrey
selectElementWithMatcher:ManualFallbackCreditCardTableViewMatcher()]
assertWithMatcher:grey_sufficientlyVisible()]; assertWithMatcher:grey_sufficientlyVisible()];
[[EarlGrey selectElementWithMatcher:CreditCardTableViewMatcher()] [[EarlGrey
selectElementWithMatcher:ManualFallbackCreditCardTableViewMatcher()]
performAction:grey_typeText(@"text")]; performAction:grey_typeText(@"text")];
// Verify the credit card controller table view and the credit card icon is // Verify the credit card controller table view and the credit card icon is
// NOT visible. // NOT visible.
[[EarlGrey selectElementWithMatcher:CreditCardTableViewMatcher()] [[EarlGrey
selectElementWithMatcher:ManualFallbackCreditCardTableViewMatcher()]
assertWithMatcher:grey_notVisible()]; assertWithMatcher:grey_notVisible()];
[[EarlGrey selectElementWithMatcher:KeyboardIconMatcher()] [[EarlGrey selectElementWithMatcher:ManualFallbackKeyboardIconMatcher()]
assertWithMatcher:grey_notVisible()]; assertWithMatcher:grey_notVisible()];
} }
// Tests that after switching fields the content size of the table view didn't // Tests that after switching fields the content size of the table view didn't
// grow. // grow.
- (void)testCreditCardControllerKeepsRightSize { - (void)testCreditCardControllerKeepsRightSize {
[self saveLocalCreditCard]; [AutofillAppInterface saveLocalCreditCard];
// Bring up the keyboard. // Bring up the keyboard.
[[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewMatcher()] [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewMatcher()]
performAction:TapWebElementWithId(kFormElementUsername)]; performAction:TapWebElementWithId(kFormElementUsername)];
// Tap on the credit cards icon. // Tap on the credit cards icon.
[[EarlGrey selectElementWithMatcher:CreditCardIconMatcher()] [[EarlGrey selectElementWithMatcher:ManualFallbackCreditCardIconMatcher()]
performAction:grey_tap()]; performAction:grey_tap()];
// Tap the second element. // Tap the second element.
...@@ -584,34 +491,40 @@ BOOL WaitForJavaScriptCondition(NSString* java_script_condition) { ...@@ -584,34 +491,40 @@ BOOL WaitForJavaScriptCondition(NSString* java_script_condition) {
performAction:TapWebElementWithId(kFormElementOtherStuff)]; performAction:TapWebElementWithId(kFormElementOtherStuff)];
// Try to scroll. // Try to scroll.
[[EarlGrey selectElementWithMatcher:CreditCardTableViewMatcher()] [[EarlGrey
selectElementWithMatcher:ManualFallbackCreditCardTableViewMatcher()]
performAction:grey_scrollToContentEdge(kGREYContentEdgeBottom)]; performAction:grey_scrollToContentEdge(kGREYContentEdgeBottom)];
} }
// Tests that the credit card View Controller stays on rotation. // Tests that the credit card View Controller stays on rotation.
- (void)testCreditCardControllerSupportsRotation { - (void)testCreditCardControllerSupportsRotation {
[self saveLocalCreditCard]; [AutofillAppInterface saveLocalCreditCard];
// Bring up the keyboard. // Bring up the keyboard.
[[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewMatcher()] [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewMatcher()]
performAction:TapWebElementWithId(kFormElementUsername)]; performAction:TapWebElementWithId(kFormElementUsername)];
// Tap on the credit cards icon. // Tap on the credit cards icon.
[[EarlGrey selectElementWithMatcher:CreditCardIconMatcher()] [[EarlGrey selectElementWithMatcher:ManualFallbackCreditCardIconMatcher()]
performAction:grey_tap()]; performAction:grey_tap()];
// Verify the credit card controller table view is visible. // Verify the credit card controller table view is visible.
[[EarlGrey selectElementWithMatcher:CreditCardTableViewMatcher()] [[EarlGrey
selectElementWithMatcher:ManualFallbackCreditCardTableViewMatcher()]
assertWithMatcher:grey_sufficientlyVisible()]; assertWithMatcher:grey_sufficientlyVisible()];
[EarlGrey rotateDeviceToOrientation:UIDeviceOrientationLandscapeLeft [ChromeEarlGrey rotateDeviceToOrientation:UIDeviceOrientationLandscapeLeft
errorOrNil:nil]; error:nil];
// Verify the credit card controller table view is still visible. // Verify the credit card controller table view is still visible.
[[EarlGrey selectElementWithMatcher:CreditCardTableViewMatcher()] [[EarlGrey
selectElementWithMatcher:ManualFallbackCreditCardTableViewMatcher()]
assertWithMatcher:grey_sufficientlyVisible()]; assertWithMatcher:grey_sufficientlyVisible()];
} }
// TODO(crbug.com/1016367): Remove the guard once ExecuteJavaScript is updated
// to compile on EG2.
#if defined(CHROME_EARL_GREY_1)
// Tests that credit card number (for local card) is injected. // Tests that credit card number (for local card) is injected.
// TODO(crbug.com/845472): maybe figure a way to test successfull injection // TODO(crbug.com/845472): maybe figure a way to test successfull injection
// when page is https, but right now if we use the https embedded server, // when page is https, but right now if we use the https embedded server,
...@@ -649,25 +562,27 @@ BOOL WaitForJavaScriptCondition(NSString* java_script_condition) { ...@@ -649,25 +562,27 @@ BOOL WaitForJavaScriptCondition(NSString* java_script_condition) {
[self verifyCreditCardButtonWithTitle:kLocalCardExpirationYear [self verifyCreditCardButtonWithTitle:kLocalCardExpirationYear
doesInjectValue:kLocalCardExpirationYear]; doesInjectValue:kLocalCardExpirationYear];
} }
#endif
// Tests that masked credit card offer CVC input. // Tests that masked credit card offer CVC input.
// TODOD(crbug.com/909748) can't test this one until https tests are possible. // TODOD(crbug.com/909748) can't test this one until https tests are possible.
- (void)DISABLED_testCreditCardServerNumberRequiresCVC { - (void)DISABLED_testCreditCardServerNumberRequiresCVC {
[self saveMaskedCreditCard]; [AutofillAppInterface saveMaskedCreditCard];
// Bring up the keyboard. // Bring up the keyboard.
[[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewMatcher()] [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewMatcher()]
performAction:TapWebElementWithId(kFormElementUsername)]; performAction:TapWebElementWithId(kFormElementUsername)];
// Wait for the accessory icon to appear. // Wait for the accessory icon to appear.
[GREYKeyboard waitForKeyboardToAppear]; GREYAssert(WaitForKeyboardToAppear(), @"Keyboard didn't appear.");
// Tap on the passwords icon. // Tap on the passwords icon.
[[EarlGrey selectElementWithMatcher:CreditCardIconMatcher()] [[EarlGrey selectElementWithMatcher:ManualFallbackCreditCardIconMatcher()]
performAction:grey_tap()]; performAction:grey_tap()];
// Verify the password controller table view is visible. // Verify the password controller table view is visible.
[[EarlGrey selectElementWithMatcher:CreditCardTableViewMatcher()] [[EarlGrey
selectElementWithMatcher:ManualFallbackCreditCardTableViewMatcher()]
assertWithMatcher:grey_sufficientlyVisible()]; assertWithMatcher:grey_sufficientlyVisible()];
// Select a the masked number. // Select a the masked number.
...@@ -684,23 +599,27 @@ BOOL WaitForJavaScriptCondition(NSString* java_script_condition) { ...@@ -684,23 +599,27 @@ BOOL WaitForJavaScriptCondition(NSString* java_script_condition) {
#pragma mark - Private #pragma mark - Private
// TODO(crbug.com/1016367): Remove the guard once ExecuteJavaScript is updated
// to compile on EG2.
#if defined(CHROME_EARL_GREY_1)
- (void)verifyCreditCardButtonWithTitle:(NSString*)title - (void)verifyCreditCardButtonWithTitle:(NSString*)title
doesInjectValue:(NSString*)result { doesInjectValue:(NSString*)result {
[self saveLocalCreditCard]; [AutofillAppInterface saveLocalCreditCard];
// Bring up the keyboard. // Bring up the keyboard.
[[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewMatcher()] [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewMatcher()]
performAction:TapWebElementWithId(kFormElementUsername)]; performAction:TapWebElementWithId(kFormElementUsername)];
// Wait for the accessory icon to appear. // Wait for the accessory icon to appear.
[GREYKeyboard waitForKeyboardToAppear]; GREYAssert(WaitForKeyboardToAppear(), @"Keyboard didn't appear.");
// Tap on the passwords icon. // Tap on the passwords icon.
[[EarlGrey selectElementWithMatcher:CreditCardIconMatcher()] [[EarlGrey selectElementWithMatcher:ManualFallbackCreditCardIconMatcher()]
performAction:grey_tap()]; performAction:grey_tap()];
// Verify the password controller table view is visible. // Verify the password controller table view is visible.
[[EarlGrey selectElementWithMatcher:CreditCardTableViewMatcher()] [[EarlGrey
selectElementWithMatcher:ManualFallbackCreditCardTableViewMatcher()]
assertWithMatcher:grey_sufficientlyVisible()]; assertWithMatcher:grey_sufficientlyVisible()];
// Select a field. // Select a field.
...@@ -713,5 +632,6 @@ BOOL WaitForJavaScriptCondition(NSString* java_script_condition) { ...@@ -713,5 +632,6 @@ BOOL WaitForJavaScriptCondition(NSString* java_script_condition) {
kFormElementUsername, result]; kFormElementUsername, result];
XCTAssertTrue(WaitForJavaScriptCondition(javaScriptCondition)); XCTAssertTrue(WaitForJavaScriptCondition(javaScriptCondition));
} }
#endif
@end @end
...@@ -134,6 +134,7 @@ source_set("eg2_tests") { ...@@ -134,6 +134,7 @@ source_set("eg2_tests") {
":feature_flags", ":feature_flags",
"//base", "//base",
"//ios/chrome/app/strings", "//ios/chrome/app/strings",
"//ios/chrome/browser/ui/autofill:eg_test_support+eg2",
"//ios/chrome/test/earl_grey:eg_test_support+eg2", "//ios/chrome/test/earl_grey:eg_test_support+eg2",
"//ios/testing/earl_grey:eg_test_support+eg2", "//ios/testing/earl_grey:eg_test_support+eg2",
"//ios/third_party/earl_grey2:test_lib", "//ios/third_party/earl_grey2:test_lib",
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
#include "base/ios/ios_util.h" #include "base/ios/ios_util.h"
#import "ios/chrome/browser/ui/autofill/autofill_app_interface.h"
#import "ios/chrome/browser/ui/settings/autofill/features.h" #import "ios/chrome/browser/ui/settings/autofill/features.h"
#include "ios/chrome/grit/ios_strings.h" #include "ios/chrome/grit/ios_strings.h"
#import "ios/chrome/test/earl_grey/chrome_earl_grey.h" #import "ios/chrome/test/earl_grey/chrome_earl_grey.h"
...@@ -107,7 +108,7 @@ id<GREYMatcher> CardNumberIconView(NSString* icon_type) { ...@@ -107,7 +108,7 @@ id<GREYMatcher> CardNumberIconView(NSString* icon_type) {
} }
- (void)tearDown { - (void)tearDown {
[ChromeEarlGrey clearCreditCards]; [AutofillAppInterface clearCreditCardStore];
[super tearDown]; [super tearDown];
} }
...@@ -230,7 +231,7 @@ id<GREYMatcher> CardNumberIconView(NSString* icon_type) { ...@@ -230,7 +231,7 @@ id<GREYMatcher> CardNumberIconView(NSString* icon_type) {
// and the new card number appears on the Autofill Credit Card 'Payment Methods' // and the new card number appears on the Autofill Credit Card 'Payment Methods'
// screen. // screen.
- (void)testAddButtonOnValidNumber { - (void)testAddButtonOnValidNumber {
[ChromeEarlGrey clearCreditCards]; [AutofillAppInterface clearCreditCardStore];
[[EarlGrey selectElementWithMatcher:CardNumberTextField()] [[EarlGrey selectElementWithMatcher:CardNumberTextField()]
performAction:grey_typeText(@"4111111111111111")]; performAction:grey_typeText(@"4111111111111111")];
[[EarlGrey selectElementWithMatcher:MonthOfExpiryTextField()] [[EarlGrey selectElementWithMatcher:MonthOfExpiryTextField()]
......
...@@ -370,11 +370,6 @@ id ExecuteJavaScript(NSString* javascript, NSError* __autoreleasing* out_error); ...@@ -370,11 +370,6 @@ id ExecuteJavaScript(NSString* javascript, NSError* __autoreleasing* out_error);
// doesn't specify a title. // doesn't specify a title.
- (NSString*)displayTitleForURL:(const GURL&)URL; - (NSString*)displayTitleForURL:(const GURL&)URL;
#pragma mark - Autofill Utilities (EG2)
// Removes the stored credit cards.
- (void)clearCreditCards;
#pragma mark - JavaScript Utilities (EG2) #pragma mark - JavaScript Utilities (EG2)
// Executes JavaScript on current WebState, and waits for either the completion // Executes JavaScript on current WebState, and waits for either the completion
......
...@@ -669,12 +669,6 @@ GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(ChromeEarlGreyAppInterface) ...@@ -669,12 +669,6 @@ GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(ChromeEarlGreyAppInterface)
return [ChromeEarlGreyAppInterface displayTitleForURL:spec]; return [ChromeEarlGreyAppInterface displayTitleForURL:spec];
} }
#pragma mark - Autofill Utilities (EG2)
- (void)clearCreditCards {
[ChromeEarlGreyAppInterface clearCreditCards];
}
#pragma mark - Accessibility Utilities (EG2) #pragma mark - Accessibility Utilities (EG2)
- (void)verifyAccessibilityForCurrentScreen { - (void)verifyAccessibilityForCurrentScreen {
......
...@@ -219,11 +219,6 @@ ...@@ -219,11 +219,6 @@
// doesn't specify a title. // doesn't specify a title.
+ (NSString*)displayTitleForURL:(NSString*)URL; + (NSString*)displayTitleForURL:(NSString*)URL;
#pragma mark - Autofill Utilities (EG2)
// Removes the stored credit cards.
+ (void)clearCreditCards;
#pragma mark - Sync Utilities (EG2) #pragma mark - Sync Utilities (EG2)
// Clears fake sync server data. // Clears fake sync server data.
......
...@@ -376,17 +376,6 @@ using chrome_test_util::BrowserCommandDispatcherForMainBVC; ...@@ -376,17 +376,6 @@ using chrome_test_util::BrowserCommandDispatcherForMainBVC;
web::GetDisplayTitleForUrl(GURL(base::SysNSStringToUTF8(URL)))); web::GetDisplayTitleForUrl(GURL(base::SysNSStringToUTF8(URL))));
} }
#pragma mark - Autofill Utilities (EG2)
+ (void)clearCreditCards {
autofill::PersonalDataManager* personalDataManager =
autofill::PersonalDataManagerFactory::GetForBrowserState(
chrome_test_util::GetOriginalBrowserState());
for (const auto* creditCard : personalDataManager->GetCreditCards()) {
personalDataManager->RemoveByGUID(creditCard->guid());
}
}
#pragma mark - Sync Utilities (EG2) #pragma mark - Sync Utilities (EG2)
+ (int)numberOfSyncEntitiesWithType:(syncer::ModelType)type { + (int)numberOfSyncEntitiesWithType:(syncer::ModelType)type {
......
...@@ -377,6 +377,9 @@ id<GREYMatcher> SettingsPasswordSearchMatcher(); ...@@ -377,6 +377,9 @@ id<GREYMatcher> SettingsPasswordSearchMatcher();
// Returns a matcher for the profiles settings collection view. // Returns a matcher for the profiles settings collection view.
id<GREYMatcher> SettingsProfileMatcher(); id<GREYMatcher> SettingsProfileMatcher();
// Returns a matcher for the credit card settings collection view.
id<GREYMatcher> SettingsCreditCardMatcher();
// Returns a matcher for an autofill suggestion view. // Returns a matcher for an autofill suggestion view.
id<GREYMatcher> AutofillSuggestionViewMatcher(); id<GREYMatcher> AutofillSuggestionViewMatcher();
...@@ -428,6 +431,23 @@ id<GREYMatcher> SettingsProfileMatcher(); ...@@ -428,6 +431,23 @@ id<GREYMatcher> SettingsProfileMatcher();
// Returns a matcher for the ProfileTableView window. // Returns a matcher for the ProfileTableView window.
id<GREYMatcher> ManualFallbackProfileTableViewWindowMatcher(); id<GREYMatcher> ManualFallbackProfileTableViewWindowMatcher();
// Returns a matcher for the credit card icon in the keyboard accessory bar.
id<GREYMatcher> ManualFallbackCreditCardIconMatcher();
// Returns a matcher for the credit card table view in manual fallback.
id<GREYMatcher> ManualFallbackCreditCardTableViewMatcher();
// Returns a matcher for the button to open password settings in manual
// fallback.
id<GREYMatcher> ManualFallbackManageCreditCardsMatcher();
// Returns a matcher for the button to add credit cards settings in manual
// fallback.
id<GREYMatcher> ManualFallbackAddCreditCardsMatcher();
// Returns a matcher for the CreditCardTableView window.
id<GREYMatcher> ManualFallbackCreditCardTableViewWindowMatcher();
} // namespace chrome_test_util } // namespace chrome_test_util
#endif // IOS_CHROME_TEST_EARL_GREY_CHROME_MATCHERS_H_ #endif // IOS_CHROME_TEST_EARL_GREY_CHROME_MATCHERS_H_
...@@ -471,6 +471,10 @@ id<GREYMatcher> SettingsProfileMatcher() { ...@@ -471,6 +471,10 @@ id<GREYMatcher> SettingsProfileMatcher() {
return [ChromeMatchersAppInterface settingsProfileMatcher]; return [ChromeMatchersAppInterface settingsProfileMatcher];
} }
id<GREYMatcher> SettingsCreditCardMatcher() {
return [ChromeMatchersAppInterface settingsCreditCardMatcher];
}
id<GREYMatcher> AutofillSuggestionViewMatcher() { id<GREYMatcher> AutofillSuggestionViewMatcher() {
return [ChromeMatchersAppInterface autofillSuggestionViewMatcher]; return [ChromeMatchersAppInterface autofillSuggestionViewMatcher];
} }
...@@ -536,4 +540,27 @@ id<GREYMatcher> ManualFallbackProfileTableViewWindowMatcher() { ...@@ -536,4 +540,27 @@ id<GREYMatcher> ManualFallbackProfileTableViewWindowMatcher() {
[ChromeMatchersAppInterface manualFallbackProfileTableViewWindowMatcher]; [ChromeMatchersAppInterface manualFallbackProfileTableViewWindowMatcher];
} }
id<GREYMatcher> ManualFallbackCreditCardIconMatcher() {
return [ChromeMatchersAppInterface manualFallbackCreditCardIconMatcher];
}
id<GREYMatcher> ManualFallbackCreditCardTableViewMatcher() {
return [ChromeMatchersAppInterface manualFallbackCreditCardTableViewMatcher];
}
// Returns a matcher for the button to open password settings in manual
id<GREYMatcher> ManualFallbackManageCreditCardsMatcher() {
return [ChromeMatchersAppInterface manualFallbackManageCreditCardsMatcher];
}
// Returns a matcher for the button to add credit cards settings in manual
id<GREYMatcher> ManualFallbackAddCreditCardsMatcher() {
return [ChromeMatchersAppInterface manualFallbackAddCreditCardsMatcher];
}
id<GREYMatcher> ManualFallbackCreditCardTableViewWindowMatcher() {
return [ChromeMatchersAppInterface
manualFallbackCreditCardTableViewWindowMatcher];
}
} // namespace chrome_test_util } // namespace chrome_test_util
...@@ -382,6 +382,9 @@ ...@@ -382,6 +382,9 @@
// Returns a matcher for the profiles settings collection view. // Returns a matcher for the profiles settings collection view.
+ (id<GREYMatcher>)settingsProfileMatcher; + (id<GREYMatcher>)settingsProfileMatcher;
// Returns a matcher for the credit card settings collection view.
+ (id<GREYMatcher>)settingsCreditCardMatcher;
// Returns a matcher for an autofill suggestion view. // Returns a matcher for an autofill suggestion view.
+ (id<GREYMatcher>)autofillSuggestionViewMatcher; + (id<GREYMatcher>)autofillSuggestionViewMatcher;
...@@ -430,6 +433,23 @@ ...@@ -430,6 +433,23 @@
// Returns a matcher for the ProfileTableView window. // Returns a matcher for the ProfileTableView window.
+ (id<GREYMatcher>)manualFallbackProfileTableViewWindowMatcher; + (id<GREYMatcher>)manualFallbackProfileTableViewWindowMatcher;
// Returns a matcher for the credit card icon in the keyboard accessory bar.
+ (id<GREYMatcher>)manualFallbackCreditCardIconMatcher;
// Returns a matcher for the credit card table view in manual fallback.
+ (id<GREYMatcher>)manualFallbackCreditCardTableViewMatcher;
// Returns a matcher for the button to open password settings in manual
// fallback.
+ (id<GREYMatcher>)manualFallbackManageCreditCardsMatcher;
// Returns a matcher for the button to add credit cards settings in manual
// fallback.
+ (id<GREYMatcher>)manualFallbackAddCreditCardsMatcher;
// Returns a matcher for the CreditCardTableView window.
+ (id<GREYMatcher>)manualFallbackCreditCardTableViewWindowMatcher;
@end @end
#endif // IOS_CHROME_TEST_EARL_GREY_CHROME_MATCHERS_APP_INTERFACE_H_ #endif // IOS_CHROME_TEST_EARL_GREY_CHROME_MATCHERS_APP_INTERFACE_H_
...@@ -11,6 +11,9 @@ ...@@ -11,6 +11,9 @@
#import "ios/chrome/browser/ui/authentication/cells/signin_promo_view.h" #import "ios/chrome/browser/ui/authentication/cells/signin_promo_view.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/address_mediator.h" #import "ios/chrome/browser/ui/autofill/manual_fill/address_mediator.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/address_view_controller.h" #import "ios/chrome/browser/ui/autofill/manual_fill/address_view_controller.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/card_coordinator.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/card_mediator.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/card_view_controller.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/manual_fill_accessory_view_controller.h" #import "ios/chrome/browser/ui/autofill/manual_fill/manual_fill_accessory_view_controller.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/manual_fill_password_cell.h" #import "ios/chrome/browser/ui/autofill/manual_fill/manual_fill_password_cell.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/manual_fill_password_mediator.h" #import "ios/chrome/browser/ui/autofill/manual_fill/manual_fill_password_mediator.h"
...@@ -748,6 +751,10 @@ UIView* SubviewWithAccessibilityIdentifier(NSString* accessibility_id, ...@@ -748,6 +751,10 @@ UIView* SubviewWithAccessibilityIdentifier(NSString* accessibility_id,
return grey_accessibilityID(kAutofillProfileTableViewID); return grey_accessibilityID(kAutofillProfileTableViewID);
} }
+ (id<GREYMatcher>)settingsCreditCardMatcher {
return grey_accessibilityID(kAutofillCreditCardTableViewId);
}
+ (id<GREYMatcher>)autofillSuggestionViewMatcher { + (id<GREYMatcher>)autofillSuggestionViewMatcher {
return grey_accessibilityID(kFormSuggestionLabelAccessibilityIdentifier); return grey_accessibilityID(kFormSuggestionLabelAccessibilityIdentifier);
} }
...@@ -825,4 +832,31 @@ UIView* SubviewWithAccessibilityIdentifier(NSString* accessibility_id, ...@@ -825,4 +832,31 @@ UIView* SubviewWithAccessibilityIdentifier(NSString* accessibility_id,
grey_descendant([self manualFallbackProfilesTableViewMatcher]); grey_descendant([self manualFallbackProfilesTableViewMatcher]);
return grey_allOf(classMatcher, parentMatcher, nil); return grey_allOf(classMatcher, parentMatcher, nil);
} }
+ (id<GREYMatcher>)manualFallbackCreditCardIconMatcher {
return grey_accessibilityID(
manual_fill::AccessoryCreditCardAccessibilityIdentifier);
}
+ (id<GREYMatcher>)manualFallbackCreditCardTableViewMatcher {
return grey_accessibilityID(
manual_fill::CardTableViewAccessibilityIdentifier);
}
+ (id<GREYMatcher>)manualFallbackManageCreditCardsMatcher {
return grey_accessibilityID(manual_fill::ManageCardsAccessibilityIdentifier);
}
+ (id<GREYMatcher>)manualFallbackAddCreditCardsMatcher {
return grey_accessibilityID(
manual_fill::kAddCreditCardsAccessibilityIdentifier);
}
+ (id<GREYMatcher>)manualFallbackCreditCardTableViewWindowMatcher {
id<GREYMatcher> classMatcher = grey_kindOfClass([UIWindow class]);
id<GREYMatcher> parentMatcher =
grey_descendant([self manualFallbackCreditCardTableViewMatcher]);
return grey_allOf(classMatcher, parentMatcher, nil);
}
@end @end
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