Skip to content

Commit 5b298d1

Browse files
AtkinsSJmikiubo
authored andcommitted
LibWeb/WebDriver: Extract "wait for an action queue token" algorithm
This reflects part of w3c/webdriver#1853
1 parent d879771 commit 5b298d1

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

Libraries/LibWeb/WebDriver/Actions.cpp

+14-8
Original file line numberDiff line numberDiff line change
@@ -1346,8 +1346,8 @@ class ActionExecutor final : public JS::Cell {
13461346

13471347
GC_DEFINE_ALLOCATOR(ActionExecutor);
13481348

1349-
// https://w3c.github.io/webdriver/#dfn-dispatch-actions
1350-
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)
1349+
// https://w3c.github.io/webdriver/#dfn-wait-for-an-action-queue-token
1350+
void wait_for_an_action_queue_token(InputState& input_state)
13511351
{
13521352
// 1. Let token be a new unique identifier.
13531353
auto token = MUST(Crypto::generate_random_uuid());
@@ -1359,19 +1359,25 @@ GC::Ref<JS::Cell> dispatch_actions(InputState& input_state, Vector<Vector<Action
13591359
// FIXME: We should probably do this, but our WebDriver currently blocks until a given action is complete anyways,
13601360
// so we should never arrive here with an ongoing action (which we verify for now).
13611361
VERIFY(input_state.actions_queue.size() == 1);
1362+
}
1363+
1364+
// https://w3c.github.io/webdriver/#dfn-dispatch-actions
1365+
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)
1366+
{
1367+
// 1. Wait for an action queue token with input state.
1368+
wait_for_an_action_queue_token(input_state);
13621369

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

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

1371-
// 6. Assert: this returns token
1372-
VERIFY(executed_token == token);
1373-
1374-
// 7. Return actions result.
1380+
// 4. Return actions result.
13751381
return action_executor;
13761382
}
13771383

Libraries/LibWeb/WebDriver/Actions.h

+1
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ using OnActionsComplete = GC::Ref<GC::Function<void(Web::WebDriver::Response)>>;
128128

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

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

0 commit comments

Comments
 (0)