Title: [237924] trunk
Revision
237924
Author
commit-qu...@webkit.org
Date
2018-11-07 06:57:40 -0800 (Wed, 07 Nov 2018)

Log 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 <zha...@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 <zha...@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 <zha...@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):

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (237923 => 237924)


--- trunk/LayoutTests/ChangeLog	2018-11-07 14:49:17 UTC (rev 237923)
+++ trunk/LayoutTests/ChangeLog	2018-11-07 14:57:40 UTC (rev 237924)
@@ -1,3 +1,23 @@
+2018-11-07  Zamiul Haque  <zha...@apple.com>
+
+        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
+
+        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):
+
 2018-11-07  Tadeu Zagallo  <tzaga...@apple.com>
 
         REGRESSION(r237547): Test failures on 32-bit JSC since the JIT was disabled

Added: trunk/LayoutTests/fast/forms/ios/force-gregorian-calendar-for-credit-card-expiry-expected.txt (0 => 237924)


--- trunk/LayoutTests/fast/forms/ios/force-gregorian-calendar-for-credit-card-expiry-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/forms/ios/force-gregorian-calendar-for-credit-card-expiry-expected.txt	2018-11-07 14:57:40 UTC (rev 237924)
@@ -0,0 +1,9 @@
+ 
+Date input control marked as 'cc-exp' (default calendar set to japanese):
+{ calendarType = gregorian }
+Date input control not marked as 'cc-exp' (default calendar set to japanese):
+{ calendarType = japanese }
+Date input control marked as 'cc-exp' (default calendar set to gregorian):
+{ calendarType = gregorian }
+Date input control not marked as 'cc-exp' (default calendar set to gregorian):
+{ calendarType = gregorian }

Added: trunk/LayoutTests/fast/forms/ios/force-gregorian-calendar-for-credit-card-expiry.html (0 => 237924)


--- trunk/LayoutTests/fast/forms/ios/force-gregorian-calendar-for-credit-card-expiry.html	                        (rev 0)
+++ trunk/LayoutTests/fast/forms/ios/force-gregorian-calendar-for-credit-card-expiry.html	2018-11-07 14:57:40 UTC (rev 237924)
@@ -0,0 +1,73 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <script src=""
+    <meta name=viewport content="width=device-width">
+    <style>
+        body, html {
+            width: 100%;
+            height: 100%;
+            margin: 0;
+        }
+
+        #target0, #target1 {
+            font-size: 150px;
+        }
+    </style>
+</head>
+<body>
+    <input type='date' id='target0' autocomplete='cc-exp'>
+    <input type='date' id='target1'>
+    <pre id="output"></pre>
+    <script>
+        if (window.testRunner) {
+            testRunner.dumpAsText();
+            testRunner.waitUntilDone();
+        }
+
+        function appendOutput(s)
+        {
+            const paragraph = document.createElement("div");
+            paragraph.innerHTML = s;
+            output.appendChild(paragraph);
+        }
+
+        function toString(value)
+        {
+            return `{ calendarType = ${value} }`;
+        }
+
+        (async () => {
+
+            if (!window.testRunner || !testRunner.runUIScript) {
+                appendOutput(`This test checks if a gregorian calendar is presented when a date input control marked
+                    as a credit card expiry date field (ie. through autocomplete='cc-exp') is tapped on Safari iOS. For
+                    manual testing, tap the date field(s) and ensure the proper calendar types are presented.`);
+                return;
+            }
+
+            await UIHelper.setDefaultCalendarType("japanese");
+            await UIHelper.activateElement(target0);
+            appendOutput("Date input control marked as 'cc-exp' (default calendar set to japanese):");
+            appendOutput(toString(await UIHelper.calendarType()));
+
+            await UIHelper.activateElement(target1);
+            appendOutput("Date input control not marked as 'cc-exp' (default calendar set to japanese):");
+            appendOutput(toString(await UIHelper.calendarType()));
+
+            await UIHelper.setDefaultCalendarType("gregorian");
+            await UIHelper.activateElement(target0);
+            appendOutput("Date input control marked as 'cc-exp' (default calendar set to gregorian):");
+            appendOutput(toString(await UIHelper.calendarType()));
+
+            await UIHelper.activateElement(target1);
+            appendOutput("Date input control not marked as 'cc-exp' (default calendar set to gregorian):");
+            appendOutput(toString(await UIHelper.calendarType()));
+
+            testRunner.notifyDone();
+
+        })()
+
+    </script>
+</body>
+</html>
\ No newline at end of file

Modified: trunk/LayoutTests/resources/ui-helper.js (237923 => 237924)


--- trunk/LayoutTests/resources/ui-helper.js	2018-11-07 14:49:17 UTC (rev 237923)
+++ trunk/LayoutTests/resources/ui-helper.js	2018-11-07 14:57:40 UTC (rev 237924)
@@ -346,6 +346,31 @@
         });
     }
 
+    static calendarType()
+    {
+        if (!this.isWebKit2())
+            return Promise.resolve();
+
+        return new Promise(resolve => {
+            testRunner.runUIScript(`(() => {
+                uiController.doAfterNextStablePresentationUpdate(() => {
+                    uiController.uiScriptComplete(JSON.stringify(uiController.calendarType));
+                })
+            })()`, jsonString => {
+                resolve(JSON.parse(jsonString));
+            });
+        });
+    }
+
+    static setDefaultCalendarType(calendarIdentifier)
+    {
+        if (!this.isWebKit2())
+            return Promise.resolve();
+
+        return new Promise(resolve => testRunner.runUIScript(`uiController.setDefaultCalendarType('${calendarIdentifier}')`, resolve));
+
+    }
+
     static setViewScale(scale)
     {
         if (!this.isWebKit2())

Modified: trunk/Source/WebKit/ChangeLog (237923 => 237924)


--- trunk/Source/WebKit/ChangeLog	2018-11-07 14:49:17 UTC (rev 237923)
+++ trunk/Source/WebKit/ChangeLog	2018-11-07 14:57:40 UTC (rev 237924)
@@ -1,3 +1,21 @@
+2018-11-07  Zamiul Haque  <zha...@apple.com>
+
+        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
+
+        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:
+
 2018-11-07  Carlos Garcia Campos  <cgar...@igalia.com>
 
         Unreviewed. Fix GTK/WPE build when memfd is not available after r237922.

Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h (237923 => 237924)


--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h	2018-11-07 14:49:17 UTC (rev 237923)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h	2018-11-07 14:57:40 UTC (rev 237924)
@@ -92,6 +92,7 @@
 @class WebEvent;
 @class WKActionSheetAssistant;
 @class WKFocusedFormControlView;
+@class WKFormInputControl;
 @class WKFormInputSession;
 @class WKInspectorNodeSearchGestureRecognizer;
 
@@ -422,6 +423,7 @@
 @property (nonatomic, readonly) NSString *textContentTypeForTesting;
 @property (nonatomic, readonly) NSString *selectFormPopoverTitle;
 @property (nonatomic, readonly) NSString *formInputLabel;
+@property (nonatomic, readonly) WKFormInputControl *formInputControl;
 
 @end
 

Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (237923 => 237924)


--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2018-11-07 14:49:17 UTC (rev 237923)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2018-11-07 14:57:40 UTC (rev 237924)
@@ -5961,6 +5961,13 @@
 
 @implementation WKContentView (WKTesting)
 
+- (WKFormInputControl *)formInputControl
+{
+    if ([_inputPeripheral isKindOfClass:WKFormInputControl.class])
+        return (WKFormInputControl *)_inputPeripheral.get();
+    return nil;
+}
+
 - (void)_simulateTextEntered:(NSString *)text
 {
 #if PLATFORM(WATCHOS)

Modified: trunk/Source/WebKit/UIProcess/ios/forms/WKFormInputControl.h (237923 => 237924)


--- trunk/Source/WebKit/UIProcess/ios/forms/WKFormInputControl.h	2018-11-07 14:49:17 UTC (rev 237923)
+++ trunk/Source/WebKit/UIProcess/ios/forms/WKFormInputControl.h	2018-11-07 14:57:40 UTC (rev 237924)
@@ -33,4 +33,8 @@
 - (instancetype)initWithView:(WKContentView *)view;
 @end
 
+@interface WKFormInputControl (WKTesting)
+@property (nonatomic, readonly) NSString *dateTimePickerCalendarType;
+@end
+
 #endif // PLATFORM(IOS_FAMILY)

Modified: trunk/Source/WebKit/UIProcess/ios/forms/WKFormInputControl.mm (237923 => 237924)


--- trunk/Source/WebKit/UIProcess/ios/forms/WKFormInputControl.mm	2018-11-07 14:49:17 UTC (rev 237923)
+++ trunk/Source/WebKit/UIProcess/ios/forms/WKFormInputControl.mm	2018-11-07 14:57:40 UTC (rev 237924)
@@ -47,6 +47,14 @@
 - (NSObject<WKFormControl> *)innerControl;
 @end
 
+@interface WKDateTimePopover : WKFormRotatingAccessoryPopover<WKFormControl> {
+    RetainPtr<WKDateTimePopoverViewController> _viewController;
+    WKContentView *_view;
+}
+- (id)initWithView:(WKContentView *)view datePickerMode:(UIDatePickerMode)mode;
+- (WKDateTimePopoverViewController *)viewController;
+@end
+
 @interface WKDateTimePicker : NSObject<WKFormControl> {
     RetainPtr<UIDatePicker> _datePicker;
     NSString *_formatString;
@@ -56,14 +64,7 @@
 }
 - (id)initWithView:(WKContentView *)view datePickerMode:(UIDatePickerMode)mode;
 - (UIDatePicker *)datePicker;
-@end
 
-@interface WKDateTimePopover : WKFormRotatingAccessoryPopover<WKFormControl> {
-    RetainPtr<WKDateTimePopoverViewController> _viewController;
-    WKContentView* _view;
-}
-- (id)initWithView:(WKContentView *)view datePickerMode:(UIDatePickerMode)mode;
-- (WKDateTimePopoverViewController *) viewController;
 @end
 
 @implementation WKDateTimePicker
@@ -109,11 +110,20 @@
     _datePicker = adoptNS([[UIDatePicker alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)]);
     _datePicker.get().datePickerMode = mode;
     _datePicker.get().hidden = NO;
+    
+    if ([self shouldPresentGregorianCalendar:view.assistedNodeInformation])
+        _datePicker.get().calendar = [NSCalendar calendarWithIdentifier:NSCalendarIdentifierGregorian];
+    
     [_datePicker addTarget:self action:@selector(_dateChangeHandler:) forControlEvents:UIControlEventValueChanged];
 
     return self;
 }
 
+- (NSString *)calendarType
+{
+    return _datePicker.get().calendar.calendarIdentifier;
+}
+
 - (void)dealloc
 {
     [_datePicker removeTarget:self action:NULL forControlEvents:UIControlEventValueChanged];
@@ -120,6 +130,13 @@
     [super dealloc];
 }
 
+- (BOOL)shouldPresentGregorianCalendar:(const AssistedNodeInformation&)nodeInfo
+{
+    return nodeInfo.autofillFieldName == WebCore::AutofillFieldName::CcExpMonth
+        || nodeInfo.autofillFieldName == WebCore::AutofillFieldName::CcExp
+        || nodeInfo.autofillFieldName == WebCore::AutofillFieldName::CcExpYear;
+}
+
 - (UIView *)controlView
 {
     return _datePicker.get();
@@ -280,6 +297,14 @@
 
 @end
 
+@implementation WKFormInputControl (WKTesting)
+- (NSString *)dateTimePickerCalendarType
+{
+    if ([(NSObject *)_control.get() isKindOfClass:WKDateTimePicker.class])
+        return [(WKDateTimePicker *)_control.get() calendarType];
+    return nil;
+}
+@end
 
 @implementation WKDateTimePopoverViewController
 

Modified: trunk/Tools/ChangeLog (237923 => 237924)


--- trunk/Tools/ChangeLog	2018-11-07 14:49:17 UTC (rev 237923)
+++ trunk/Tools/ChangeLog	2018-11-07 14:57:40 UTC (rev 237924)
@@ -1,3 +1,40 @@
+2018-11-07  Zamiul Haque  <zha...@apple.com>
+
+        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
+
+        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.
+
 2018-11-06  Jonathan Bedard  <jbed...@apple.com>
 
         webkitpy: Boot a single worker for custom devices

Modified: trunk/Tools/DumpRenderTree/ios/UIScriptControllerIOS.mm (237923 => 237924)


--- trunk/Tools/DumpRenderTree/ios/UIScriptControllerIOS.mm	2018-11-07 14:49:17 UTC (rev 237923)
+++ trunk/Tools/DumpRenderTree/ios/UIScriptControllerIOS.mm	2018-11-07 14:57:40 UTC (rev 237924)
@@ -394,6 +394,15 @@
     return false;
 }
 
+JSObjectRef UIScriptController::calendarType() const
+{
+    return nullptr;
+}
+
+void UIScriptController::setDefaultCalendarType(JSStringRef calendarIdentifier)
+{
+}
+
 void UIScriptController::overridePreference(JSStringRef, JSStringRef)
 {
 }

Modified: trunk/Tools/DumpRenderTree/mac/UIScriptControllerMac.mm (237923 => 237924)


--- trunk/Tools/DumpRenderTree/mac/UIScriptControllerMac.mm	2018-11-07 14:49:17 UTC (rev 237923)
+++ trunk/Tools/DumpRenderTree/mac/UIScriptControllerMac.mm	2018-11-07 14:57:40 UTC (rev 237924)
@@ -196,7 +196,16 @@
 void UIScriptController::setShareSheetCompletesImmediatelyWithResolution(bool)
 {
 }
+    
+JSObjectRef UIScriptController::calendarType() const
+{
+    return nullptr;
+}
 
+void UIScriptController::setDefaultCalendarType(JSStringRef calendarIdentifier)
+{
 }
+    
+}
 
 #endif // PLATFORM(MAC)

Modified: trunk/Tools/TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl (237923 => 237924)


--- trunk/Tools/TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl	2018-11-07 14:49:17 UTC (rev 237923)
+++ trunk/Tools/TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl	2018-11-07 14:57:40 UTC (rev 237924)
@@ -22,7 +22,7 @@
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
- 
+
 enum DeviceOrientation {
     "portrait",
     "portrait-upsidedown",
@@ -242,7 +242,8 @@
     readonly attribute object textSelectionCaretRect; // An object with 'left', 'top', 'width', 'height' properties.
     readonly attribute object selectionStartGrabberViewRect;
     readonly attribute object selectionEndGrabberViewRect;
-
+    readonly attribute object calendarType;
+    void setDefaultCalendarType(DOMString calendarIdentifier);
     readonly attribute object inputViewBounds;
 
     void replaceTextAtRange(DOMString text, long location, long length);

Modified: trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptController.cpp (237923 => 237924)


--- trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptController.cpp	2018-11-07 14:49:17 UTC (rev 237923)
+++ trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptController.cpp	2018-11-07 14:57:40 UTC (rev 237924)
@@ -226,6 +226,16 @@
 {
     return nullptr;
 }
+    
+void UIScriptController::setDefaultCalendarType(JSStringRef calendarIdentifier)
+{
+}
+
+JSObjectRef UIScriptController::calendarType() const
+{
+    return nullptr;
+}
+    
 #endif
 
 void UIScriptController::playBackEventStream(JSStringRef stream, JSValueRef callback)

Modified: trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptController.h (237923 => 237924)


--- trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptController.h	2018-11-07 14:49:17 UTC (rev 237923)
+++ trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptController.h	2018-11-07 14:57:40 UTC (rev 237924)
@@ -163,6 +163,8 @@
     JSObjectRef textSelectionCaretRect() const;
     JSObjectRef selectionStartGrabberViewRect() const;
     JSObjectRef selectionEndGrabberViewRect() const;
+    JSObjectRef calendarType() const;
+    void setDefaultCalendarType(JSStringRef calendarIdentifier);
     JSObjectRef inputViewBounds() const;
 
     void replaceTextAtRange(JSStringRef, int location, int length);

Modified: trunk/Tools/WebKitTestRunner/TestController.h (237923 => 237924)


--- trunk/Tools/WebKitTestRunner/TestController.h	2018-11-07 14:49:17 UTC (rev 237923)
+++ trunk/Tools/WebKitTestRunner/TestController.h	2018-11-07 14:57:40 UTC (rev 237924)
@@ -33,10 +33,18 @@
 #include <string>
 #include <vector>
 #include <wtf/HashMap.h>
+#include <wtf/Noncopyable.h>
 #include <wtf/Seconds.h>
 #include <wtf/Vector.h>
 #include <wtf/text/StringHash.h>
 
+#if PLATFORM(COCOA)
+
+#include <objc/runtime.h>
+
+#endif
+
+OBJC_CLASS NSString;
 OBJC_CLASS WKWebViewConfiguration;
 
 namespace WTR {
@@ -48,6 +56,19 @@
 struct TestCommand;
 struct TestOptions;
 
+#if PLATFORM(COCOA)
+// FIXME: This should be shared with TestWebKitAPI.
+class ClassMethodSwizzler {
+    WTF_MAKE_NONCOPYABLE(ClassMethodSwizzler);
+public:
+    ClassMethodSwizzler(Class, SEL, IMP);
+    ~ClassMethodSwizzler();
+    
+    Method m_method;
+    IMP m_originalImplementation;
+};
+#endif // PLATFORM(COCOA)
+
 class AsyncTask {
 public:
     AsyncTask(WTF::Function<void ()>&& task, WTF::Seconds timeout)
@@ -262,6 +283,10 @@
 
     void toggleCapsLock();
 
+#if PLATFORM(COCOA)
+    RetainPtr<NSString> getOverriddenCalendarIdentifier() const;
+    void setDefaultCalendarType(NSString *identifier);
+#endif // PLATFORM(COCOA)
 private:
     WKRetainPtr<WKPageConfigurationRef> generatePageConfiguration(WKContextConfigurationRef);
     WKRetainPtr<WKContextConfigurationRef> generateContextConfiguration() const;
@@ -413,7 +438,10 @@
     static const char* platformLibraryPathForTesting();
 
     std::unique_ptr<TestInvocation> m_currentInvocation;
-
+#if PLATFORM(COCOA)
+    std::unique_ptr<ClassMethodSwizzler> m_calendarSwizzler;
+    RetainPtr<NSString> m_overriddenCalendarIdentifier;
+#endif // PLATFORM(COCOA)
     bool m_verbose { false };
     bool m_printSeparators { false };
     bool m_usingServerMode { false };

Modified: trunk/Tools/WebKitTestRunner/UIScriptControllerCocoa.mm (237923 => 237924)


--- trunk/Tools/WebKitTestRunner/UIScriptControllerCocoa.mm	2018-11-07 14:49:17 UTC (rev 237923)
+++ trunk/Tools/WebKitTestRunner/UIScriptControllerCocoa.mm	2018-11-07 14:57:40 UTC (rev 237924)
@@ -164,4 +164,24 @@
 #endif
 }
 
+void UIScriptController::setDefaultCalendarType(JSStringRef calendarIdentifier)
+{
+#if WK_API_ENABLED
+    TestController::singleton().setDefaultCalendarType((__bridge NSString *)adoptCF(JSStringCopyCFString(kCFAllocatorDefault, calendarIdentifier)).get());
+#endif
+}
+
+JSObjectRef UIScriptController::calendarType() const
+{
+#if WK_API_ENABLED
+    WKWebView *webView = TestController::singleton().mainWebView()->platformView();
+    UIView *contentView = [webView valueForKeyPath:@"_currentContentView"];
+    NSString *calendarTypeString = [contentView valueForKeyPath:@"formInputControl.dateTimePickerCalendarType"];
+    auto jsContext = m_context->jsContext();
+    return JSValueToObject(jsContext, [JSValue valueWithObject:calendarTypeString inContext:[JSContext contextWithJSGlobalContextRef:jsContext]].JSValueRef, nullptr);
+#else
+    return nullptr;
+#endif
+}
+    
 } // namespace WTR

Modified: trunk/Tools/WebKitTestRunner/cocoa/TestControllerCocoa.mm (237923 => 237924)


--- trunk/Tools/WebKitTestRunner/cocoa/TestControllerCocoa.mm	2018-11-07 14:49:17 UTC (rev 237923)
+++ trunk/Tools/WebKitTestRunner/cocoa/TestControllerCocoa.mm	2018-11-07 14:57:40 UTC (rev 237924)
@@ -203,6 +203,34 @@
         [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:endDate];
 }
 
+ClassMethodSwizzler::ClassMethodSwizzler(Class cls, SEL originalSelector, IMP implementation)
+    : m_method(class_getClassMethod(objc_getMetaClass(NSStringFromClass(cls).UTF8String), originalSelector))
+    , m_originalImplementation(method_setImplementation(m_method, implementation))
+{
+}
+
+ClassMethodSwizzler::~ClassMethodSwizzler()
+{
+    method_setImplementation(m_method, m_originalImplementation);
+}
+    
+static NSCalendar *swizzledCalendar()
+{
+    return [NSCalendar calendarWithIdentifier:TestController::singleton().getOverriddenCalendarIdentifier().get()];
+}
+    
+RetainPtr<NSString> TestController::getOverriddenCalendarIdentifier() const
+{
+    return m_overriddenCalendarIdentifier;
+}
+
+void TestController::setDefaultCalendarType(NSString *identifier)
+{
+    m_overriddenCalendarIdentifier = identifier;
+    if (!m_calendarSwizzler)
+        m_calendarSwizzler = std::make_unique<ClassMethodSwizzler>([NSCalendar class], @selector(currentCalendar), reinterpret_cast<IMP>(swizzledCalendar));
+}
+    
 void TestController::cocoaResetStateToConsistentValues(const TestOptions& options)
 {
 #if WK_API_ENABLED
@@ -214,6 +242,9 @@
     [[_WKUserContentExtensionStore defaultStore] _removeAllContentExtensions];
 
 
+    m_calendarSwizzler = nullptr;
+    m_overriddenCalendarIdentifier = nil;
+    
     if (auto* webView = mainWebView()) {
         TestRunnerWKWebView *platformView = webView->platformView();
         [platformView.configuration.userContentController _removeAllUserContentFilters];
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to