Commit aeed64d2 authored by Randall Raymond's avatar Randall Raymond Committed by Commit Bot

[Payment Request] Adds tests for accessibility & Moves PR EG tests into its own target

Because the original CL for this got reverted multiple times due to issues with working
with the build bots, the original CL has combined with a second CL (both described
below) such that the second CL moves the accessibility tests to a separate component.

From first CL:
- Adds html and js files for testing accessibility in Payment Request
- CL link: https://chromium-review.googlesource.com/c/578135
- Author: rayraymond

From second CL:
- Creates a new target, ios_chrome_payments_egtests, for Payment Request
  EG tests, in expectation of a dozen coming tests.
- Makes the target depend on the Payment Request test data in
  components/test/data/payments
- CL link: https://chromium-review.googlesource.com/c/575206
- Author: mahmadi

TBR=eugenebut@,lpromero@,michaeldo@,sdefresne@,eisinger@

Bug: 734571
Change-Id: I2a1213018dca57e14301b7188ac092ab9ff2ae56
Reviewed-on: https://chromium-review.googlesource.com/579647
Commit-Queue: Randall Raymond <rayraymond@google.com>
Reviewed-by: default avatarmahmadi <mahmadi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#488313}
parent 5a278665
......@@ -115,3 +115,99 @@ source_set("unit_tests") {
"//ui/base",
]
}
bundle_data("payments_test_bundle_data") {
testonly = true
sources = [
"//components/test/data/payments/abort.js",
"//components/test/data/payments/alicepay_bobpay_charliepay_and_cards.js",
"//components/test/data/payments/app.json",
"//components/test/data/payments/blob_url.js",
"//components/test/data/payments/bobpay.js",
"//components/test/data/payments/bobpay_and_basic_card_with_basic_card_modifiers.js",
"//components/test/data/payments/bobpay_and_basic_card_with_modifiers.js",
"//components/test/data/payments/bobpay_and_cards.js",
"//components/test/data/payments/bobpay_ui_skip.js",
"//components/test/data/payments/bobpay_ui_skip_preload.js",
"//components/test/data/payments/can_make_payment_metrics.js",
"//components/test/data/payments/can_make_payment_query.js",
"//components/test/data/payments/can_make_payment_query_bobpay.js",
"//components/test/data/payments/can_make_payment_query_cc.js",
"//components/test/data/payments/contact_details.js",
"//components/test/data/payments/contact_details_and_free_shipping.js",
"//components/test/data/payments/debit.js",
"//components/test/data/payments/dynamic_shipping.js",
"//components/test/data/payments/email.js",
"//components/test/data/payments/email_and_free_shipping.js",
"//components/test/data/payments/email_and_phone.js",
"//components/test/data/payments/extra_shipping_options.js",
"//components/test/data/payments/fail_complete.js",
"//components/test/data/payments/free_shipping.js",
"//components/test/data/payments/initiated.js",
"//components/test/data/payments/initiated_test.html",
"//components/test/data/payments/long_id.js",
"//components/test/data/payments/metrics.js",
"//components/test/data/payments/modifier.js",
"//components/test/data/payments/multiple_show.js",
"//components/test/data/payments/name.js",
"//components/test/data/payments/name_and_free_shipping.js",
"//components/test/data/payments/no_shipping.js",
"//components/test/data/payments/payment-manifest.json",
"//components/test/data/payments/payment_method_identifier.js",
"//components/test/data/payments/payment_request.html",
"//components/test/data/payments/payment_request.js",
"//components/test/data/payments/payment_request_abort_test.html",
"//components/test/data/payments/payment_request_alicepay_bobpay_charliepay_and_cards_test.html",
"//components/test/data/payments/payment_request_blob_url_test.html",
"//components/test/data/payments/payment_request_bobpay_and_basic_card_with_basic_card_modifiers_test.html",
"//components/test/data/payments/payment_request_bobpay_and_basic_card_with_modifiers_test.html",
"//components/test/data/payments/payment_request_bobpay_and_cards_test.html",
"//components/test/data/payments/payment_request_bobpay_test.html",
"//components/test/data/payments/payment_request_bobpay_ui_skip_preload_test.html",
"//components/test/data/payments/payment_request_bobpay_ui_skip_test.html",
"//components/test/data/payments/payment_request_can_make_payment_metrics_test.html",
"//components/test/data/payments/payment_request_can_make_payment_query_bobpay_test.html",
"//components/test/data/payments/payment_request_can_make_payment_query_cc_test.html",
"//components/test/data/payments/payment_request_can_make_payment_query_test.html",
"//components/test/data/payments/payment_request_contact_details_and_free_shipping_test.html",
"//components/test/data/payments/payment_request_contact_details_test.html",
"//components/test/data/payments/payment_request_debit_test.html",
"//components/test/data/payments/payment_request_dynamic_shipping_test.html",
"//components/test/data/payments/payment_request_email_and_free_shipping_test.html",
"//components/test/data/payments/payment_request_email_and_phone_test.html",
"//components/test/data/payments/payment_request_email_test.html",
"//components/test/data/payments/payment_request_extra_shipping_options_test.html",
"//components/test/data/payments/payment_request_fail_complete_test.html",
"//components/test/data/payments/payment_request_free_shipping_test.html",
"//components/test/data/payments/payment_request_id.js",
"//components/test/data/payments/payment_request_id_test.html",
"//components/test/data/payments/payment_request_iframe.html",
"//components/test/data/payments/payment_request_long_id_test.html",
"//components/test/data/payments/payment_request_main.html",
"//components/test/data/payments/payment_request_metrics_test.html",
"//components/test/data/payments/payment_request_modifier_test.html",
"//components/test/data/payments/payment_request_multiple_requests.html",
"//components/test/data/payments/payment_request_multiple_show_test.html",
"//components/test/data/payments/payment_request_name_and_free_shipping_test.html",
"//components/test/data/payments/payment_request_name_test.html",
"//components/test/data/payments/payment_request_no_shipping_test.html",
"//components/test/data/payments/payment_request_payment_method_identifier_test.html",
"//components/test/data/payments/payment_request_phone_and_free_shipping_test.html",
"//components/test/data/payments/payment_request_phone_test.html",
"//components/test/data/payments/payment_request_shipping_address_change_test.html",
"//components/test/data/payments/payment_request_show_twice_test.html",
"//components/test/data/payments/phone.js",
"//components/test/data/payments/phone_and_free_shipping.js",
"//components/test/data/payments/shipping_address_change.js",
"//components/test/data/payments/show_twice.js",
"//components/test/data/payments/style.css",
"//components/test/data/payments/util.js",
"//components/test/data/payments/webpay",
"//components/test/data/payments/webpay.mock-http-headers",
]
outputs = [
"{{bundle_resources_dir}}/" +
"{{source_root_relative_dir}}/{{source_file_part}}",
]
}
<!doctype html>
<!-- Copyright 2017 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. -->
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>US-only delivery with e-mail address</title>
</head>
<body>
<div id="contents">
<h1>Worldwide multi-option shipping</h1>
<p>This merchant provides multiple shipping options worldwide, independent of the shipping address. No payment will be processed.</p>
<p>Price: USD <strong>$55.00</strong></p>
<p><button id="buy" onclick="onBuyClicked()">Buy</button></p>
</div>
<pre id="msg"></pre>
<script src="payment_request.js"></script>
</body>
</html>
\ No newline at end of file
// Copyright 2017 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.
/**
* Updates the price based on the selected shipping option.
* @param {object} details - The current details to update.
* @param {string} shippingOption - The shipping option selected by user.
* @return {object} The updated details.
*/
function updateDetails(details, shippingOption) {
var selectedShippingOption;
var otherShippingOption;
if (shippingOption === 'standard') {
selectedShippingOption = details.shippingOptions[0];
otherShippingOption = details.shippingOptions[1];
details.total.amount.value = '55.00';
} else {
selectedShippingOption = details.shippingOptions[1];
otherShippingOption = details.shippingOptions[0];
details.total.amount.value = '67.00';
}
if (details.displayItems.length === 2) {
details.displayItems.splice(1, 0, selectedShippingOption);
} else {
details.displayItems.splice(1, 1, selectedShippingOption);
}
selectedShippingOption.selected = true;
otherShippingOption.selected = false;
return details;
}
/**
* Launches payment request that provides multiple shipping options worldwide,
* regardless of the shipping address.
*/
function onBuyClicked() { // eslint-disable-line no-unused-vars
var supportedInstruments = [
{
supportedMethods: ['https://android.com/pay'],
data: {
merchantName: 'Rouslan Solomakhin',
merchantId: '00184145120947117657',
allowedCardNetworks: ['AMEX', 'MASTERCARD', 'VISA', 'DISCOVER'],
paymentMethodTokenizationParameters: {
tokenizationType: 'GATEWAY_TOKEN',
parameters: {
'gateway': 'stripe',
'stripe:publishableKey': 'pk_live_lNk21zqKM2BENZENh3rzCUgo',
'stripe:version': '2016-07-06',
},
},
},
},
{
supportedMethods: ['basic-card'],
},
];
var details = {
total: {
label: 'Donation',
amount: {
currency: 'USD',
value: '55.00',
},
},
displayItems: [
{
label: 'Original donation amount',
amount: {
currency: 'USD',
value: '65.00',
},
},
{
label: 'Friends and family discount',
amount: {
currency: 'USD',
value: '-10.00',
},
},
],
shippingOptions: [
{
id: 'standard',
label: 'Standard shipping',
amount: {
currency: 'USD',
value: '0.00',
},
selected: true,
},
{
id: 'express',
label: 'Express shipping',
amount: {
currency: 'USD',
value: '12.00',
},
},
],
};
var options = {
requestShipping: true,
requestPayerName: true,
requestPayerPhone: true,
requestPayerEmail: true,
};
if (!window.PaymentRequest) {
error('PaymentRequest API is not supported.');
return;
}
try {
var request = new PaymentRequest(supportedInstruments, details, options);
request.addEventListener('shippingaddresschange', function(e) {
e.updateWith(new Promise(function(resolve) {
window.setTimeout(function() {
// No changes in price based on shipping address change.
resolve(details);
}, 2000);
}));
});
request.addEventListener('shippingoptionchange', function(e) {
e.updateWith(new Promise(function(resolve) {
resolve(updateDetails(details, request.shippingOption));
}));
});
request.show()
.then(function(instrumentResponse) {
window.setTimeout(function() {
instrumentResponse.complete('success')
.then(function() {
done(
'This is a demo website. No payment will be processed.',
instrumentResponse);
})
.catch(function(err) {
error(err);
});
}, 2000);
})
.catch(function(err) {
error(err);
});
} catch (e) {
error('Developer mistake: \'' + e.message + '\'');
}
}
......@@ -21,6 +21,16 @@
"xcode version": "8.0",
"xctest": true
},
{
"app": "ios_chrome_payments_egtests",
"test args": [
"--enable-features=WebPayments"
],
"device type": "iPhone 6s",
"os": "10.0",
"xcode version": "8.0",
"xctest": true
},
{
"app": "ios_chrome_reading_list_egtests",
"test args": [
......@@ -80,6 +90,16 @@
"xcode version": "8.0",
"xctest": true
},
{
"app": "ios_chrome_payments_egtests",
"test args": [
"--enable-features=WebPayments"
],
"device type": "iPad Air 2",
"os": "10.0",
"xcode version": "8.0",
"xctest": true
},
{
"app": "ios_chrome_reading_list_egtests",
"test args": [
......
......@@ -21,6 +21,16 @@
"xcode version": "8.0",
"xctest": true
},
{
"app": "ios_chrome_payments_egtests",
"test args": [
"--enable-features=WebPayments"
],
"device type": "iPhone 6s",
"os": "10.0",
"xcode version": "8.0",
"xctest": true
},
{
"app": "ios_chrome_reading_list_egtests",
"test args": [
......@@ -80,6 +90,16 @@
"xcode version": "8.0",
"xctest": true
},
{
"app": "ios_chrome_payments_egtests",
"test args": [
"--enable-features=WebPayments"
],
"device type": "iPad Air 2",
"os": "10.0",
"xcode version": "8.0",
"xctest": true
},
{
"app": "ios_chrome_reading_list_egtests",
"test args": [
......
......@@ -216,3 +216,34 @@ source_set("unit_tests") {
"//ui/base",
]
}
source_set("eg_tests") {
configs += [ "//build/config/compiler:enable_arc" ]
testonly = true
sources = [
"payments_accessibility_egtest.mm",
]
deps = [
":payments_ui",
"//base",
"//components/autofill/core/browser",
"//components/autofill/core/browser:test_support",
"//components/payments/core",
"//components/strings",
"//ios/chrome/app:app_internal",
"//ios/chrome/browser/autofill",
"//ios/chrome/browser/payments",
"//ios/chrome/browser/ui/payments/cells",
"//ios/chrome/browser/ui/tools_menu",
"//ios/chrome/test/app:test_support",
"//ios/chrome/test/earl_grey:test_support",
"//ios/testing/earl_grey:earl_grey_support",
"//ios/third_party/material_components_ios",
"//ios/web/public/test/http_server",
]
libs = [
"UIKit.framework",
"XCTest.framework",
]
}
// Copyright 2017 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 <XCTest/XCTest.h>
#include "base/strings/sys_string_conversions.h"
#include "components/autofill/core/browser/autofill_profile.h"
#include "components/autofill/core/browser/autofill_test_utils.h"
#include "components/autofill/core/browser/personal_data_manager.h"
#include "components/strings/grit/components_strings.h"
#include "ios/chrome/browser/autofill/personal_data_manager_factory.h"
#include "ios/chrome/browser/payments/payment_request_util.h"
#import "ios/chrome/browser/ui/payments/cells/payments_text_item.h"
#import "ios/chrome/browser/ui/payments/cells/price_item.h"
#import "ios/chrome/browser/ui/payments/payment_request_view_controller.h"
#import "ios/chrome/test/app/chrome_test_util.h"
#import "ios/chrome/test/app/web_view_interaction_test_util.h"
#import "ios/chrome/test/earl_grey/accessibility_util.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_test_case.h"
#import "ios/web/public/test/http_server/http_server.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
using chrome_test_util::ButtonWithAccessibilityLabel;
using chrome_test_util::ButtonWithAccessibilityLabelId;
using payment_request_util::GetAddressNotificationLabelFromAutofillProfile;
using payment_request_util::GetEmailLabelFromAutofillProfile;
using payment_request_util::GetNameLabelFromAutofillProfile;
using payment_request_util::GetPhoneNumberLabelFromAutofillProfile;
using payment_request_util::GetShippingAddressLabelFromAutofillProfile;
// Displacement for scroll action.
const CGFloat kScrollDisplacement = 100.0;
// URL of the Payment Request test page.
const char kPaymentRequestDemoPage[] =
"http://components/test/data/payments/payment_request.html";
// Finds the shipping address cell on the Payment Summary page.
id<GREYMatcher> ShippingAddressCellMatcher(autofill::AutofillProfile* profile) {
NSString* email_label = nil;
NSString* notification_label = nil;
return chrome_test_util::ButtonWithAccessibilityLabel([NSString
stringWithFormat:@"%@, %@, %@, %@, %@",
GetNameLabelFromAutofillProfile(*profile),
GetShippingAddressLabelFromAutofillProfile(*profile),
GetPhoneNumberLabelFromAutofillProfile(*profile),
email_label, notification_label]);
}
// Finds the payment method cell on the Payment Summary page.
id<GREYMatcher> PaymentMethodCellMatcher(autofill::CreditCard* credit_card) {
NSString* billing_address_label = nil;
NSString* notification_label = nil;
return chrome_test_util::ButtonWithAccessibilityLabel([NSString
stringWithFormat:@"%@, %@, %@, %@",
base::SysUTF16ToNSString(
credit_card->NetworkAndLastFourDigits()),
base::SysUTF16ToNSString(credit_card->GetRawInfo(
autofill::CREDIT_CARD_NAME_FULL)),
billing_address_label, notification_label]);
}
// Finds the order summary cell on the Payment Summary page.
id<GREYMatcher> PriceCellMatcher(NSString* main_label, NSString* price_label) {
NSString* notification_label = nil;
return chrome_test_util::ButtonWithAccessibilityLabel(
[NSString stringWithFormat:@"%@, %@, %@", main_label, notification_label,
price_label]);
}
// Finds the shipping option cell on the Payment Summary page.
id<GREYMatcher> ShippingOptionCellMatcher(NSString* main_label,
NSString* detail_label) {
return chrome_test_util::ButtonWithAccessibilityLabel(
[NSString stringWithFormat:@"%@, %@", main_label, detail_label]);
}
// Finds the contact info cell on the Payment Summary page.
id<GREYMatcher> ContactInfoCellMatcher(autofill::AutofillProfile* profile) {
NSString* address_label = nil;
NSString* notification_label = nil;
return chrome_test_util::ButtonWithAccessibilityLabel([NSString
stringWithFormat:@"%@, %@, %@, %@, %@",
GetNameLabelFromAutofillProfile(*profile), address_label,
GetPhoneNumberLabelFromAutofillProfile(*profile),
GetEmailLabelFromAutofillProfile(*profile),
notification_label]);
}
} // namespace
// Various tests for Payment Request.
@interface PaymentRequestTestCase : ChromeTestCase
@end
@implementation PaymentRequestTestCase {
autofill::AutofillProfile _profile;
autofill::CreditCard _creditCard1;
autofill::CreditCard _creditCard2;
GURL _testURL;
}
#pragma mark - XCTest.
// Set up called once before each test.
- (void)setUp {
[super setUp];
autofill::PersonalDataManager* personalDataManager =
autofill::PersonalDataManagerFactory::GetForBrowserState(
chrome_test_util::GetOriginalBrowserState());
_profile = autofill::test::GetFullProfile();
_creditCard1 = autofill::test::GetCreditCard();
_creditCard2 = autofill::test::GetCreditCard2();
personalDataManager->AddProfile(_profile);
_creditCard1.set_billing_address_id(_profile.guid());
personalDataManager->AddCreditCard(_creditCard1);
personalDataManager->AddCreditCard(_creditCard2);
_testURL = web::test::HttpServer::MakeUrl(kPaymentRequestDemoPage);
}
#pragma mark - Tests.
// Tests accessibility on the Payment Request summary page.
- (void)testAccessibilityOnPaymentRequestSummaryPage {
[ChromeEarlGrey loadURL:_testURL];
// Tap the buy button.
chrome_test_util::TapWebViewElementWithId("buy");
chrome_test_util::VerifyAccessibilityForCurrentScreen();
}
// Tests accessibility on the Payment Request order summary page.
- (void)testAccessibilityOnPaymentRequestOrderSummaryPage {
[ChromeEarlGrey loadURL:_testURL];
// Tap the buy button.
chrome_test_util::TapWebViewElementWithId("buy");
[[EarlGrey
selectElementWithMatcher:PriceCellMatcher(@"Donation", @"USD $55.00")]
performAction:grey_tap()];
chrome_test_util::VerifyAccessibilityForCurrentScreen();
}
// Tests accessibility on the Payment Request delivery address page.
- (void)testAccessibilityOnPaymentRequestDeliveryAddressPage {
[ChromeEarlGrey loadURL:_testURL];
// Tap the buy button.
chrome_test_util::TapWebViewElementWithId("buy");
[[EarlGrey selectElementWithMatcher:ShippingAddressCellMatcher(&_profile)]
performAction:grey_tap()];
chrome_test_util::VerifyAccessibilityForCurrentScreen();
}
// Tests accessibility on the Payment Request delivery method page.
- (void)testAccessibilityOnPaymentRequestDeliveryMethodPage {
[ChromeEarlGrey loadURL:_testURL];
// Tap the buy button.
chrome_test_util::TapWebViewElementWithId("buy");
[[EarlGrey selectElementWithMatcher:ShippingOptionCellMatcher(
@"Standard shipping", @"$0.00")]
performAction:grey_tap()];
chrome_test_util::VerifyAccessibilityForCurrentScreen();
}
// Tests accessibility on the Payment Request payment method page.
- (void)testAccessibilityOnPaymentRequestPaymentMethodPage {
[ChromeEarlGrey loadURL:_testURL];
// Tap the buy button.
chrome_test_util::TapWebViewElementWithId("buy");
[[[EarlGrey selectElementWithMatcher:PaymentMethodCellMatcher(&_creditCard1)]
usingSearchAction:grey_scrollInDirection(kGREYDirectionDown,
kScrollDisplacement)
onElementWithMatcher:grey_accessibilityID(
kPaymentRequestCollectionViewID)]
performAction:grey_tap()];
chrome_test_util::VerifyAccessibilityForCurrentScreen();
}
// Tests accessibility on the Payment Request contact info page.
- (void)testAccessibilityOnPaymentRequestContactInfoPage {
[ChromeEarlGrey loadURL:_testURL];
// Tap the buy button.
chrome_test_util::TapWebViewElementWithId("buy");
[[[EarlGrey selectElementWithMatcher:ContactInfoCellMatcher(&_profile)]
usingSearchAction:grey_scrollInDirection(kGREYDirectionDown,
kScrollDisplacement)
onElementWithMatcher:grey_accessibilityID(
kPaymentRequestCollectionViewID)]
performAction:grey_tap()];
chrome_test_util::VerifyAccessibilityForCurrentScreen();
}
@end
......@@ -31,6 +31,14 @@ chrome_ios_eg_test("ios_chrome_integration_egtests") {
]
}
chrome_ios_eg_test("ios_chrome_payments_egtests") {
deps = [
":test_support",
"//components/payments/core:payments_test_bundle_data",
"//ios/chrome/browser/ui/payments:eg_tests",
]
}
chrome_ios_eg_test("ios_chrome_reading_list_egtests") {
deps = [
":test_support",
......
......@@ -543,6 +543,13 @@
"type": "raw",
"args": [],
},
"ios_chrome_payments_egtests": {
"label": "//ios/chrome/test/earl_grey:ios_chrome_payments_egtests",
"type": "raw",
"args": [
"--enable-features=WebPayments",
],
},
"ios_chrome_reading_list_egtests": {
"label": "//ios/chrome/test/earl_grey:ios_chrome_reading_list_egtests",
"type": "raw",
......
......@@ -99,6 +99,7 @@ SKIP_GN_ISOLATE_MAP_TARGETS = {
# iOS tests are listed in //ios/build/bots.
'cronet_test',
'ios_chrome_integration_egtests',
'ios_chrome_payments_egtests',
'ios_chrome_reading_list_egtests',
'ios_chrome_settings_egtests',
'ios_chrome_smoke_egtests',
......
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