Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add input sources in GetOrCreateInputSource #44

Merged
merged 1 commit into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions src/FlaUI.WebDriver/Controllers/ActionsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,7 @@ private static List<List<Action>> ExtractActionSequence(Session session, Actions
// TODO: Implement other input source types.
if (actionSequence.Type == "key")
{
var source = session.InputState.GetOrCreateInputSource(actionSequence.Type, actionSequence.Id);

// The spec says that input sources must be created for actions and they are later expected to be
// found in the input source map, but doesn't specify what should add them. Guessing that it should
// be done here. https://github.com/w3c/webdriver/issues/1810
session.InputState.AddInputSource(actionSequence.Id, source);
session.InputState.GetOrCreateInputSource(actionSequence.Type, actionSequence.Id);
}

for (var tickIndex = 0; tickIndex < actionSequence.Actions.Count; tickIndex++)
Expand Down
14 changes: 12 additions & 2 deletions src/FlaUI.WebDriver/InputState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ public InputSource CreateInputSource(string type)
/// </summary>
/// <remarks>
/// Implements "get or create an input source" from https://www.w3.org/TR/webdriver2/#input-state
/// Note: The spec does not specify that a created input source should be added to the input state map.
/// Note: The spec does not specify that a created input source should be added to the input state map
/// but this implementation does.
/// </remarks>
public InputSource GetOrCreateInputSource(string type, string id)
{
Expand All @@ -86,7 +87,16 @@ public InputSource GetOrCreateInputSource(string type, string id)
$"Input source with id '{id}' already exists and has a different type: {source.Type}");
}

return CreateInputSource(type);
// Note: The spec does not specify that a created input source should be added to the input state map,
// however it needs to be added somewhere. The caller can't do it because it doesn't know if the source
// was created or already existed. See https://github.com/w3c/webdriver/issues/1810
if (source == null)
{
source = CreateInputSource(type);
AddInputSource(id, source);
}

return source;
}

/// <summary>
Expand Down
Loading