haikuwebkit/LayoutTests/contact-picker/contacts-select-after-dismi...

75 lines
2.9 KiB
HTML
Raw Permalink Normal View History

<!DOCTYPE html> <!-- webkit-test-runner [ ContactPickerAPIEnabled=true ] -->
[Contact Picker API] Add support for picker UI on iOS https://bugs.webkit.org/show_bug.cgi?id=218189 <rdar://problem/69862277> Reviewed by Devin Rousso. Source/WebKit: ContactsManager.select() should present a contact picker on platforms which support one. This patch enables the end-to-end functionality on iOS, presenting a contact picker upon a call to the API and returning the selected contacts upon dismissal. Tests: contact-picker/contacts-select-after-dismissing-picker.html contact-picker/contacts-select-while-presenting-picker.html contact-picker/contacts-select.html * Platform/spi/Cocoa/ContactsUISPI.h: Added. * SourcesCocoa.txt: * UIProcess/API/Cocoa/WKWebViewPrivateForTesting.h: * UIProcess/API/Cocoa/WKWebViewTesting.mm: (-[WKWebView _didPresentContactPicker]): (-[WKWebView _didDismissContactPicker]): (-[WKWebView _dismissContactPickerWithContacts:]): * UIProcess/Cocoa/WKContactPicker.h: Added. * UIProcess/Cocoa/WKContactPicker.mm: Added. WKContactPicker is a WebKit wrapper around CNContactPickerViewController. (-[WKCNContactPickerDelegate initWithContactPickerDelegate:]): WKCNContactPickerDelegate is wrapper around CNContactPickerDelegate. This is necessary as single/multiple selection in a CNContactPickerViewController is determined by which delegate methods are implemented. The two specializations of this class include the methods necessary to present a single-select and multi-select picker respectively. (-[WKCNContactPickerDelegate contactPickerDidCancel:]): (-[WKCNContactPickerSingleSelectDelegate contactPicker:didSelectContact:]): (-[WKCNContactPickerMultiSelectDelegate contactPicker:didSelectContacts:]): (-[WKContactPicker delegate]): (-[WKContactPicker setDelegate:]): (-[WKContactPicker initWithView:]): (-[WKContactPicker presentWithRequestData:completionHandler:]): (-[WKContactPicker contactPickerDidCancel:]): This delegate method is called when the picker is dismissed by tapping the done button or when the picker is dismissed by swiping down. (-[WKContactPicker contactPicker:didSelectContact:]): (-[WKContactPicker contactPicker:didSelectContacts:]): (-[WKContactPicker _contactPickerDidDismissWithContactInfo:]): (-[WKContactPicker _contactInfoFromCNContact:]): (-[WKContactPicker dismissWithContacts:]): (-[WKContactPicker _contactsFromJSContacts:]): * UIProcess/ios/PageClientImplIOS.h: * UIProcess/ios/PageClientImplIOS.mm: (WebKit::PageClientImpl::showContactPicker): * UIProcess/ios/WKContentViewInteraction.h: * UIProcess/ios/WKContentViewInteraction.mm: (-[WKContentView _showContactPicker:completionHandler:]): (-[WKContentView contactPickerDidPresent:]): (-[WKContentView contactPickerDidDismiss:]): (-[WKContentView _dismissContactPickerWithContacts:]): * WebKit.xcodeproj/project.pbxproj: Source/WTF: * wtf/PlatformHave.h: Added HAVE(CONTACTSUI) and HAVE(CNCONTACTPICKERVIEWCONTROLLER) macros. Tools: Added UIScriptController hooks to observe the presentation and dismissal of a contact picker. Furthermore, the dismissContactPickerWithContacts method was added to allow tests to dismiss the presented contact picker with a set of selected contacts. * TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl: * TestRunnerShared/UIScriptContext/UIScriptContext.h: * TestRunnerShared/UIScriptContext/UIScriptController.h: (WTR::UIScriptController::isShowingContactPicker const): (WTR::UIScriptController::dismissContactPickerWithContacts): * TestRunnerShared/UIScriptContext/UIScriptControllerShared.cpp: (WTR::UIScriptController::setDidShowContactPickerCallback): (WTR::UIScriptController::didShowContactPickerCallback const): (WTR::UIScriptController::setDidHideContactPickerCallback): (WTR::UIScriptController::didHideContactPickerCallback const): * WebKitTestRunner/cocoa/TestRunnerWKWebView.h: * WebKitTestRunner/cocoa/TestRunnerWKWebView.mm: (-[TestRunnerWKWebView resetInteractionCallbacks]): (-[TestRunnerWKWebView _didPresentContactPicker]): (-[TestRunnerWKWebView _didDismissContactPicker]): * WebKitTestRunner/cocoa/UIScriptControllerCocoa.h: * WebKitTestRunner/cocoa/UIScriptControllerCocoa.mm: (WTR::UIScriptControllerCocoa::setDidShowContactPickerCallback): (WTR::UIScriptControllerCocoa::setDidHideContactPickerCallback): (WTR::UIScriptControllerCocoa::isShowingContactPicker const): (WTR::UIScriptControllerCocoa::dismissContactPickerWithContacts): LayoutTests: Added tests to verify the presentation and dismissal of a contact picker on iOS. The new tests are only run on iOS WK2, since that is the only platform which currently supports the presentation of a contact picker. Note that these tests will be enabled on macOS WK2 once support is added in a forthcoming patch. * TestExpectations: * contact-picker/contacts-select-after-dismissing-picker-expected.txt: Added. * contact-picker/contacts-select-after-dismissing-picker.html: Added. * contact-picker/contacts-select-expected.txt: Added. * contact-picker/contacts-select-while-presenting-picker-expected.txt: Added. * contact-picker/contacts-select-while-presenting-picker.html: Added. * contact-picker/contacts-select.html: Added. * platform/ios-wk2/TestExpectations: * resources/ui-helper.js: (window.UIHelper.waitForContactPickerToShow): (window.UIHelper.waitForContactPickerToHide): (window.UIHelper.dismissContactPickerWithContacts): Canonical link: https://commits.webkit.org/231232@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@269394 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-11-04 22:36:46 +00:00
<html>
<head>
<script src="../resources/js-test.js"></script>
<script src="../resources/ui-helper.js"></script>
</head>
<script>
jsTestIsAsync = true;
finishedContactSelection = false;
const addressBook = [
{
"name": ["Person A"],
"email": ["person.a@webkit.org"],
"tel": ["555-5555"]
},
{
"name": ["Person B"],
"email": ["person.b@webkit.org", "person.b.alt@webkit.org"],
},
{
"name": ["Person C"],
"tel": ["777-7777"],
}
];
async function runTest()
{
description("This test verifies that navigator.contacts.select succeeds after another call to navigator.contacts.select was completed.\n");
const contactsButton = document.getElementById("contacts");
contactsButton.addEventListener("click", async () => {
if (finishedContactSelection) {
debug("\nPerforming second contacts request.")
} else {
debug("Performing first contacts request.")
}
const request = navigator.contacts.select(["name", "email", "tel"]);
await UIHelper.waitForContactPickerToShow();
UIHelper.dismissContactPickerWithContacts(addressBook);
await UIHelper.waitForContactPickerToHide();
[contact1, contact2, contact3] = await request;
shouldBeTrue("areArraysEqual(contact1.name, addressBook[0].name)");
shouldBeTrue("areArraysEqual(contact1.email, addressBook[0].email)");
shouldBeTrue("areArraysEqual(contact1.tel, addressBook[0].tel)");
shouldBeTrue("areArraysEqual(contact2.name, addressBook[1].name)");
shouldBeTrue("areArraysEqual(contact2.email, addressBook[1].email)");
shouldBeEqualToNumber("contact2.tel.length", 0);
shouldBeTrue("areArraysEqual(contact3.name, addressBook[2].name)");
shouldBeEqualToNumber("contact3.email.length", 0);
shouldBeTrue("areArraysEqual(contact3.tel, addressBook[2].tel)");
if (finishedContactSelection) {
finishJSTest();
} else {
finishedContactSelection = true;
}
});
await UIHelper.activateElement(contactsButton);
await new Promise(resolve => shouldBecomeEqual("finishedContactSelection", "true", resolve));
await UIHelper.activateElement(contactsButton);
}
</script>
<body onload=runTest()>
<button id="contacts">Show contacts</button>
</body>
</html>