LibWeb: Add a test-only API to spoof the current URL and origin

This is not that easy to use for test developers, as forgetting to set
the url back to its original state after testing your specific API will
cause future navigations to fail in inexplicable ways.
This commit is contained in:
Andrew Kaster 2024-09-14 21:16:46 -06:00 committed by Tim Ledbetter
commit acd604c5e1
Notes: github-actions[bot] 2024-09-20 21:42:25 +00:00
5 changed files with 38 additions and 3 deletions

View file

@ -10,6 +10,7 @@
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/Event.h>
#include <LibWeb/DOM/EventTarget.h>
#include <LibWeb/DOMURL/DOMURL.h>
#include <LibWeb/HTML/BrowsingContext.h>
#include <LibWeb/HTML/HTMLElement.h>
#include <LibWeb/HTML/Window.h>
@ -136,6 +137,19 @@ WebIDL::ExceptionOr<bool> Internals::dispatch_user_activated_event(DOM::EventTar
return target.dispatch_event(event);
}
void Internals::spoof_current_url(String const& url_string)
{
auto url = DOMURL::parse(url_string);
VERIFY(url.is_valid());
auto origin = DOMURL::url_origin(url);
auto& window = internals_window();
window.associated_document().set_url(url);
window.associated_document().set_origin(origin);
}
JS::NonnullGCPtr<InternalAnimationTimeline> Internals::create_internal_animation_timeline()
{
auto& realm = this->realm();