Changeset 237924 in webkit


Ignore:
Timestamp:
Nov 7, 2018 6:57:40 AM (5 years ago)
Author:
commit-queue@webkit.org
Message:

Source/WebKit:
Force a gregorian calendar to show for credit card expiration date inputs
(autocomplete='cc-exp'*) regardless of default system settings.
https://bugs.webkit.org/show_bug.cgi?id=191096
rdar://problem/42640256

Patch by Zamiul Haque <zhaque@apple.com> on 2018-11-07
Reviewed by Tim Horton.

Added some plumbing code to expose the calendar identifier of the calendar used by a
presented date picker. Added shouldPresentGregorianCalendar:, to be used for
determining what property values a date input control must present a Gregorian
calendar for.

  • UIProcess/ios/WKContentViewInteraction.mm:

(-[WKContentView formInputPeripheral]):

  • UIProcess/ios/forms/WKFormInputControl.mm:

Tools:
Force a gregorian calendar to show for credit card expiration date inputs
(autocomplete='cc-exp'*) regardless of default system settings.
https://bugs.webkit.org/show_bug.cgi?id=191096
rdar://problem/42640256

Patch by Zamiul Haque <zhaque@apple.com> on 2018-11-07
Reviewed by Tim Horton.

Implemented simulateForeignDefaultCalendar and calendarType to be used
for changing the default calendar returned by the system (ie. [NSCalendar
currentCalendar]) and getting the calendar type identifier of a presented date
picker.

  • DumpRenderTree/ios/UIScriptControllerIOS.mm:

(WTR::UIScriptController::isShowingDataListSuggestions const):
(WTR::UIScriptController::calendarType const):
(WTR::UIScriptController::setDefaultCalendarType):

  • DumpRenderTree/mac/UIScriptControllerMac.mm:

(WTR::UIScriptController::calendarType const):
(WTR::UIScriptController::setDefaultCalendarType):

  • TestRunnerShared/UIScriptContext/UIScriptController.cpp:

(WTR::UIScriptController::selectionEndGrabberViewRect const):
(WTR::UIScriptController::calendarType const): Deleted.

  • WebKitTestRunner/TestController.cpp:
  • WebKitTestRunner/TestController.h:
  • WebKitTestRunner/UIScriptControllerCocoa.mm:

(WTR::UIScriptController::calendarType const):

  • WebKitTestRunner/cocoa/TestControllerCocoa.mm:

(WTR::swizzledCalendar):
(WTR::TestController::getOverriddenCalendarIdentifier const):
(WTR::TestController::setDefaultCalendarType):
(WTR::TestController::cocoaResetStateToConsistentValues):

  • WebKitTestRunner/ios/UIScriptControllerIOS.mm:

(WTR::UIScriptController::selectionEndGrabberViewRect const):
(WTR::UIScriptController::calendarType const): Deleted.

LayoutTests:
Created a layout test to ensure that date controls marked as credit card expiry
fields present a Gregorian calendar regardless of default system settings.
https://bugs.webkit.org/show_bug.cgi?id=191096
rdar://problem/42640256

Patch by Zamiul Haque <zhaque@apple.com> on 2018-11-07
Reviewed by Tim Horton.

Added two new methods to UIHelper, helping to facilitate this. calendarType
returns the calendar identifier of the NSCalendar instance used by the presented
date picker and setDefaultCalendarType accepts a calendar identifier as an
argument for changing the default system settings.

  • fast/forms/ios/force-gregorian-calendar-for-credit-card-expiry.html:
  • platform/win/TestExpectations:
  • resources/ui-helper.js:

(window.UIHelper.calendarType):
(window.UIHelper.setDefaultCalendarType):

Location:
trunk
Files:
2 added
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r237919 r237924  
     12018-11-07  Zamiul Haque  <zhaque@apple.com>
     2
     3        Created a layout test to ensure that date controls marked as credit card expiry
     4        fields present a Gregorian calendar regardless of default system settings.
     5        https://bugs.webkit.org/show_bug.cgi?id=191096
     6        rdar://problem/42640256
     7
     8        Reviewed by Tim Horton.
     9
     10        Added two new methods to UIHelper, helping to facilitate this. calendarType
     11        returns the calendar identifier of the NSCalendar instance used by the presented
     12        date picker and setDefaultCalendarType accepts a calendar identifier as an
     13        argument for changing the default system settings.
     14
     15        * fast/forms/ios/force-gregorian-calendar-for-credit-card-expiry.html:
     16        * platform/win/TestExpectations:
     17        * resources/ui-helper.js:
     18        (window.UIHelper.calendarType):
     19        (window.UIHelper.setDefaultCalendarType):
     20
    1212018-11-07  Tadeu Zagallo  <tzagallo@apple.com>
    222
  • trunk/LayoutTests/resources/ui-helper.js

    r237743 r237924  
    347347    }
    348348
     349    static calendarType()
     350    {
     351        if (!this.isWebKit2())
     352            return Promise.resolve();
     353
     354        return new Promise(resolve => {
     355            testRunner.runUIScript(`(() => {
     356                uiController.doAfterNextStablePresentationUpdate(() => {
     357                    uiController.uiScriptComplete(JSON.stringify(uiController.calendarType));
     358                })
     359            })()`, jsonString => {
     360                resolve(JSON.parse(jsonString));
     361            });
     362        });
     363    }
     364
     365    static setDefaultCalendarType(calendarIdentifier)
     366    {
     367        if (!this.isWebKit2())
     368            return Promise.resolve();
     369
     370        return new Promise(resolve => testRunner.runUIScript(`uiController.setDefaultCalendarType('${calendarIdentifier}')`, resolve));
     371
     372    }
     373
    349374    static setViewScale(scale)
    350375    {
  • trunk/Source/WebKit/ChangeLog

    r237923 r237924  
     12018-11-07  Zamiul Haque  <zhaque@apple.com>
     2
     3        Force a gregorian calendar to show for credit card expiration date inputs
     4        (autocomplete='cc-exp'*) regardless of default system settings.
     5        https://bugs.webkit.org/show_bug.cgi?id=191096
     6        rdar://problem/42640256
     7
     8        Reviewed by Tim Horton.
     9
     10        Added some plumbing code to expose the calendar identifier of the calendar used by a
     11        presented date picker. Added shouldPresentGregorianCalendar:, to be used for
     12        determining what property values a date input control must present a Gregorian
     13        calendar for.
     14
     15        * UIProcess/ios/WKContentViewInteraction.mm:
     16        (-[WKContentView formInputPeripheral]):
     17        * UIProcess/ios/forms/WKFormInputControl.mm:
     18
    1192018-11-07  Carlos Garcia Campos  <cgarcia@igalia.com>
    220
  • trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h

    r237820 r237924  
    9393@class WKActionSheetAssistant;
    9494@class WKFocusedFormControlView;
     95@class WKFormInputControl;
    9596@class WKFormInputSession;
    9697@class WKInspectorNodeSearchGestureRecognizer;
     
    423424@property (nonatomic, readonly) NSString *selectFormPopoverTitle;
    424425@property (nonatomic, readonly) NSString *formInputLabel;
     426@property (nonatomic, readonly) WKFormInputControl *formInputControl;
    425427
    426428@end
  • trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm

    r237820 r237924  
    59625962@implementation WKContentView (WKTesting)
    59635963
     5964- (WKFormInputControl *)formInputControl
     5965{
     5966    if ([_inputPeripheral isKindOfClass:WKFormInputControl.class])
     5967        return (WKFormInputControl *)_inputPeripheral.get();
     5968    return nil;
     5969}
     5970
    59645971- (void)_simulateTextEntered:(NSString *)text
    59655972{
  • trunk/Source/WebKit/UIProcess/ios/forms/WKFormInputControl.h

    r237266 r237924  
    3434@end
    3535
     36@interface WKFormInputControl (WKTesting)
     37@property (nonatomic, readonly) NSString *dateTimePickerCalendarType;
     38@end
     39
    3640#endif // PLATFORM(IOS_FAMILY)
  • trunk/Source/WebKit/UIProcess/ios/forms/WKFormInputControl.mm

    r237266 r237924  
    4848@end
    4949
     50@interface WKDateTimePopover : WKFormRotatingAccessoryPopover<WKFormControl> {
     51    RetainPtr<WKDateTimePopoverViewController> _viewController;
     52    WKContentView *_view;
     53}
     54- (id)initWithView:(WKContentView *)view datePickerMode:(UIDatePickerMode)mode;
     55- (WKDateTimePopoverViewController *)viewController;
     56@end
     57
    5058@interface WKDateTimePicker : NSObject<WKFormControl> {
    5159    RetainPtr<UIDatePicker> _datePicker;
     
    5765- (id)initWithView:(WKContentView *)view datePickerMode:(UIDatePickerMode)mode;
    5866- (UIDatePicker *)datePicker;
    59 @end
    60 
    61 @interface WKDateTimePopover : WKFormRotatingAccessoryPopover<WKFormControl> {
    62     RetainPtr<WKDateTimePopoverViewController> _viewController;
    63     WKContentView* _view;
    64 }
    65 - (id)initWithView:(WKContentView *)view datePickerMode:(UIDatePickerMode)mode;
    66 - (WKDateTimePopoverViewController *) viewController;
     67
    6768@end
    6869
     
    110111    _datePicker.get().datePickerMode = mode;
    111112    _datePicker.get().hidden = NO;
     113   
     114    if ([self shouldPresentGregorianCalendar:view.assistedNodeInformation])
     115        _datePicker.get().calendar = [NSCalendar calendarWithIdentifier:NSCalendarIdentifierGregorian];
     116   
    112117    [_datePicker addTarget:self action:@selector(_dateChangeHandler:) forControlEvents:UIControlEventValueChanged];
    113118
    114119    return self;
     120}
     121
     122- (NSString *)calendarType
     123{
     124    return _datePicker.get().calendar.calendarIdentifier;
    115125}
    116126
     
    119129    [_datePicker removeTarget:self action:NULL forControlEvents:UIControlEventValueChanged];
    120130    [super dealloc];
     131}
     132
     133- (BOOL)shouldPresentGregorianCalendar:(const AssistedNodeInformation&)nodeInfo
     134{
     135    return nodeInfo.autofillFieldName == WebCore::AutofillFieldName::CcExpMonth
     136        || nodeInfo.autofillFieldName == WebCore::AutofillFieldName::CcExp
     137        || nodeInfo.autofillFieldName == WebCore::AutofillFieldName::CcExpYear;
    121138}
    122139
     
    281298@end
    282299
     300@implementation WKFormInputControl (WKTesting)
     301- (NSString *)dateTimePickerCalendarType
     302{
     303    if ([(NSObject *)_control.get() isKindOfClass:WKDateTimePicker.class])
     304        return [(WKDateTimePicker *)_control.get() calendarType];
     305    return nil;
     306}
     307@end
    283308
    284309@implementation WKDateTimePopoverViewController
  • trunk/Tools/ChangeLog

    r237914 r237924  
     12018-11-07  Zamiul Haque  <zhaque@apple.com>
     2
     3        Force a gregorian calendar to show for credit card expiration date inputs
     4        (autocomplete='cc-exp'*) regardless of default system settings.
     5        https://bugs.webkit.org/show_bug.cgi?id=191096
     6        rdar://problem/42640256
     7
     8        Reviewed by Tim Horton.
     9
     10        Implemented simulateForeignDefaultCalendar and calendarType to be used
     11        for changing the default calendar returned by the system (ie. [NSCalendar
     12        currentCalendar]) and getting the calendar type identifier of a presented date
     13        picker.
     14
     15        * DumpRenderTree/ios/UIScriptControllerIOS.mm:
     16        (WTR::UIScriptController::isShowingDataListSuggestions const):
     17        (WTR::UIScriptController::calendarType const):
     18        (WTR::UIScriptController::setDefaultCalendarType):
     19        * DumpRenderTree/mac/UIScriptControllerMac.mm:
     20        (WTR::UIScriptController::calendarType const):
     21        (WTR::UIScriptController::setDefaultCalendarType):
     22        * TestRunnerShared/UIScriptContext/UIScriptController.cpp:
     23        (WTR::UIScriptController::selectionEndGrabberViewRect const):
     24        (WTR::UIScriptController::calendarType const): Deleted.
     25        * WebKitTestRunner/TestController.cpp:
     26        * WebKitTestRunner/TestController.h:
     27        * WebKitTestRunner/UIScriptControllerCocoa.mm:
     28        (WTR::UIScriptController::calendarType const):
     29        * WebKitTestRunner/cocoa/TestControllerCocoa.mm:
     30        (WTR::swizzledCalendar):
     31        (WTR::TestController::getOverriddenCalendarIdentifier const):
     32        (WTR::TestController::setDefaultCalendarType):
     33        (WTR::TestController::cocoaResetStateToConsistentValues):
     34        * WebKitTestRunner/ios/UIScriptControllerIOS.mm:
     35        (WTR::UIScriptController::selectionEndGrabberViewRect const):
     36        (WTR::UIScriptController::calendarType const): Deleted.
     37
    1382018-11-06  Jonathan Bedard  <jbedard@apple.com>
    239
  • trunk/Tools/DumpRenderTree/ios/UIScriptControllerIOS.mm

    r237786 r237924  
    395395}
    396396
     397JSObjectRef UIScriptController::calendarType() const
     398{
     399    return nullptr;
     400}
     401
     402void UIScriptController::setDefaultCalendarType(JSStringRef calendarIdentifier)
     403{
     404}
     405
    397406void UIScriptController::overridePreference(JSStringRef, JSStringRef)
    398407{
  • trunk/Tools/DumpRenderTree/mac/UIScriptControllerMac.mm

    r237305 r237924  
    197197{
    198198}
    199 
     199   
     200JSObjectRef UIScriptController::calendarType() const
     201{
     202    return nullptr;
     203}
     204
     205void UIScriptController::setDefaultCalendarType(JSStringRef calendarIdentifier)
     206{
     207}
     208   
    200209}
    201210
  • trunk/Tools/TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl

    r237305 r237924  
    2323 * THE POSSIBILITY OF SUCH DAMAGE.
    2424 */
    25  
     25
    2626enum DeviceOrientation {
    2727    "portrait",
     
    243243    readonly attribute object selectionStartGrabberViewRect;
    244244    readonly attribute object selectionEndGrabberViewRect;
    245 
     245    readonly attribute object calendarType;
     246    void setDefaultCalendarType(DOMString calendarIdentifier);
    246247    readonly attribute object inputViewBounds;
    247248
  • trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptController.cpp

    r237786 r237924  
    227227    return nullptr;
    228228}
     229   
     230void UIScriptController::setDefaultCalendarType(JSStringRef calendarIdentifier)
     231{
     232}
     233
     234JSObjectRef UIScriptController::calendarType() const
     235{
     236    return nullptr;
     237}
     238   
    229239#endif
    230240
  • trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptController.h

    r237305 r237924  
    164164    JSObjectRef selectionStartGrabberViewRect() const;
    165165    JSObjectRef selectionEndGrabberViewRect() const;
     166    JSObjectRef calendarType() const;
     167    void setDefaultCalendarType(JSStringRef calendarIdentifier);
    166168    JSObjectRef inputViewBounds() const;
    167169
  • trunk/Tools/WebKitTestRunner/TestController.h

    r237893 r237924  
    3434#include <vector>
    3535#include <wtf/HashMap.h>
     36#include <wtf/Noncopyable.h>
    3637#include <wtf/Seconds.h>
    3738#include <wtf/Vector.h>
    3839#include <wtf/text/StringHash.h>
    3940
     41#if PLATFORM(COCOA)
     42
     43#include <objc/runtime.h>
     44
     45#endif
     46
     47OBJC_CLASS NSString;
    4048OBJC_CLASS WKWebViewConfiguration;
    4149
     
    4856struct TestCommand;
    4957struct TestOptions;
     58
     59#if PLATFORM(COCOA)
     60// FIXME: This should be shared with TestWebKitAPI.
     61class ClassMethodSwizzler {
     62    WTF_MAKE_NONCOPYABLE(ClassMethodSwizzler);
     63public:
     64    ClassMethodSwizzler(Class, SEL, IMP);
     65    ~ClassMethodSwizzler();
     66   
     67    Method m_method;
     68    IMP m_originalImplementation;
     69};
     70#endif // PLATFORM(COCOA)
    5071
    5172class AsyncTask {
     
    263284    void toggleCapsLock();
    264285
     286#if PLATFORM(COCOA)
     287    RetainPtr<NSString> getOverriddenCalendarIdentifier() const;
     288    void setDefaultCalendarType(NSString *identifier);
     289#endif // PLATFORM(COCOA)
    265290private:
    266291    WKRetainPtr<WKPageConfigurationRef> generatePageConfiguration(WKContextConfigurationRef);
     
    414439
    415440    std::unique_ptr<TestInvocation> m_currentInvocation;
    416 
     441#if PLATFORM(COCOA)
     442    std::unique_ptr<ClassMethodSwizzler> m_calendarSwizzler;
     443    RetainPtr<NSString> m_overriddenCalendarIdentifier;
     444#endif // PLATFORM(COCOA)
    417445    bool m_verbose { false };
    418446    bool m_printSeparators { false };
  • trunk/Tools/WebKitTestRunner/UIScriptControllerCocoa.mm

    r237786 r237924  
    165165}
    166166
     167void UIScriptController::setDefaultCalendarType(JSStringRef calendarIdentifier)
     168{
     169#if WK_API_ENABLED
     170    TestController::singleton().setDefaultCalendarType((__bridge NSString *)adoptCF(JSStringCopyCFString(kCFAllocatorDefault, calendarIdentifier)).get());
     171#endif
     172}
     173
     174JSObjectRef UIScriptController::calendarType() const
     175{
     176#if WK_API_ENABLED
     177    WKWebView *webView = TestController::singleton().mainWebView()->platformView();
     178    UIView *contentView = [webView valueForKeyPath:@"_currentContentView"];
     179    NSString *calendarTypeString = [contentView valueForKeyPath:@"formInputControl.dateTimePickerCalendarType"];
     180    auto jsContext = m_context->jsContext();
     181    return JSValueToObject(jsContext, [JSValue valueWithObject:calendarTypeString inContext:[JSContext contextWithJSGlobalContextRef:jsContext]].JSValueRef, nullptr);
     182#else
     183    return nullptr;
     184#endif
     185}
     186   
    167187} // namespace WTR
  • trunk/Tools/WebKitTestRunner/cocoa/TestControllerCocoa.mm

    r237893 r237924  
    204204}
    205205
     206ClassMethodSwizzler::ClassMethodSwizzler(Class cls, SEL originalSelector, IMP implementation)
     207    : m_method(class_getClassMethod(objc_getMetaClass(NSStringFromClass(cls).UTF8String), originalSelector))
     208    , m_originalImplementation(method_setImplementation(m_method, implementation))
     209{
     210}
     211
     212ClassMethodSwizzler::~ClassMethodSwizzler()
     213{
     214    method_setImplementation(m_method, m_originalImplementation);
     215}
     216   
     217static NSCalendar *swizzledCalendar()
     218{
     219    return [NSCalendar calendarWithIdentifier:TestController::singleton().getOverriddenCalendarIdentifier().get()];
     220}
     221   
     222RetainPtr<NSString> TestController::getOverriddenCalendarIdentifier() const
     223{
     224    return m_overriddenCalendarIdentifier;
     225}
     226
     227void TestController::setDefaultCalendarType(NSString *identifier)
     228{
     229    m_overriddenCalendarIdentifier = identifier;
     230    if (!m_calendarSwizzler)
     231        m_calendarSwizzler = std::make_unique<ClassMethodSwizzler>([NSCalendar class], @selector(currentCalendar), reinterpret_cast<IMP>(swizzledCalendar));
     232}
     233   
    206234void TestController::cocoaResetStateToConsistentValues(const TestOptions& options)
    207235{
     
    215243
    216244
     245    m_calendarSwizzler = nullptr;
     246    m_overriddenCalendarIdentifier = nil;
     247   
    217248    if (auto* webView = mainWebView()) {
    218249        TestRunnerWKWebView *platformView = webView->platformView();
Note: See TracChangeset for help on using the changeset viewer.