Skip to content

Commit

Permalink
LibWeb/WebDriver: Extract "wait for an action queue token" algorithm
Browse files Browse the repository at this point in the history
This reflects part of w3c/webdriver#1853
  • Loading branch information
AtkinsSJ authored and pbrw committed Jan 14, 2025
1 parent adb7226 commit 679773a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
22 changes: 14 additions & 8 deletions Libraries/LibWeb/WebDriver/Actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1346,8 +1346,8 @@ class ActionExecutor final : public JS::Cell {

GC_DEFINE_ALLOCATOR(ActionExecutor);

// https://w3c.github.io/webdriver/#dfn-dispatch-actions
GC::Ref<JS::Cell> dispatch_actions(InputState& input_state, Vector<Vector<ActionObject>> actions_by_tick, HTML::BrowsingContext& browsing_context, ActionsOptions actions_options, OnActionsComplete on_complete)
// https://w3c.github.io/webdriver/#dfn-wait-for-an-action-queue-token
void wait_for_an_action_queue_token(InputState& input_state)
{
// 1. Let token be a new unique identifier.
auto token = MUST(Crypto::generate_random_uuid());
Expand All @@ -1359,19 +1359,25 @@ GC::Ref<JS::Cell> dispatch_actions(InputState& input_state, Vector<Vector<Action
// FIXME: We should probably do this, but our WebDriver currently blocks until a given action is complete anyways,
// so we should never arrive here with an ongoing action (which we verify for now).
VERIFY(input_state.actions_queue.size() == 1);
}

// https://w3c.github.io/webdriver/#dfn-dispatch-actions
GC::Ref<JS::Cell> dispatch_actions(InputState& input_state, Vector<Vector<ActionObject>> actions_by_tick, HTML::BrowsingContext& browsing_context, ActionsOptions actions_options, OnActionsComplete on_complete)
{
// 1. Wait for an action queue token with input state.
wait_for_an_action_queue_token(input_state);

// 4. Let actions result be the result of dispatch actions inner with input state, actions by tick, browsing
// 2. Let actions result be the result of dispatch actions inner with input state, actions by tick, browsing
// context, and actions options.
auto action_executor = browsing_context.heap().allocate<ActionExecutor>(input_state, move(actions_by_tick), browsing_context, move(actions_options), on_complete);
action_executor->process_next_tick();

// 5. Dequeue input state's actions queue.
// 3. Dequeue input state's actions queue.
// Assert: this returns token
// NOTE: We can't assert because `token` isn't defined here, it exists in `wait_for_an_action_queue_token()` instead.
auto executed_token = input_state.actions_queue.take_first();

// 6. Assert: this returns token
VERIFY(executed_token == token);

// 7. Return actions result.
// 4. Return actions result.
return action_executor;
}

Expand Down
1 change: 1 addition & 0 deletions Libraries/LibWeb/WebDriver/Actions.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ using OnActionsComplete = GC::Ref<GC::Function<void(Web::WebDriver::Response)>>;

ErrorOr<Vector<Vector<ActionObject>>, WebDriver::Error> extract_an_action_sequence(InputState&, JsonValue const&, ActionsOptions const&);

void wait_for_an_action_queue_token(InputState&);
GC::Ref<JS::Cell> dispatch_actions(InputState&, Vector<Vector<ActionObject>>, HTML::BrowsingContext&, ActionsOptions, OnActionsComplete);
ErrorOr<void, WebDriver::Error> dispatch_tick_actions(InputState&, ReadonlySpan<ActionObject>, AK::Duration, HTML::BrowsingContext&, ActionsOptions const&);
GC::Ref<JS::Cell> dispatch_list_of_actions(InputState&, Vector<ActionObject>, HTML::BrowsingContext&, ActionsOptions, OnActionsComplete);
Expand Down

0 comments on commit 679773a

Please sign in to comment.