mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 21:42:43 +00:00 
			
		
		
		
	LibWeb+WebDriver: Move the timeouts configuration object to LibWeb
This commit is contained in:
		
							parent
							
								
									7972916be7
								
							
						
					
					
						commit
						cb4b9108d1
					
				
					 7 changed files with 15 additions and 15 deletions
				
			
		|  | @ -443,6 +443,7 @@ set(SOURCES | ||||||
|     WebDriver/ExecuteScript.cpp |     WebDriver/ExecuteScript.cpp | ||||||
|     WebDriver/Response.cpp |     WebDriver/Response.cpp | ||||||
|     WebDriver/Screenshot.cpp |     WebDriver/Screenshot.cpp | ||||||
|  |     WebDriver/TimeoutsConfiguration.cpp | ||||||
|     WebGL/WebGLContextAttributes.cpp |     WebGL/WebGLContextAttributes.cpp | ||||||
|     WebGL/WebGLContextEvent.cpp |     WebGL/WebGLContextEvent.cpp | ||||||
|     WebGL/WebGLRenderingContext.cpp |     WebGL/WebGLRenderingContext.cpp | ||||||
|  |  | ||||||
|  | @ -5,9 +5,9 @@ | ||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| #include <AK/JsonObject.h> | #include <AK/JsonObject.h> | ||||||
| #include <WebDriver/TimeoutsConfiguration.h> | #include <LibWeb/WebDriver/TimeoutsConfiguration.h> | ||||||
| 
 | 
 | ||||||
| namespace WebDriver { | namespace Web::WebDriver { | ||||||
| 
 | 
 | ||||||
| // https://w3c.github.io/webdriver/#dfn-timeouts-object
 | // https://w3c.github.io/webdriver/#dfn-timeouts-object
 | ||||||
| JsonObject timeouts_object(TimeoutsConfiguration const& timeouts) | JsonObject timeouts_object(TimeoutsConfiguration const& timeouts) | ||||||
|  | @ -34,7 +34,7 @@ JsonObject timeouts_object(TimeoutsConfiguration const& timeouts) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // https://w3c.github.io/webdriver/#ref-for-dfn-json-deserialize-3
 | // https://w3c.github.io/webdriver/#ref-for-dfn-json-deserialize-3
 | ||||||
| ErrorOr<TimeoutsConfiguration, Web::WebDriver::Error> json_deserialize_as_a_timeouts_configuration(JsonValue const& value) | ErrorOr<TimeoutsConfiguration, Error> json_deserialize_as_a_timeouts_configuration(JsonValue const& value) | ||||||
| { | { | ||||||
|     constexpr i64 max_safe_integer = 9007199254740991; |     constexpr i64 max_safe_integer = 9007199254740991; | ||||||
| 
 | 
 | ||||||
|  | @ -43,7 +43,7 @@ ErrorOr<TimeoutsConfiguration, Web::WebDriver::Error> json_deserialize_as_a_time | ||||||
| 
 | 
 | ||||||
|     // 2. If value is not a JSON Object, return error with error code invalid argument.
 |     // 2. If value is not a JSON Object, return error with error code invalid argument.
 | ||||||
|     if (!value.is_object()) |     if (!value.is_object()) | ||||||
|         return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "Payload is not a JSON object"); |         return Error::from_code(ErrorCode::InvalidArgument, "Payload is not a JSON object"); | ||||||
| 
 | 
 | ||||||
|     // 3. If value has a property with the key "script":
 |     // 3. If value has a property with the key "script":
 | ||||||
|     if (value.as_object().has("script"sv)) { |     if (value.as_object().has("script"sv)) { | ||||||
|  | @ -52,7 +52,7 @@ ErrorOr<TimeoutsConfiguration, Web::WebDriver::Error> json_deserialize_as_a_time | ||||||
| 
 | 
 | ||||||
|         // 2. If script duration is a number and less than 0 or greater than maximum safe integer, or it is not null, return error with error code invalid argument.
 |         // 2. If script duration is a number and less than 0 or greater than maximum safe integer, or it is not null, return error with error code invalid argument.
 | ||||||
|         if ((script_duration.is_number() && (script_duration.to_i64() < 0 || script_duration.to_i64() > max_safe_integer)) || !script_duration.is_null()) |         if ((script_duration.is_number() && (script_duration.to_i64() < 0 || script_duration.to_i64() > max_safe_integer)) || !script_duration.is_null()) | ||||||
|             return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "Invalid script duration"); |             return Error::from_code(ErrorCode::InvalidArgument, "Invalid script duration"); | ||||||
| 
 | 
 | ||||||
|         // 3. Set timeouts’s script timeout to script duration.
 |         // 3. Set timeouts’s script timeout to script duration.
 | ||||||
|         timeouts.script_timeout = script_duration.is_null() ? Optional<u64> {} : script_duration.to_u64(); |         timeouts.script_timeout = script_duration.is_null() ? Optional<u64> {} : script_duration.to_u64(); | ||||||
|  | @ -65,7 +65,7 @@ ErrorOr<TimeoutsConfiguration, Web::WebDriver::Error> json_deserialize_as_a_time | ||||||
| 
 | 
 | ||||||
|         // 2. If page load duration is less than 0 or greater than maximum safe integer, return error with error code invalid argument.
 |         // 2. If page load duration is less than 0 or greater than maximum safe integer, return error with error code invalid argument.
 | ||||||
|         if (!page_load_duration.is_number() || page_load_duration.to_i64() < 0 || page_load_duration.to_i64() > max_safe_integer) |         if (!page_load_duration.is_number() || page_load_duration.to_i64() < 0 || page_load_duration.to_i64() > max_safe_integer) | ||||||
|             return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "Invalid page load duration"); |             return Error::from_code(ErrorCode::InvalidArgument, "Invalid page load duration"); | ||||||
| 
 | 
 | ||||||
|         // 3. Set timeouts’s page load timeout to page load duration.
 |         // 3. Set timeouts’s page load timeout to page load duration.
 | ||||||
|         timeouts.page_load_timeout = page_load_duration.to_u64(); |         timeouts.page_load_timeout = page_load_duration.to_u64(); | ||||||
|  | @ -78,7 +78,7 @@ ErrorOr<TimeoutsConfiguration, Web::WebDriver::Error> json_deserialize_as_a_time | ||||||
| 
 | 
 | ||||||
|         // 2. If implicit duration is less than 0 or greater than maximum safe integer, return error with error code invalid argument.
 |         // 2. If implicit duration is less than 0 or greater than maximum safe integer, return error with error code invalid argument.
 | ||||||
|         if (!implicit_duration.is_number() || implicit_duration.to_i64() < 0 || implicit_duration.to_i64() > max_safe_integer) |         if (!implicit_duration.is_number() || implicit_duration.to_i64() < 0 || implicit_duration.to_i64() > max_safe_integer) | ||||||
|             return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "Invalid implicit duration"); |             return Error::from_code(ErrorCode::InvalidArgument, "Invalid implicit duration"); | ||||||
| 
 | 
 | ||||||
|         // 3. Set timeouts’s implicit wait timeout to implicit duration.
 |         // 3. Set timeouts’s implicit wait timeout to implicit duration.
 | ||||||
|         timeouts.implicit_wait_timeout = implicit_duration.to_u64(); |         timeouts.implicit_wait_timeout = implicit_duration.to_u64(); | ||||||
|  | @ -10,7 +10,7 @@ | ||||||
| #include <AK/Optional.h> | #include <AK/Optional.h> | ||||||
| #include <LibWeb/WebDriver/Error.h> | #include <LibWeb/WebDriver/Error.h> | ||||||
| 
 | 
 | ||||||
| namespace WebDriver { | namespace Web::WebDriver { | ||||||
| 
 | 
 | ||||||
| // https://w3c.github.io/webdriver/#dfn-timeouts-configuration
 | // https://w3c.github.io/webdriver/#dfn-timeouts-configuration
 | ||||||
| struct TimeoutsConfiguration { | struct TimeoutsConfiguration { | ||||||
|  | @ -20,6 +20,6 @@ struct TimeoutsConfiguration { | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| JsonObject timeouts_object(TimeoutsConfiguration const&); | JsonObject timeouts_object(TimeoutsConfiguration const&); | ||||||
| ErrorOr<TimeoutsConfiguration, Web::WebDriver::Error> json_deserialize_as_a_timeouts_configuration(JsonValue const&); | ErrorOr<TimeoutsConfiguration, Error> json_deserialize_as_a_timeouts_configuration(JsonValue const&); | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
|  | @ -7,7 +7,6 @@ serenity_component( | ||||||
| set(SOURCES | set(SOURCES | ||||||
|     Client.cpp |     Client.cpp | ||||||
|     Session.cpp |     Session.cpp | ||||||
|     TimeoutsConfiguration.cpp |  | ||||||
|     WebContentConnection.cpp |     WebContentConnection.cpp | ||||||
|     main.cpp |     main.cpp | ||||||
| ) | ) | ||||||
|  |  | ||||||
|  | @ -16,9 +16,9 @@ | ||||||
| #include <LibCore/MemoryStream.h> | #include <LibCore/MemoryStream.h> | ||||||
| #include <LibHTTP/HttpRequest.h> | #include <LibHTTP/HttpRequest.h> | ||||||
| #include <LibHTTP/HttpResponse.h> | #include <LibHTTP/HttpResponse.h> | ||||||
|  | #include <LibWeb/WebDriver/TimeoutsConfiguration.h> | ||||||
| #include <WebDriver/Client.h> | #include <WebDriver/Client.h> | ||||||
| #include <WebDriver/Session.h> | #include <WebDriver/Session.h> | ||||||
| #include <WebDriver/TimeoutsConfiguration.h> |  | ||||||
| 
 | 
 | ||||||
| namespace WebDriver { | namespace WebDriver { | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -135,7 +135,7 @@ Web::WebDriver::Response Session::stop() | ||||||
| JsonObject Session::get_timeouts() | JsonObject Session::get_timeouts() | ||||||
| { | { | ||||||
|     // 1. Let timeouts be the timeouts object for session’s timeouts configuration
 |     // 1. Let timeouts be the timeouts object for session’s timeouts configuration
 | ||||||
|     auto timeouts = timeouts_object(m_timeouts_configuration); |     auto timeouts = Web::WebDriver::timeouts_object(m_timeouts_configuration); | ||||||
| 
 | 
 | ||||||
|     // 2. Return success with data timeouts.
 |     // 2. Return success with data timeouts.
 | ||||||
|     return timeouts; |     return timeouts; | ||||||
|  | @ -145,7 +145,7 @@ JsonObject Session::get_timeouts() | ||||||
| Web::WebDriver::Response Session::set_timeouts(JsonValue const& payload) | Web::WebDriver::Response Session::set_timeouts(JsonValue const& payload) | ||||||
| { | { | ||||||
|     // 1. Let timeouts be the result of trying to JSON deserialize as a timeouts configuration the request’s parameters.
 |     // 1. Let timeouts be the result of trying to JSON deserialize as a timeouts configuration the request’s parameters.
 | ||||||
|     auto timeouts = TRY(json_deserialize_as_a_timeouts_configuration(payload)); |     auto timeouts = TRY(Web::WebDriver::json_deserialize_as_a_timeouts_configuration(payload)); | ||||||
| 
 | 
 | ||||||
|     // 2. Make the session timeouts the new timeouts.
 |     // 2. Make the session timeouts the new timeouts.
 | ||||||
|     m_timeouts_configuration = move(timeouts); |     m_timeouts_configuration = move(timeouts); | ||||||
|  |  | ||||||
|  | @ -14,7 +14,7 @@ | ||||||
| #include <LibCore/Promise.h> | #include <LibCore/Promise.h> | ||||||
| #include <LibWeb/WebDriver/Error.h> | #include <LibWeb/WebDriver/Error.h> | ||||||
| #include <LibWeb/WebDriver/Response.h> | #include <LibWeb/WebDriver/Response.h> | ||||||
| #include <WebDriver/TimeoutsConfiguration.h> | #include <LibWeb/WebDriver/TimeoutsConfiguration.h> | ||||||
| #include <WebDriver/WebContentConnection.h> | #include <WebDriver/WebContentConnection.h> | ||||||
| #include <unistd.h> | #include <unistd.h> | ||||||
| 
 | 
 | ||||||
|  | @ -68,7 +68,7 @@ private: | ||||||
|     Optional<pid_t> m_browser_pid; |     Optional<pid_t> m_browser_pid; | ||||||
| 
 | 
 | ||||||
|     // https://w3c.github.io/webdriver/#dfn-session-script-timeout
 |     // https://w3c.github.io/webdriver/#dfn-session-script-timeout
 | ||||||
|     TimeoutsConfiguration m_timeouts_configuration; |     Web::WebDriver::TimeoutsConfiguration m_timeouts_configuration; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Timothy Flynn
						Timothy Flynn