AX: Automatically compute accessibility labels for Apple Pay buttons
authorcfleizach@apple.com <cfleizach@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 9 Apr 2019 00:58:19 +0000 (00:58 +0000)
committercfleizach@apple.com <cfleizach@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 9 Apr 2019 00:58:19 +0000 (00:58 +0000)
https://bugs.webkit.org/show_bug.cgi?id=196661

Reviewed by Joanmarie Diggs.

Source/WebCore:

Detect Apple Pay buttons and return a standard role and label for them based on their type.

Test: accessibility/mac/apple-pay-labels.html
      accessibility/mac/apple-pay-session-v4.html

* accessibility/AccessibilityNodeObject.cpp:
(WebCore::AccessibilityNodeObject::isControl const):
* accessibility/AccessibilityNodeObject.h:
* accessibility/AccessibilityRenderObject.cpp:
(WebCore::AccessibilityRenderObject::applePayButtonDescription const):
(WebCore::AccessibilityRenderObject::titleElementText const):
(WebCore::AccessibilityRenderObject::determineAccessibilityRole):
(WebCore::AccessibilityRenderObject::isApplePayButton const):
(WebCore::AccessibilityRenderObject::applePayButtonType const):
* accessibility/AccessibilityRenderObject.h:
* en.lproj/Localizable.strings:
* platform/LocalizedStrings.cpp:
(WebCore::AXApplePayPlainLabel):
(WebCore::AXApplePayBuyLabel):
(WebCore::AXApplePaySetupLabel):
(WebCore::AXApplePayDonateLabel):
(WebCore::AXApplePayCheckOutLabel):
(WebCore::AXApplePayBookLabel):
(WebCore::AXApplePaySubscribeLabel):
* platform/LocalizedStrings.h:

LayoutTests:

* accessibility/mac/apple-pay-labels-expected.txt: Added.
* accessibility/mac/apple-pay-labels.html: Added.
* accessibility/mac/apple-pay-session-v4-expected.txt: Added.
* accessibility/mac/apple-pay-session-v4.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@244061 268f45cc-cd09-0410-ab3c-d52691b4dbfc

15 files changed:
LayoutTests/ChangeLog
LayoutTests/accessibility/mac/apple-pay-labels-expected.txt [new file with mode: 0644]
LayoutTests/accessibility/mac/apple-pay-labels.html [new file with mode: 0644]
LayoutTests/accessibility/mac/apple-pay-session-v4-expected.txt [new file with mode: 0644]
LayoutTests/accessibility/mac/apple-pay-session-v4.html [new file with mode: 0644]
LayoutTests/platform/mac-wk1/TestExpectations
LayoutTests/platform/mac-wk2/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/accessibility/AccessibilityNodeObject.cpp
Source/WebCore/accessibility/AccessibilityNodeObject.h
Source/WebCore/accessibility/AccessibilityRenderObject.cpp
Source/WebCore/accessibility/AccessibilityRenderObject.h
Source/WebCore/en.lproj/Localizable.strings
Source/WebCore/platform/LocalizedStrings.cpp
Source/WebCore/platform/LocalizedStrings.h

index ef0535b..4125b73 100644 (file)
@@ -1,3 +1,15 @@
+2019-04-08  Chris Fleizach  <cfleizach@apple.com>
+
+        AX: Automatically compute accessibility labels for Apple Pay buttons
+        https://bugs.webkit.org/show_bug.cgi?id=196661
+
+        Reviewed by Joanmarie Diggs.
+
+        * accessibility/mac/apple-pay-labels-expected.txt: Added.
+        * accessibility/mac/apple-pay-labels.html: Added.
+        * accessibility/mac/apple-pay-session-v4-expected.txt: Added.
+        * accessibility/mac/apple-pay-session-v4.html: Added.
+
 2019-04-08  Youenn Fablet  <youenn@apple.com>
 
         Add a test to check for the service worker process name
diff --git a/LayoutTests/accessibility/mac/apple-pay-labels-expected.txt b/LayoutTests/accessibility/mac/apple-pay-labels-expected.txt
new file mode 100644 (file)
index 0000000..f40ccc2
--- /dev/null
@@ -0,0 +1,9 @@
+PASS plain.role is 'AXRole: AXButton'
+PASS plain.description is 'AXDescription: Apple Pay'
+PASS buy.description is 'AXDescription: Buy with Apple Pay'
+PASS donate.description is 'AXDescription: Donate with Apple Pay'
+PASS setup.description is 'AXDescription: Set up with Apple Pay'
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/accessibility/mac/apple-pay-labels.html b/LayoutTests/accessibility/mac/apple-pay-labels.html
new file mode 100644 (file)
index 0000000..e3e4bd9
--- /dev/null
@@ -0,0 +1,30 @@
+<html>
+<html>
+<head>
+<script src='../../resources/js-test-pre.js'></script>
+</head>
+<body id='body'>
+
+    <div id="plain" style="-webkit-appearance: -apple-pay-button; -apple-pay-button-type: plain;"></div>
+    <div id="buy" style="-webkit-appearance: -apple-pay-button; -apple-pay-button-type: buy;"></div>
+    <div id="donate" style="-webkit-appearance: -apple-pay-button; -apple-pay-button-type: donate;"></div>
+    <div id="setup" style="-webkit-appearance: -apple-pay-button; -apple-pay-button-type: set-up;"></div>
+
+
+    <script>
+        if (window.accessibilityController) {
+            var plain = accessibilityController.accessibleElementById("plain");
+            var buy = accessibilityController.accessibleElementById("buy");
+            var donate = accessibilityController.accessibleElementById("donate");
+            var setup = accessibilityController.accessibleElementById("setup");
+
+            shouldBe("plain.role", "'AXRole: AXButton'");
+            shouldBe("plain.description", "'AXDescription: Apple Pay'");
+            shouldBe("buy.description", "'AXDescription: Buy with Apple Pay'");
+            shouldBe("donate.description", "'AXDescription: Donate with Apple Pay'");
+            shouldBe("setup.description", "'AXDescription: Set up with Apple Pay'");
+        }
+    </script>
+<script src='../../resources/js-test-post.js'></script>
+</body>
+</html>
diff --git a/LayoutTests/accessibility/mac/apple-pay-session-v4-expected.txt b/LayoutTests/accessibility/mac/apple-pay-session-v4-expected.txt
new file mode 100644 (file)
index 0000000..54311d5
--- /dev/null
@@ -0,0 +1,7 @@
+PASS book.description is 'AXDescription: Book with Apple Pay'
+PASS checkout.description is 'AXDescription: Check out with Apple Pay'
+PASS subscribe.description is 'AXDescription: Subscribe with Apple Pay'
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/accessibility/mac/apple-pay-session-v4.html b/LayoutTests/accessibility/mac/apple-pay-session-v4.html
new file mode 100644 (file)
index 0000000..2aaa6ca
--- /dev/null
@@ -0,0 +1,26 @@
+<html>
+<html>
+<head>
+<script src='../../resources/js-test-pre.js'></script>
+</head>
+<body id='body'>
+
+    <div id="book" style="-webkit-appearance: -apple-pay-button; -apple-pay-button-type: book;"></div>
+    <div id="checkout" style="-webkit-appearance: -apple-pay-button; -apple-pay-button-type: check-out;"></div>
+    <div id="subscribe" style="-webkit-appearance: -apple-pay-button; -apple-pay-button-type: subscribe;"></div>
+
+
+    <script>
+        if (window.accessibilityController) {
+            var book = accessibilityController.accessibleElementById("book");
+            var checkout = accessibilityController.accessibleElementById("checkout");
+            var subscribe = accessibilityController.accessibleElementById("subscribe");
+
+            shouldBe("book.description", "'AXDescription: Book with Apple Pay'");
+            shouldBe("checkout.description", "'AXDescription: Check out with Apple Pay'");
+            shouldBe("subscribe.description", "'AXDescription: Subscribe with Apple Pay'");
+        }
+    </script>
+<script src='../../resources/js-test-post.js'></script>
+</body>
+</html>
index 5ae5a16..fa72769 100644 (file)
@@ -62,6 +62,9 @@ imported/w3c/web-platform-tests/html/semantics/forms/the-datalist-element [ Wont
 # ShouldOpenExternalURLs not yet supported in WK1
 loader/navigation-policy [ Skip ]
 
+[ Sierra ] accessibility/mac/apple-pay-labels.html [ Skip ]
+[ HighSierra ] accessibility/mac/apple-pay-session-v4.html [ Skip ]
+
 # <a download> is not supported in WK1 yet.
 webkit.org/b/156069 fast/dom/HTMLAnchorElement/anchor-nodownload-set.html [ Failure ]
 webkit.org/b/156069 fast/dom/HTMLAnchorElement/anchor-download.html [ Failure ]
@@ -703,4 +706,4 @@ webkit.org/b/159724 [ Debug ] imported/w3c/web-platform-tests/xhr/send-redirect-
 
 webkit.org/b/196448 [ Debug ] inspector/audit/basic.html [ Pass Timeout ]
 
-webkit.org/b/196502 media/video-background-tab-playback.html [ Pass Failure ]
\ No newline at end of file
+webkit.org/b/196502 media/video-background-tab-playback.html [ Pass Failure ]
index 0ede89c..7523298 100644 (file)
@@ -33,9 +33,11 @@ fast/media/mq-prefers-reduced-motion-live-update.html [ Pass ]
 [ Sierra ] http/tests/ssl/applepay/ApplePaySessionV5.html [ Skip ]
 [ Sierra ] http/tests/ssl/applepay/ApplePayRequestShippingContactV3.https.html [ Skip ]
 [ Sierra ] http/tests/ssl/applepay/ApplePayShippingAddressChangeEventErrorsV3.https.html [ Skip ]
+[ Sierra ] accessibility/mac/apple-pay-labels.html [ Skip ]
 [ HighSierra ] http/tests/ssl/applepay/ApplePayButtonV4.html [ Skip ]
 [ HighSierra ] http/tests/ssl/applepay/ApplePaySessionV4.html [ Skip ]
 [ HighSierra ] http/tests/ssl/applepay/ApplePaySessionV5.html [ Skip ]
+[ HighSierra ] accessibility/mac/apple-pay-session-v4.html [ Skip ]
 
 fast/visual-viewport/rubberbanding-viewport-rects.html [ Pass ]
 fast/visual-viewport/rubberbanding-viewport-rects-header-footer.html  [ Pass ]
@@ -775,6 +777,8 @@ webkit.org/b/185994 fast/text/user-installed-fonts/shadow-postscript-family.html
 [ Mojave+ ] http/tests/ssl/applepay/ApplePaySessionV5.html [ Pass ]
 [ HighSierra+ ] http/tests/ssl/applepay/ApplePayRequestShippingContactV3.https.html [ Pass ]
 [ HighSierra+ ] http/tests/ssl/applepay/ApplePayShippingAddressChangeEventErrorsV3.https.html [ Pass ]
+[ HighSierra+ ] accessibility/mac/apple-pay-labels.html [ Pass ]
+[ Mojave+ ] accessibility/mac/apple-pay-session-v4.html [ Pass ]
 # <rdar://problem/31634451>
 [ HighSierra+ ] http/tests/resourceLoadStatistics/cookies-with-and-without-user-interaction.html [ Pass ]
 [ HighSierra+ ] http/tests/resourceLoadStatistics/cookie-deletion.html [ Pass ]
index e22a954..79610e0 100644 (file)
@@ -1,5 +1,38 @@
 2019-04-08  Chris Fleizach  <cfleizach@apple.com>
 
+        AX: Automatically compute accessibility labels for Apple Pay buttons
+        https://bugs.webkit.org/show_bug.cgi?id=196661
+
+        Reviewed by Joanmarie Diggs.
+
+        Detect Apple Pay buttons and return a standard role and label for them based on their type.
+
+        Test: accessibility/mac/apple-pay-labels.html
+              accessibility/mac/apple-pay-session-v4.html
+
+        * accessibility/AccessibilityNodeObject.cpp:
+        (WebCore::AccessibilityNodeObject::isControl const):
+        * accessibility/AccessibilityNodeObject.h:
+        * accessibility/AccessibilityRenderObject.cpp:
+        (WebCore::AccessibilityRenderObject::applePayButtonDescription const):
+        (WebCore::AccessibilityRenderObject::titleElementText const):
+        (WebCore::AccessibilityRenderObject::determineAccessibilityRole):
+        (WebCore::AccessibilityRenderObject::isApplePayButton const):
+        (WebCore::AccessibilityRenderObject::applePayButtonType const):
+        * accessibility/AccessibilityRenderObject.h:
+        * en.lproj/Localizable.strings:
+        * platform/LocalizedStrings.cpp:
+        (WebCore::AXApplePayPlainLabel):
+        (WebCore::AXApplePayBuyLabel):
+        (WebCore::AXApplePaySetupLabel):
+        (WebCore::AXApplePayDonateLabel):
+        (WebCore::AXApplePayCheckOutLabel):
+        (WebCore::AXApplePayBookLabel):
+        (WebCore::AXApplePaySubscribeLabel):
+        * platform/LocalizedStrings.h:
+
+2019-04-08  Chris Fleizach  <cfleizach@apple.com>
+
         AX: Support API: accessibilityReplaceRange:withText
         https://bugs.webkit.org/show_bug.cgi?id=196636
 
index c76c77e..4e00496 100644 (file)
@@ -886,7 +886,7 @@ bool AccessibilityNodeObject::isControl() const
     if (!node)
         return false;
 
-    return is<HTMLFormControlElement>(*node) || AccessibilityObject::isARIAControl(ariaRoleAttribute());
+    return is<HTMLFormControlElement>(*node) || AccessibilityObject::isARIAControl(ariaRoleAttribute()) || roleValue() == AccessibilityRole::Button;
 }
 
 bool AccessibilityNodeObject::isFieldset() const
index 29a53bf..a867c0c 100644 (file)
@@ -177,11 +177,11 @@ protected:
     Element* menuItemElementForMenu() const;
     AccessibilityObject* menuButtonForMenu() const;
     AccessibilityObject* captionForFigure() const;
+    virtual void titleElementText(Vector<AccessibilityText>&) const;
 
 private:
     bool isAccessibilityNodeObject() const final { return true; }
     void accessibilityText(Vector<AccessibilityText>&) const override;
-    virtual void titleElementText(Vector<AccessibilityText>&) const;
     void alternativeText(Vector<AccessibilityText>&) const;
     void visibleText(Vector<AccessibilityText>&) const;
     void helpText(Vector<AccessibilityText>&) const;
index b599ed3..5be6c85 100644 (file)
@@ -1075,6 +1075,42 @@ bool AccessibilityRenderObject::exposesTitleUIElement() const
     
     return true;
 }
+
+#if ENABLE(APPLE_PAY)
+String AccessibilityRenderObject::applePayButtonDescription() const
+{
+    switch (applePayButtonType()) {
+    case ApplePayButtonType::Plain:
+        return AXApplePayPlainLabel();
+    case ApplePayButtonType::Buy:
+        return AXApplePayBuyLabel();
+    case ApplePayButtonType::SetUp:
+        return AXApplePaySetupLabel();
+    case ApplePayButtonType::Donate:
+        return AXApplePayDonateLabel();
+#if ENABLE(APPLE_PAY_SESSION_V4)
+    case ApplePayButtonType::CheckOut:
+        return AXApplePayCheckOutLabel();
+    case ApplePayButtonType::Book:
+        return AXApplePayBookLabel();
+    case ApplePayButtonType::Subscribe:
+        return AXApplePaySubscribeLabel();
+#endif
+    }
+}
+#endif
+
+void AccessibilityRenderObject::titleElementText(Vector<AccessibilityText>& textOrder) const
+{
+#if ENABLE(APPLE_PAY)
+    if (isApplePayButton()) {
+        textOrder.append(AccessibilityText(applePayButtonDescription(), AccessibilityTextSource::Alternative));
+        return;
+    }
+#endif
+
+    AccessibilityNodeObject::titleElementText(textOrder);
+}
     
 AccessibilityObject* AccessibilityRenderObject::titleUIElement() const
 {
@@ -2672,6 +2708,11 @@ AccessibilityRole AccessibilityRenderObject::determineAccessibilityRole()
     if (!m_renderer)
         return AccessibilityRole::Unknown;
 
+#if ENABLE(APPLE_PAY)
+    if (isApplePayButton())
+        return AccessibilityRole::Button;
+#endif
+
     // Sometimes we need to ignore the attribute role. Like if a tree is malformed,
     // we want to ignore the treeitem's attribute role.
     if ((m_ariaRole = determineAriaRoleAttribute()) != AccessibilityRole::Unknown && !shouldIgnoreAttributeRole())
@@ -3629,6 +3670,22 @@ bool AccessibilityRenderObject::hasSameFont(RenderObject* renderer) const
     return m_renderer->style().fontDescription().families() == renderer->style().fontDescription().families();
 }
 
+#if ENABLE(APPLE_PAY)
+bool AccessibilityRenderObject::isApplePayButton() const
+{
+    if (!m_renderer)
+        return false;
+    return m_renderer->style().appearance() == ApplePayButtonPart;
+}
+
+ApplePayButtonType AccessibilityRenderObject::applePayButtonType() const
+{
+    if (!m_renderer)
+        return ApplePayButtonType::Plain;
+    return m_renderer->style().applePayButtonType();
+}
+#endif
+
 bool AccessibilityRenderObject::hasSameFontColor(RenderObject* renderer) const
 {
     if (!m_renderer || !renderer)
index a75560c..19ad8fe 100644 (file)
@@ -200,6 +200,7 @@ public:
     AccessibilityRole roleValueForMSAA() const override;
 
     String passwordFieldValue() const override;
+    void titleElementText(Vector<AccessibilityText>&) const override;
 
 protected:
     explicit AccessibilityRenderObject(RenderObject*);
@@ -283,6 +284,12 @@ private:
 
     bool shouldGetTextFromNode(AccessibilityTextUnderElementMode) const;
 
+#if ENABLE(APPLE_PAY)
+    bool isApplePayButton() const;
+    ApplePayButtonType applePayButtonType() const;
+    String applePayButtonDescription() const;
+#endif
+
     RenderObject* targetElementForActiveDescendant(const QualifiedName&, AccessibilityObject*) const;
     bool canHavePlainText() const;
 };
index 3b45a3f..bc1854e 100644 (file)
 /* Undo action name */
 "Align Right (Undo action name)" = "Align Right";
 
-/* Allow Storage Access API */
-"Allow" = "Allow";
-
-/* Title for Allow button label in the Storage Access API request dialog */
+/* Button title in Storage Access API prompt */
 "Allow (cross-site cookie and website data access)" = "Allow";
 
-/* Storage Access API request validation (iOS phrasing) */
+/* Message for requesting cross-site cookie and website data access. */
 "Allow \"%@\" to use cookies and website data while browsing \"%@\"?" = "Allow \"%@\" to use cookies and website data while browsing \"%@\"?";
 
 /* WKErrorUnknown description */
 "An unknown error occurred" = "An unknown error occurred";
 
+/* Label for the plain Apple Pay button. */
+"Apple Pay" = "Apple Pay";
+
 /* Malware confirmation dialog title */
 "Are you sure you wish to go to this site?" = "Are you sure you wish to go to this site?";
 
 /* Undo action name */
 "Bold (Undo action name)" = "Bold";
 
+/* Label for the book with Apple Pay button. */
+"Book with Apple Pay" = "Book with Apple Pay";
+
 /* Option in segmented control for inserting a bulleted list in text editing */
 "Bulleted list" = "Bulleted list";
 
+/* Label for the buy with Apple Pay button. */
+"Buy with Apple Pay" = "Buy with Apple Pay";
+
 /* Cancel */
 "Cancel" = "Cancel";
 
 /* Check spelling while typing context menu item */
 "Check Spelling While Typing" = "Check Spelling While Typing";
 
+/* Label for the check out with Apple Pay button. */
+"Check out with Apple Pay" = "Check out with Apple Pay";
+
 /* title for a single file chooser button used in HTML forms */
 "Choose File" = "Choose File";
 
 /* Undo action name */
 "Dictation (Undo action name)" = "Dictation";
 
-/* Storage Access API request validation (macOS phrasing) */
+/* Message for requesting cross-site cookie and website data access. */
 "Do you want to allow \"%@\" to use cookies and website data while browsing \"%@\"?" = "Do you want to allow \"%@\" to use cookies and website data while browsing \"%@\"?";
 
-/* Storage Access API deny access */
-"Don't Allow" = "Don't Allow";
-
-/* Title for Don't Allow button label in the Storage Access API request dialog */
+/* Button title in Storage Access API prompt */
 "Don't Allow (cross-site cookie and website data access)" = "Don't Allow";
 
+/* Label for the donate with Apple Pay button. */
+"Donate with Apple Pay" = "Donate with Apple Pay";
+
 /* Title of the Done button for zoomed form controls. */
 "Done" = "Done";
 
 /* Undo action name */
 "Set Writing Direction (Undo action name)" = "Set Writing Direction";
 
+/* Label for the set up with Apple Pay button. */
+"Set up with Apple Pay" = "Set up with Apple Pay";
+
 /* Title for Share action button */
 "Share…" = "Share…";
 
 /* alt text for <input> elements with no alt, title, or value */
 "Submit (input element)" = "Submit";
 
+/* Label for the subcribe with Apple Pay button. */
+"Subscribe with Apple Pay" = "Subscribe with Apple Pay";
+
 /* Undo action name */
 "Subscript (Undo action name)" = "Subscript";
 
 /* Unwanted software warning */
 "This website may try to trick you into installing software that harms your browsing experience, like changing your settings without your permission or showing you unwanted ads. Once installed, it may be difficult to remove." = "This website may try to trick you into installing software that harms your browsing experience, like changing your settings without your permission or showing you unwanted ads. Once installed, it may be difficult to remove.";
 
-/* Storage Access API tracking warning */
+/* Informative text for requesting cross-site cookie and website data access. */
 "This will allow \"%@\" to track your activity." = "This will allow \"%@\" to track your activity.";
 
 /* Undo action name */
index 2f096d6..68c2599 100644 (file)
@@ -628,6 +628,43 @@ String AXListItemActionVerb()
     return "select";
 }
 
+#if ENABLE(APPLE_PAY)
+String AXApplePayPlainLabel()
+{
+    return WEB_UI_STRING("Apple Pay", "Label for the plain Apple Pay button.");
+}
+
+String AXApplePayBuyLabel()
+{
+    return WEB_UI_STRING("Buy with Apple Pay", "Label for the buy with Apple Pay button.");
+}
+
+String AXApplePaySetupLabel()
+{
+    return WEB_UI_STRING("Set up with Apple Pay", "Label for the set up with Apple Pay button.");
+}
+
+String AXApplePayDonateLabel()
+{
+    return WEB_UI_STRING("Donate with Apple Pay", "Label for the donate with Apple Pay button.");
+}
+
+String AXApplePayCheckOutLabel()
+{
+    return WEB_UI_STRING("Check out with Apple Pay", "Label for the check out with Apple Pay button.");
+}
+
+String AXApplePayBookLabel()
+{
+    return WEB_UI_STRING("Book with Apple Pay", "Label for the book with Apple Pay button.");
+}
+
+String AXApplePaySubscribeLabel()
+{
+    return WEB_UI_STRING("Subscribe with Apple Pay", "Label for the subcribe with Apple Pay button.");
+}
+#endif
+
 String AXAutoFillCredentialsLabel()
 {
     return WEB_UI_STRING("password AutoFill", "Label for the AutoFill credentials button inside a text field.");
index 6d9ee33..b4e111e 100644 (file)
@@ -213,7 +213,16 @@ namespace WebCore {
     String AXMeterGaugeRegionLessGoodText();
 #endif
 #endif
-    
+#if ENABLE(APPLE_PAY)
+    String AXApplePayPlainLabel();
+    String AXApplePayBuyLabel();
+    String AXApplePaySetupLabel();
+    String AXApplePayDonateLabel();
+    String AXApplePayCheckOutLabel();
+    String AXApplePayBookLabel();
+    String AXApplePaySubscribeLabel();
+#endif
+
     String AXAutoFillCredentialsLabel();
     String AXAutoFillContactsLabel();
     String AXAutoFillStrongPasswordLabel();