mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 21:58:12 +00:00
LibWeb/WebDriver: Handle WindowProxy in internal_json_clone_algorithm()
To test: ```console curl http://0.0.0.0:8000/session \ -H 'Content-Type: application/json' \ -d '{"capabilities": {}}' curl http://0.0.0.0:8000/session/0/execute/sync \ -H 'Content-Type: application/json' \ -d '{"script": "return window;", "args": []}' ``` Which should result in: ```json { "value": { "window-fcc6-11e5-b4f8-330a88ab9d7f": "86307df6-e2f1-4175-85cb-77295ff90898" } } ```
This commit is contained in:
parent
84a231d4e5
commit
e6be5c37c0
8 changed files with 88 additions and 5 deletions
33
Userland/Libraries/LibWeb/WebDriver/Contexts.cpp
Normal file
33
Userland/Libraries/LibWeb/WebDriver/Contexts.cpp
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Linus Groh <linusg@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/JsonObject.h>
|
||||
#include <LibWeb/HTML/BrowsingContext.h>
|
||||
#include <LibWeb/HTML/WindowProxy.h>
|
||||
#include <LibWeb/WebDriver/Contexts.h>
|
||||
|
||||
namespace Web::WebDriver {
|
||||
|
||||
// https://w3c.github.io/webdriver/#dfn-windowproxy-reference-object
|
||||
JsonObject window_proxy_reference_object(HTML::WindowProxy const& window)
|
||||
{
|
||||
// 1. Let identifier be the web window identifier if the associated browsing context of window is a top-level browsing context.
|
||||
// Otherwise let it be the web frame identifier.
|
||||
auto identifier = window.associated_browsing_context()->is_top_level()
|
||||
? WEB_WINDOW_IDENTIFIER
|
||||
: WEB_FRAME_IDENTIFIER;
|
||||
|
||||
// 2. Return a JSON Object initialized with the following properties:
|
||||
JsonObject object;
|
||||
|
||||
// identifier
|
||||
// Associated window handle of the window’s browsing context.
|
||||
object.set(identifier, window.associated_browsing_context()->window_handle().to_deprecated_string());
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue