Skip to content
Open
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
64 changes: 64 additions & 0 deletions digital-credentials/webdriver/create.https.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<!DOCTYPE html>
<title>Digital Credential API: create() webdriver tests.</title>
<link rel="help" href="https://wicg.github.io/digital-credentials/">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js?feature=bidi"></script>
<script src="/resources/testdriver-vendor.js"></script>
Comment thread
mohamedamir marked this conversation as resolved.
<body></body>
<script type="module">
import { makeCreateOptions } from "../support/helper.js";

promise_test(async (t) => {
const responseData = "test-create-response-data";
await test_driver.set_virtual_wallet_behavior("respond", "openid4vci", { "value": responseData });
t.add_cleanup(() => test_driver.set_virtual_wallet_behavior("clear"));
await test_driver.bless("user activation");

const options = makeCreateOptions({ protocol: "openid4vci" });
const result = await navigator.credentials.create(options);

assert_equals(result.protocol, "openid4vci");
assert_equals(result.data.value, responseData);
}, "navigator.credentials.create() with respond mode should resolve with the specified data.");

promise_test(async (t) => {
const complexData = { "a": 1, "b": [2, 3], "c": { "d": 4 } };
await test_driver.set_virtual_wallet_behavior("respond", "openid4vci", complexData);
t.add_cleanup(() => test_driver.set_virtual_wallet_behavior("clear"));
await test_driver.bless("user activation");

const options = makeCreateOptions({ protocol: "openid4vci" });
const result = await navigator.credentials.create(options);

assert_equals(result.protocol, "openid4vci");
assert_equals(result.data.a, 1);
assert_array_equals(result.data.b, [2, 3]);
assert_equals(result.data.c.d, 4);
}, "navigator.credentials.create() with complex data response should resolve with structured data.");

promise_test(async (t) => {
await test_driver.set_virtual_wallet_behavior("decline");
t.add_cleanup(() => test_driver.set_virtual_wallet_behavior("clear"));
await test_driver.bless("user activation");

const options = makeCreateOptions({ protocol: "openid4vci" });
await promise_rejects_dom(t, "NotAllowedError", navigator.credentials.create(options));
}, "navigator.credentials.create() with decline mode should reject with NotAllowedError.");

promise_test(async (t) => {
await test_driver.set_virtual_wallet_behavior("wait");
t.add_cleanup(() => test_driver.set_virtual_wallet_behavior("clear"));
await test_driver.bless("user activation");

const controller = new AbortController();
const options = makeCreateOptions({ protocol: "openid4vci", signal: controller.signal });
const promise = navigator.credentials.create(options);

// Give it some time to make sure it's pending.
await new Promise(resolve => t.step_timeout(resolve, 100));

controller.abort();
await promise_rejects_dom(t, "AbortError", promise);
}, "navigator.credentials.create() with wait mode should remain pending until aborted.");
</script>
64 changes: 64 additions & 0 deletions digital-credentials/webdriver/get.https.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<!DOCTYPE html>
<title>Digital Credential API: get() webdriver tests.</title>
<link rel="help" href="https://wicg.github.io/digital-credentials/">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js?feature=bidi"></script>
<script src="/resources/testdriver-vendor.js"></script>
Comment thread
mohamedamir marked this conversation as resolved.
<body></body>
<script type="module">
import { makeGetOptions } from "../support/helper.js";

promise_test(async (t) => {
const responseData = "test-response-data";
await test_driver.set_virtual_wallet_behavior("respond", "openid4vp-v1-unsigned", { "value": responseData });
t.add_cleanup(() => test_driver.set_virtual_wallet_behavior("clear"));
await test_driver.bless("user activation");

const options = makeGetOptions({ protocol: "openid4vp-v1-unsigned" });
const result = await navigator.credentials.get(options);

assert_equals(result.protocol, "openid4vp-v1-unsigned");
assert_equals(result.data.value, responseData);
}, "navigator.credentials.get() with respond mode should resolve with the specified data.");

promise_test(async (t) => {
const complexData = { "a": 1, "b": [2, 3], "c": { "d": 4 } };
await test_driver.set_virtual_wallet_behavior("respond", "openid4vp-v1-unsigned", complexData);
t.add_cleanup(() => test_driver.set_virtual_wallet_behavior("clear"));
await test_driver.bless("user activation");

const options = makeGetOptions({ protocol: "openid4vp-v1-unsigned" });
const result = await navigator.credentials.get(options);

assert_equals(result.protocol, "openid4vp-v1-unsigned");
assert_equals(result.data.a, 1);
assert_array_equals(result.data.b, [2, 3]);
assert_equals(result.data.c.d, 4);
}, "navigator.credentials.get() with complex data response should resolve with structured data.");

promise_test(async (t) => {
await test_driver.set_virtual_wallet_behavior("decline");
t.add_cleanup(() => test_driver.set_virtual_wallet_behavior("clear"));
await test_driver.bless("user activation");

const options = makeGetOptions({ protocol: "openid4vp-v1-unsigned" });
await promise_rejects_dom(t, "NotAllowedError", navigator.credentials.get(options));
}, "navigator.credentials.get() with decline mode should reject with NotAllowedError.");

promise_test(async (t) => {
await test_driver.set_virtual_wallet_behavior("wait");
t.add_cleanup(() => test_driver.set_virtual_wallet_behavior("clear"));
await test_driver.bless("user activation");

const controller = new AbortController();
const options = makeGetOptions({ protocol: "openid4vp-v1-unsigned", signal: controller.signal });
const promise = navigator.credentials.get(options);

// Give it some time to make sure it's pending.
await new Promise(resolve => t.step_timeout(resolve, 100));

controller.abort();
await promise_rejects_dom(t, "AbortError", promise);
}, "navigator.credentials.get() with wait mode should remain pending until aborted.");
</script>
23 changes: 23 additions & 0 deletions resources/testdriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -1985,6 +1985,24 @@
return window.test_driver_internal.reset_fedcm_cooldown(context);
},

/**
* Sets the behavior for the virtual wallet.
*
* Matches the `Set Virtual Wallet Behavior`
* WebDriver BiDi command in Digital Credentials spec.
*
* @param {String} action - The action to take ("decline", "respond", "wait", "clear").
* @param {String} [protocol=null] - The protocol requested (required for "respond").
* @param {Object} [response=null] - The response data (optional for "respond").
* @param {WindowProxy} [context=null] - Browsing context in which to run the call.
*
* @returns {Promise} Fulfilled after the behavior has been set.
*/
set_virtual_wallet_behavior: function(action, protocol=null, response=null, context=null) {
return window.test_driver_internal.set_virtual_wallet_behavior(action, protocol, response, context);
},


/**
* Creates a virtual sensor for use with the Generic Sensors APIs.
*
Expand Down Expand Up @@ -2695,6 +2713,11 @@
throw new Error("reset_fedcm_cooldown() is not implemented by testdriver-vendor.js");
},

async set_virtual_wallet_behavior(action, protocol=null, response=null, context=null) {
throw new Error("set_virtual_wallet_behavior() is not implemented by testdriver-vendor.js");
},


async create_virtual_sensor(sensor_type, sensor_params, context=null) {
throw new Error("create_virtual_sensor() is not implemented by testdriver-vendor.js");
},
Expand Down
16 changes: 16 additions & 0 deletions tools/wptrunner/wptrunner/executors/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,21 @@ def __call__(self, payload):
return self.protocol.fedcm.reset_fedcm_cooldown()


class SetVirtualWalletBehaviorAction:
name = "set_virtual_wallet_behavior"

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

def __call__(self, payload):
action = payload["action"]
protocol = payload.get("protocol")
response = payload.get("response")
self.logger.debug("Setting virtual wallet behavior to %s" % action)
return self.protocol.digital_credentials.set_virtual_wallet_behavior(action, protocol, response)


class CreateVirtualSensorAction:
name = "create_virtual_sensor"

Expand Down Expand Up @@ -653,6 +668,7 @@ def __call__(self, payload):
GetFedCMDialogTypeAction,
SetFedCMDelayEnabledAction,
ResetFedCMCooldownAction,
SetVirtualWalletBehaviorAction,
CreateVirtualSensorAction,
UpdateVirtualSensorAction,
RemoveVirtualSensorAction,
Expand Down
19 changes: 18 additions & 1 deletion tools/wptrunner/wptrunner/executors/asyncactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,22 @@ async def __call__(self, payload):
embedded_origin)


class BidiDigitalCredentialsSetVirtualWalletBehaviorAction:
name = "set_virtual_wallet_behavior"

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

async def execute(self, context: str, payload: Mapping[str, Any]) -> Any:
action = payload["action"]
protocol = payload.get("protocol")
response = payload.get("response")
self.logger.debug("Setting virtual wallet behavior to %s" % action)
return await self.protocol.digital_credentials.set_virtual_wallet_behavior(action, protocol, response, context)


async_actions = [
BidiBluetoothHandleRequestDevicePrompt,
BidiBluetoothSimulateAdapterAction,
Expand All @@ -362,4 +378,5 @@ async def __call__(self, payload):
BidiPermissionsSetPermissionAction,
BidiSessionSubscribeAction,
BidiSessionUnsubscribeAction,
BidiPermissionsSetPermissionAction]
BidiPermissionsSetPermissionAction,
BidiDigitalCredentialsSetVirtualWalletBehaviorAction]
19 changes: 19 additions & 0 deletions tools/wptrunner/wptrunner/executors/executorwebdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
SPCTransactionsProtocolPart,
RPHRegistrationsProtocolPart,
FedCMProtocolPart,
DigitalCredentialsProtocolPart,
VirtualSensorProtocolPart,
BidiBluetoothProtocolPart,
BidiBrowsingContextProtocolPart,
Expand Down Expand Up @@ -965,6 +966,23 @@ def clear_device_posture(self):
return self.webdriver.send_session_command("DELETE", "deviceposture")


class WebDriverDigitalCredentialsPart(DigitalCredentialsProtocolPart):
def setup(self):
self.webdriver = self.parent.webdriver

async def set_virtual_wallet_behavior(self, action, protocol=None, response=None, context=None):
if context is None:
context = self.webdriver.current_window_handle

params = {"action": action, "context": context}
if protocol is not None:
params["protocol"] = protocol
if response is not None:
params["response"] = response

return await self.webdriver.bidi_session.send_command("digitalCredentials.setVirtualWalletBehavior", params)


class WebDriverStorageProtocolPart(StorageProtocolPart):
def setup(self):
self.webdriver = self.parent.webdriver
Expand Down Expand Up @@ -1056,6 +1074,7 @@ class WebDriverProtocol(Protocol):
WebDriverSPCTransactionsProtocolPart,
WebDriverRPHRegistrationsProtocolPart,
WebDriverFedCMProtocolPart,
WebDriverDigitalCredentialsPart,
WebDriverDebugProtocolPart,
WebDriverVirtualSensorPart,
WebDriverDevicePostureProtocolPart,
Expand Down
16 changes: 16 additions & 0 deletions tools/wptrunner/wptrunner/executors/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -1145,6 +1145,22 @@ def reset_fedcm_cooldown(self):
pass


class DigitalCredentialsProtocolPart(ProtocolPart):
"""Protocol part for Digital Credentials"""
__metaclass__ = ABCMeta

name = "digital_credentials"

@abstractmethod
async def set_virtual_wallet_behavior(self, action, protocol=None, response=None, context=None):
"""Set the virtual wallet behavior

:param str action: The action to take ("decline", "respond", "wait", "clear")
:param str protocol: The protocol requested (required for "respond")
:param dict response: The response data (optional for "respond")"""
pass


class PrintProtocolPart(ProtocolPart):
"""Protocol part for rendering to a PDF."""
__metaclass__ = ABCMeta
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 @@ -655,6 +655,10 @@
return create_context_action("reset_fedcm_cooldown", context, {});
};

window.test_driver_internal.set_virtual_wallet_behavior = function(action, protocol=null, response=null, context=null) {
return create_context_action("set_virtual_wallet_behavior", context, {action, protocol, response});
};

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