Skip to content

Commit

Permalink
Remove redundant context form bidi actions
Browse files Browse the repository at this point in the history
  • Loading branch information
sadym-chromium committed Apr 16, 2024
1 parent 5b3cd8c commit 8b261c9
Showing 1 changed file with 59 additions and 40 deletions.
99 changes: 59 additions & 40 deletions tools/wptrunner/wptrunner/testdriver-extra.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,23 +132,23 @@
return selector;
};

/**
* Create an action and return a promise that resolves when the action is complete.
* @param name: The name of the action to create.
* @param props: The properties to pass to the action.
* @return {Promise<any>}: A promise that resolves with the action result when the action is complete.
*/
const create_action = function(name, props) {
let cmd_id;
const action_msg = {type: "action",
action: name,
...props};
if (action_msg.context) {
action_msg.context = get_window_id(action_msg.context);
}
if (is_test_context()) {
cmd_id = window.__wptrunner_message_queue.push(action_msg);
} else {
if (testharness_context === null) {
throw new Error("Tried to run in a non-testharness window without a call to set_test_context");
}
if (action_msg.context === null) {
action_msg.context = get_window_id(window);
}
cmd_id = ctx_cmd_id++;
action_msg.cmd_id = cmd_id;
window.test_driver.message_test({type: "testdriver-command",
Expand All @@ -167,6 +167,25 @@
return pending_promise;
};

/**
* Create an action in a specific context and return a promise that resolves when the action is complete. This is
* required for WebDriver Classic actions, as they require a specific context.
* @param name: The name of the action to create.
* @param context: The context in which to run the action. `null` for the current window.
* @param props: The properties to pass to the action.
* @return {Promise<any>}: A promise that resolves with the action result when the action is complete.
*/
const create_context_action = function (name, context, props) {
const context_props = {...props};
if (context) {
context_props.context = get_window_id(context_props.context);
}
if (context === null && !is_test_context()) {
context_props.context = get_window_id(window);
}
return create_action(name, context_props);
};

const subscribe = function (props) {
return create_action("bidi.session.subscribe", {
// Default to subscribing to the window's events.
Expand Down Expand Up @@ -202,49 +221,49 @@
window.test_driver_internal.click = function(element) {
const selector = get_selector(element);
const context = get_context(element);
return create_action("click", {selector, context});
return create_context_action("click", context, {selector});
};

window.test_driver_internal.delete_all_cookies = function(context=null) {
return create_action("delete_all_cookies", {context});
return create_context_action("delete_all_cookies", context, {});
};

window.test_driver_internal.get_all_cookies = function(context=null) {
return create_action("get_all_cookies", {context});
return create_context_action("get_all_cookies", context, {});
};

window.test_driver_internal.get_computed_label = function(element) {
const selector = get_selector(element);
const context = get_context(element);
return create_action("get_computed_label", {selector, context});
return create_context_action("get_computed_label", context, {selector});
};

window.test_driver_internal.get_computed_role = function(element) {
const selector = get_selector(element);
const context = get_context(element);
return create_action("get_computed_role", {selector, context});
return create_context_action("get_computed_role", context, {selector});
};

window.test_driver_internal.get_named_cookie = function(name, context=null) {
return create_action("get_named_cookie", {name, context});
return create_context_action("get_named_cookie", context, {name});
};

window.test_driver_internal.minimize_window = function(context=null) {
return create_action("minimize_window", {context});
return create_context_action("minimize_window", context, {});
};

window.test_driver_internal.set_window_rect = function(rect, context=null) {
return create_action("set_window_rect", {rect, context});
return create_context_action("set_window_rect", context, {rect});
};

window.test_driver_internal.get_window_rect = function(context=null) {
return create_action("get_window_rect", {context});
return create_context_action("get_window_rect", context, {});
};

window.test_driver_internal.send_keys = function(element, keys) {
const selector = get_selector(element);
const context = get_context(element);
return create_action("send_keys", {selector, keys, context});
return create_context_action("send_keys", context, {selector, keys});
};

window.test_driver_internal.action_sequence = function(actions, context=null) {
Expand All @@ -263,98 +282,98 @@
}
}
}
return create_action("action_sequence", {actions, context});
return create_context_action("action_sequence", context, {actions});
};

window.test_driver_internal.generate_test_report = function(message, context=null) {
return create_action("generate_test_report", {message, context});
return create_context_action("generate_test_report", context, {message});
};

window.test_driver_internal.set_permission = function(permission_params, context=null) {
return create_action("set_permission", {permission_params, context});
return create_context_action("set_permission", context, {permission_params});
};

window.test_driver_internal.add_virtual_authenticator = function(config, context=null) {
return create_action("add_virtual_authenticator", {config, context});
return create_context_action("add_virtual_authenticator", context, {config});
};

window.test_driver_internal.remove_virtual_authenticator = function(authenticator_id, context=null) {
return create_action("remove_virtual_authenticator", {authenticator_id, context});
return create_context_action("remove_virtual_authenticator", context, {authenticator_id});
};

window.test_driver_internal.add_credential = function(authenticator_id, credential, context=null) {
return create_action("add_credential", {authenticator_id, credential, context});
return create_context_action("add_credential", context, {authenticator_id, credential});
};

window.test_driver_internal.get_credentials = function(authenticator_id, context=null) {
return create_action("get_credentials", {authenticator_id, context});
return create_context_action("get_credentials", context, {authenticator_id});
};

window.test_driver_internal.remove_credential = function(authenticator_id, credential_id, context=null) {
return create_action("remove_credential", {authenticator_id, credential_id, context});
return create_context_action("remove_credential", context, {authenticator_id, credential_id});
};

window.test_driver_internal.remove_all_credentials = function(authenticator_id, context=null) {
return create_action("remove_all_credentials", {authenticator_id, context});
return create_context_action("remove_all_credentials", context, {authenticator_id});
};

window.test_driver_internal.set_user_verified = function(authenticator_id, uv, context=null) {
return create_action("set_user_verified", {authenticator_id, uv, context});
return create_context_action("set_user_verified", context, {authenticator_id, uv});
};

window.test_driver_internal.set_spc_transaction_mode = function(mode, context = null) {
return create_action("set_spc_transaction_mode", {mode, context});
return create_context_action("set_spc_transaction_mode", context, {mode});
};

window.test_driver_internal.set_rph_registration_mode = function(mode, context = null) {
return create_action("set_rph_registration_mode", {mode, context});
return create_context_action("set_rph_registration_mode", context, {mode});
};

window.test_driver_internal.cancel_fedcm_dialog = function(context = null) {
return create_action("cancel_fedcm_dialog", {context});
return create_context_action("cancel_fedcm_dialog", context, {});
};

window.test_driver_internal.click_fedcm_dialog_button = function(dialog_button, context = null) {
return create_action("click_fedcm_dialog_button", {dialog_button, context});
return create_context_action("click_fedcm_dialog_button", context, {dialog_button});
};

window.test_driver_internal.select_fedcm_account = function(account_index, context = null) {
return create_action("select_fedcm_account", {account_index, context});
return create_context_action("select_fedcm_account", context, {account_index});
};

window.test_driver_internal.get_fedcm_account_list = function(context = null) {
return create_action("get_fedcm_account_list", {context});
return create_context_action("get_fedcm_account_list", context, {});
};

window.test_driver_internal.get_fedcm_dialog_title = function(context = null) {
return create_action("get_fedcm_dialog_title", {context});
return create_context_action("get_fedcm_dialog_title", context, {});
};

window.test_driver_internal.get_fedcm_dialog_type = function(context = null) {
return create_action("get_fedcm_dialog_type", {context});
return create_context_action("get_fedcm_dialog_type", context, {});
};

window.test_driver_internal.set_fedcm_delay_enabled = function(enabled, context = null) {
return create_action("set_fedcm_delay_enabled", {enabled, context});
return create_context_action("set_fedcm_delay_enabled", context, {enabled});
};

window.test_driver_internal.reset_fedcm_cooldown = function(context = null) {
return create_action("reset_fedcm_cooldown", {context});
return create_context_action("reset_fedcm_cooldown", context, {});
};

window.test_driver_internal.create_virtual_sensor = function(sensor_type, sensor_params={}, context=null) {
return create_action("create_virtual_sensor", {sensor_type, sensor_params, context});
return create_context_action("create_virtual_sensor", context, {sensor_type, sensor_params});
};

window.test_driver_internal.update_virtual_sensor = function(sensor_type, reading, context=null) {
return create_action("update_virtual_sensor", {sensor_type, reading, context});
return create_context_action("update_virtual_sensor", context, {sensor_type, reading});
};

window.test_driver_internal.remove_virtual_sensor = function(sensor_type, context=null) {
return create_action("remove_virtual_sensor", {sensor_type, context});
return create_context_action("remove_virtual_sensor", context, {sensor_type});
};

window.test_driver_internal.get_virtual_sensor_information = function(sensor_type, context=null) {
return create_action("get_virtual_sensor_information", {sensor_type, context});
return create_context_action("get_virtual_sensor_information", context, {sensor_type});
};
})();

0 comments on commit 8b261c9

Please sign in to comment.