Commit 571755af authored by Jinho Bang's avatar Jinho Bang Committed by Commit Bot

PaymentRequest: Implement skeleton code for PaymentMethodChange event

The event handler is triggered when the user changes payment method.
This CL only defines the event in Blink side. A follow-up CL will make
the event fire when user changes payment method on UI.

This feature is still behind runtime flag(PaymentMethodChange).

Intent to implement:
  https://groups.google.com/a/chromium.org/forum/#!topic/blink-dev/e8Zrmy52r9w

Related spec link:
  https://w3c.github.io/payment-request/#paymentmethodchangeevent-interface

Bug: 824760
Change-Id: Ica77b46cbeeee78184a2bd66ce2198aae39b0c7a
Reviewed-on: https://chromium-review.googlesource.com/1226774Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Reviewed-by: default avatarYuki Shiino <yukishiino@chromium.org>
Reviewed-by: default avatarTim Volodine <timvolodine@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Jinho Bang <jinho.bang@samsung.com>
Cr-Commit-Position: refs/heads/master@{#595664}
parent 542d7fd5
......@@ -17,6 +17,7 @@ interface Notification : EventTarget
# web payments api not enabled in webiew, crbug.com/667069
interface PaymentAddress
interface PaymentMethodChangeEvent : PaymentRequestUpdateEvent
interface PaymentRequest : EventTarget
interface PaymentRequestUpdateEvent : Event
interface PaymentResponse : EventTarget
......
This is a testharness.js-based test.
FAIL Must have a methodDetails IDL attribute, which is initialized with to the methodName dictionary value PaymentMethodChangeEvent is not defined
FAIL The methodDetails member defaults to null PaymentMethodChangeEvent is not defined
Harness: the test ran to completion.
This is a testharness.js-based test.
FAIL Must have a methodName IDL attribute, which is initialized with to the methodName dictionary value PaymentMethodChangeEvent is not defined
FAIL When no dictionary is passed, the methodName member defaults to the empty string PaymentMethodChangeEvent is not defined
Harness: the test ran to completion.
......@@ -16,7 +16,7 @@ PASS PaymentRequest interface: attribute shippingType
FAIL PaymentRequest interface: attribute onmerchantvalidation assert_true: The prototype object must have a property "onmerchantvalidation" expected true got false
PASS PaymentRequest interface: attribute onshippingaddresschange
PASS PaymentRequest interface: attribute onshippingoptionchange
FAIL PaymentRequest interface: attribute onpaymentmethodchange assert_true: The prototype object must have a property "onpaymentmethodchange" expected true got false
PASS PaymentRequest interface: attribute onpaymentmethodchange
PASS PaymentRequest must be primary interface of paymentRequest
PASS Stringification of paymentRequest
PASS PaymentRequest interface: paymentRequest must inherit property "show([object Object])" with the proper type
......@@ -30,7 +30,7 @@ PASS PaymentRequest interface: paymentRequest must inherit property "shippingTyp
FAIL PaymentRequest interface: paymentRequest must inherit property "onmerchantvalidation" with the proper type assert_inherits: property "onmerchantvalidation" not found in prototype chain
PASS PaymentRequest interface: paymentRequest must inherit property "onshippingaddresschange" with the proper type
PASS PaymentRequest interface: paymentRequest must inherit property "onshippingoptionchange" with the proper type
FAIL PaymentRequest interface: paymentRequest must inherit property "onpaymentmethodchange" with the proper type assert_inherits: property "onpaymentmethodchange" not found in prototype chain
PASS PaymentRequest interface: paymentRequest must inherit property "onpaymentmethodchange" with the proper type
PASS PaymentAddress interface: existence and properties of interface object
PASS PaymentAddress interface object length
PASS PaymentAddress interface object name
......@@ -83,20 +83,20 @@ FAIL MerchantValidationEvent interface: new MerchantValidationEvent("merchantval
FAIL MerchantValidationEvent interface: new MerchantValidationEvent("merchantvalidation") must inherit property "validationURL" with the proper type assert_equals: Unexpected exception when evaluating object expected null but got object "ReferenceError: MerchantValidationEvent is not defined"
FAIL MerchantValidationEvent interface: new MerchantValidationEvent("merchantvalidation") must inherit property "complete([object Object])" with the proper type assert_equals: Unexpected exception when evaluating object expected null but got object "ReferenceError: MerchantValidationEvent is not defined"
FAIL MerchantValidationEvent interface: calling complete([object Object]) on new MerchantValidationEvent("merchantvalidation") with too few arguments must throw TypeError assert_equals: Unexpected exception when evaluating object expected null but got object "ReferenceError: MerchantValidationEvent is not defined"
FAIL PaymentMethodChangeEvent interface: existence and properties of interface object assert_own_property: self does not have own property "PaymentMethodChangeEvent" expected property "PaymentMethodChangeEvent" missing
FAIL PaymentMethodChangeEvent interface object length assert_own_property: self does not have own property "PaymentMethodChangeEvent" expected property "PaymentMethodChangeEvent" missing
FAIL PaymentMethodChangeEvent interface object name assert_own_property: self does not have own property "PaymentMethodChangeEvent" expected property "PaymentMethodChangeEvent" missing
FAIL PaymentMethodChangeEvent interface: existence and properties of interface prototype object assert_own_property: self does not have own property "PaymentMethodChangeEvent" expected property "PaymentMethodChangeEvent" missing
FAIL PaymentMethodChangeEvent interface: existence and properties of interface prototype object's "constructor" property assert_own_property: self does not have own property "PaymentMethodChangeEvent" expected property "PaymentMethodChangeEvent" missing
FAIL PaymentMethodChangeEvent interface: existence and properties of interface prototype object's @@unscopables property assert_own_property: self does not have own property "PaymentMethodChangeEvent" expected property "PaymentMethodChangeEvent" missing
FAIL PaymentMethodChangeEvent interface: attribute methodName assert_own_property: self does not have own property "PaymentMethodChangeEvent" expected property "PaymentMethodChangeEvent" missing
FAIL PaymentMethodChangeEvent interface: attribute methodDetails assert_own_property: self does not have own property "PaymentMethodChangeEvent" expected property "PaymentMethodChangeEvent" missing
FAIL PaymentMethodChangeEvent must be primary interface of new PaymentMethodChangeEvent("paymentmethodchange") assert_equals: Unexpected exception when evaluating object expected null but got object "ReferenceError: PaymentMethodChangeEvent is not defined"
FAIL Stringification of new PaymentMethodChangeEvent("paymentmethodchange") assert_equals: Unexpected exception when evaluating object expected null but got object "ReferenceError: PaymentMethodChangeEvent is not defined"
FAIL PaymentMethodChangeEvent interface: new PaymentMethodChangeEvent("paymentmethodchange") must inherit property "methodName" with the proper type assert_equals: Unexpected exception when evaluating object expected null but got object "ReferenceError: PaymentMethodChangeEvent is not defined"
FAIL PaymentMethodChangeEvent interface: new PaymentMethodChangeEvent("paymentmethodchange") must inherit property "methodDetails" with the proper type assert_equals: Unexpected exception when evaluating object expected null but got object "ReferenceError: PaymentMethodChangeEvent is not defined"
FAIL PaymentRequestUpdateEvent interface: new PaymentMethodChangeEvent("paymentmethodchange") must inherit property "updateWith([object Object])" with the proper type assert_equals: Unexpected exception when evaluating object expected null but got object "ReferenceError: PaymentMethodChangeEvent is not defined"
FAIL PaymentRequestUpdateEvent interface: calling updateWith([object Object]) on new PaymentMethodChangeEvent("paymentmethodchange") with too few arguments must throw TypeError assert_equals: Unexpected exception when evaluating object expected null but got object "ReferenceError: PaymentMethodChangeEvent is not defined"
PASS PaymentMethodChangeEvent interface: existence and properties of interface object
PASS PaymentMethodChangeEvent interface object length
PASS PaymentMethodChangeEvent interface object name
PASS PaymentMethodChangeEvent interface: existence and properties of interface prototype object
PASS PaymentMethodChangeEvent interface: existence and properties of interface prototype object's "constructor" property
PASS PaymentMethodChangeEvent interface: existence and properties of interface prototype object's @@unscopables property
PASS PaymentMethodChangeEvent interface: attribute methodName
PASS PaymentMethodChangeEvent interface: attribute methodDetails
PASS PaymentMethodChangeEvent must be primary interface of new PaymentMethodChangeEvent("paymentmethodchange")
PASS Stringification of new PaymentMethodChangeEvent("paymentmethodchange")
PASS PaymentMethodChangeEvent interface: new PaymentMethodChangeEvent("paymentmethodchange") must inherit property "methodName" with the proper type
PASS PaymentMethodChangeEvent interface: new PaymentMethodChangeEvent("paymentmethodchange") must inherit property "methodDetails" with the proper type
PASS PaymentRequestUpdateEvent interface: new PaymentMethodChangeEvent("paymentmethodchange") must inherit property "updateWith([object Object])" with the proper type
PASS PaymentRequestUpdateEvent interface: calling updateWith([object Object]) on new PaymentMethodChangeEvent("paymentmethodchange") with too few arguments must throw TypeError
PASS PaymentRequestUpdateEvent interface: existence and properties of interface object
PASS PaymentRequestUpdateEvent interface object length
PASS PaymentRequestUpdateEvent interface object name
......
This is a testharness.js-based test.
FAIL Must have a onpaymentmethodchange IDL attribute assert_idl_attribute: property "onpaymentmethodchange" not found in prototype chain
FAIL onpaymentmethodchange attribute is a generic handler for "paymentmethodchange" assert_true: event did not fire expected true got false
FAIL onpaymentmethodchange attribute is a handler for PaymentMethodChangeEvent PaymentMethodChangeEvent is not defined
FAIL onpaymentmethodchange attribute and listeners both work PaymentMethodChangeEvent is not defined
Harness: the test ran to completion.
......@@ -5068,9 +5068,15 @@ interface PaymentManager
getter userHint
method constructor
setter userHint
interface PaymentMethodChangeEvent : PaymentRequestUpdateEvent
attribute @@toStringTag
getter methodDetails
getter methodName
method constructor
interface PaymentRequest : EventTarget
attribute @@toStringTag
getter id
getter onpaymentmethodchange
getter onshippingaddresschange
getter onshippingoptionchange
getter shippingAddress
......@@ -5080,6 +5086,7 @@ interface PaymentRequest : EventTarget
method canMakePayment
method constructor
method show
setter onpaymentmethodchange
setter onshippingaddresschange
setter onshippingoptionchange
interface PaymentRequestUpdateEvent : Event
......
......@@ -195,6 +195,7 @@
"paste",
"pause",
"payerdetailchange",
"paymentmethodchange",
"paymentrequest",
"periodicsync",
"pictureinpicturecontrolclick",
......
......@@ -212,6 +212,7 @@ modules_idl_files =
"payments/payment_address.idl",
"payments/payment_instruments.idl",
"payments/payment_manager.idl",
"payments/payment_method_change_event.idl",
"payments/payment_request.idl",
"payments/payment_request_event.idl",
"payments/payment_request_update_event.idl",
......@@ -591,6 +592,7 @@ modules_dictionary_idl_files =
"payments/payment_handler_response.idl",
"payments/payment_instrument.idl",
"payments/payment_item.idl",
"payments/payment_method_change_event_init.idl",
"payments/payment_method_data.idl",
"payments/payment_options.idl",
"payments/payment_request_event_init.idl",
......
......@@ -31,6 +31,8 @@ blink_modules_sources("payments") {
"payment_instruments.h",
"payment_manager.cc",
"payment_manager.h",
"payment_method_change_event.cc",
"payment_method_change_event.h",
"payment_request.cc",
"payment_request.h",
"payment_request_event.cc",
......
// Copyright 2018 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.
#include "third_party/blink/renderer/modules/payments/payment_method_change_event.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/platform/bindings/script_state.h"
namespace blink {
PaymentMethodChangeEvent::~PaymentMethodChangeEvent() = default;
// static
PaymentMethodChangeEvent* PaymentMethodChangeEvent::Create(
ScriptState* script_state,
const AtomicString& type,
const PaymentMethodChangeEventInit& init) {
return new PaymentMethodChangeEvent(script_state, type, init);
}
const String& PaymentMethodChangeEvent::methodName() const {
return method_name_;
}
const ScriptValue PaymentMethodChangeEvent::methodDetails(
ScriptState* script_state) const {
return ScriptValue(script_state, method_details_.V8ValueFor(script_state));
}
PaymentMethodChangeEvent::PaymentMethodChangeEvent(
ScriptState* script_state,
const AtomicString& type,
const PaymentMethodChangeEventInit& init)
: PaymentRequestUpdateEvent(ExecutionContext::From(script_state),
type,
init),
method_name_(init.methodName()),
method_details_(init.hasMethodDetails()
? init.methodDetails()
: ScriptValue::CreateNull(script_state)) {}
} // namespace blink
// Copyright 2018 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.
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_PAYMENTS_PAYMENT_METHOD_CHANGE_EVENT_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_PAYMENTS_PAYMENT_METHOD_CHANGE_EVENT_H_
#include "third_party/blink/renderer/bindings/core/v8/script_value.h"
#include "third_party/blink/renderer/modules/modules_export.h"
#include "third_party/blink/renderer/modules/payments/payment_method_change_event_init.h"
#include "third_party/blink/renderer/modules/payments/payment_request_update_event.h"
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
#include "third_party/blink/renderer/platform/heap/handle.h"
#include "third_party/blink/renderer/platform/wtf/text/atomic_string.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
namespace blink {
class ScriptState;
class MODULES_EXPORT PaymentMethodChangeEvent final
: public PaymentRequestUpdateEvent {
DEFINE_WRAPPERTYPEINFO();
public:
~PaymentMethodChangeEvent() override;
static PaymentMethodChangeEvent* Create(
ScriptState*,
const AtomicString& type,
const PaymentMethodChangeEventInit& = PaymentMethodChangeEventInit());
const String& methodName() const;
const ScriptValue methodDetails(ScriptState*) const;
private:
PaymentMethodChangeEvent(ScriptState*,
const AtomicString& type,
const PaymentMethodChangeEventInit&);
String method_name_;
ScriptValue method_details_;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_PAYMENTS_PAYMENT_METHOD_CHANGE_EVENT_H_
// Copyright 2018 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.
// https://w3c.github.io/payment-request/#paymentmethodchangeevent-interface
[
RuntimeEnabled=PaymentMethodChangeEvent,
ConstructorCallWith=ScriptState,
Constructor(DOMString type, optional PaymentMethodChangeEventInit eventInitDict),
SecureContext,
Exposed=Window
] interface PaymentMethodChangeEvent : PaymentRequestUpdateEvent {
readonly attribute DOMString methodName;
[CallWith=ScriptState] readonly attribute object? methodDetails;
};
// Copyright 2018 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.
// https://w3c.github.io/payment-request/#paymentmethodchangeeventinit-dictionary
dictionary PaymentMethodChangeEventInit : PaymentRequestUpdateEventInit {
DOMString methodName = "";
object? methodDetails = null;
};
......@@ -71,6 +71,7 @@ class MODULES_EXPORT PaymentRequest final
DEFINE_ATTRIBUTE_EVENT_LISTENER(shippingaddresschange);
DEFINE_ATTRIBUTE_EVENT_LISTENER(shippingoptionchange);
DEFINE_ATTRIBUTE_EVENT_LISTENER(paymentmethodchange);
ScriptPromise canMakePayment(ScriptState*);
......
......@@ -25,4 +25,5 @@
attribute EventHandler onshippingaddresschange;
attribute EventHandler onshippingoptionchange;
[RuntimeEnabled=PaymentMethodChangeEvent] attribute EventHandler onpaymentmethodchange;
};
......@@ -20,8 +20,8 @@ class ExceptionState;
class ExecutionContext;
class ScriptState;
class MODULES_EXPORT PaymentRequestUpdateEvent final : public Event,
public PaymentUpdater {
class MODULES_EXPORT PaymentRequestUpdateEvent : public Event,
public PaymentUpdater {
DEFINE_WRAPPERTYPEINFO();
USING_GARBAGE_COLLECTED_MIXIN(PaymentRequestUpdateEvent)
......@@ -47,11 +47,12 @@ class MODULES_EXPORT PaymentRequestUpdateEvent final : public Event,
void OnUpdateEventTimeoutForTesting();
private:
protected:
PaymentRequestUpdateEvent(ExecutionContext*,
const AtomicString& type,
const PaymentRequestUpdateEventInit&);
private:
void OnUpdateEventTimeout(TimerBase*);
// True after event.updateWith() was called.
......
......@@ -933,6 +933,10 @@
name: "PaymentApp",
status: "experimental",
},
{
name: "PaymentMethodChangeEvent",
status: "experimental",
},
// PaymentRequest is enabled by default on Android
{
name: "PaymentRequest",
......
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