Title: [294258] branches/safari-7614.1.14.1-branch
Revision
294258
Author
alanc...@apple.com
Date
2022-05-16 14:21:07 -0700 (Mon, 16 May 2022)

Log Message

Cherry-pick r294218. rdar://problem/90400867

    Right click > "Open Link" should trigger a navigation action with WKNavigationTypeLinkActivated
    https://bugs.webkit.org/show_bug.cgi?id=240427
    rdar://90400867

    Reviewed by Tim Horton.

    Add a new linked-on-or-after check to guard this new behavior for apps built against newer SDK versions.

    * wtf/cocoa/RuntimeApplicationChecksCocoa.h:
    Right click > "Open Link" should trigger a navigation action with WKNavigationTypeLinkActivated
    https://bugs.webkit.org/show_bug.cgi?id=240427
    rdar://90400867

    Reviewed by Tim Horton.

    Make a couple of minor adjustments to `ContextMenuController` to ensure that right clicking a link and choosing
    "Open Link" or "Open Link in New Window" surfaces a navigation action with `WKNavigationTypeLinkActivated`,
    rather than `WKNavigationTypeOther`.

    Test: ContextMenuTests.NavigationTypeWhenOpeningLink

    * page/ContextMenuContext.cpp:
    (WebCore::ContextMenuContext::ContextMenuContext):
    * page/ContextMenuContext.h:
    (WebCore::ContextMenuContext::event const):

    Save a reference to the `Event` of type "contextmenu" that's triggering context menu presentation in the
    `ContextMenuContext`.

    * page/ContextMenuController.cpp:
    (WebCore::ContextMenuController::maybeCreateContextMenu):
    (WebCore::openNewWindow):

    Plumb the `"contextmenu"` event through to `FrameLoader::loadFrameRequest` when opening links via context menu.

    (WebCore::ContextMenuController::contextMenuItemSelected):
    Right click > "Open Link" should trigger a navigation action with WKNavigationTypeLinkActivated
    https://bugs.webkit.org/show_bug.cgi?id=240427
    rdar://90400867

    Reviewed by Tim Horton.

    Add an API test to verify that right clicking a link and selecting "Open Link" triggers a navigation action with
    the type `WKNavigationTypeLinkActivated`.

    * TestWebKitAPI/Tests/mac/ContextMenuTests.mm:
    (TestWebKitAPI::TEST):

    Canonical link: https://commits.webkit.org/250576@main

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

Modified Paths

Diff

Modified: branches/safari-7614.1.14.1-branch/Source/WTF/ChangeLog (294257 => 294258)


--- branches/safari-7614.1.14.1-branch/Source/WTF/ChangeLog	2022-05-16 21:19:45 UTC (rev 294257)
+++ branches/safari-7614.1.14.1-branch/Source/WTF/ChangeLog	2022-05-16 21:21:07 UTC (rev 294258)
@@ -1,3 +1,72 @@
+2022-05-16  Alan Coon  <alanc...@apple.com>
+
+        Cherry-pick r294218. rdar://problem/90400867
+
+    Right click > "Open Link" should trigger a navigation action with WKNavigationTypeLinkActivated
+    https://bugs.webkit.org/show_bug.cgi?id=240427
+    rdar://90400867
+    
+    Reviewed by Tim Horton.
+    
+    Add a new linked-on-or-after check to guard this new behavior for apps built against newer SDK versions.
+    
+    * wtf/cocoa/RuntimeApplicationChecksCocoa.h:
+    Right click > "Open Link" should trigger a navigation action with WKNavigationTypeLinkActivated
+    https://bugs.webkit.org/show_bug.cgi?id=240427
+    rdar://90400867
+    
+    Reviewed by Tim Horton.
+    
+    Make a couple of minor adjustments to `ContextMenuController` to ensure that right clicking a link and choosing
+    "Open Link" or "Open Link in New Window" surfaces a navigation action with `WKNavigationTypeLinkActivated`,
+    rather than `WKNavigationTypeOther`.
+    
+    Test: ContextMenuTests.NavigationTypeWhenOpeningLink
+    
+    * page/ContextMenuContext.cpp:
+    (WebCore::ContextMenuContext::ContextMenuContext):
+    * page/ContextMenuContext.h:
+    (WebCore::ContextMenuContext::event const):
+    
+    Save a reference to the `Event` of type "contextmenu" that's triggering context menu presentation in the
+    `ContextMenuContext`.
+    
+    * page/ContextMenuController.cpp:
+    (WebCore::ContextMenuController::maybeCreateContextMenu):
+    (WebCore::openNewWindow):
+    
+    Plumb the `"contextmenu"` event through to `FrameLoader::loadFrameRequest` when opening links via context menu.
+    
+    (WebCore::ContextMenuController::contextMenuItemSelected):
+    Right click > "Open Link" should trigger a navigation action with WKNavigationTypeLinkActivated
+    https://bugs.webkit.org/show_bug.cgi?id=240427
+    rdar://90400867
+    
+    Reviewed by Tim Horton.
+    
+    Add an API test to verify that right clicking a link and selecting "Open Link" triggers a navigation action with
+    the type `WKNavigationTypeLinkActivated`.
+    
+    * TestWebKitAPI/Tests/mac/ContextMenuTests.mm:
+    (TestWebKitAPI::TEST):
+    
+    Canonical link: https://commits.webkit.org/250576@main
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@294218 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2022-05-15  Wenson Hsieh  <wenson_hs...@apple.com>
+
+            Right click > "Open Link" should trigger a navigation action with WKNavigationTypeLinkActivated
+            https://bugs.webkit.org/show_bug.cgi?id=240427
+            rdar://90400867
+
+            Reviewed by Tim Horton.
+
+            Add a new linked-on-or-after check to guard this new behavior for apps built against newer SDK versions.
+
+            * wtf/cocoa/RuntimeApplicationChecksCocoa.h:
+
 2022-05-06  Brent Fulgham  <bfulg...@apple.com>
 
         Remove unused ApplePayRemoteUIEnabled preference

Modified: branches/safari-7614.1.14.1-branch/Source/WTF/wtf/cocoa/RuntimeApplicationChecksCocoa.h (294257 => 294258)


--- branches/safari-7614.1.14.1-branch/Source/WTF/wtf/cocoa/RuntimeApplicationChecksCocoa.h	2022-05-16 21:19:45 UTC (rev 294257)
+++ branches/safari-7614.1.14.1-branch/Source/WTF/wtf/cocoa/RuntimeApplicationChecksCocoa.h	2022-05-16 21:21:07 UTC (rev 294258)
@@ -36,6 +36,7 @@
     ApplicationCacheDisabledByDefault,
     AuthorizationHeaderOnSameOriginRedirects,
     BlanksViewOnJSPrompt,
+    ContextMenuTriggersLinkActivationNavigationType,
     ConvertsInvalidURLsToBlank,
     DataURLFragmentRemoval,
     DecidesPolicyBeforeLoadingQuickLookPreview,

Modified: branches/safari-7614.1.14.1-branch/Source/WebCore/ChangeLog (294257 => 294258)


--- branches/safari-7614.1.14.1-branch/Source/WebCore/ChangeLog	2022-05-16 21:19:45 UTC (rev 294257)
+++ branches/safari-7614.1.14.1-branch/Source/WebCore/ChangeLog	2022-05-16 21:21:07 UTC (rev 294258)
@@ -1,3 +1,90 @@
+2022-05-16  Alan Coon  <alanc...@apple.com>
+
+        Cherry-pick r294218. rdar://problem/90400867
+
+    Right click > "Open Link" should trigger a navigation action with WKNavigationTypeLinkActivated
+    https://bugs.webkit.org/show_bug.cgi?id=240427
+    rdar://90400867
+    
+    Reviewed by Tim Horton.
+    
+    Add a new linked-on-or-after check to guard this new behavior for apps built against newer SDK versions.
+    
+    * wtf/cocoa/RuntimeApplicationChecksCocoa.h:
+    Right click > "Open Link" should trigger a navigation action with WKNavigationTypeLinkActivated
+    https://bugs.webkit.org/show_bug.cgi?id=240427
+    rdar://90400867
+    
+    Reviewed by Tim Horton.
+    
+    Make a couple of minor adjustments to `ContextMenuController` to ensure that right clicking a link and choosing
+    "Open Link" or "Open Link in New Window" surfaces a navigation action with `WKNavigationTypeLinkActivated`,
+    rather than `WKNavigationTypeOther`.
+    
+    Test: ContextMenuTests.NavigationTypeWhenOpeningLink
+    
+    * page/ContextMenuContext.cpp:
+    (WebCore::ContextMenuContext::ContextMenuContext):
+    * page/ContextMenuContext.h:
+    (WebCore::ContextMenuContext::event const):
+    
+    Save a reference to the `Event` of type "contextmenu" that's triggering context menu presentation in the
+    `ContextMenuContext`.
+    
+    * page/ContextMenuController.cpp:
+    (WebCore::ContextMenuController::maybeCreateContextMenu):
+    (WebCore::openNewWindow):
+    
+    Plumb the `"contextmenu"` event through to `FrameLoader::loadFrameRequest` when opening links via context menu.
+    
+    (WebCore::ContextMenuController::contextMenuItemSelected):
+    Right click > "Open Link" should trigger a navigation action with WKNavigationTypeLinkActivated
+    https://bugs.webkit.org/show_bug.cgi?id=240427
+    rdar://90400867
+    
+    Reviewed by Tim Horton.
+    
+    Add an API test to verify that right clicking a link and selecting "Open Link" triggers a navigation action with
+    the type `WKNavigationTypeLinkActivated`.
+    
+    * TestWebKitAPI/Tests/mac/ContextMenuTests.mm:
+    (TestWebKitAPI::TEST):
+    
+    Canonical link: https://commits.webkit.org/250576@main
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@294218 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2022-05-15  Wenson Hsieh  <wenson_hs...@apple.com>
+
+            Right click > "Open Link" should trigger a navigation action with WKNavigationTypeLinkActivated
+            https://bugs.webkit.org/show_bug.cgi?id=240427
+            rdar://90400867
+
+            Reviewed by Tim Horton.
+
+            Make a couple of minor adjustments to `ContextMenuController` to ensure that right clicking a link and choosing
+            "Open Link" or "Open Link in New Window" surfaces a navigation action with `WKNavigationTypeLinkActivated`,
+            rather than `WKNavigationTypeOther`.
+
+            Test: ContextMenuTests.NavigationTypeWhenOpeningLink
+
+            * page/ContextMenuContext.cpp:
+            (WebCore::ContextMenuContext::ContextMenuContext):
+            * page/ContextMenuContext.h:
+            (WebCore::ContextMenuContext::event const):
+
+            Save a reference to the `Event` of type "contextmenu" that's triggering context menu presentation in the
+            `ContextMenuContext`.
+
+            * page/ContextMenuController.cpp:
+            (WebCore::ContextMenuController::maybeCreateContextMenu):
+            (WebCore::openNewWindow):
+
+            Plumb the `"contextmenu"` event through to `FrameLoader::loadFrameRequest` when opening links via context menu.
+
+            (WebCore::ContextMenuController::contextMenuItemSelected):
+
 2022-05-13  Russell Epstein  <repst...@apple.com>
 
         Cherry-pick r294135. rdar://problem/93201070

Modified: branches/safari-7614.1.14.1-branch/Source/WebCore/page/ContextMenuContext.cpp (294257 => 294258)


--- branches/safari-7614.1.14.1-branch/Source/WebCore/page/ContextMenuContext.cpp	2022-05-16 21:19:45 UTC (rev 294257)
+++ branches/safari-7614.1.14.1-branch/Source/WebCore/page/ContextMenuContext.cpp	2022-05-16 21:21:07 UTC (rev 294258)
@@ -27,17 +27,21 @@
 #include "config.h"
 #include "ContextMenuContext.h"
 
+#include "Event.h"
+
 #if ENABLE(CONTEXT_MENUS)
 
 namespace WebCore {
 
-ContextMenuContext::ContextMenuContext()
-{
-}
+ContextMenuContext::ContextMenuContext() = default;
+ContextMenuContext::~ContextMenuContext() = default;
 
-ContextMenuContext::ContextMenuContext(Type type, const HitTestResult& hitTestResult)
+ContextMenuContext& ContextMenuContext::operator=(const ContextMenuContext&) = default;
+
+ContextMenuContext::ContextMenuContext(Type type, const HitTestResult& hitTestResult, Event* event)
     : m_type(type)
     , m_hitTestResult(hitTestResult)
+    , m_event(event)
 #if ENABLE(SERVICE_CONTROLS)
     , m_controlledImage(nullptr)
 #endif

Modified: branches/safari-7614.1.14.1-branch/Source/WebCore/page/ContextMenuContext.h (294257 => 294258)


--- branches/safari-7614.1.14.1-branch/Source/WebCore/page/ContextMenuContext.h	2022-05-16 21:19:45 UTC (rev 294257)
+++ branches/safari-7614.1.14.1-branch/Source/WebCore/page/ContextMenuContext.h	2022-05-16 21:21:07 UTC (rev 294258)
@@ -33,6 +33,8 @@
 
 namespace WebCore {
 
+class Event;
+
 class ContextMenuContext {
 public:
     enum class Type : uint8_t {
@@ -46,11 +48,16 @@
     };
 
     ContextMenuContext();
-    ContextMenuContext(Type, const HitTestResult&);
+    ContextMenuContext(Type, const HitTestResult&, Event*);
 
+    ~ContextMenuContext();
+
+    ContextMenuContext& operator=(const ContextMenuContext&);
+
     Type type() const { return m_type; }
 
     const HitTestResult& hitTestResult() const { return m_hitTestResult; }
+    Event* event() const { return m_event.get(); }
 
     void setSelectedText(const String& selectedText) { m_selectedText = selectedText; }
     const String& selectedText() const { return m_selectedText; }
@@ -63,6 +70,7 @@
 private:
     Type m_type { Type::ContextMenu };
     HitTestResult m_hitTestResult;
+    RefPtr<Event> m_event;
     String m_selectedText;
 
 #if ENABLE(SERVICE_CONTROLS)

Modified: branches/safari-7614.1.14.1-branch/Source/WebCore/page/ContextMenuController.cpp (294257 => 294258)


--- branches/safari-7614.1.14.1-branch/Source/WebCore/page/ContextMenuController.cpp	2022-05-16 21:19:45 UTC (rev 294257)
+++ branches/safari-7614.1.14.1-branch/Source/WebCore/page/ContextMenuController.cpp	2022-05-16 21:21:07 UTC (rev 294258)
@@ -77,6 +77,9 @@
 #include "ImageControlsMac.h"
 #endif
 
+#if PLATFORM(COCOA)
+#include <wtf/cocoa/RuntimeApplicationChecksCocoa.h>
+#endif
 
 namespace WebCore {
 
@@ -164,7 +167,7 @@
     if (!result.innerNonSharedNode())
         return nullptr;
 
-    m_context = ContextMenuContext(contextType, result);
+    m_context = { contextType, result, &event };
     
     return makeUnique<ContextMenu>();
 }
@@ -183,7 +186,7 @@
         m_menuProvider->didDismissContextMenu();
 }
 
-static void openNewWindow(const URL& urlToLoad, Frame& frame, ShouldOpenExternalURLsPolicy shouldOpenExternalURLsPolicy)
+static void openNewWindow(const URL& urlToLoad, Frame& frame, Event* event, ShouldOpenExternalURLsPolicy shouldOpenExternalURLsPolicy)
 {
     Page* oldPage = frame.page();
     if (!oldPage)
@@ -197,7 +200,7 @@
     if (!newPage)
         return;
     newPage->chrome().show();
-    newPage->mainFrame().loader().loadFrameRequest(WTFMove(frameLoadRequest), nullptr, { });
+    newPage->mainFrame().loader().loadFrameRequest(WTFMove(frameLoadRequest), event, { });
 }
 
 #if PLATFORM(GTK)
@@ -229,10 +232,17 @@
         return;
 
     Ref<Frame> protector(*frame);
+    RefPtr<Event> eventForLoadRequests = [&]() -> Event* {
+#if PLATFORM(COCOA)
+        if (!linkedOnOrAfterSDKWithBehavior(SDKAlignedBehavior::ContextMenuTriggersLinkActivationNavigationType))
+            return nullptr;
+#endif
+        return m_context.event();
+    }();
 
     switch (action) {
     case ContextMenuItemTagOpenLinkInNewWindow:
-        openNewWindow(m_context.hitTestResult().absoluteLinkURL(), *frame, ShouldOpenExternalURLsPolicy::ShouldAllowExternalSchemesButNotAppLinks);
+        openNewWindow(m_context.hitTestResult().absoluteLinkURL(), *frame, eventForLoadRequests.get(), ShouldOpenExternalURLsPolicy::ShouldAllowExternalSchemesButNotAppLinks);
         break;
     case ContextMenuItemTagDownloadLinkToDisk:
         // FIXME: Some day we should be able to do this from within WebCore. (Bug 117709)
@@ -242,7 +252,7 @@
         frame->editor().copyURL(m_context.hitTestResult().absoluteLinkURL(), m_context.hitTestResult().textContent());
         break;
     case ContextMenuItemTagOpenImageInNewWindow:
-        openNewWindow(m_context.hitTestResult().absoluteImageURL(), *frame, ShouldOpenExternalURLsPolicy::ShouldNotAllow);
+        openNewWindow(m_context.hitTestResult().absoluteImageURL(), *frame, nullptr, ShouldOpenExternalURLsPolicy::ShouldNotAllow);
         break;
     case ContextMenuItemTagDownloadImageToDisk:
         // FIXME: Some day we should be able to do this from within WebCore. (Bug 117709)
@@ -259,7 +269,7 @@
         break;
 #endif
     case ContextMenuItemTagOpenMediaInNewWindow:
-        openNewWindow(m_context.hitTestResult().absoluteMediaURL(), *frame, ShouldOpenExternalURLsPolicy::ShouldNotAllow);
+        openNewWindow(m_context.hitTestResult().absoluteMediaURL(), *frame, nullptr, ShouldOpenExternalURLsPolicy::ShouldNotAllow);
         break;
     case ContextMenuItemTagDownloadMediaToDisk:
         // FIXME: Some day we should be able to do this from within WebCore. (Bug 117709)
@@ -292,9 +302,9 @@
     case ContextMenuItemTagOpenFrameInNewWindow: {
         DocumentLoader* loader = frame->loader().documentLoader();
         if (!loader->unreachableURL().isEmpty())
-            openNewWindow(loader->unreachableURL(), *frame, ShouldOpenExternalURLsPolicy::ShouldNotAllow);
+            openNewWindow(loader->unreachableURL(), *frame, nullptr, ShouldOpenExternalURLsPolicy::ShouldNotAllow);
         else
-            openNewWindow(loader->url(), *frame, ShouldOpenExternalURLsPolicy::ShouldNotAllow);
+            openNewWindow(loader->url(), *frame, nullptr, ShouldOpenExternalURLsPolicy::ShouldNotAllow);
         break;
     }
     case ContextMenuItemTagCopy:
@@ -407,9 +417,9 @@
             frameLoadRequest.setNewFrameOpenerPolicy(NewFrameOpenerPolicy::Suppress);
             if (targetFrame->isMainFrame())
                 frameLoadRequest.setShouldOpenExternalURLsPolicy(ShouldOpenExternalURLsPolicy::ShouldAllow);
-            targetFrame->loader().loadFrameRequest(WTFMove(frameLoadRequest), nullptr,  { });
+            targetFrame->loader().loadFrameRequest(WTFMove(frameLoadRequest), eventForLoadRequests.get(), { });
         } else
-            openNewWindow(m_context.hitTestResult().absoluteLinkURL(), *frame, ShouldOpenExternalURLsPolicy::ShouldAllow);
+            openNewWindow(m_context.hitTestResult().absoluteLinkURL(), *frame, eventForLoadRequests.get(), ShouldOpenExternalURLsPolicy::ShouldAllow);
         break;
     case ContextMenuItemTagBold:
         frame->editor().command("ToggleBold"_s).execute();

Modified: branches/safari-7614.1.14.1-branch/Tools/ChangeLog (294257 => 294258)


--- branches/safari-7614.1.14.1-branch/Tools/ChangeLog	2022-05-16 21:19:45 UTC (rev 294257)
+++ branches/safari-7614.1.14.1-branch/Tools/ChangeLog	2022-05-16 21:21:07 UTC (rev 294258)
@@ -1,3 +1,74 @@
+2022-05-16  Alan Coon  <alanc...@apple.com>
+
+        Cherry-pick r294218. rdar://problem/90400867
+
+    Right click > "Open Link" should trigger a navigation action with WKNavigationTypeLinkActivated
+    https://bugs.webkit.org/show_bug.cgi?id=240427
+    rdar://90400867
+    
+    Reviewed by Tim Horton.
+    
+    Add a new linked-on-or-after check to guard this new behavior for apps built against newer SDK versions.
+    
+    * wtf/cocoa/RuntimeApplicationChecksCocoa.h:
+    Right click > "Open Link" should trigger a navigation action with WKNavigationTypeLinkActivated
+    https://bugs.webkit.org/show_bug.cgi?id=240427
+    rdar://90400867
+    
+    Reviewed by Tim Horton.
+    
+    Make a couple of minor adjustments to `ContextMenuController` to ensure that right clicking a link and choosing
+    "Open Link" or "Open Link in New Window" surfaces a navigation action with `WKNavigationTypeLinkActivated`,
+    rather than `WKNavigationTypeOther`.
+    
+    Test: ContextMenuTests.NavigationTypeWhenOpeningLink
+    
+    * page/ContextMenuContext.cpp:
+    (WebCore::ContextMenuContext::ContextMenuContext):
+    * page/ContextMenuContext.h:
+    (WebCore::ContextMenuContext::event const):
+    
+    Save a reference to the `Event` of type "contextmenu" that's triggering context menu presentation in the
+    `ContextMenuContext`.
+    
+    * page/ContextMenuController.cpp:
+    (WebCore::ContextMenuController::maybeCreateContextMenu):
+    (WebCore::openNewWindow):
+    
+    Plumb the `"contextmenu"` event through to `FrameLoader::loadFrameRequest` when opening links via context menu.
+    
+    (WebCore::ContextMenuController::contextMenuItemSelected):
+    Right click > "Open Link" should trigger a navigation action with WKNavigationTypeLinkActivated
+    https://bugs.webkit.org/show_bug.cgi?id=240427
+    rdar://90400867
+    
+    Reviewed by Tim Horton.
+    
+    Add an API test to verify that right clicking a link and selecting "Open Link" triggers a navigation action with
+    the type `WKNavigationTypeLinkActivated`.
+    
+    * TestWebKitAPI/Tests/mac/ContextMenuTests.mm:
+    (TestWebKitAPI::TEST):
+    
+    Canonical link: https://commits.webkit.org/250576@main
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@294218 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2022-05-15  Wenson Hsieh  <wenson_hs...@apple.com>
+
+            Right click > "Open Link" should trigger a navigation action with WKNavigationTypeLinkActivated
+            https://bugs.webkit.org/show_bug.cgi?id=240427
+            rdar://90400867
+
+            Reviewed by Tim Horton.
+
+            Add an API test to verify that right clicking a link and selecting "Open Link" triggers a navigation action with
+            the type `WKNavigationTypeLinkActivated`.
+
+            * TestWebKitAPI/Tests/mac/ContextMenuTests.mm:
+            (TestWebKitAPI::TEST):
+
 2022-05-12  Russell Epstein  <repst...@apple.com>
 
         Cherry-pick r294088. rdar://problem/93134975

Modified: branches/safari-7614.1.14.1-branch/Tools/TestWebKitAPI/Tests/mac/ContextMenuTests.mm (294257 => 294258)


--- branches/safari-7614.1.14.1-branch/Tools/TestWebKitAPI/Tests/mac/ContextMenuTests.mm	2022-05-16 21:19:45 UTC (rev 294257)
+++ branches/safari-7614.1.14.1-branch/Tools/TestWebKitAPI/Tests/mac/ContextMenuTests.mm	2022-05-16 21:21:07 UTC (rev 294258)
@@ -28,6 +28,8 @@
 
 #if PLATFORM(MAC)
 
+#import "PlatformUtilities.h"
+#import "TestNavigationDelegate.h"
 #import "TestUIDelegate.h"
 #import "TestWKWebView.h"
 #import "Utilities.h"
@@ -83,6 +85,50 @@
     EXPECT_NOT_NULL([spellingSubmenu itemWithIdentifier:_WKMenuItemIdentifierCheckGrammarWithSpelling]);
 }
 
+TEST(ContextMenuTests, NavigationTypeWhenOpeningLink)
+{
+    auto delegate = adoptNS([[TestUIDelegate alloc] init]);
+
+    __block RetainPtr<NSMenu> proposedMenu;
+    [delegate setGetContextMenuFromProposedMenu:^(NSMenu *menu, _WKContextMenuElementInfo *, id<NSSecureCoding>, void (^completion)(NSMenu *)) {
+        proposedMenu = menu;
+        completion(menu);
+    }];
+
+    auto navigationDelegate = adoptNS([[TestNavigationDelegate alloc] init]);
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 400, 400)]);
+    [webView setNavigationDelegate:navigationDelegate.get()];
+    [webView setUIDelegate:delegate.get()];
+    [webView loadHTMLString:@"<a href='' style='font-size: 100px;'>Hello world</a>" baseURL:[NSBundle.mainBundle.bundleURL URLByAppendingPathComponent:@"TestWebKitAPI.resources"]];
+    [navigationDelegate waitForDidFinishNavigation];
+
+    RetainPtr openLinkTimer = [NSTimer timerWithTimeInterval:0.25 repeats:YES block:^(NSTimer *timer) {
+        if (!proposedMenu)
+            return;
+
+        for (NSInteger index = 0; index < [proposedMenu numberOfItems]; ++index) {
+            if ([[proposedMenu itemAtIndex:index].identifier isEqualToString:_WKMenuItemIdentifierOpenLink])
+                [proposedMenu performActionForItemAtIndex:index];
+        }
+        [proposedMenu cancelTracking];
+        [timer invalidate];
+    }];
+    [NSRunLoop.mainRunLoop addTimer:openLinkTimer.get() forMode:NSEventTrackingRunLoopMode];
+
+    __block bool didDecideNavigationPolicy = false;
+    [navigationDelegate setDecidePolicyForNavigationAction:^(WKNavigationAction *action, void (^decisionHandler)(WKNavigationActionPolicy)) {
+        EXPECT_EQ(action.navigationType, WKNavigationTypeLinkActivated);
+        EXPECT_WK_STREQ("simple.html", action.request.URL.lastPathComponent);
+        decisionHandler(WKNavigationActionPolicyAllow);
+        didDecideNavigationPolicy = true;
+    }];
+
+    [[webView window] orderFrontRegardless];
+    [webView mouseDownAtPoint:NSMakePoint(50, 350) simulatePressure:NO withFlags:0 eventType:NSEventTypeRightMouseDown];
+    [webView mouseUpAtPoint:NSMakePoint(50, 350) withFlags:0 eventType:NSEventTypeRightMouseUp];
+    Util::run(&didDecideNavigationPolicy);
+}
+
 } // namespace TestWebKitAPI
 
 #endif // PLATFORM(MAC)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to