Skip to content

Commit

Permalink
[Navigation] Call intercept handlers and dispatch navigateerror/navig…
Browse files Browse the repository at this point in the history
…atesuccess

https://bugs.webkit.org/show_bug.cgi?id=273893

Reviewed by Alex Christensen.

* LayoutTests/imported/w3c/web-platform-tests/navigation-api/focus-reset/change-focus-again-in-blur-during-intercept-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/focus-reset/change-focus-back-to-origial-during-intercept-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/focus-reset/change-focus-during-intercept-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/focus-reset/change-focus-then-remove-during-intercept-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/focus-reset/focus-reset-timing-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/intercept-handler-null-or-undefined-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/intercept-handler-throws-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/intercept-multiple-times-reject-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/intercept-reject-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/navigatesuccess-same-document-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/ordering-and-transition/navigate-204-205-download-then-same-document-expected.txt:
* Source/WebCore/page/NavigateEvent.cpp:
(WebCore::NavigateEvent::intercept):
* Source/WebCore/page/Navigation.cpp:
(WebCore::Navigation::innerDispatchNavigateEvent):

Canonical link: https://commits.webkit.org/278546@main
  • Loading branch information
TingPing committed May 9, 2024
1 parent da80566 commit 2c7219b
Show file tree
Hide file tree
Showing 14 changed files with 47 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@

FAIL change-focus-again-in-blur-during-intercept promise_test: Unhandled rejection with value: object "TypeError: intercept_resolve is not a function. (In 'intercept_resolve()', 'intercept_resolve' is undefined)"
PASS change-focus-again-in-blur-during-intercept

Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@

FAIL change-focus-back-to-origial-during-intercept promise_test: Unhandled rejection with value: object "TypeError: intercept_resolve is not a function. (In 'intercept_resolve()', 'intercept_resolve' is undefined)"
PASS change-focus-back-to-origial-during-intercept

Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@

FAIL change-focus-during-intercept promise_test: Unhandled rejection with value: object "TypeError: intercept_resolve is not a function. (In 'intercept_resolve()', 'intercept_resolve' is undefined)"
PASS change-focus-during-intercept

Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@

FAIL change-focus-then-remove-during-intercept promise_test: Unhandled rejection with value: object "TypeError: intercept_resolve is not a function. (In 'intercept_resolve()', 'intercept_resolve' is undefined)"
PASS change-focus-then-remove-during-intercept

Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
CONSOLE MESSAGE: Unhandled Promise Rejection: undefined

FAIL Focus should be reset before navigatesuccess assert_true: expected true got false
FAIL Focus should be reset before navigatesuccess assert_equals: Focus must be reset before navigatesuccess expected Element node <body>
<script>
promise_test(async t => {
navigation.ad... but got Element node <button></button>
FAIL Focus should be reset before navigateerror assert_unreached: Should have rejected: undefined Reached unreachable code

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

PASS event.intercept() should throw if the handler is null
FAIL event.intercept() should not throw if the handler is explicit undefined assert_equals: expected "#2" but got "#1"
PASS event.intercept() should not throw if the handler is explicit undefined

Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
CONSOLE MESSAGE: TypeError: a message

Harness Error (FAIL), message = TypeError: a message

FAIL event.intercept() should abort if the handler throws assert_equals: expected "#1" but got ""

Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@

FAIL event.intercept() is called multiple times and one of the promises rejects assert_true: expected true got false
FAIL event.intercept() is called multiple times and one of the promises rejects assert_unreached: [object Event] Reached unreachable code

Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@

FAIL event.intercept() should abort if the given promise rejects assert_equals: expected "#1" but got ""
FAIL event.intercept() should abort if the given promise rejects assert_unreached: [object Event] Reached unreachable code

Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@

Harness Error (TIMEOUT), message = null

TIMEOUT navigatesuccess fires for a same-document navigation Test timed out
FAIL navigatesuccess fires for a same-document navigation assert_equals: expected "#1" but got ""

Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

FAIL event and promise ordering when navigate() is to a 204s and then to a same-document navigation assert_array_equals: lengths differ, expected array ["navigate", "AbortSignal abort", "navigateerror", "navigate", "currententrychange", "committed rejected 1", "finished rejected 1", "committed fulfilled 2", "promise microtask", "navigatesuccess", "finished fulfilled 2"] length 11, got ["finished fulfilled 1", "finished fulfilled 2", "promise microtask"] length 3
FAIL event and promise ordering when navigate() is to a 205s and then to a same-document navigation assert_array_equals: lengths differ, expected array ["navigate", "AbortSignal abort", "navigateerror", "navigate", "currententrychange", "committed rejected 1", "finished rejected 1", "committed fulfilled 2", "promise microtask", "navigatesuccess", "finished fulfilled 2"] length 11, got ["finished fulfilled 1", "finished fulfilled 2", "promise microtask"] length 3
FAIL event and promise ordering when navigate() is to a Content-Disposition: attachment responses and then to a same-document navigation assert_array_equals: lengths differ, expected array ["navigate", "AbortSignal abort", "navigateerror", "navigate", "currententrychange", "committed rejected 1", "finished rejected 1", "committed fulfilled 2", "promise microtask", "navigatesuccess", "finished fulfilled 2"] length 11, got ["finished fulfilled 1", "navigate", "currententrychange", "finished fulfilled 2", "promise microtask"] length 5
FAIL event and promise ordering when navigate() is to a Content-Disposition: attachment responses and then to a same-document navigation assert_array_equals: lengths differ, expected array ["navigate", "AbortSignal abort", "navigateerror", "navigate", "currententrychange", "committed rejected 1", "finished rejected 1", "committed fulfilled 2", "promise microtask", "navigatesuccess", "finished fulfilled 2"] length 11, got ["finished fulfilled 1", "navigate", "navigatesuccess", "currententrychange", "finished fulfilled 2", "promise microtask"] length 6

2 changes: 1 addition & 1 deletion Source/WebCore/page/NavigateEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ ExceptionOr<void> NavigateEvent::intercept(NavigationInterceptOptions&& options)
ASSERT(!m_interceptionState || m_interceptionState == InterceptionState::Intercepted);

if (options.handler)
m_handlers.append(WTFMove(options.handler));
m_handlers.append(options.handler.releaseNonNull());

if (options.focusReset) {
// FIXME: Print warning to console if it was already set.
Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/page/NavigateEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class NavigateEvent final : public Event {

void finish();

Vector<RefPtr<NavigationInterceptHandler>> handlers() { return m_handlers; };
Vector<Ref<NavigationInterceptHandler>>& handlers() { return m_handlers; };

private:
NavigateEvent(const AtomString& type, const Init&, AbortController*);
Expand All @@ -111,7 +111,7 @@ class NavigateEvent final : public Event {
RefPtr<AbortSignal> m_signal;
RefPtr<DOMFormData> m_formData;
String m_downloadRequest;
Vector<RefPtr<NavigationInterceptHandler>> m_handlers;
Vector<Ref<NavigationInterceptHandler>> m_handlers;
JSC::JSValue m_info;
bool m_canIntercept { false };
bool m_userInitiated { false };
Expand Down
36 changes: 27 additions & 9 deletions Source/WebCore/page/Navigation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include "Navigation.h"

#include "AbortController.h"
#include "CallbackResult.h"
#include "ErrorEvent.h"
#include "EventNames.h"
#include "Exception.h"
#include "FrameLoadRequest.h"
Expand Down Expand Up @@ -561,27 +563,43 @@ bool Navigation::innerDispatchNavigateEvent(NavigationNavigationType navigationT
}

if (endResultIsSameDocument) {
// FIXME: Step 33: Wait on Handler promises
Vector<RefPtr<DOMPromise>> promiseList;
bool failure = false;

for (auto& handler : event->handlers()) {
auto callbackResult = handler->handleEvent();
if (callbackResult.type() == CallbackResultType::Success)
promiseList.append(callbackResult.releaseReturnValue());
else
failure = true;
// FIXME: We need to keep around the failure reason but the generated handleEvent() catches and consumes it.
}

// FIXME: Step 33.4: We need to wait for all promises.

if (document->isFullyActive() && !abortController->signal().aborted()) {
ASSERT(m_ongoingNavigateEvent == event.ptr());
m_ongoingNavigateEvent = nullptr;

event->finish();

// FIXME: 6. Fire an event named navigatesuccess at navigation.
// FIXME: 7. If navigation's transition is not null, then resolve navigation's transition's finished promise with undefined.
m_transition = nullptr;
if (!failure) {
dispatchEvent(Event::create(eventNames().navigatesuccessEvent, { }));

// FIXME: 7. If navigation's transition is not null, then resolve navigation's transition's finished promise with undefined.
m_transition = nullptr;

if (apiMethodTracker)
resolveFinishedPromise(*apiMethodTracker);
if (apiMethodTracker)
resolveFinishedPromise(*apiMethodTracker);
} else {
// FIXME: Fill in error information.
dispatchEvent(ErrorEvent::create(eventNames().navigateerrorEvent, { }, { }, 0, 0, { }));
}
}

// FIXME: and the following failure steps given reason rejectionReason:
m_ongoingNavigateEvent = nullptr;
}

if (apiMethodTracker)
} else if (apiMethodTracker)
cleanupAPIMethodTracker(*apiMethodTracker);

// FIXME: Step 35 Clean up after running script
Expand Down

0 comments on commit 2c7219b

Please sign in to comment.