Changeset 224606 in webkit


Ignore:
Timestamp:
Nov 8, 2017, 4:36:15 PM (8 years ago)
Author:
Joseph Pecoraro
Message:

Web Inspector: Show Internal properties of PaymentRequest in Web Inspector Console
https://bugs.webkit.org/show_bug.cgi?id=179276

Reviewed by Andy Estes.

Source/JavaScriptCore:

  • inspector/InjectedScriptHost.h:
  • inspector/JSInjectedScriptHost.cpp:

(Inspector::JSInjectedScriptHost::getInternalProperties):
Call through to virtual implementation so that WebCore can provide custom
internal properties for Web / DOM objects.

Source/WebCore:

Test: http/tests/inspector/runtime/internal-properties-payment-request.https.html

  • Modules/paymentrequest/PaymentRequest.h:

Expose access to internal state.

  • inspector/WebInjectedScriptHost.h:
  • inspector/WebInjectedScriptHost.cpp:

(WebCore::constructInternalProperty):
(WebCore::WebInjectedScriptHost::getInternalProperties):
Provide internal properties for a PaymentRequest.

  • testing/Internals.cpp:

(WebCore::Internals::withUserGesture):

  • testing/Internals.h:
  • testing/Internals.idl:

Provide a simple way to run code inside of a user gesture.

Source/WebInspectorUI:

  • UserInterface/Test.html:
  • UserInterface/Test/FrontendTestHarness.js:

(FrontendTestHarness.prototype.evaluateInPage):

  • UserInterface/Test/TestUtilities.js: Added.

(promisify):
Make async tests a little easier to work with by providing promises
in some cases that would normally take a callback.

LayoutTests:

Pass test on platforms that support Payment Requests.

  • http/tests/inspector/paymentrequest/payment-request-internal-properties.https-expected.txt: Added.
  • http/tests/inspector/paymentrequest/payment-request-internal-properties.https.html: Added.

Test for internal properties on PaymentRequest instances.

  • resources/ui-helper.js:

(window.UIHelper.withUserGesture):
Provide an easier way to simulate work inside of a user gesture.

Location:
trunk
Files:
4 added
19 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r224605 r224606  
     12017-11-08  Joseph Pecoraro  <pecoraro@apple.com>
     2
     3        Web Inspector: Show Internal properties of PaymentRequest in Web Inspector Console
     4        https://bugs.webkit.org/show_bug.cgi?id=179276
     5
     6        Reviewed by Andy Estes.
     7
     8        * TestExpectations:
     9        * platform/mac-wk2/TestExpectations:
     10        Pass test on platforms that support Payment Requests.
     11
     12        * http/tests/inspector/paymentrequest/payment-request-internal-properties.https-expected.txt: Added.
     13        * http/tests/inspector/paymentrequest/payment-request-internal-properties.https.html: Added.
     14        Test for internal properties on PaymentRequest instances.
     15
     16        * resources/ui-helper.js:
     17        (window.UIHelper.withUserGesture):
     18        Provide an easier way to simulate work inside of a user gesture.
     19
    1202017-11-08  Ryan Haddad  <ryanhaddad@apple.com>
    221
  • trunk/LayoutTests/TestExpectations

    r224585 r224606  
    201201# Payment Request is only enabled on Cocoa platforms.
    202202http/tests/paymentrequest [ Skip ]
     203http/tests/inspector/paymentrequest [ Skip ]
    203204imported/w3c/web-platform-tests/payment-request [ Skip ]
    204205
  • trunk/LayoutTests/http/tests/inspector/network/resource-response-service-worker.html

    r224357 r224606  
    1717function test()
    1818{
    19     InspectorTest.debug();
    2019    let suite = InspectorTest.createAsyncSuite("Resource.ResponseSource.ServiceWorker");
    2120
  • trunk/LayoutTests/platform/mac-wk2/TestExpectations

    r224417 r224606  
    2727
    2828[ Sierra+ ] http/tests/paymentrequest [ Pass ]
     29[ Sierra+ ] http/tests/inspector/paymentrequest [ Pass ]
    2930[ Sierra+ ] imported/w3c/web-platform-tests/payment-request [ Pass ]
    3031webkit.org/b/178107 [ Sierra+ ] http/tests/paymentrequest/payment-request-abort-method.https.html [ Pass Failure ]
  • trunk/LayoutTests/resources/ui-helper.js

    r224402 r224606  
    157157        return promise.then(finish, finish);
    158158    }
     159
     160    static withUserGesture(callback)
     161    {
     162        internals.withUserGesture(callback);
     163    }
    159164}
  • trunk/Source/JavaScriptCore/ChangeLog

    r224603 r224606  
     12017-11-08  Joseph Pecoraro  <pecoraro@apple.com>
     2
     3        Web Inspector: Show Internal properties of PaymentRequest in Web Inspector Console
     4        https://bugs.webkit.org/show_bug.cgi?id=179276
     5
     6        Reviewed by Andy Estes.
     7
     8        * inspector/InjectedScriptHost.h:
     9        * inspector/JSInjectedScriptHost.cpp:
     10        (Inspector::JSInjectedScriptHost::getInternalProperties):
     11        Call through to virtual implementation so that WebCore can provide custom
     12        internal properties for Web / DOM objects.
     13
    1142017-11-08  Saam Barati  <sbarati@apple.com>
    215
  • trunk/Source/JavaScriptCore/inspector/InjectedScriptHost.h

    r218794 r224606  
    3838
    3939    virtual JSC::JSValue subtype(JSC::ExecState*, JSC::JSValue) { return JSC::jsUndefined(); }
     40    virtual JSC::JSValue getInternalProperties(JSC::VM&, JSC::ExecState*, JSC::JSValue) { return { }; }
    4041    virtual bool isHTMLAllCollection(JSC::VM&, JSC::JSValue) { return false; }
    4142
  • trunk/Source/JavaScriptCore/inspector/JSInjectedScriptHost.cpp

    r222421 r224606  
    273273    JSValue value = exec->uncheckedArgument(0);
    274274
     275    JSValue internalProperties = impl().getInternalProperties(vm, exec, value);
     276    if (internalProperties)
     277        return internalProperties;
     278
    275279    if (JSPromise* promise = jsDynamicCast<JSPromise*>(vm, value)) {
    276280        unsigned index = 0;
  • trunk/Source/WebCore/ChangeLog

    r224604 r224606  
     12017-11-08  Joseph Pecoraro  <pecoraro@apple.com>
     2
     3        Web Inspector: Show Internal properties of PaymentRequest in Web Inspector Console
     4        https://bugs.webkit.org/show_bug.cgi?id=179276
     5
     6        Reviewed by Andy Estes.
     7
     8        Test: http/tests/inspector/runtime/internal-properties-payment-request.https.html
     9
     10        * Modules/paymentrequest/PaymentRequest.h:
     11        Expose access to internal state.
     12
     13        * inspector/WebInjectedScriptHost.h:
     14        * inspector/WebInjectedScriptHost.cpp:
     15        (WebCore::constructInternalProperty):
     16        (WebCore::WebInjectedScriptHost::getInternalProperties):
     17        Provide internal properties for a PaymentRequest.
     18
     19        * testing/Internals.cpp:
     20        (WebCore::Internals::withUserGesture):
     21        * testing/Internals.h:
     22        * testing/Internals.idl:
     23        Provide a simple way to run code inside of a user gesture.
     24
    1252017-11-08  Ryosuke Niwa  <rniwa@webkit.org>
    226
  • trunk/Source/WebCore/Modules/paymentrequest/PaymentRequest.h

    r224459 r224606  
    6666    std::optional<PaymentShippingType> shippingType() const;
    6767
     68    enum class State {
     69        Created,
     70        Interactive,
     71        Closed,
     72    };
     73
     74    State state() const { return m_state; }
     75
    6876    const PaymentOptions& paymentOptions() const { return m_options; }
    6977    const PaymentDetailsInit& paymentDetails() const { return m_details; }
     
    8189
    8290private:
    83     enum class State {
    84         Created,
    85         Interactive,
    86         Closed,
    87     };
    88 
    8991    struct Method {
    9092        MethodIdentifier identifier;
  • trunk/Source/WebCore/html/VoidCallback.idl

    r208408 r224606  
    2121 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    2222 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
     23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2424 */
    2525
    26 callback VoidCallback = void ();
     26[
     27    ExportMacro=WEBCORE_EXPORT
     28] callback VoidCallback = void ();
  • trunk/Source/WebCore/inspector/WebInjectedScriptHost.cpp

    r223476 r224606  
    11/*
    2  * Copyright (C) 2013 Apple Inc. All rights reserved.
     2 * Copyright (C) 2013-2017 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    3434#include "JSNodeList.h"
    3535
     36#if ENABLE(PAYMENT_REQUEST)
     37#include "JSPaymentRequest.h"
     38#include "JSPaymentShippingType.h"
     39#include "PaymentOptions.h"
     40#include "PaymentRequest.h"
     41#endif
    3642
    3743namespace WebCore {
     44
    3845using namespace JSC;
    3946
    40 JSValue WebInjectedScriptHost::subtype(JSC::ExecState* exec, JSC::JSValue value)
     47JSValue WebInjectedScriptHost::subtype(ExecState* exec, JSValue value)
    4148{
    4249    VM& vm = exec->vm();
     
    5360}
    5461
     62#if ENABLE(PAYMENT_REQUEST)
     63static JSObject* constructInternalProperty(VM& vm, ExecState* exec, const String& name, JSValue value)
     64{
     65    auto* object = constructEmptyObject(exec);
     66    object->putDirect(vm, Identifier::fromString(exec, "name"), jsString(exec, name));
     67    object->putDirect(vm, Identifier::fromString(exec, "value"), value);
     68    return object;
     69}
     70
     71static JSObject* objectForPaymentOptions(VM& vm, ExecState* exec, const PaymentOptions& paymentOptions)
     72{
     73    auto* object = constructEmptyObject(exec);
     74    object->putDirect(vm, Identifier::fromString(exec, "requestPayerName"), jsBoolean(paymentOptions.requestPayerName));
     75    object->putDirect(vm, Identifier::fromString(exec, "requestPayerEmail"), jsBoolean(paymentOptions.requestPayerEmail));
     76    object->putDirect(vm, Identifier::fromString(exec, "requestPayerPhone"), jsBoolean(paymentOptions.requestPayerPhone));
     77    object->putDirect(vm, Identifier::fromString(exec, "requestShipping"), jsBoolean(paymentOptions.requestShipping));
     78    object->putDirect(vm, Identifier::fromString(exec, "shippingType"), jsNontrivialString(exec, convertEnumerationToString(paymentOptions.shippingType)));
     79    return object;
     80}
     81
     82static JSObject* objectForPaymentCurrencyAmount(VM& vm, ExecState* exec, const PaymentCurrencyAmount& paymentCurrencyAmount)
     83{
     84    auto* object = constructEmptyObject(exec);
     85    object->putDirect(vm, Identifier::fromString(exec, "currency"), jsString(exec, paymentCurrencyAmount.currency));
     86    object->putDirect(vm, Identifier::fromString(exec, "value"), jsString(exec, paymentCurrencyAmount.value));
     87    object->putDirect(vm, Identifier::fromString(exec, "currencySystem"), jsString(exec, paymentCurrencyAmount.currencySystem));
     88    return object;
     89}
     90
     91static JSObject* objectForPaymentItem(VM& vm, ExecState* exec, const PaymentItem& paymentItem)
     92{
     93    auto* object = constructEmptyObject(exec);
     94    object->putDirect(vm, Identifier::fromString(exec, "label"), jsString(exec, paymentItem.label));
     95    object->putDirect(vm, Identifier::fromString(exec, "amount"), objectForPaymentCurrencyAmount(vm, exec, paymentItem.amount));
     96    object->putDirect(vm, Identifier::fromString(exec, "pending"), jsBoolean(paymentItem.pending));
     97    return object;
     98}
     99
     100static JSObject* objectForPaymentShippingOption(VM& vm, ExecState* exec, const PaymentShippingOption& paymentShippingOption)
     101{
     102    auto* object = constructEmptyObject(exec);
     103    object->putDirect(vm, Identifier::fromString(exec, "id"), jsString(exec, paymentShippingOption.id));
     104    object->putDirect(vm, Identifier::fromString(exec, "label"), jsString(exec, paymentShippingOption.label));
     105    object->putDirect(vm, Identifier::fromString(exec, "amount"), objectForPaymentCurrencyAmount(vm, exec, paymentShippingOption.amount));
     106    object->putDirect(vm, Identifier::fromString(exec, "selected"), jsBoolean(paymentShippingOption.selected));
     107    return object;
     108}
     109
     110static JSObject* objectForPaymentDetailsModifier(VM& vm, ExecState* exec, const PaymentDetailsModifier& modifier)
     111{
     112    auto* additionalDisplayItems = constructEmptyArray(exec, nullptr);
     113    for (unsigned i = 0; i < modifier.additionalDisplayItems.size(); ++i)
     114        additionalDisplayItems->putDirectIndex(exec, i, objectForPaymentItem(vm, exec, modifier.additionalDisplayItems[i]));
     115
     116    auto* object = constructEmptyObject(exec);
     117    object->putDirect(vm, Identifier::fromString(exec, "supportedMethods"), jsString(exec, modifier.supportedMethods));
     118    object->putDirect(vm, Identifier::fromString(exec, "total"), !modifier.total ? jsNull() : objectForPaymentItem(vm, exec, *modifier.total));
     119    object->putDirect(vm, Identifier::fromString(exec, "additionalDisplayItems"), additionalDisplayItems);
     120    object->putDirect(vm, Identifier::fromString(exec, "data"), !modifier.data ? jsNull() : modifier.data.get());
     121    return object;
     122}
     123
     124static JSObject* objectForPaymentDetails(VM& vm, ExecState* exec, const PaymentDetailsInit& paymentDetails)
     125{
     126    auto* displayItems = constructEmptyArray(exec, nullptr);
     127    for (unsigned i = 0; i < paymentDetails.displayItems.size(); ++i)
     128        displayItems->putDirectIndex(exec, i, objectForPaymentItem(vm, exec, paymentDetails.displayItems[i]));
     129
     130    auto* shippingOptions = constructEmptyArray(exec, nullptr);
     131    for (unsigned i = 0; i < paymentDetails.shippingOptions.size(); ++i)
     132        shippingOptions->putDirectIndex(exec, i, objectForPaymentShippingOption(vm, exec, paymentDetails.shippingOptions[i]));
     133
     134    auto* modifiers = constructEmptyArray(exec, nullptr);
     135    for (unsigned i = 0; i < paymentDetails.modifiers.size(); ++i)
     136        modifiers->putDirectIndex(exec, i, objectForPaymentDetailsModifier(vm, exec, paymentDetails.modifiers[i]));
     137
     138    auto* object = constructEmptyObject(exec);
     139    object->putDirect(vm, Identifier::fromString(exec, "id"), jsString(exec, paymentDetails.id));
     140    object->putDirect(vm, Identifier::fromString(exec, "total"), objectForPaymentItem(vm, exec, paymentDetails.total));
     141    object->putDirect(vm, Identifier::fromString(exec, "displayItems"), displayItems);
     142    object->putDirect(vm, Identifier::fromString(exec, "shippingOptions"), shippingOptions);
     143    object->putDirect(vm, Identifier::fromString(exec, "modifiers"), modifiers);
     144    return object;
     145}
     146
     147static JSString* jsStringForPaymentRequestState(VM& vm, ExecState* exec, PaymentRequest::State state)
     148{
     149    switch (state) {
     150    case PaymentRequest::State::Created:
     151        return jsNontrivialString(exec, ASCIILiteral("created"));
     152    case PaymentRequest::State::Interactive:
     153        return jsNontrivialString(exec, ASCIILiteral("interactive"));
     154    case PaymentRequest::State::Closed:
     155        return jsNontrivialString(exec, ASCIILiteral("closed"));
     156    }
     157
     158    ASSERT_NOT_REACHED();
     159    return jsEmptyString(&vm);
     160}
     161#endif
     162
     163JSValue WebInjectedScriptHost::getInternalProperties(VM& vm, ExecState* exec, JSC::JSValue value)
     164{
     165    auto scope = DECLARE_THROW_SCOPE(vm);
     166
     167#if ENABLE(PAYMENT_REQUEST)
     168    if (PaymentRequest* paymentRequest = JSPaymentRequest::toWrapped(vm, value)) {
     169        unsigned index = 0;
     170        auto* array = constructEmptyArray(exec, nullptr);
     171        array->putDirectIndex(exec, index++, constructInternalProperty(vm, exec, ASCIILiteral("options"), objectForPaymentOptions(vm, exec, paymentRequest->paymentOptions())));
     172        array->putDirectIndex(exec, index++, constructInternalProperty(vm, exec, ASCIILiteral("details"), objectForPaymentDetails(vm, exec, paymentRequest->paymentDetails())));
     173        array->putDirectIndex(exec, index++, constructInternalProperty(vm, exec, ASCIILiteral("state"), jsStringForPaymentRequestState(vm, exec, paymentRequest->state())));
     174        RETURN_IF_EXCEPTION(scope, { });
     175        return array;
     176    }
     177#else
     178    UNUSED_PARAM(exec);
     179    UNUSED_PARAM(value);
     180#endif
     181
     182    return { };
     183}
     184
    55185bool WebInjectedScriptHost::isHTMLAllCollection(JSC::VM& vm, JSC::JSValue value)
    56186{
  • trunk/Source/WebCore/inspector/WebInjectedScriptHost.h

    r211247 r224606  
    3535
    3636    JSC::JSValue subtype(JSC::ExecState*, JSC::JSValue) override;
     37    JSC::JSValue getInternalProperties(JSC::VM&, JSC::ExecState*, JSC::JSValue) override;
    3738    bool isHTMLAllCollection(JSC::VM&, JSC::JSValue) override;
    3839};
  • trunk/Source/WebCore/testing/Internals.cpp

    r224584 r224606  
    149149#include "UserMediaController.h"
    150150#include "ViewportArguments.h"
     151#include "VoidCallback.h"
    151152#include "WebCoreJSClientData.h"
    152153#if ENABLE(WEBGL)
     
    38983899}
    38993900
     3901void Internals::withUserGesture(RefPtr<VoidCallback>&& callback)
     3902{
     3903    UserGestureIndicator gestureIndicator(ProcessingUserGesture, contextDocument());
     3904    callback->handleEvent();
     3905}
     3906
    39003907double Internals::lastHandledUserGestureTimestamp()
    39013908{
  • trunk/Source/WebCore/testing/Internals.h

    r224584 r224606  
    7777class NodeList;
    7878class Page;
     79class RTCPeerConnection;
    7980class Range;
    8081class RenderedDocumentMarker;
    81 class RTCPeerConnection;
    8282class SVGSVGElement;
    8383class SerializedScriptValue;
     
    8787class TimeRanges;
    8888class TypeConversions;
     89class VoidCallback;
    8990class WebGLRenderingContext;
    9091class XMLHttpRequest;
     
    559560    double lastHandledUserGestureTimestamp();
    560561
     562    void withUserGesture(RefPtr<VoidCallback>&&);
     563
    561564    RefPtr<GCObservation> observeGC(JSC::JSValue);
    562565
  • trunk/Source/WebCore/testing/Internals.idl

    r224584 r224606  
    514514    double lastHandledUserGestureTimestamp();
    515515
     516    void withUserGesture(VoidCallback callback);
     517
    516518    GCObservation? observeGC(any observed);
    517519
  • trunk/Source/WebInspectorUI/ChangeLog

    r224595 r224606  
     12017-11-08  Joseph Pecoraro  <pecoraro@apple.com>
     2
     3        Web Inspector: Show Internal properties of PaymentRequest in Web Inspector Console
     4        https://bugs.webkit.org/show_bug.cgi?id=179276
     5
     6        Reviewed by Andy Estes.
     7
     8        * UserInterface/Test.html:
     9        * UserInterface/Test/FrontendTestHarness.js:
     10        (FrontendTestHarness.prototype.evaluateInPage):
     11        * UserInterface/Test/TestUtilities.js: Added.
     12        (promisify):
     13        Make async tests a little easier to work with by providing promises
     14        in some cases that would normally take a callback.
     15
    1162017-11-08  Brian Burg  <bburg@apple.com>
    217
  • trunk/Source/WebInspectorUI/UserInterface/Test.html

    r224367 r224606  
    4949    <script src="Controllers/AppControllerBase.js"></script>
    5050    <script src="Test/TestAppController.js"></script>
     51    <script src="Test/TestUtilities.js"></script>
    5152
    5253    <script src="Base/DOMUtilities.js"></script>
  • trunk/Source/WebInspectorUI/UserInterface/Test/FrontendTestHarness.js

    r223308 r224606  
    8787        }
    8888
    89         RuntimeAgent.evaluate.invoke({expression, objectGroup: "test", includeCommandLineAPI: false}, callback);
     89        if (typeof callback === "function")
     90            RuntimeAgent.evaluate.invoke({expression, objectGroup: "test", includeCommandLineAPI: false}, callback);
     91        else
     92            return RuntimeAgent.evaluate.invoke({expression, objectGroup: "test", includeCommandLineAPI: false});
    9093    }
    9194
Note: See TracChangeset for help on using the changeset viewer.