mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 15:12:45 +00:00 
			
		
		
		
	WebDriver: Make functions always match their spec command name
This is easier to grasp than sometimes naming it after the HTTP method, and sometimes not.
This commit is contained in:
		
							parent
							
								
									47f25d4008
								
							
						
					
					
						commit
						dd4e5d5028
					
				
					 4 changed files with 24 additions and 24 deletions
				
			
		|  | @ -21,17 +21,17 @@ namespace WebDriver { | |||
| Atomic<unsigned> Client::s_next_session_id; | ||||
| NonnullOwnPtrVector<Session> Client::s_sessions; | ||||
| Vector<Client::Route> Client::s_routes = { | ||||
|     { HTTP::HttpRequest::Method::POST, { "session" }, &Client::handle_post_session }, | ||||
|     { HTTP::HttpRequest::Method::POST, { "session" }, &Client::handle_new_session }, | ||||
|     { HTTP::HttpRequest::Method::DELETE, { "session", ":session_id" }, &Client::handle_delete_session }, | ||||
|     { HTTP::HttpRequest::Method::GET, { "status" }, &Client::handle_get_status }, | ||||
|     { HTTP::HttpRequest::Method::POST, { "session", ":session_id", "url" }, &Client::handle_post_url }, | ||||
|     { HTTP::HttpRequest::Method::GET, { "session", ":session_id", "url" }, &Client::handle_get_url }, | ||||
|     { HTTP::HttpRequest::Method::POST, { "session", ":session_id", "url" }, &Client::handle_navigate_to }, | ||||
|     { HTTP::HttpRequest::Method::GET, { "session", ":session_id", "url" }, &Client::handle_get_current_url }, | ||||
|     { HTTP::HttpRequest::Method::POST, { "session", ":session_id", "back" }, &Client::handle_back }, | ||||
|     { HTTP::HttpRequest::Method::POST, { "session", ":session_id", "forward" }, &Client::handle_forward }, | ||||
|     { HTTP::HttpRequest::Method::POST, { "session", ":session_id", "refresh" }, &Client::handle_refresh }, | ||||
|     { HTTP::HttpRequest::Method::GET, { "session", ":session_id", "title" }, &Client::handle_get_title }, | ||||
|     { HTTP::HttpRequest::Method::GET, { "session", ":session_id", "window" }, &Client::handle_get_window_handle }, | ||||
|     { HTTP::HttpRequest::Method::DELETE, { "session", ":session_id", "window" }, &Client::handle_delete_window }, | ||||
|     { HTTP::HttpRequest::Method::DELETE, { "session", ":session_id", "window" }, &Client::handle_close_window }, | ||||
|     { HTTP::HttpRequest::Method::POST, { "session", ":session_id", "element" }, &Client::handle_find_element }, | ||||
|     { HTTP::HttpRequest::Method::GET, { "session", ":session_id", "cookie" }, &Client::handle_get_all_cookies }, | ||||
|     { HTTP::HttpRequest::Method::GET, { "session", ":session_id", "cookie", ":name" }, &Client::handle_get_named_cookie }, | ||||
|  | @ -320,7 +320,7 @@ JsonValue Client::make_json_value(JsonValue const& value) | |||
| 
 | ||||
| // 8.1 New Session, https://w3c.github.io/webdriver/#dfn-new-sessions
 | ||||
| // POST /session
 | ||||
| ErrorOr<JsonValue, HttpError> Client::handle_post_session(Vector<StringView> const&, JsonValue const&) | ||||
| ErrorOr<JsonValue, HttpError> Client::handle_new_session(Vector<StringView> const&, JsonValue const&) | ||||
| { | ||||
|     dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session"); | ||||
| 
 | ||||
|  | @ -422,25 +422,25 @@ ErrorOr<JsonValue, HttpError> Client::handle_get_status(Vector<StringView> const | |||
| 
 | ||||
| // 10.1 Navigate To, https://w3c.github.io/webdriver/#dfn-navigate-to
 | ||||
| // POST /session/{session id}/url
 | ||||
| ErrorOr<JsonValue, HttpError> Client::handle_post_url(Vector<StringView> const& parameters, JsonValue const& payload) | ||||
| ErrorOr<JsonValue, HttpError> Client::handle_navigate_to(Vector<StringView> const& parameters, JsonValue const& payload) | ||||
| { | ||||
|     dbgln_if(WEBDRIVER_DEBUG, "Handling POST /session/<session_id>/url"); | ||||
|     auto* session = TRY(find_session_with_id(parameters[0])); | ||||
| 
 | ||||
|     // NOTE: Spec steps handled in Session::post_url().
 | ||||
|     auto result = TRY(session->post_url(payload)); | ||||
|     // NOTE: Spec steps handled in Session::navigate_to().
 | ||||
|     auto result = TRY(session->navigate_to(payload)); | ||||
|     return make_json_value(result); | ||||
| } | ||||
| 
 | ||||
| // 10.2 Get Current URL, https://w3c.github.io/webdriver/#dfn-get-current-url
 | ||||
| // GET /session/{session id}/url
 | ||||
| ErrorOr<JsonValue, HttpError> Client::handle_get_url(Vector<StringView> const& parameters, JsonValue const&) | ||||
| ErrorOr<JsonValue, HttpError> Client::handle_get_current_url(Vector<StringView> const& parameters, JsonValue const&) | ||||
| { | ||||
|     dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session/<session_id>/url"); | ||||
|     auto* session = TRY(find_session_with_id(parameters[0])); | ||||
| 
 | ||||
|     // NOTE: Spec steps handled in Session::get_url().
 | ||||
|     auto result = TRY(session->get_url()); | ||||
|     // NOTE: Spec steps handled in Session::get_current_url().
 | ||||
|     auto result = TRY(session->get_current_url()); | ||||
|     return make_json_value(result); | ||||
| } | ||||
| 
 | ||||
|  | @ -511,13 +511,13 @@ ErrorOr<JsonValue, HttpError> Client::handle_get_window_handle(Vector<StringView | |||
| 
 | ||||
| // 11.2 Close Window, https://w3c.github.io/webdriver/#dfn-close-window
 | ||||
| // DELETE /session/{session id}/window
 | ||||
| ErrorOr<JsonValue, HttpError> Client::handle_delete_window(Vector<StringView> const& parameters, JsonValue const&) | ||||
| ErrorOr<JsonValue, HttpError> Client::handle_close_window(Vector<StringView> const& parameters, JsonValue const&) | ||||
| { | ||||
|     dbgln_if(WEBDRIVER_DEBUG, "Handling DELETE /session/<session_id>/window"); | ||||
|     auto* session = TRY(find_session_with_id(parameters[0])); | ||||
| 
 | ||||
|     // NOTE: Spec steps handled in Session::delete_window().
 | ||||
|     TRY(unwrap_result(session->delete_window())); | ||||
|     // NOTE: Spec steps handled in Session::close_window().
 | ||||
|     TRY(unwrap_result(session->close_window())); | ||||
| 
 | ||||
|     return make_json_value(JsonValue()); | ||||
| } | ||||
|  |  | |||
|  | @ -46,17 +46,17 @@ private: | |||
|     }; | ||||
| 
 | ||||
|     ErrorOr<RoutingResult, HttpError> match_route(HTTP::HttpRequest::Method method, String const& resource); | ||||
|     ErrorOr<JsonValue, HttpError> handle_post_session(Vector<StringView> const&, JsonValue const& payload); | ||||
|     ErrorOr<JsonValue, HttpError> handle_new_session(Vector<StringView> const&, JsonValue const& payload); | ||||
|     ErrorOr<JsonValue, HttpError> handle_delete_session(Vector<StringView> const&, JsonValue const& payload); | ||||
|     ErrorOr<JsonValue, HttpError> handle_get_status(Vector<StringView> const&, JsonValue const& payload); | ||||
|     ErrorOr<JsonValue, HttpError> handle_post_url(Vector<StringView> const&, JsonValue const& payload); | ||||
|     ErrorOr<JsonValue, HttpError> handle_get_url(Vector<StringView> const&, JsonValue const& payload); | ||||
|     ErrorOr<JsonValue, HttpError> handle_navigate_to(Vector<StringView> const&, JsonValue const& payload); | ||||
|     ErrorOr<JsonValue, HttpError> handle_get_current_url(Vector<StringView> const&, JsonValue const& payload); | ||||
|     ErrorOr<JsonValue, HttpError> handle_back(Vector<StringView> const&, JsonValue const& payload); | ||||
|     ErrorOr<JsonValue, HttpError> handle_forward(Vector<StringView> const&, JsonValue const& payload); | ||||
|     ErrorOr<JsonValue, HttpError> handle_refresh(Vector<StringView> const&, JsonValue const& payload); | ||||
|     ErrorOr<JsonValue, HttpError> handle_get_title(Vector<StringView> const&, JsonValue const& payload); | ||||
|     ErrorOr<JsonValue, HttpError> handle_get_window_handle(Vector<StringView> const&, JsonValue const& payload); | ||||
|     ErrorOr<JsonValue, HttpError> handle_delete_window(Vector<StringView> const&, JsonValue const& payload); | ||||
|     ErrorOr<JsonValue, HttpError> handle_close_window(Vector<StringView> const&, JsonValue const& payload); | ||||
|     ErrorOr<JsonValue, HttpError> handle_find_element(Vector<StringView> const&, JsonValue const& payload); | ||||
|     ErrorOr<JsonValue, HttpError> handle_get_all_cookies(Vector<StringView> const&, JsonValue const& payload); | ||||
|     ErrorOr<JsonValue, HttpError> handle_get_named_cookie(Vector<StringView> const&, JsonValue const& payload); | ||||
|  |  | |||
|  | @ -73,7 +73,7 @@ ErrorOr<void> Session::stop() | |||
| } | ||||
| 
 | ||||
| // 10.1 Navigate To, https://w3c.github.io/webdriver/#dfn-navigate-to
 | ||||
| ErrorOr<JsonValue, HttpError> Session::post_url(JsonValue const& payload) | ||||
| ErrorOr<JsonValue, HttpError> Session::navigate_to(JsonValue const& payload) | ||||
| { | ||||
|     // 1. If the current top-level browsing context is no longer open, return error with error code no such window.
 | ||||
|     auto current_window = get_window_object(); | ||||
|  | @ -109,7 +109,7 @@ ErrorOr<JsonValue, HttpError> Session::post_url(JsonValue const& payload) | |||
| } | ||||
| 
 | ||||
| // 10.2 Get Current URL, https://w3c.github.io/webdriver/#dfn-get-current-url
 | ||||
| ErrorOr<JsonValue, HttpError> Session::get_url() | ||||
| ErrorOr<JsonValue, HttpError> Session::get_current_url() | ||||
| { | ||||
|     // 1. If the current top-level browsing context is no longer open, return error with error code no such window.
 | ||||
|     auto current_window = get_window_object(); | ||||
|  | @ -212,7 +212,7 @@ ErrorOr<JsonValue, HttpError> Session::get_title() | |||
| } | ||||
| 
 | ||||
| // 11.2 Close Window, https://w3c.github.io/webdriver/#dfn-close-window
 | ||||
| ErrorOr<void, Variant<HttpError, Error>> Session::delete_window() | ||||
| ErrorOr<void, Variant<HttpError, Error>> Session::close_window() | ||||
| { | ||||
|     // 1. If the current top-level browsing context is no longer open, return error with error code no such window.
 | ||||
|     auto current_window = get_window_object(); | ||||
|  |  | |||
|  | @ -37,14 +37,14 @@ public: | |||
| 
 | ||||
|     ErrorOr<void> start(); | ||||
|     ErrorOr<void> stop(); | ||||
|     ErrorOr<JsonValue, HttpError> post_url(JsonValue const& url); | ||||
|     ErrorOr<JsonValue, HttpError> get_url(); | ||||
|     ErrorOr<JsonValue, HttpError> navigate_to(JsonValue const& url); | ||||
|     ErrorOr<JsonValue, HttpError> get_current_url(); | ||||
|     ErrorOr<JsonValue, HttpError> back(); | ||||
|     ErrorOr<JsonValue, HttpError> forward(); | ||||
|     ErrorOr<JsonValue, HttpError> refresh(); | ||||
|     ErrorOr<JsonValue, HttpError> get_title(); | ||||
|     ErrorOr<JsonValue, HttpError> find_element(JsonValue const& payload); | ||||
|     ErrorOr<void, Variant<HttpError, Error>> delete_window(); | ||||
|     ErrorOr<void, Variant<HttpError, Error>> close_window(); | ||||
|     ErrorOr<JsonValue, HttpError> get_all_cookies(); | ||||
|     ErrorOr<JsonValue, HttpError> get_named_cookie(String const& name); | ||||
|     ErrorOr<JsonValue, HttpError> add_cookie(JsonValue const& payload); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Linus Groh
						Linus Groh