Skip to content

Commit

Permalink
Add temporary web navigation event to test interface.
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=248969
rdar://102820594

Reviewed by Timothy Hatcher.

* Source/WebKit/WebProcess/Extensions/API/Cocoa/WebExtensionAPITestCocoa.mm:
(WebKit::WebExtensionAPITest::testWebNavigationEvent):
(WebKit::WebExtensionAPITest::fireTestWebNavigationEvent):
* Source/WebKit/WebProcess/Extensions/API/WebExtensionAPITest.h:
* Source/WebKit/WebProcess/Extensions/API/WebExtensionAPIWebNavigationEvent.h:
(WebKit::WebExtensionAPIWebNavigationEvent::setEventType):
* Source/WebKit/WebProcess/Extensions/Interfaces/WebExtensionAPITest.idl:

Canonical link: https://commits.webkit.org/257588@main
  • Loading branch information
b-weinstein committed Dec 8, 2022
1 parent 28e425e commit c1ab7bf
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
Expand Up @@ -184,6 +184,22 @@
assertTrue(context, [expectedError isEqualWithTypeCoercionToObject:exceptionMessageValue], [NSString stringWithFormat:@"Function throw an exception (%@) that didn't equal %@.", debugString(exceptionMessageValue), debugString(expectedError)]);
}

WebExtensionAPIWebNavigationEvent& WebExtensionAPITest::testWebNavigationEvent()
{
if (!m_webNavigationEvent)
m_webNavigationEvent = WebExtensionAPIWebNavigationEvent::create(forMainWorld(), runtime(), extensionContext(), WebExtensionEventListenerType::WebNavigationOnCompleted);

return *m_webNavigationEvent;
}

void WebExtensionAPITest::fireTestWebNavigationEvent(NSString *urlString)
{
NSURL *targetURL = [NSURL URLWithString:urlString];

WebExtensionAPIWebNavigationEvent& testEvent = testWebNavigationEvent();
testEvent.invokeListenersWithArgument(@{ @"url": urlString }, targetURL);
}

} // namespace WebKit

#endif // ENABLE(WK_WEB_EXTENSIONS)
7 changes: 7 additions & 0 deletions Source/WebKit/WebProcess/Extensions/API/WebExtensionAPITest.h
Expand Up @@ -29,6 +29,7 @@

#include "JSWebExtensionAPITest.h"
#include "WebExtensionAPIObject.h"
#include "WebExtensionAPIWebNavigationEvent.h"

OBJC_CLASS NSString;

Expand Down Expand Up @@ -59,6 +60,12 @@ class WebExtensionAPITest : public WebExtensionAPIObject, public JSWebExtensionW

JSValue *assertRejects(JSContextRef, JSValue *promise, JSValue *expectedError, NSString *message);
void assertThrows(JSContextRef, JSValue *function, JSValue *expectedError, NSString *message);

WebExtensionAPIWebNavigationEvent& testWebNavigationEvent();
void fireTestWebNavigationEvent(NSString *urlString);

private:
RefPtr<WebExtensionAPIWebNavigationEvent> m_webNavigationEvent;
#endif
};

Expand Down
Expand Up @@ -55,6 +55,12 @@ class WebExtensionAPIWebNavigationEvent : public WebExtensionAPIObject, public J
bool hasListener(RefPtr<WebExtensionCallbackHandler>);

private:
explicit WebExtensionAPIWebNavigationEvent(ForMainWorld forMainWorld, WebExtensionAPIRuntimeBase& runtime, WebExtensionContextProxy& context, WebExtensionEventListenerType type)
: WebExtensionAPIObject(forMainWorld, runtime, context)
{
m_type = type;
}

WebExtensionEventListenerType m_type;
ListenerVector m_listeners;
};
Expand Down
Expand Up @@ -64,4 +64,9 @@
// Asserts the function throws an exception.
[NeedsScriptContext, ProcessArgumentsLeftToRight] void assertThrows(any function, [Optional, ValuesAllowed] any expectedError, [Optional] DOMString message);

// Temporary webNavigation event for bring-up.
// FIXME: Remove this.
readonly attribute WebExtensionAPIWebNavigationEvent testWebNavigationEvent;
void fireTestWebNavigationEvent(DOMString targetUrl);

};

0 comments on commit c1ab7bf

Please sign in to comment.