Skip to content

Commit

Permalink
Implementing the set_rph_registration_mode testdriver
Browse files Browse the repository at this point in the history
This new WebDriver extension command allows to registerProtocolHandler
method of the HTML API to operate under an automatic mode.

This PR defines also new automated tests for the registerProtocolHandler
based on the manual tests that we alaready have.
  • Loading branch information
javifernandez committed Nov 10, 2023
1 parent 2c5fe89 commit e57b2f4
Show file tree
Hide file tree
Showing 10 changed files with 207 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!doctype html>
<!-- Use a non-UTF-8 encoding to see how the handler URL is parsed -->
<meta charset=windows-1254>
<meta name=timeout content=long>
<title>registerProtocolHandler() and a handler with %s in the fragment (does not use a service worker)</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src=/service-workers/service-worker/resources/test-helpers.sub.js></script>
<script>
'use strict';
promise_setup(async () => {
await test_driver.set_rph_registration_mode("autoAccept");
await test_driver.bless('handler registration');
register();
});
// Configure expectations for individual test
window.type = "fragment";
window.noSW = true;
</script>
<script src=resources/handler-tools.js></script>
<script>
runTest();
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!doctype html>
<!-- Use a non-UTF-8 encoding to see how the handler URL is parsed -->
<meta charset=windows-1254>
<meta name=timeout content=long>
<title>registerProtocolHandler() and a handler with %s in the fragment</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src=/service-workers/service-worker/resources/test-helpers.sub.js></script>
<script>
'use strict';
promise_setup(async () => {
await test_driver.set_rph_registration_mode("autoAccept");
await test_driver.bless('handler registration');
register();
});
// Configure expectations for individual test
window.type = "fragment";
window.noSW = false;
</script>
<script src=resources/handler-tools.js></script>
<script>
runTest();
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!doctype html>
<!-- Use a non-UTF-8 encoding to see how the handler URL is parsed -->
<meta charset=windows-1254>
<meta name=timeout content=long>
<title>registerProtocolHandler() and a handler with %s in the path</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src=/service-workers/service-worker/resources/test-helpers.sub.js></script>
<script>
'use strict';
promise_setup(async () => {
await test_driver.set_rph_registration_mode("autoAccept");
await test_driver.bless('handler registration');
register();
});
// Configure expectations for individual test
window.type = "path";
window.noSW = false;
</script>
<script src=resources/handler-tools.js></script>
<script>
runTest();
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!doctype html>
<!-- Use a non-UTF-8 encoding to see how the handler URL is parsed -->
<meta charset=windows-1254>
<meta name=timeout content=long>
<title>registerProtocolHandler() and a handler with %s in the query (does not use a service worker)</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src=/service-workers/service-worker/resources/test-helpers.sub.js></script>
<script>
'use strict';
promise_setup(async () => {
await test_driver.set_rph_registration_mode("autoAccept");
await test_driver.bless('handler registration');
register();
});
// Configure expectations for individual test
window.type = "query";
window.noSW = true;
</script>
<script src=resources/handler-tools.js></script>
<script>
runTest();
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!doctype html>
<!-- Use a non-UTF-8 encoding to see how the handler URL is parsed -->
<meta charset=windows-1254>
<meta name=timeout content=long>
<title>registerProtocolHandler() and a handler with %s in the query</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src=/service-workers/service-worker/resources/test-helpers.sub.js></script>
<script>
'use strict';
promise_setup(async () => {
await test_driver.set_rph_registration_mode("autoAccept");
await test_driver.bless('handler registration');
register();
});
// Configure expectations for individual test
window.type = "query";
window.noSW = false;
</script>
<script src=resources/handler-tools.js></script>
<script>
runTest();
</script>
46 changes: 43 additions & 3 deletions resources/testdriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@
*
* This function places `Secure Payment
* Confirmation <https://w3c.github.io/secure-payment-confirmation>`_ into
* an automated 'autoaccept' or 'autoreject' mode, to allow testing
* an automated 'autoAccept' or 'autoReject' mode, to allow testing
* without user interaction with the transaction UX prompt.
*
* Matches the `Set SPC Transaction Mode
Expand All @@ -667,8 +667,8 @@
* @param {String} mode - The `transaction mode
* <https://w3c.github.io/secure-payment-confirmation/#enumdef-transactionautomationmode>`_
* to set. Must be one of "``none``",
* "``autoaccept``", or
* "``autoreject``".
* "``autoAccept``", or
* "``autoReject``".
* @param {WindowProxy} context - Browsing context in which
* to run the call, or null for the current
* browsing context.
Expand All @@ -680,6 +680,42 @@
return window.test_driver_internal.set_spc_transaction_mode(mode, context);
},

/**
* Sets the current registration automation mode for Register Protocol Handlers.
*
* This function places `Register Protocol Handlers
* <https://html.spec.whatwg.org/multipage/system-state.html#custom-handlers>`_ into
* an automated 'autoAccept' or 'autoReject' mode, to allow testing
* without user interaction with the transaction UX prompt.
*
* Matches the `Set Register Protocol Handler Mode
* <https://html.spec.whatwg.org/multipage/system-state.html#set-rph-registration-mode>`_
* WebDriver command.
*
* @example
* await test_driver.set_rph_registration_mode("autoAccept");
* test.add_cleanup(() => {
* return test_driver.set_rph_registration_mode("none");
* });
*
* navigator.registerProtocolHandler('web+soup', 'soup?url=%s');
*
* @param {String} mode - The `registration mode
* <https://html.spec.whatwg.org/multipage/system-state.html#registerprotocolhandler()-automation-mode>`_
* to set. Must be one of "``none``",
* "``autoAccept``", or
* "``autoReject``".
* @param {WindowProxy} context - Browsing context in which
* to run the call, or null for the current
* browsing context.
*
* @returns {Promise} Fulfilled after the transaction mode has been set,
* or rejected if setting the mode fails.
*/
set_rph_registration_mode: function(mode, context=null) {
return window.test_driver_internal.set_rph_registration_mode(mode, context);
},

/**
* Cancels the Federated Credential Management dialog
*
Expand Down Expand Up @@ -1094,6 +1130,10 @@
throw new Error("set_spc_transaction_mode() is not implemented by testdriver-vendor.js");
},

set_rph_registration_mode: function(mode, context=null) {
return Promise.reject(new Error("unimplemented"));
},

async cancel_fedcm_dialog(context=null) {
throw new Error("cancel_fedcm_dialog() is not implemented by testdriver-vendor.js");
},
Expand Down
13 changes: 13 additions & 0 deletions tools/wptrunner/wptrunner/executors/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,18 @@ def __call__(self, payload):
self.logger.debug("Setting SPC transaction mode to %s" % mode)
return self.protocol.spc_transactions.set_spc_transaction_mode(mode)

class SetRPHRegistrationModeAction:
name = "set_rph_registration_mode"

def __init__(self, logger, protocol):
self.logger = logger
self.protocol = protocol

def __call__(self, payload):
mode = payload["mode"]
self.logger.debug("Setting RPH registration mode to %s" % mode)
return self.protocol.rph_registrations.set_rph_registration_mode(mode)

class CancelFedCMDialogAction:
name = "cancel_fedcm_dialog"

Expand Down Expand Up @@ -442,6 +454,7 @@ def __call__(self, payload):
RemoveAllCredentialsAction,
SetUserVerifiedAction,
SetSPCTransactionModeAction,
SetRPHRegistrationModeAction,
CancelFedCMDialogAction,
ConfirmIDPLoginAction,
SelectFedCMAccountAction,
Expand Down
10 changes: 10 additions & 0 deletions tools/wptrunner/wptrunner/executors/executorwebdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
WindowProtocolPart,
DebugProtocolPart,
SPCTransactionsProtocolPart,
RPHRegistrationsProtocolPart,
FedCMProtocolPart,
VirtualSensorProtocolPart,
merge_dicts)
Expand Down Expand Up @@ -363,6 +364,13 @@ def set_spc_transaction_mode(self, mode):
body = {"mode": mode}
return self.webdriver.send_session_command("POST", "secure-payment-confirmation/set-mode", body)

class WebDriverRPHRegistrationsProtocolPart(RPHRegistrationsProtocolPart):
def setup(self):
self.webdriver = self.parent.webdriver

def set_rph_registration_mode(self, mode):
body = {"mode": mode}
return self.webdriver.send_session_command("POST", "custom-handlers/set-mode", body)

class WebDriverFedCMProtocolPart(FedCMProtocolPart):
def setup(self):
Expand Down Expand Up @@ -435,6 +443,8 @@ class WebDriverProtocol(Protocol):
WebDriverFedCMProtocolPart,
WebDriverDebugProtocolPart,
WebDriverVirtualSensorPart]
WebDriverRPHRegistrationsProtocolPart,
WebDriverDebugProtocolPart]

def __init__(self, executor, browser, capabilities, **kwargs):
super().__init__(executor, browser)
Expand Down
12 changes: 12 additions & 0 deletions tools/wptrunner/wptrunner/executors/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,18 @@ def set_spc_transaction_mode(self, mode):
:param str mode: The automation mode to set"""
pass

class RPHRegistrationsProtocolPart(ProtocolPart):
"""Protocol part for Custom Handlers registrations"""
__metaclass__ = ABCMeta

name = "rph_registrations"

@abstractmethod
def set_rph_registration_mode(self, mode):
"""Set the RPH registration automation mode
:param str mode: The automation mode to set"""
pass

class FedCMProtocolPart(ProtocolPart):
"""Protocol part for Federated Credential Management"""
Expand Down
4 changes: 4 additions & 0 deletions tools/wptrunner/wptrunner/testdriver-extra.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,10 @@
return create_action("set_spc_transaction_mode", {mode, context});
};

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

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

0 comments on commit e57b2f4

Please sign in to comment.