Add basic layout test coverage for File Picker on iOS
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 26 Mar 2019 23:24:35 +0000 (23:24 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 26 Mar 2019 23:24:35 +0000 (23:24 +0000)
https://bugs.webkit.org/show_bug.cgi?id=196265

Reviewed by Wenson Hsieh.

Source/WebKit:

Add layout test infrastructure to test the file picker on iOS.

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _dismissFilePicker]):
* UIProcess/API/Cocoa/WKWebViewPrivate.h:
* UIProcess/ios/WKContentViewInteraction.h:
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView dismissFilePicker]):
(-[WKContentView _contentsOfUserInterfaceItem:]):
* UIProcess/ios/forms/WKFileUploadPanel.h:
* UIProcess/ios/forms/WKFileUploadPanel.mm:
(-[WKFileUploadPanel currentAvailableActionTitles]):

Tools:

Add layout test infrastructure to test the file picker on iOS.

* DumpRenderTree/ios/UIScriptControllerIOS.mm:
(WTR::UIScriptController::dismissFilePicker):
* TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl:
* TestRunnerShared/UIScriptContext/UIScriptController.cpp:
(WTR::UIScriptController::dismissFilePicker):
* TestRunnerShared/UIScriptContext/UIScriptController.h:
* WebKitTestRunner/TestController.cpp:
(WTR::TestController::createWebViewWithOptions):
(WTR::updateTestOptionsFromTestHeader):
* WebKitTestRunner/TestOptions.h:
(WTR::TestOptions::hasSameInitializationOptions const):
* WebKitTestRunner/ios/TestControllerIOS.mm:
(overridePresentViewController):
(WTR::TestController::platformInitialize):
* WebKitTestRunner/ios/UIScriptControllerIOS.mm:
(WTR::UIScriptController::dismissFilePicker):

LayoutTests:

Add new layout test.

* fast/forms/ios/file-upload-panel-expected.txt: Added.
* fast/forms/ios/file-upload-panel.html: Added.

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

19 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/forms/ios/file-upload-panel-expected.txt [new file with mode: 0644]
LayoutTests/fast/forms/ios/file-upload-panel.html [new file with mode: 0644]
Source/WebKit/ChangeLog
Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h
Source/WebKit/UIProcess/ios/WKContentViewInteraction.h
Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
Source/WebKit/UIProcess/ios/forms/WKFileUploadPanel.h
Source/WebKit/UIProcess/ios/forms/WKFileUploadPanel.mm
Tools/ChangeLog
Tools/DumpRenderTree/ios/UIScriptControllerIOS.mm
Tools/TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl
Tools/TestRunnerShared/UIScriptContext/UIScriptController.cpp
Tools/TestRunnerShared/UIScriptContext/UIScriptController.h
Tools/WebKitTestRunner/TestController.cpp
Tools/WebKitTestRunner/TestOptions.h
Tools/WebKitTestRunner/ios/TestControllerIOS.mm
Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm

index edf1f62..7787e90 100644 (file)
@@ -1,3 +1,15 @@
+2019-03-26  Chris Dumez  <cdumez@apple.com>
+
+        Add basic layout test coverage for File Picker on iOS
+        https://bugs.webkit.org/show_bug.cgi?id=196265
+
+        Reviewed by Wenson Hsieh.
+
+        Add new layout test.
+
+        * fast/forms/ios/file-upload-panel-expected.txt: Added.
+        * fast/forms/ios/file-upload-panel.html: Added.
+
 2019-03-26  Shawn Roberts  <sroberts@apple.com>
 
         Layout tests editing/deleting/delete-emoji-1.html
diff --git a/LayoutTests/fast/forms/ios/file-upload-panel-expected.txt b/LayoutTests/fast/forms/ios/file-upload-panel-expected.txt
new file mode 100644 (file)
index 0000000..98014af
--- /dev/null
@@ -0,0 +1,39 @@
+Basic testing for the File Upload Panel on iOS.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+* accept = 
+PASS areArraysEqual(items, ["Photo Library", "Take Photo or Video", "Browse"]) is true
+
+* accept = image/*
+PASS areArraysEqual(items, ["Photo Library", "Take Photo", "Browse"]) is true
+
+* accept = video/*
+PASS areArraysEqual(items, ["Photo Library", "Take Video", "Browse"]) is true
+
+* accept = image/*, video/*
+PASS areArraysEqual(items, ["Photo Library", "Take Photo or Video", "Browse"]) is true
+
+* accept = .PNG, .GIF
+PASS areArraysEqual(items, ["Photo Library", "Take Photo", "Browse"]) is true
+
+* accept = .PNG, .GIF, .MOV
+PASS areArraysEqual(items, ["Photo Library", "Take Photo or Video", "Browse"]) is true
+
+* accept = audio/*
+PASS areArraysEqual(items, ["Browse"]) is true
+
+* accept = .TXT
+PASS areArraysEqual(items, ["Browse"]) is true
+
+* accept = .PDF
+PASS areArraysEqual(items, ["Browse"]) is true
+
+* accept = .PDF, .TXT
+PASS areArraysEqual(items, ["Browse"]) is true
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/forms/ios/file-upload-panel.html b/LayoutTests/fast/forms/ios/file-upload-panel.html
new file mode 100644 (file)
index 0000000..299540d
--- /dev/null
@@ -0,0 +1,90 @@
+<!DOCTYPE html> <!-- webkit-test-runner [ useFlexibleViewport=true, shouldHandleRunOpenPanel=false ] -->
+<html>
+<head>
+<meta name="viewport" content="width=device-width">
+<script src="../../../resources/js-test.js"></script>
+<script src="../../../resources/ui-helper.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<input id="testInput" type="file">
+<div id="console"></div>
+<script>
+description("Basic testing for the File Upload Panel on iOS.");
+jsTestIsAsync = true;
+
+function getFileUploadPickerMenuItemsScript()
+{ 
+    return `
+    (function() {
+        return JSON.stringify(uiController.contentsOfUserInterfaceItem('fileUploadPanelMenu'));
+    })();`
+}
+
+function dismissFilePickerScript()
+{
+    return `
+    (function() {
+        uiController.dismissFilePicker(function() {
+            uiController.uiScriptComplete();
+        });
+    })();`
+}
+
+function getFileUploadPickerMenuItems()
+{
+    return new Promise((resolve) => {
+        testRunner.runUIScript(getFileUploadPickerMenuItemsScript(), function(result) {
+            resolve(JSON.parse(result).fileUploadPanelMenu);
+        });
+    });
+}
+
+function dismissFilePicker()
+{
+    const uiScript = `uiController.dismissFilePicker(() => uiController.uiScriptComplete())`;
+    return new Promise(resolve => testRunner.runUIScript(uiScript, resolve));
+}
+
+function runAcceptTest(accept, expectedMenuItems)
+{
+    return new Promise((resolve) => {
+        debug("* accept = " + accept);
+        testInput.accept = accept;
+
+        UIHelper.activateElement(testInput).then(() => {
+            getFileUploadPickerMenuItems().then((_items) => {
+                items = _items;
+                shouldBeTrue("areArraysEqual(items, " + expectedMenuItems + ")");
+                debug("");
+                dismissFilePicker().then(() => { resolve(); });
+            });
+        });
+    });
+}
+
+async function runTests()
+{
+    document.getElementById("console").style = "display: none";
+
+    await runAcceptTest("", '["Photo Library", "Take Photo or Video", "Browse"]');
+    await runAcceptTest("image/*", '["Photo Library", "Take Photo", "Browse"]');
+    await runAcceptTest("video/*", '["Photo Library", "Take Video", "Browse"]');
+    await runAcceptTest("image/*, video/*", '["Photo Library", "Take Photo or Video", "Browse"]');
+    await runAcceptTest(".PNG, .GIF", '["Photo Library", "Take Photo", "Browse"]');
+    await runAcceptTest(".PNG, .GIF, .MOV", '["Photo Library", "Take Photo or Video", "Browse"]');
+    await runAcceptTest("audio/*", '["Browse"]');
+    await runAcceptTest(".TXT", '["Browse"]');
+    await runAcceptTest(".PDF", '["Browse"]');
+    await runAcceptTest(".PDF, .TXT", '["Browse"]');
+
+    document.getElementById("console").style = "";
+    finishJSTest();
+}
+
+
+onload = runTests;
+
+</script>
+</body>
+</html>
index 036594b..a93cec7 100644 (file)
@@ -1,3 +1,23 @@
+2019-03-26  Chris Dumez  <cdumez@apple.com>
+
+        Add basic layout test coverage for File Picker on iOS
+        https://bugs.webkit.org/show_bug.cgi?id=196265
+
+        Reviewed by Wenson Hsieh.
+
+        Add layout test infrastructure to test the file picker on iOS.
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _dismissFilePicker]):
+        * UIProcess/API/Cocoa/WKWebViewPrivate.h:
+        * UIProcess/ios/WKContentViewInteraction.h:
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView dismissFilePicker]):
+        (-[WKContentView _contentsOfUserInterfaceItem:]):
+        * UIProcess/ios/forms/WKFileUploadPanel.h:
+        * UIProcess/ios/forms/WKFileUploadPanel.mm:
+        (-[WKFileUploadPanel currentAvailableActionTitles]):
+
 2019-03-26  Daniel Bates  <dabates@apple.com>
 
         [iOS][WK2] Use a better concept to describe the reason we defer zooming a focused element: selectabiltiy
index 2219785..d90e8ea 100644 (file)
@@ -6669,6 +6669,11 @@ static WebCore::UserInterfaceLayoutDirection toUserInterfaceLayoutDirection(UISe
     [_contentView accessoryDone];
 }
 
+- (void)_dismissFilePicker
+{
+    [_contentView dismissFilePicker];
+}
+
 - (void)setTimePickerValueToHour:(NSInteger)hour minute:(NSInteger)minute
 {
     [_contentView setTimePickerValueToHour:hour minute:minute];
index 8e99ece..a86d145 100644 (file)
@@ -451,6 +451,7 @@ typedef NS_OPTIONS(NSUInteger, _WKRectEdge) {
 - (void)keyboardAccessoryBarNext WK_API_AVAILABLE(ios(10.0));
 - (void)keyboardAccessoryBarPrevious WK_API_AVAILABLE(ios(10.0));
 - (void)dismissFormAccessoryView WK_API_AVAILABLE(ios(10.3));
+- (void)_dismissFilePicker WK_API_AVAILABLE(ios(WK_IOS_TBA));
 - (void)selectFormAccessoryPickerRow:(int)rowIndex WK_API_AVAILABLE(ios(10.3));
 @property (nonatomic, readonly) NSString *textContentTypeForTesting WK_API_AVAILABLE(ios(12.0));
 @property (nonatomic, readonly) NSString *selectFormPopoverTitle WK_API_AVAILABLE(ios(12.0));
index 78839f0..f8df13c 100644 (file)
@@ -430,6 +430,7 @@ FOR_EACH_PRIVATE_WKCONTENTVIEW_ACTION(DECLARE_WKCONTENTVIEW_ACTION_FOR_WEB_VIEW)
 - (void)_showRunOpenPanel:(API::OpenPanelParameters*)parameters resultListener:(WebKit::WebOpenPanelResultListenerProxy*)listener;
 - (void)_showShareSheet:(const WebCore::ShareDataWithParsedURL&)shareData completionHandler:(WTF::CompletionHandler<void(bool)>&&)completionHandler;
 - (void)accessoryDone;
+- (void)dismissFilePicker;
 - (void)_didHandleKeyEvent:(::WebEvent *)event eventWasHandled:(BOOL)eventWasHandled;
 - (Vector<WebKit::OptionItem>&) focusedSelectElementOptions;
 - (void)_enableInspectorNodeSearch;
index 461ffa9..feb285e 100644 (file)
@@ -4509,6 +4509,11 @@ static NSString *contentTypeFromFieldName(WebCore::AutofillFieldName fieldName)
     return NO;
 }
 
+- (void)dismissFilePicker
+{
+    [_fileUploadPanel dismiss];
+}
+
 - (BOOL)isScrollableForKeyboardScrollViewAnimator:(WKKeyboardScrollViewAnimator *)animator
 {
     if (_page->editorState().isContentEditable)
@@ -7019,6 +7024,12 @@ static WebEventFlags webEventFlagsForUIKeyModifierFlags(UIKeyModifierFlags flags
         return @{ userInterfaceItem: @{ @"pageURL": url } };
     }
 #endif
+
+    if ([userInterfaceItem isEqualToString:@"fileUploadPanelMenu"]) {
+        if (!_fileUploadPanel)
+            return @{ userInterfaceItem: @[] };
+        return @{ userInterfaceItem: [_fileUploadPanel currentAvailableActionTitles] };
+    }
     
     return nil;
 }
index d6d72e6..8649701 100644 (file)
@@ -43,6 +43,8 @@ class WebOpenPanelResultListenerProxy;
 - (instancetype)initWithView:(WKContentView *)view;
 - (void)presentWithParameters:(API::OpenPanelParameters*)parameters resultListener:(WebKit::WebOpenPanelResultListenerProxy*)listener;
 - (void)dismiss;
+
+- (NSArray<NSString *> *)currentAvailableActionTitles;
 @end
 
 @protocol WKFileUploadPanelDelegate <NSObject>
index 1e94b8d..f5780d8 100644 (file)
@@ -312,6 +312,26 @@ static inline UIImage *cameraIcon()
     }
 }
 
+- (NSArray<NSString *> *)currentAvailableActionTitles
+{
+    NSMutableArray<NSString *> *actionTitles = [NSMutableArray array];
+
+    NSArray *mediaTypes = UTIsForMIMETypes(_mimeTypes.get()).allObjects;
+    BOOL containsImageMediaType = !mediaTypes.count || arrayContainsUTIThatConformsTo(mediaTypes, kUTTypeImage);
+    BOOL containsVideoMediaType = !mediaTypes.count || arrayContainsUTIThatConformsTo(mediaTypes, kUTTypeMovie);
+    if (containsImageMediaType || containsVideoMediaType) {
+        [actionTitles addObject:@"Photo Library"];
+        if (containsImageMediaType && containsVideoMediaType)
+            [actionTitles addObject:@"Take Photo or Video"];
+        else if (containsVideoMediaType)
+            [actionTitles addObject:@"Take Video"];
+        else
+            [actionTitles addObject:@"Take Photo"];
+    }
+    [actionTitles addObject:@"Browse"];
+    return actionTitles;
+}
+
 #pragma mark - Media Types
 
 static NSSet<NSString *> *UTIsForMIMETypes(NSArray *mimeTypes)
index c8af0ac..708bd7d 100644 (file)
@@ -1,3 +1,29 @@
+2019-03-26  Chris Dumez  <cdumez@apple.com>
+
+        Add basic layout test coverage for File Picker on iOS
+        https://bugs.webkit.org/show_bug.cgi?id=196265
+
+        Reviewed by Wenson Hsieh.
+
+        Add layout test infrastructure to test the file picker on iOS.
+
+        * DumpRenderTree/ios/UIScriptControllerIOS.mm:
+        (WTR::UIScriptController::dismissFilePicker):
+        * TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl:
+        * TestRunnerShared/UIScriptContext/UIScriptController.cpp:
+        (WTR::UIScriptController::dismissFilePicker):
+        * TestRunnerShared/UIScriptContext/UIScriptController.h:
+        * WebKitTestRunner/TestController.cpp:
+        (WTR::TestController::createWebViewWithOptions):
+        (WTR::updateTestOptionsFromTestHeader):
+        * WebKitTestRunner/TestOptions.h:
+        (WTR::TestOptions::hasSameInitializationOptions const):
+        * WebKitTestRunner/ios/TestControllerIOS.mm:
+        (overridePresentViewController):
+        (WTR::TestController::platformInitialize):
+        * WebKitTestRunner/ios/UIScriptControllerIOS.mm:
+        (WTR::UIScriptController::dismissFilePicker):
+
 2019-03-26  Wenson Hsieh  <wenson_hsieh@apple.com>
 
         Implement async paste method on UIWKInteractionViewProtocol
index c120952..22d55ab 100644 (file)
@@ -175,6 +175,10 @@ void UIScriptController::dismissFormAccessoryView()
 {
 }
 
+void UIScriptController::dismissFilePicker(JSValueRef)
+{
+}
+
 void UIScriptController::setTimePickerValue(long, long)
 {
 }
index 9afc51e..eecb206 100644 (file)
@@ -187,6 +187,8 @@ interface UIScriptController {
     // Equivalent of pressing the Done button in the form accessory bar.
     void dismissFormAccessoryView();
 
+    void dismissFilePicker(object callback);
+
     readonly attribute DOMString textContentType;
 
     // Form control handling
index ed3e342..23e42d1 100644 (file)
@@ -347,6 +347,10 @@ void UIScriptController::dismissFormAccessoryView()
 {
 }
 
+void UIScriptController::dismissFilePicker(JSValueRef)
+{
+}
+
 void UIScriptController::setTimePickerValue(long, long)
 {
 }
index 5a8df6e..e41f8a3 100644 (file)
@@ -106,6 +106,7 @@ public:
 
     void applyAutocorrection(JSStringRef newString, JSStringRef oldString, JSValueRef callback);
     
+    void dismissFilePicker(JSValueRef callback);
     void dismissFormAccessoryView();
     void selectFormAccessoryPickerRow(long);
     JSRetainPtr<JSStringRef> textContentType() const;
index 3b53123..e3db659 100644 (file)
@@ -607,7 +607,7 @@ void TestController::createWebViewWithOptions(const TestOptions& options)
         0, // didDraw
         0, // pageDidScroll
         0, // exceededDatabaseQuota,
-        runOpenPanel,
+        options.shouldHandleRunOpenPanel ? runOpenPanel : 0,
         decidePolicyForGeolocationPermissionRequest,
         0, // headerHeight
         0, // footerHeight
@@ -1316,6 +1316,8 @@ static void updateTestOptionsFromTestHeader(TestOptions& testOptions, const std:
             testOptions.editable = parseBooleanTestHeaderValue(value);
         else if (key == "enableUndoManagerAPI")
             testOptions.enableUndoManagerAPI = parseBooleanTestHeaderValue(value);
+        else if (key == "shouldHandleRunOpenPanel")
+            testOptions.shouldHandleRunOpenPanel = parseBooleanTestHeaderValue(value);
         else if (key == "contentInset.top")
             testOptions.contentInsetTop = std::stod(value);
         else if (key == "ignoreSynchronousMessagingTimeouts")
index b0fed72..1d0aee0 100644 (file)
@@ -89,6 +89,7 @@ struct TestOptions {
     bool enableEditableImages { false };
     bool editable { false };
     bool enableUndoManagerAPI { false };
+    bool shouldHandleRunOpenPanel { true };
 
     double contentInsetTop { 0 };
 
@@ -136,6 +137,7 @@ struct TestOptions {
             || enableEditableImages != options.enableEditableImages
             || editable != options.editable
             || enableUndoManagerAPI != options.enableUndoManagerAPI
+            || shouldHandleRunOpenPanel != options.shouldHandleRunOpenPanel
             || contentInsetTop != options.contentInsetTop)
             return false;
 
index eaf1f5a..ed466be 100644 (file)
@@ -50,6 +50,10 @@ static BOOL overrideIsInHardwareKeyboardMode()
     return NO;
 }
 
+static void overridePresentViewControllerOrPopover()
+{
+}
+
 namespace WTR {
 
 static bool isDoneWaitingForKeyboardToDismiss = true;
@@ -96,6 +100,9 @@ void TestController::platformInitialize()
     // Override the implementation of +[UIKeyboard isInHardwareKeyboardMode] to ensure that test runs are deterministic
     // regardless of whether a hardware keyboard is attached. We intentionally never restore the original implementation.
     method_setImplementation(class_getClassMethod([UIKeyboard class], @selector(isInHardwareKeyboardMode)), reinterpret_cast<IMP>(overrideIsInHardwareKeyboardMode));
+
+    method_setImplementation(class_getInstanceMethod([UIViewController class], @selector(presentViewController:animated:completion:)), reinterpret_cast<IMP>(overridePresentViewControllerOrPopover));
+    method_setImplementation(class_getInstanceMethod([UIPopoverController class], @selector(presentPopoverFromRect:inView:permittedArrowDirections:animated:)), reinterpret_cast<IMP>(overridePresentViewControllerOrPopover));
 }
 
 void TestController::platformDestroy()
index 9517b4e..aa9d848 100644 (file)
@@ -482,6 +482,19 @@ void UIScriptController::dismissFormAccessoryView()
     [webView dismissFormAccessoryView];
 }
 
+void UIScriptController::dismissFilePicker(JSValueRef callback)
+{
+    TestRunnerWKWebView *webView = TestController::singleton().mainWebView()->platformView();
+    [webView _dismissFilePicker];
+
+    // Round-trip with the WebProcess to make sure it has been notified of the dismissal.
+    unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
+    [webView evaluateJavaScript:@"" completionHandler:^(id result, NSError *error) {
+        if (m_context)
+            m_context->asyncTaskComplete(callbackID);
+    }];
+}
+
 JSRetainPtr<JSStringRef> UIScriptController::selectFormPopoverTitle() const
 {
     TestRunnerWKWebView *webView = TestController::singleton().mainWebView()->platformView();