Changeset 238471 in webkit
- Timestamp:
- Nov 24, 2018 1:06:09 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 19 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r238470 r238471 1 2018-11-24 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 [Cocoa] Add WKWebView SPI to trigger and remove data detection 4 https://bugs.webkit.org/show_bug.cgi?id=191918 5 <rdar://problem/36185051> 6 7 Reviewed by Tim Horton. 8 9 Add a helper method on DataDetection to remove all data detected links in the given document. See WebKit changes 10 for more detail. 11 12 * editing/cocoa/DataDetection.h: 13 * editing/cocoa/DataDetection.mm: 14 (WebCore::DataDetection::removeDataDetectedLinksInDocument): 15 1 16 2018-11-24 Andy Estes <aestes@apple.com> 2 17 -
trunk/Source/WebCore/editing/cocoa/DataDetection.h
r237266 r238471 38 38 namespace WebCore { 39 39 40 class Document; 40 41 class Element; 41 42 class FloatRect; … … 62 63 #endif 63 64 WEBCORE_EXPORT static NSArray *detectContentInRange(RefPtr<Range>& contextRange, DataDetectorTypes, NSDictionary *context); 65 WEBCORE_EXPORT static void removeDataDetectedLinksInDocument(Document&); 64 66 #if PLATFORM(IOS_FAMILY) 65 67 WEBCORE_EXPORT static bool canBePresentedByDataDetectors(const URL&); -
trunk/Source/WebCore/editing/cocoa/DataDetection.mm
r238470 r238471 430 430 } 431 431 432 void DataDetection::removeDataDetectedLinksInDocument(Document& document) 433 { 434 Vector<Ref<HTMLAnchorElement>> allAnchorElements; 435 for (auto& anchor : descendantsOfType<HTMLAnchorElement>(document)) 436 allAnchorElements.append(anchor); 437 438 for (auto& anchor : allAnchorElements) 439 removeResultLinksFromAnchor(anchor.get()); 440 } 441 432 442 NSArray *DataDetection::detectContentInRange(RefPtr<Range>& contextRange, DataDetectorTypes types, NSDictionary *context) 433 443 { … … 648 658 649 659 #else 660 650 661 NSArray *DataDetection::detectContentInRange(RefPtr<Range>&, DataDetectorTypes, NSDictionary *) 651 662 { 652 663 return nil; 653 664 } 665 666 void DataDetection::removeDataDetectedLinksInDocument(Document&) 667 { 668 } 669 654 670 #endif 655 671 -
trunk/Source/WebKit/ChangeLog
r238470 r238471 1 2018-11-24 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 [Cocoa] Add WKWebView SPI to trigger and remove data detection 4 https://bugs.webkit.org/show_bug.cgi?id=191918 5 <rdar://problem/36185051> 6 7 Reviewed by Tim Horton. 8 9 Adds support for two new WKWebView SPI methods, `-_detectDataWithTypes:completionHandler:` and 10 `-_removeAllDataDetectedLinks:`, to allow internal WebKit clients to run data detection and add links to data 11 detected content, or remove all data detected links from the document. 12 13 Test: WebKit.AddAndRemoveDataDetectors 14 15 * Shared/Cocoa/DataDetectionResult.h: 16 * Shared/Cocoa/DataDetectionResult.mm: 17 (WebKit::DataDetectionResult::decode): 18 19 Modernize DataDetectionResult's IPC decoding, so that it can be used with reply-based async IPC. 20 21 * UIProcess/API/Cocoa/WKWebView.mm: 22 (-[WKWebView _removeDataDetectedLinks:]): 23 (-[WKWebView _detectDataWithTypes:completionHandler:]): 24 * UIProcess/API/Cocoa/WKWebViewPrivate.h: 25 * UIProcess/WebPageProxy.cpp: 26 (WebKit::WebPageProxy::detectDataInAllFrames): 27 (WebKit::WebPageProxy::removeDataDetectedLinks): 28 29 Add or remove data detected links from each frame in the page, and then propagate the new data detector 30 results of the main frame to the UI process (this matches current behavior, where the results of -[WKWebView 31 _dataDetectionResults] only reflects data detection results in the main frame of the page). 32 33 * UIProcess/WebPageProxy.h: 34 * WebProcess/WebPage/WebPage.cpp: 35 (WebKit::WebPage::removeDataDetectedLinks): 36 (WebKit::WebPage::detectDataInAllFrames): 37 * WebProcess/WebPage/WebPage.h: 38 * WebProcess/WebPage/WebPage.messages.in: 39 1 40 2018-11-24 Andy Estes <aestes@apple.com> 2 41 -
trunk/Source/WebKit/Shared/Cocoa/DataDetectionResult.h
r204668 r238471 39 39 40 40 void encode(IPC::Encoder&) const; 41 static bool decode(IPC::Decoder&, DataDetectionResult&);41 static std::optional<DataDetectionResult> decode(IPC::Decoder&); 42 42 }; 43 43 -
trunk/Source/WebKit/Shared/Cocoa/DataDetectionResult.mm
r232520 r238471 47 47 } 48 48 49 bool DataDetectionResult::decode(IPC::Decoder& decoder, DataDetectionResult& result)49 std::optional<DataDetectionResult> DataDetectionResult::decode(IPC::Decoder& decoder) 50 50 { 51 51 RetainPtr<CFDataRef> data; 52 52 if (!IPC::decode(decoder, data)) 53 return false;53 return std::nullopt; 54 54 55 DataDetectionResult result; 55 56 auto unarchiver = secureUnarchiverFromData((__bridge NSData *)data.get()); 56 57 @try { … … 58 59 } @catch (NSException *exception) { 59 60 LOG_ERROR("Failed to decode NSArray of DDScanResult: %@", exception); 60 return false;61 return std::nullopt; 61 62 } 62 63 63 64 [unarchiver finishDecoding]; 64 return true;65 return { WTFMove(result) }; 65 66 } 66 67 #endif -
trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
r238468 r238471 5424 5424 } 5425 5425 5426 - (void)_removeDataDetectedLinks:(dispatch_block_t)completion 5427 { 5428 #if ENABLE(DATA_DETECTION) 5429 _page->removeDataDetectedLinks([completion = makeBlockPtr(completion), page = makeWeakPtr(_page.get())] (auto& result) { 5430 if (page) 5431 page->setDataDetectionResult(result); 5432 if (completion) 5433 completion(); 5434 }); 5435 #else 5436 UNUSED_PARAM(completion); 5437 #endif 5438 } 5439 5426 5440 #pragma mark iOS-specific methods 5427 5441 5428 5442 #if PLATFORM(IOS_FAMILY) 5443 5444 - (void)_detectDataWithTypes:(WKDataDetectorTypes)types completionHandler:(dispatch_block_t)completion 5445 { 5446 #if ENABLE(DATA_DETECTION) 5447 _page->detectDataInAllFrames(fromWKDataDetectorTypes(types), [completion = makeBlockPtr(completion), page = makeWeakPtr(_page.get())] (auto& result) { 5448 if (page) 5449 page->setDataDetectionResult(result); 5450 if (completion) 5451 completion(); 5452 }); 5453 #else 5454 UNUSED_PARAM(types); 5455 UNUSED_PARAM(completion); 5456 #endif 5457 } 5429 5458 5430 5459 #if ENABLE(FULLSCREEN_API) -
trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h
r238388 r238471 28 28 #if WK_API_ENABLED 29 29 30 #import <WebKit/WKDataDetectorTypes.h> 30 31 #import <WebKit/_WKActivatedElementInfo.h> 31 32 #import <WebKit/_WKAttachment.h> … … 194 195 195 196 - (void)_isJITEnabled:(void(^)(BOOL))completionHandler WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA)); 197 - (void)_removeDataDetectedLinks:(dispatch_block_t)completion WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA)); 198 196 199 - (IBAction)_alignCenter:(id)sender WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA)); 197 200 - (IBAction)_alignJustified:(id)sender WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA)); … … 216 219 - (void)_setFontSize:(CGFloat)fontSize sender:(id)sender WK_API_AVAILABLE(ios(WK_IOS_TBA)); 217 220 - (void)_setTextColor:(UIColor *)color sender:(id)sender WK_API_AVAILABLE(ios(WK_IOS_TBA)); 221 222 - (void)_detectDataWithTypes:(WKDataDetectorTypes)types completionHandler:(dispatch_block_t)completion WK_API_AVAILABLE(ios(WK_IOS_TBA)); 218 223 219 224 // DERECATED: The setters of the three following function are deprecated, please use overrideLayoutParameters. -
trunk/Source/WebKit/UIProcess/WebPageProxy.cpp
r238438 r238471 8244 8244 } 8245 8245 8246 #if ENABLE(DATA_DETECTION) 8247 8248 void WebPageProxy::detectDataInAllFrames(WebCore::DataDetectorTypes types, CompletionHandler<void(const DataDetectionResult&)>&& completionHandler) 8249 { 8250 m_process->connection()->sendWithAsyncReply(Messages::WebPage::DetectDataInAllFrames(static_cast<uint64_t>(types)), WTFMove(completionHandler), m_pageID); 8251 } 8252 8253 void WebPageProxy::removeDataDetectedLinks(CompletionHandler<void(const DataDetectionResult&)>&& completionHandler) 8254 { 8255 m_process->connection()->sendWithAsyncReply(Messages::WebPage::RemoveDataDetectedLinks(), WTFMove(completionHandler), m_pageID); 8256 } 8257 8258 #endif 8259 8246 8260 } // namespace WebKit 8247 8261 -
trunk/Source/WebKit/UIProcess/WebPageProxy.h
r238468 r238471 363 363 #if ENABLE(DATA_DETECTION) 364 364 NSArray *dataDetectionResults() { return m_dataDetectionResults.get(); } 365 void detectDataInAllFrames(WebCore::DataDetectorTypes, CompletionHandler<void(const DataDetectionResult&)>&&); 366 void removeDataDetectedLinks(CompletionHandler<void(const DataDetectionResult&)>&&); 365 367 #endif 366 368 -
trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp
r238454 r238471 3386 3386 3387 3387 #if ENABLE(DATA_DETECTION) 3388 3388 3389 void WebPage::setDataDetectionResults(NSArray *detectionResults) 3389 3390 { … … 3392 3393 send(Messages::WebPageProxy::SetDataDetectionResult(dataDetectionResult)); 3393 3394 } 3394 #endif 3395 3396 void WebPage::removeDataDetectedLinks(Messages::WebPage::RemoveDataDetectedLinks::AsyncReply&& reply) 3397 { 3398 for (auto frame = makeRefPtr(&m_page->mainFrame()); frame; frame = frame->tree().traverseNext()) { 3399 auto document = makeRefPtr(frame->document()); 3400 if (!document) 3401 continue; 3402 3403 DataDetection::removeDataDetectedLinksInDocument(*document); 3404 frame->setDataDetectionResults(nullptr); 3405 } 3406 reply({ m_page->mainFrame().dataDetectionResults() }); 3407 } 3408 3409 void WebPage::detectDataInAllFrames(uint64_t types, Messages::WebPage::DetectDataInAllFrames::AsyncReply&& reply) 3410 { 3411 auto dataDetectorTypes = static_cast<WebCore::DataDetectorTypes>(types); 3412 for (auto frame = makeRefPtr(&m_page->mainFrame()); frame; frame = frame->tree().traverseNext()) { 3413 auto document = makeRefPtr(frame->document()); 3414 if (!document) 3415 continue; 3416 3417 RefPtr<Range> range = Range::create(*document, Position { document.get(), Position::PositionIsBeforeChildren }, Position { document.get(), Position::PositionIsAfterChildren }); 3418 frame->setDataDetectionResults(DataDetection::detectContentInRange(range, dataDetectorTypes, m_dataDetectionContext.get())); 3419 } 3420 reply({ m_page->mainFrame().dataDetectionResults() }); 3421 } 3422 3423 #endif // ENABLE(DATA_DETECTION) 3395 3424 3396 3425 #if PLATFORM(COCOA) -
trunk/Source/WebKit/WebProcess/WebPage/WebPage.h
r238454 r238471 49 49 #include "UserData.h" 50 50 #include "WebBackForwardListProxy.h" 51 #include "WebPageMessages.h" 51 52 #include "WebURLSchemeHandler.h" 52 53 #include "WebUserContentController.h" … … 93 94 #if PLATFORM(IOS_FAMILY) 94 95 #include "GestureTypes.h" 95 #include "WebPageMessages.h"96 96 #include <WebCore/IntPointHash.h> 97 97 #include <WebCore/ViewportConfiguration.h> … … 106 106 #elif ENABLE(TOUCH_EVENTS) 107 107 #include <WebCore/PlatformTouchEvent.h> 108 #endif 109 110 #if ENABLE(DATA_DETECTION) 111 #include <WebCore/DataDetection.h> 108 112 #endif 109 113 … … 993 997 #if ENABLE(DATA_DETECTION) 994 998 void setDataDetectionResults(NSArray *); 999 void detectDataInAllFrames(uint64_t, Messages::WebPage::DetectDataInAllFrames::AsyncReply&&); 1000 void removeDataDetectedLinks(Messages::WebPage::RemoveDataDetectedLinks::AsyncReply&&); 995 1001 #endif 996 1002 -
trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in
r238438 r238471 194 194 #endif 195 195 196 #if ENABLE(DATA_DETECTION) 197 DetectDataInAllFrames(uint64_t types) -> (struct WebKit::DataDetectionResult result) Async 198 RemoveDataDetectedLinks() -> (struct WebKit::DataDetectionResult result) Async 199 #endif 200 196 201 #if PLATFORM(MAC) 197 202 PerformDictionaryLookupOfCurrentSelection() -
trunk/Tools/ChangeLog
r238467 r238471 1 2018-11-24 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 [Cocoa] Add WKWebView SPI to trigger and remove data detection 4 https://bugs.webkit.org/show_bug.cgi?id=191918 5 <rdar://problem/36185051> 6 7 Reviewed by Tim Horton. 8 9 Add an API test to exercise the new WebKit SPI. 10 11 * TestWebKitAPI/DataDetectorsCoreSPI.h: Added. 12 * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: 13 * TestWebKitAPI/Tests/WebKitCocoa/DataDetection.mm: 14 (-[WKWebView synchronouslyDetectDataWithTypes:]): 15 (-[WKWebView synchronouslyRemoveDataDetectedLinks]): 16 (TEST): 17 * TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm: 18 (TestWebKitAPI::TEST): 19 (-[TestWKWebView tagsInBody]): Deleted. 20 (-[TestWKWebView expectElementTagsInOrder:]): Deleted. 21 (-[TestWKWebView expectElementCount:tagName:]): Deleted. 22 (-[TestWKWebView expectElementTag:toComeBefore:]): Deleted. 23 24 Rename this from `-expectElementCount:tagName:` to `-expectElementCount:querySelector:`. 25 26 * TestWebKitAPI/Tests/WebKitCocoa/data-detectors.html: Added. 27 28 Add a new test page containing some content that can be data detected. 29 30 * TestWebKitAPI/cocoa/TestWKWebView.h: 31 * TestWebKitAPI/cocoa/TestWKWebView.mm: 32 (-[WKWebView tagsInBody]): 33 (-[WKWebView expectElementTagsInOrder:]): 34 (-[WKWebView expectElementCount:querySelector:]): 35 (-[WKWebView expectElementTag:toComeBefore:]): 36 37 Move some testing helper functions from WKAttachmentTests to a testing category on WKWebView. This allows us to 38 use `-expectElementCount:querySelector:` in tests outside of WKAttachmentTests. 39 40 (-[WKWebView objectByEvaluatingJavaScript:]): 41 (-[WKWebView objectByEvaluatingJavaScriptWithUserGesture:]): 42 (-[WKWebView stringByEvaluatingJavaScript:]): 43 44 Move some common helper functions from TestWKWebView to a testing category on WKWebView. 45 46 (-[TestWKWebView objectByEvaluatingJavaScript:]): Deleted. 47 (-[TestWKWebView objectByEvaluatingJavaScriptWithUserGesture:]): Deleted. 48 (-[TestWKWebView stringByEvaluatingJavaScript:]): Deleted. 49 1 50 2018-11-23 Sam Weinig <sam@webkit.org> 2 51 -
trunk/Tools/TestWebKitAPI/DataDetectorsCoreSPI.h
r238470 r238471 1 1 /* 2 * Copyright (C) 201 6Apple Inc. All rights reserved.2 * Copyright (C) 2018 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 24 24 */ 25 25 26 #ifndef DataDetectionResult_h 27 #define DataDetectionResult_h 26 #pragma once 28 27 29 28 #if ENABLE(DATA_DETECTION) 30 29 31 #import "ArgumentCoders.h"30 #import <pal/spi/cocoa/DataDetectorsCoreSPI.h> 32 31 33 #i mport <wtf/RetainPtr.h>32 #if !USE(APPLE_INTERNAL_SDK) 34 33 35 namespace WebKit { 34 @interface DDScannerResult (Private) 35 @property (readonly, nonatomic) NSString *value; 36 @property (readonly, nonatomic) NSString *type; 37 @property (readonly, nonatomic) DDResultCategory category; 38 @end 36 39 37 struct DataDetectionResult { 38 RetainPtr<NSArray> results; 39 40 void encode(IPC::Encoder&) const; 41 static bool decode(IPC::Decoder&, DataDetectionResult&); 42 }; 43 44 } 40 #endif // !USE(APPLE_INTERNAL_SDK) 45 41 46 42 #endif // ENABLE(DATA_DETECTION) 47 48 #endif // DataDetectionResult_h -
trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
r238408 r238471 853 853 F46A095B1ED8A6E600D4AA55 /* gif-and-file-input.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F47D30ED1ED28A6C000482E1 /* gif-and-file-input.html */; }; 854 854 F47728991E4AE3C1007ABF6A /* full-page-contenteditable.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F47728981E4AE3AD007ABF6A /* full-page-contenteditable.html */; }; 855 F47DFB2621A878DF00021FB6 /* data-detectors.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F47DFB2421A8704A00021FB6 /* data-detectors.html */; }; 855 856 F4811E5921940BDE00A5E0FD /* WKWebViewEditActions.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4811E5821940B4400A5E0FD /* WKWebViewEditActions.mm */; }; 856 857 F4856CA31E649EA8009D7EE7 /* attachment-element.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4856CA21E6498A8009D7EE7 /* attachment-element.html */; }; … … 1020 1021 F4AB578A1F65165400DB0DA1 /* custom-draggable-div.html in Copy Resources */, 1021 1022 290F4275172A221C00939FF0 /* custom-protocol-sync-xhr.html in Copy Resources */, 1023 F47DFB2621A878DF00021FB6 /* data-detectors.html in Copy Resources */, 1022 1024 F486B1D01F67952300F34BDD /* DataTransfer-setDragImage.html in Copy Resources */, 1023 1025 F457A9D6202D68AF00F7E9D5 /* DataTransfer.html in Copy Resources */, … … 2148 2150 F47D30EB1ED28619000482E1 /* apple.gif */ = {isa = PBXFileReference; lastKnownFileType = image.gif; path = apple.gif; sourceTree = "<group>"; }; 2149 2151 F47D30ED1ED28A6C000482E1 /* gif-and-file-input.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "gif-and-file-input.html"; sourceTree = "<group>"; }; 2152 F47DFB2421A8704A00021FB6 /* data-detectors.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "data-detectors.html"; sourceTree = "<group>"; }; 2153 F47DFB2721A885E700021FB6 /* DataDetectorsCoreSPI.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DataDetectorsCoreSPI.h; sourceTree = "<group>"; }; 2150 2154 F4811E5821940B4400A5E0FD /* WKWebViewEditActions.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebViewEditActions.mm; sourceTree = "<group>"; }; 2151 2155 F4856CA21E6498A8009D7EE7 /* attachment-element.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "attachment-element.html"; sourceTree = "<group>"; }; … … 2312 2316 F4517B682054E0AC00C26721 /* ClassMethodSwizzler.h */, 2313 2317 F4517B692054E0AC00C26721 /* ClassMethodSwizzler.mm */, 2318 F47DFB2721A885E700021FB6 /* DataDetectorsCoreSPI.h */, 2314 2319 F46128B4211C861A00D9FADB /* DragAndDropSimulator.h */, 2315 2320 F44D06481F3962E3001A0E29 /* EditingTestHarness.h */, … … 2741 2746 9B62630B1F8C2510007EE29B /* copy-url.html */, 2742 2747 F4AB57891F65164B00DB0DA1 /* custom-draggable-div.html */, 2748 F47DFB2421A8704A00021FB6 /* data-detectors.html */, 2743 2749 F486B1CF1F6794FF00F34BDD /* DataTransfer-setDragImage.html */, 2744 2750 F457A9B3202D535300F7E9D5 /* DataTransfer.html */, -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/DataDetection.mm
r237266 r238471 26 26 #include "config.h" 27 27 28 #import "DataDetectorsCoreSPI.h" 28 29 #import "PlatformUtilities.h" 29 30 #import "Test.h" 30 31 #import "TestNavigationDelegate.h" 32 #import "TestWKWebView.h" 31 33 #import <WebKit/WebKit.h> 32 34 #import <wtf/RetainPtr.h> 33 35 34 36 #if WK_API_ENABLED && PLATFORM(IOS_FAMILY) 37 38 @interface WKWebView (DataDetection) 39 - (void)synchronouslyDetectDataWithTypes:(WKDataDetectorTypes)types; 40 - (void)synchronouslyRemoveDataDetectedLinks; 41 @end 42 43 @implementation WKWebView (DataDetection) 44 45 - (void)synchronouslyDetectDataWithTypes:(WKDataDetectorTypes)types 46 { 47 __block bool done = false; 48 [self _detectDataWithTypes:types completionHandler:^{ 49 done = true; 50 }]; 51 TestWebKitAPI::Util::run(&done); 52 } 53 54 - (void)synchronouslyRemoveDataDetectedLinks 55 { 56 __block bool done = false; 57 [self _removeDataDetectedLinks:^{ 58 done = true; 59 }]; 60 TestWebKitAPI::Util::run(&done); 61 } 62 63 @end 35 64 36 65 static bool ranScript; … … 98 127 } 99 128 129 TEST(WebKit, AddAndRemoveDataDetectors) 130 { 131 auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]); 132 [webView synchronouslyLoadTestPageNamed:@"data-detectors"]; 133 [webView expectElementCount:0 querySelector:@"a[x-apple-data-detectors=true]"]; 134 EXPECT_EQ(0U, [webView _dataDetectionResults].count); 135 136 auto checkDataDetectionResults = [] (NSArray<DDScannerResult *> *results) { 137 EXPECT_EQ(3U, results.count); 138 EXPECT_EQ(DDResultCategoryUnknown, results[0].category); 139 EXPECT_TRUE([results[0].value containsString:@"+1-234-567-8900"]); 140 EXPECT_TRUE([results[0].value containsString:@"https://www.apple.com"]); 141 EXPECT_TRUE([results[0].value containsString:@"2 Apple Park Way, Cupertino 95014"]); 142 EXPECT_WK_STREQ("SignatureBlock", results[0].type); 143 EXPECT_EQ(DDResultCategoryCalendarEvent, results[1].category); 144 EXPECT_WK_STREQ("Date", results[1].type); 145 EXPECT_WK_STREQ("December 21, 2021", results[1].value); 146 EXPECT_EQ(DDResultCategoryMisc, results[2].category); 147 EXPECT_WK_STREQ("FlightInformation", results[2].type); 148 EXPECT_WK_STREQ("AC780", results[2].value); 149 }; 150 151 [webView synchronouslyDetectDataWithTypes:WKDataDetectorTypeAll]; 152 [webView expectElementCount:5 querySelector:@"a[x-apple-data-detectors=true]"]; 153 checkDataDetectionResults([webView _dataDetectionResults]); 154 155 [webView synchronouslyRemoveDataDetectedLinks]; 156 [webView expectElementCount:0 querySelector:@"a[x-apple-data-detectors=true]"]; 157 EXPECT_EQ(0U, [webView _dataDetectionResults].count); 158 159 [webView synchronouslyDetectDataWithTypes:WKDataDetectorTypeAddress | WKDataDetectorTypePhoneNumber]; 160 [webView expectElementCount:2 querySelector:@"a[x-apple-data-detectors=true]"]; 161 checkDataDetectionResults([webView _dataDetectionResults]); 162 } 163 100 164 #endif -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm
r238360 r238471 216 216 @implementation TestWKWebView (AttachmentTesting) 217 217 218 - (NSArray<NSString *> *)tagsInBody219 {220 return [self objectByEvaluatingJavaScript:@"Array.from(document.body.getElementsByTagName('*')).map(e => e.tagName)"];221 }222 223 - (void)expectElementTagsInOrder:(NSArray<NSString *> *)tagNames224 {225 auto remainingTags = adoptNS([tagNames mutableCopy]);226 NSArray<NSString *> *tagsInBody = self.tagsInBody;227 for (NSString *tag in tagsInBody.reverseObjectEnumerator) {228 if ([tag isEqualToString:[remainingTags lastObject]])229 [remainingTags removeLastObject];230 if (![remainingTags count])231 break;232 }233 EXPECT_EQ([remainingTags count], 0U);234 if ([remainingTags count])235 NSLog(@"Expected to find ordered tags: %@ in: %@", tagNames, tagsInBody);236 }237 238 - (void)expectElementCount:(NSInteger)count tagName:(NSString *)tagName239 {240 NSString *script = [NSString stringWithFormat:@"document.querySelectorAll('%@').length", tagName];241 EXPECT_EQ(count, [self stringByEvaluatingJavaScript:script].integerValue);242 }243 244 - (void)expectElementTag:(NSString *)tagName toComeBefore:(NSString *)otherTagName245 {246 [self expectElementTagsInOrder:@[tagName, otherTagName]];247 }248 249 218 - (_WKAttachment *)synchronouslyInsertAttachmentWithFileWrapper:(NSFileWrapper *)fileWrapper contentType:(NSString *)contentType 250 219 { … … 832 801 833 802 auto checkAttachmentConsistency = [webView, file, folder] (_WKAttachment *expectedFileAttachment, _WKAttachment *expectedFolderAttachment) { 834 [webView expectElementCount:2 tagName:@"ATTACHMENT"];803 [webView expectElementCount:2 querySelector:@"ATTACHMENT"]; 835 804 EXPECT_TRUE(UTTypeConformsTo((__bridge CFStringRef)[webView valueOfAttribute:@"type" forQuerySelector:@"attachment[title=folder]"], kUTTypeDirectory)); 836 805 EXPECT_TRUE(UTTypeConformsTo((__bridge CFStringRef)[webView valueOfAttribute:@"type" forQuerySelector:@"attachment[title^=test]"], kUTTypeData)); … … 929 898 [webView _synchronouslyExecuteEditCommand:@"DeleteBackward" argument:nil]; 930 899 observer.expectAttachmentUpdates(@[ ], @[ ]); 931 [webView expectElementCount:0 tagName:@"BR"];900 [webView expectElementCount:0 querySelector:@"BR"]; 932 901 } 933 902 } … … 972 941 [webView _synchronouslyExecuteEditCommand:@"InsertParagraph" argument:nil]; 973 942 [webView expectElementTag:@"IMG" toComeBefore:@"STRONG"]; 974 [webView expectElementCount:1 tagName:@"IMG"];943 [webView expectElementCount:1 querySelector:@"IMG"]; 975 944 976 945 // Drag the attachment element to somewhere below the strong text. … … 978 947 979 948 [webView expectElementTag:@"STRONG" toComeBefore:@"IMG"]; 980 [webView expectElementCount:1 tagName:@"IMG"];949 [webView expectElementCount:1 querySelector:@"IMG"]; 981 950 EXPECT_EQ([simulator insertedAttachments].count, [simulator removedAttachments].count); 982 951 … … 1035 1004 1036 1005 EXPECT_TRUE(zipAttachment && imageAttachment && pdfAttachment); 1037 [webView expectElementCount:2 tagName:@"ATTACHMENT"];1038 [webView expectElementCount:1 tagName:@"IMG"];1006 [webView expectElementCount:2 querySelector:@"ATTACHMENT"]; 1007 [webView expectElementCount:1 querySelector:@"IMG"]; 1039 1008 EXPECT_WK_STREQ("application/pdf", [webView stringByEvaluatingJavaScript:@"document.querySelectorAll('attachment')[0].getAttribute('type')"]); 1040 1009 … … 1339 1308 ObserveAttachmentUpdatesForScope observer(webView.get()); 1340 1309 [webView _synchronouslyExecuteEditCommand:@"Paste" argument:nil]; 1341 [webView expectElementCount:2 tagName:@"IMG"];1310 [webView expectElementCount:2 querySelector:@"IMG"]; 1342 1311 1343 1312 for (_WKAttachment *attachment in observer.observer().inserted) { … … 1474 1443 ObserveAttachmentUpdatesForScope observer(secondWebView.get()); 1475 1444 [secondWebView paste:nil]; 1476 [secondWebView expectElementCount:3 tagName:@"attachment"];1445 [secondWebView expectElementCount:3 querySelector:@"attachment"]; 1477 1446 EXPECT_EQ(3U, observer.observer().inserted.count); 1478 1447 … … 1517 1486 } 1518 1487 1519 [webView expectElementCount:1 tagName:@"ATTACHMENT"];1520 [webView expectElementCount:1 tagName:@"IMG"];1488 [webView expectElementCount:1 querySelector:@"ATTACHMENT"]; 1489 [webView expectElementCount:1 querySelector:@"IMG"]; 1521 1490 EXPECT_WK_STREQ("application/pdf", [webView stringByEvaluatingJavaScript:@"document.querySelector('attachment').getAttribute('type')"]); 1522 1491 EXPECT_WK_STREQ("test.pdf", [webView stringByEvaluatingJavaScript:@"document.querySelector('attachment').getAttribute('title')"]); … … 1553 1522 [simulator runFrom:CGPointMake(0, 0) to:CGPointMake(50, 50)]; 1554 1523 1555 [webView expectElementCount:1 tagName:@"ATTACHMENT"];1556 [webView expectElementCount:1 tagName:@"IMG"];1524 [webView expectElementCount:1 querySelector:@"ATTACHMENT"]; 1525 [webView expectElementCount:1 querySelector:@"IMG"]; 1557 1526 EXPECT_EQ(2U, [simulator insertedAttachments].count); 1558 1527 … … 1574 1543 auto removedAttachments = retainPtr([simulator removedAttachments]); 1575 1544 EXPECT_EQ(2U, [removedAttachments count]); 1576 [webView expectElementCount:0 tagName:@"ATTACHMENT"];1577 [webView expectElementCount:0 tagName:@"IMG"];1545 [webView expectElementCount:0 querySelector:@"ATTACHMENT"]; 1546 [webView expectElementCount:0 querySelector:@"IMG"]; 1578 1547 EXPECT_TRUE([removedAttachments containsObject:[insertedAttachments firstObject]]); 1579 1548 EXPECT_TRUE([removedAttachments containsObject:[insertedAttachments lastObject]]); … … 1682 1651 EXPECT_GT([attachment info].data.length, 0U); 1683 1652 1684 [webView expectElementCount:2 tagName:@"ATTACHMENT"];1653 [webView expectElementCount:2 querySelector:@"ATTACHMENT"]; 1685 1654 EXPECT_WK_STREQ("hello.rtf", [webView stringByEvaluatingJavaScript:@"document.querySelectorAll('attachment')[0].getAttribute('title')"]); 1686 1655 EXPECT_WK_STREQ("text/rtf", [webView stringByEvaluatingJavaScript:@"document.querySelectorAll('attachment')[0].getAttribute('type')"]); … … 1707 1676 EXPECT_EQ(0U, [dragAndDropSimulator removedAttachments].count); 1708 1677 [[dragAndDropSimulator insertedAttachments].firstObject expectRequestedDataToBe:data]; 1709 [webView expectElementCount:1 tagName:@"ATTACHMENT"];1678 [webView expectElementCount:1 querySelector:@"ATTACHMENT"]; 1710 1679 EXPECT_WK_STREQ("archive.zip", [webView valueOfAttribute:@"title" forQuerySelector:@"attachment"]); 1711 1680 EXPECT_WK_STREQ("application/zip", [webView valueOfAttribute:@"type" forQuerySelector:@"attachment"]); -
trunk/Tools/TestWebKitAPI/cocoa/TestWKWebView.h
r238381 r238471 49 49 50 50 @interface WKWebView (TestWebKitAPI) 51 @property (nonatomic, readonly) NSArray<NSString *> *tagsInBody; 51 52 - (BOOL)_synchronouslyExecuteEditCommand:(NSString *)command argument:(NSString *)argument; 53 - (void)expectElementTagsInOrder:(NSArray<NSString *> *)tagNames; 54 - (void)expectElementCount:(NSInteger)count querySelector:(NSString *)querySelector; 55 - (void)expectElementTag:(NSString *)tagName toComeBefore:(NSString *)otherTagName; 56 - (NSString *)stringByEvaluatingJavaScript:(NSString *)script; 57 - (id)objectByEvaluatingJavaScriptWithUserGesture:(NSString *)script; 58 - (id)objectByEvaluatingJavaScript:(NSString *)script; 52 59 @end 53 60 … … 65 72 - (void)synchronouslyLoadHTMLString:(NSString *)html baseURL:(NSURL *)url; 66 73 - (void)synchronouslyLoadTestPageNamed:(NSString *)pageName; 67 - (id)objectByEvaluatingJavaScript:(NSString *)script;68 - (id)objectByEvaluatingJavaScriptWithUserGesture:(NSString *)script;69 - (NSString *)stringByEvaluatingJavaScript:(NSString *)script;70 74 - (void)waitForMessage:(NSString *)message; 71 75 - (void)performAfterLoading:(dispatch_block_t)actions; -
trunk/Tools/TestWebKitAPI/cocoa/TestWKWebView.mm
r238381 r238471 79 79 } 80 80 81 - (NSArray<NSString *> *)tagsInBody 82 { 83 return [self objectByEvaluatingJavaScript:@"Array.from(document.body.getElementsByTagName('*')).map(e => e.tagName)"]; 84 } 85 86 - (void)expectElementTagsInOrder:(NSArray<NSString *> *)tagNames 87 { 88 auto remainingTags = adoptNS([tagNames mutableCopy]); 89 NSArray<NSString *> *tagsInBody = self.tagsInBody; 90 for (NSString *tag in tagsInBody.reverseObjectEnumerator) { 91 if ([tag isEqualToString:[remainingTags lastObject]]) 92 [remainingTags removeLastObject]; 93 if (![remainingTags count]) 94 break; 95 } 96 EXPECT_EQ([remainingTags count], 0U); 97 if ([remainingTags count]) 98 NSLog(@"Expected to find ordered tags: %@ in: %@", tagNames, tagsInBody); 99 } 100 101 - (void)expectElementCount:(NSInteger)count querySelector:(NSString *)querySelector 102 { 103 NSString *script = [NSString stringWithFormat:@"document.querySelectorAll('%@').length", querySelector]; 104 EXPECT_EQ(count, [self stringByEvaluatingJavaScript:script].integerValue); 105 } 106 107 - (void)expectElementTag:(NSString *)tagName toComeBefore:(NSString *)otherTagName 108 { 109 [self expectElementTagsInOrder:@[tagName, otherTagName]]; 110 } 111 112 - (id)objectByEvaluatingJavaScript:(NSString *)script 113 { 114 bool isWaitingForJavaScript = false; 115 RetainPtr<id> evalResult; 116 [self _evaluateJavaScriptWithoutUserGesture:script completionHandler:[&] (id result, NSError *error) { 117 evalResult = result; 118 isWaitingForJavaScript = true; 119 EXPECT_TRUE(!error); 120 if (error) 121 NSLog(@"Encountered error: %@ while evaluating script: %@", error, script); 122 }]; 123 TestWebKitAPI::Util::run(&isWaitingForJavaScript); 124 return evalResult.autorelease(); 125 } 126 127 - (id)objectByEvaluatingJavaScriptWithUserGesture:(NSString *)script 128 { 129 bool isWaitingForJavaScript = false; 130 RetainPtr<id> evalResult; 131 [self evaluateJavaScript:script completionHandler:[&] (id result, NSError *error) { 132 evalResult = result; 133 isWaitingForJavaScript = true; 134 EXPECT_TRUE(!error); 135 if (error) 136 NSLog(@"Encountered error: %@ while evaluating script: %@", error, script); 137 }]; 138 TestWebKitAPI::Util::run(&isWaitingForJavaScript); 139 return evalResult.autorelease(); 140 } 141 142 - (NSString *)stringByEvaluatingJavaScript:(NSString *)script 143 { 144 return [NSString stringWithFormat:@"%@", [self objectByEvaluatingJavaScript:script]]; 145 } 146 81 147 @end 82 148 … … 290 356 } 291 357 292 - (id)objectByEvaluatingJavaScript:(NSString *)script293 {294 bool isWaitingForJavaScript = false;295 RetainPtr<id> evalResult;296 [self _evaluateJavaScriptWithoutUserGesture:script completionHandler:[&] (id result, NSError *error) {297 evalResult = result;298 isWaitingForJavaScript = true;299 EXPECT_TRUE(!error);300 if (error)301 NSLog(@"Encountered error: %@ while evaluating script: %@", error, script);302 }];303 TestWebKitAPI::Util::run(&isWaitingForJavaScript);304 return evalResult.autorelease();305 }306 307 - (id)objectByEvaluatingJavaScriptWithUserGesture:(NSString *)script308 {309 bool isWaitingForJavaScript = false;310 RetainPtr<id> evalResult;311 [self evaluateJavaScript:script completionHandler:[&] (id result, NSError *error) {312 evalResult = result;313 isWaitingForJavaScript = true;314 EXPECT_TRUE(!error);315 if (error)316 NSLog(@"Encountered error: %@ while evaluating script: %@", error, script);317 }];318 TestWebKitAPI::Util::run(&isWaitingForJavaScript);319 return evalResult.autorelease();320 }321 322 - (NSString *)stringByEvaluatingJavaScript:(NSString *)script323 {324 return [NSString stringWithFormat:@"%@", [self objectByEvaluatingJavaScript:script]];325 }326 327 358 - (void)waitForMessage:(NSString *)message 328 359 {
Note: See TracChangeset
for help on using the changeset viewer.