mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-30 04:39:06 +00:00
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:
parent
f0270b92f1
commit
acd604c5e1
Notes:
github-actions[bot]
2024-09-20 21:42:25 +00:00
Author: https://github.com/ADKaster
Commit: acd604c5e1
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1404
Reviewed-by: https://github.com/tcl3 ✅
5 changed files with 38 additions and 3 deletions
|
@ -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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue