| 1 |
(function() { |
| 2 |
"use strict"; |
| 3 |
var idCounter = 0; |
| 4 |
let testharness_context = null; |
| 5 |
|
| 6 |
const features = (() => { |
| 7 |
function getFeatures(scriptSrc) { |
| 8 |
try { |
| 9 |
const url = new URL(scriptSrc); |
| 10 |
return url.searchParams.getAll('feature'); |
| 11 |
} catch (e) { |
| 12 |
return []; |
| 13 |
} |
| 14 |
} |
| 15 |
|
| 16 |
return getFeatures(document?.currentScript?.src ?? ''); |
| 17 |
})(); |
| 18 |
|
| 19 |
function assertBidiIsEnabled(){ |
| 20 |
if (!features.includes('bidi')) { |
| 21 |
throw new Error( |
| 22 |
"`?feature=bidi` is missing when importing testdriver.js but the test is using WebDriver BiDi APIs"); |
| 23 |
} |
| 24 |
} |
| 25 |
|
| 26 |
function getInViewCenterPoint(rect) { |
| 27 |
var left = Math.max(0, rect.left); |
| 28 |
var right = Math.min(window.innerWidth, rect.right); |
| 29 |
var top = Math.max(0, rect.top); |
| 30 |
var bottom = Math.min(window.innerHeight, rect.bottom); |
| 31 |
|
| 32 |
var x = 0.5 * (left + right); |
| 33 |
var y = 0.5 * (top + bottom); |
| 34 |
|
| 35 |
return [x, y]; |
| 36 |
} |
| 37 |
|
| 38 |
function getPointerInteractablePaintTree(element) { |
| 39 |
let elementDocument = element.ownerDocument; |
| 40 |
if (!elementDocument.contains(element)) { |
| 41 |
return []; |
| 42 |
} |
| 43 |
|
| 44 |
var rectangles = element.getClientRects(); |
| 45 |
|
| 46 |
if (rectangles.length === 0) { |
| 47 |
return []; |
| 48 |
} |
| 49 |
|
| 50 |
var centerPoint = getInViewCenterPoint(rectangles[0]); |
| 51 |
|
| 52 |
if ("elementsFromPoint" in elementDocument) { |
| 53 |
return elementDocument.elementsFromPoint(centerPoint[0], centerPoint[1]); |
| 54 |
} else if ("msElementsFromPoint" in elementDocument) { |
| 55 |
var rv = elementDocument.msElementsFromPoint(centerPoint[0], centerPoint[1]); |
| 56 |
return Array.prototype.slice.call(rv ? rv : []); |
| 57 |
} else { |
| 58 |
throw new Error("document.elementsFromPoint unsupported"); |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
function inView(element) { |
| 63 |
var pointerInteractablePaintTree = getPointerInteractablePaintTree(element); |
| 64 |
return pointerInteractablePaintTree.indexOf(element) !== -1; |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
/** |
| 69 |
* @namespace {test_driver} |
| 70 |
*/ |
| 71 |
window.test_driver = { |
| 72 |
/** |
| 73 |
Represents `WebDriver BiDi <https://w3c.github.io/webdriver-bidi>`_ protocol. |
| 74 |
*/ |
| 75 |
bidi: { |
| 76 |
/** |
| 77 |
* @typedef {(String|WindowProxy)} Context A browsing context. Can |
| 78 |
* be specified by its ID (a string) or using a `WindowProxy` |
| 79 |
* object. |
| 80 |
*/ |
| 81 |
/** |
| 82 |
* `bluetooth <https://webbluetoothcg.github.io/web-bluetooth>`_ module. |
| 83 |
*/ |
| 84 |
bluetooth: { |
| 85 |
/** |
| 86 |
* Handle a bluetooth device prompt with the given params. Matches the |
| 87 |
* `bluetooth.handleRequestDevicePrompt |
| 88 |
* <https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-handlerequestdeviceprompt-command>`_ |
| 89 |
* WebDriver BiDi command. |
| 90 |
* |
| 91 |
* @example |
| 92 |
* await test_driver.bidi.bluetooth.handleRequestDevicePrompt({ |
| 93 |
* prompt: "pmt-e0a234b", |
| 94 |
* accept: true, |
| 95 |
* device: "dvc-9b3b872" |
| 96 |
* }); |
| 97 |
* |
| 98 |
* @param {object} params - Parameters for the command. |
| 99 |
* @param {string} params.prompt - The id of a bluetooth device prompt. |
| 100 |
* Matches the |
| 101 |
* `bluetooth.HandleRequestDevicePromptParameters:prompt <https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-handlerequestdeviceprompt-command>`_ |
| 102 |
* value. |
| 103 |
* @param {bool} params.accept - Whether to accept a bluetooth device prompt. |
| 104 |
* Matches the |
| 105 |
* `bluetooth.HandleRequestDevicePromptAcceptParameters:accept <https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-handlerequestdeviceprompt-command>`_ |
| 106 |
* value. |
| 107 |
* @param {string} params.device - The device id from a bluetooth device |
| 108 |
* prompt to be accepted. Matches the |
| 109 |
* `bluetooth.HandleRequestDevicePromptAcceptParameters:device <https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-handlerequestdeviceprompt-command>`_ |
| 110 |
* value. |
| 111 |
* @param {Context} [params.context] The optional context parameter specifies in |
| 112 |
* which browsing context the bluetooth device prompt should be handled. If not |
| 113 |
* provided, the current browsing context is used. |
| 114 |
* @returns {Promise} fulfilled after the bluetooth device prompt |
| 115 |
* is handled, or rejected if the operation fails. |
| 116 |
*/ |
| 117 |
handle_request_device_prompt: function(params) { |
| 118 |
return window.test_driver_internal.bidi.bluetooth |
| 119 |
.handle_request_device_prompt(params); |
| 120 |
}, |
| 121 |
/** |
| 122 |
* Creates a simulated bluetooth adapter with the given params. Matches the |
| 123 |
* `bluetooth.simulateAdapter <https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-simulateAdapter-command>`_ |
| 124 |
* WebDriver BiDi command. |
| 125 |
* |
| 126 |
* @example |
| 127 |
* await test_driver.bidi.bluetooth.simulate_adapter({ |
| 128 |
* state: "powered-on" |
| 129 |
* }); |
| 130 |
* |
| 131 |
* @param {object} params - Parameters for the command. |
| 132 |
* @param {string} params.state The state of the simulated bluetooth adapter. |
| 133 |
* Matches the |
| 134 |
* `bluetooth.SimulateAdapterParameters:state <https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-simulateAdapter-command>`_ |
| 135 |
* value. |
| 136 |
* @param {Context} [params.context] The optional context parameter specifies in |
| 137 |
* which browsing context the simulated bluetooth adapter should be set. If not |
| 138 |
* provided, the current browsing context is used. |
| 139 |
* @returns {Promise} fulfilled after the simulated bluetooth adapter is created |
| 140 |
* and set, or rejected if the operation fails. |
| 141 |
*/ |
| 142 |
simulate_adapter: function (params) { |
| 143 |
return window.test_driver_internal.bidi.bluetooth.simulate_adapter(params); |
| 144 |
}, |
| 145 |
/** |
| 146 |
* Creates a simulated bluetooth peripheral with the given params. |
| 147 |
* Matches the |
| 148 |
* `bluetooth.simulatePreconnectedPeripheral <https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-simulateconnectedperipheral-command>`_ |
| 149 |
* WebDriver BiDi command. |
| 150 |
* |
| 151 |
* @example |
| 152 |
* await test_driver.bidi.bluetooth.simulatePreconnectedPeripheral({ |
| 153 |
* "address": "09:09:09:09:09:09", |
| 154 |
* "name": "Some Device", |
| 155 |
* "manufacturerData": [{key: 17, data: "AP8BAX8="}], |
| 156 |
* "knownServiceUuids": [ |
| 157 |
* "12345678-1234-5678-9abc-def123456789", |
| 158 |
* ], |
| 159 |
* }); |
| 160 |
* |
| 161 |
* @param {object} params - Parameters for the command. |
| 162 |
* @param {string} params.address - The address of the simulated |
| 163 |
* bluetooth peripheral. Matches the |
| 164 |
* `bluetooth.SimulatePreconnectedPeripheralParameters:address <https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-simulateconnectedperipheral-command>`_ |
| 165 |
* value. |
| 166 |
* @param {string} params.name - The name of the simulated bluetooth |
| 167 |
* peripheral. Matches the |
| 168 |
* `bluetooth.SimulatePreconnectedPeripheralParameters:name <https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-simulateconnectedperipheral-command>`_ |
| 169 |
* value. |
| 170 |
* @param {Array.ManufacturerData} params.manufacturerData - The manufacturerData of the |
| 171 |
* simulated bluetooth peripheral. Matches the |
| 172 |
* `bluetooth.SimulatePreconnectedPeripheralParameters:manufacturerData <https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-simulateconnectedperipheral-command>`_ |
| 173 |
* value. |
| 174 |
* @param {string} params.knownServiceUuids - The knownServiceUuids of |
| 175 |
* the simulated bluetooth peripheral. Matches the |
| 176 |
* `bluetooth.SimulatePreconnectedPeripheralParameters:knownServiceUuids <https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-simulateconnectedperipheral-command>`_ |
| 177 |
* value. |
| 178 |
* @param {Context} [params.context] The optional context parameter |
| 179 |
* specifies in which browsing context the simulated bluetooth peripheral should be |
| 180 |
* set. If not provided, the current browsing context is used. |
| 181 |
* @returns {Promise} fulfilled after the simulated bluetooth peripheral is created |
| 182 |
* and set, or rejected if the operation fails. |
| 183 |
*/ |
| 184 |
simulate_preconnected_peripheral: function(params) { |
| 185 |
return window.test_driver_internal.bidi.bluetooth |
| 186 |
.simulate_preconnected_peripheral(params); |
| 187 |
}, |
| 188 |
/** |
| 189 |
* `bluetooth.RequestDevicePromptUpdatedParameters <https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-requestdevicepromptupdated-event>`_ |
| 190 |
* event. |
| 191 |
*/ |
| 192 |
request_device_prompt_updated: { |
| 193 |
/** |
| 194 |
* @typedef {object} RequestDevicePromptUpdated |
| 195 |
* `bluetooth.RequestDevicePromptUpdatedParameters <https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-requestdevicepromptupdated-event>`_ |
| 196 |
* event. |
| 197 |
*/ |
| 198 |
|
| 199 |
/** |
| 200 |
* Subscribes to the event. Events will be emitted only if |
| 201 |
* there is a subscription for the event. This method does |
| 202 |
* not add actual listeners. To listen to the event, use the |
| 203 |
* `on` or `once` methods. The buffered events will be |
| 204 |
* emitted before the command promise is resolved. |
| 205 |
* |
| 206 |
* @param {object} [params] Parameters for the subscription. |
| 207 |
* @param {null|Array.<(Context)>} [params.contexts] The |
| 208 |
* optional contexts parameter specifies which browsing |
| 209 |
* contexts to subscribe to the event on. It should be |
| 210 |
* either an array of Context objects, or null. If null, the |
| 211 |
* event will be subscribed to globally. If omitted, the |
| 212 |
* event will be subscribed to on the current browsing |
| 213 |
* context. |
| 214 |
* @returns {Promise<void>} Resolves when the subscription |
| 215 |
* is successfully done. |
| 216 |
*/ |
| 217 |
subscribe: async function(params = {}) { |
| 218 |
assertBidiIsEnabled(); |
| 219 |
return window.test_driver_internal.bidi.bluetooth |
| 220 |
.request_device_prompt_updated.subscribe(params); |
| 221 |
}, |
| 222 |
/** |
| 223 |
* Adds an event listener for the event. |
| 224 |
* |
| 225 |
* @param {function(RequestDevicePromptUpdated): void} callback The |
| 226 |
* callback to be called when the event is emitted. The |
| 227 |
* callback is called with the event object as a parameter. |
| 228 |
* @returns {function(): void} A function that removes the |
| 229 |
* added event listener when called. |
| 230 |
*/ |
| 231 |
on: function(callback) { |
| 232 |
assertBidiIsEnabled(); |
| 233 |
return window.test_driver_internal.bidi.bluetooth |
| 234 |
.request_device_prompt_updated.on(callback); |
| 235 |
}, |
| 236 |
/** |
| 237 |
* Adds an event listener for the event that is only called |
| 238 |
* once and removed afterward. |
| 239 |
* |
| 240 |
* @return {Promise<RequestDevicePromptUpdated>} The promise which |
| 241 |
* is resolved with the event object when the event is emitted. |
| 242 |
*/ |
| 243 |
once: function() { |
| 244 |
assertBidiIsEnabled(); |
| 245 |
return new Promise(resolve => { |
| 246 |
const remove_handler = |
| 247 |
window.test_driver_internal.bidi.bluetooth |
| 248 |
.request_device_prompt_updated.on(event => { |
| 249 |
resolve(event); |
| 250 |
remove_handler(); |
| 251 |
}); |
| 252 |
}); |
| 253 |
}, |
| 254 |
} |
| 255 |
}, |
| 256 |
/** |
| 257 |
* `emulation <https://www.w3.org/TR/webdriver-bidi/#module-emulation>`_ module. |
| 258 |
*/ |
| 259 |
emulation: { |
| 260 |
/** |
| 261 |
* Overrides the geolocation coordinates for the specified |
| 262 |
* browsing contexts. |
| 263 |
* Matches the `emulation.setGeolocationOverride |
| 264 |
* <https://w3c.github.io/webdriver-bidi/#command-emulation-setGeolocationOverride>`_ |
| 265 |
* WebDriver BiDi command. |
| 266 |
* |
| 267 |
* @example |
| 268 |
* await test_driver.bidi.emulation.set_geolocation_override({ |
| 269 |
* coordinates: { |
| 270 |
* latitude: 52.51, |
| 271 |
* longitude: 13.39, |
| 272 |
* accuracy: 0.5, |
| 273 |
* altitude: 34, |
| 274 |
* altitudeAccuracy: 0.75, |
| 275 |
* heading: 180, |
| 276 |
* speed: 2.77 |
| 277 |
* } |
| 278 |
* }); |
| 279 |
* |
| 280 |
* @param {object} params - Parameters for the command. |
| 281 |
* @param {null|object} params.coordinates - The optional |
| 282 |
* geolocation coordinates to set. Matches the |
| 283 |
* `emulation.GeolocationCoordinates <https://w3c.github.io/webdriver-bidi/#commands-emulationsetgeolocationoverride>`_ |
| 284 |
* value. If null or omitted and the `params.error` is set, the |
| 285 |
* emulation will be removed. Mutually exclusive with |
| 286 |
* `params.error`. |
| 287 |
* @param {object} params.error - The optional |
| 288 |
* geolocation error to emulate. Matches the |
| 289 |
* `emulation.GeolocationPositionError <https://w3c.github.io/webdriver-bidi/#commands-emulationsetgeolocationoverride>`_ |
| 290 |
* value. Mutually exclusive with `params.coordinates`. |
| 291 |
* @param {null|Array.<(Context)>} [params.contexts] The |
| 292 |
* optional contexts parameter specifies which browsing contexts |
| 293 |
* to set the geolocation override on. It should be either an |
| 294 |
* array of Context objects (window or browsing context id), or |
| 295 |
* null. If null or omitted, the override will be set on the |
| 296 |
* current browsing context. |
| 297 |
* @returns {Promise<void>} Resolves when the geolocation |
| 298 |
* override is successfully set. |
| 299 |
*/ |
| 300 |
set_geolocation_override: function (params) { |
| 301 |
// Ensure the bidi feature is enabled before calling the internal method |
| 302 |
assertBidiIsEnabled(); |
| 303 |
return window.test_driver_internal.bidi.emulation.set_geolocation_override( |
| 304 |
params); |
| 305 |
}, |
| 306 |
}, |
| 307 |
/** |
| 308 |
* `log <https://www.w3.org/TR/webdriver-bidi/#module-log>`_ module. |
| 309 |
*/ |
| 310 |
log: { |
| 311 |
entry_added: { |
| 312 |
/** |
| 313 |
* @typedef {object} LogEntryAdded `log.entryAdded <https://www.w3.org/TR/webdriver-bidi/#event-log-entryAdded>`_ event. |
| 314 |
*/ |
| 315 |
|
| 316 |
/** |
| 317 |
* Subscribes to the event. Events will be emitted only if |
| 318 |
* there is a subscription for the event. This method does |
| 319 |
* not add actual listeners. To listen to the event, use the |
| 320 |
* `on` or `once` methods. The buffered events will be |
| 321 |
* emitted before the command promise is resolved. |
| 322 |
* |
| 323 |
* @param {object} [params] Parameters for the subscription. |
| 324 |
* @param {null|Array.<(Context)>} [params.contexts] The |
| 325 |
* optional contexts parameter specifies which browsing |
| 326 |
* contexts to subscribe to the event on. It should be |
| 327 |
* either an array of Context objects, or null. If null, the |
| 328 |
* event will be subscribed to globally. If omitted, the |
| 329 |
* event will be subscribed to on the current browsing |
| 330 |
* context. |
| 331 |
* @returns {Promise<void>} Resolves when the subscription |
| 332 |
* is successfully done. |
| 333 |
*/ |
| 334 |
subscribe: async function (params = {}) { |
| 335 |
assertBidiIsEnabled(); |
| 336 |
return window.test_driver_internal.bidi.log.entry_added.subscribe(params); |
| 337 |
}, |
| 338 |
/** |
| 339 |
* Adds an event listener for the event. |
| 340 |
* |
| 341 |
* @param {function(LogEntryAdded): void} callback The |
| 342 |
* callback to be called when the event is emitted. The |
| 343 |
* callback is called with the event object as a parameter. |
| 344 |
* @returns {function(): void} A function that removes the |
| 345 |
* added event listener when called. |
| 346 |
*/ |
| 347 |
on: function (callback) { |
| 348 |
assertBidiIsEnabled(); |
| 349 |
return window.test_driver_internal.bidi.log.entry_added.on(callback); |
| 350 |
}, |
| 351 |
/** |
| 352 |
* Adds an event listener for the event that is only called |
| 353 |
* once and removed afterward. |
| 354 |
* |
| 355 |
* @return {Promise<LogEntryAdded>} The promise which is resolved |
| 356 |
* with the event object when the event is emitted. |
| 357 |
*/ |
| 358 |
once: function () { |
| 359 |
assertBidiIsEnabled(); |
| 360 |
return new Promise(resolve => { |
| 361 |
const remove_handler = window.test_driver_internal.bidi.log.entry_added.on( |
| 362 |
event => { |
| 363 |
resolve(event); |
| 364 |
remove_handler(); |
| 365 |
}); |
| 366 |
}); |
| 367 |
}, |
| 368 |
} |
| 369 |
}, |
| 370 |
/** |
| 371 |
* `permissions <https://www.w3.org/TR/permissions/>`_ module. |
| 372 |
*/ |
| 373 |
permissions: { |
| 374 |
/** |
| 375 |
* Sets the state of a permission |
| 376 |
* |
| 377 |
* This function causes permission requests and queries for the status |
| 378 |
* of a certain permission type (e.g. "push", or "background-fetch") to |
| 379 |
* always return ``state`` for the specific origin. |
| 380 |
* |
| 381 |
* Matches the `permissions.setPermission <https://w3c.github.io/permissions/#webdriver-bidi-command-permissions-setPermission>`_ |
| 382 |
* WebDriver BiDi command. |
| 383 |
* |
| 384 |
* @example |
| 385 |
* await test_driver.bidi.permissions.set_permission({ |
| 386 |
* {name: "geolocation"}, |
| 387 |
* state: "granted", |
| 388 |
* }); |
| 389 |
* |
| 390 |
* @param {object} params - Parameters for the command. |
| 391 |
* @param {PermissionDescriptor} params.descriptor - a `PermissionDescriptor |
| 392 |
* <https://w3c.github.io/permissions/#dom-permissiondescriptor>`_ |
| 393 |
* or derived object. |
| 394 |
* @param {PermissionState} params.state - a `PermissionState |
| 395 |
* <https://w3c.github.io/permissions/#dom-permissionstate>`_ |
| 396 |
* value. |
| 397 |
* @param {string} [params.origin] - an optional `origin` string to set the |
| 398 |
* permission for. If omitted, the permission is set for the |
| 399 |
* current window's origin. |
| 400 |
* @returns {Promise} fulfilled after the permission is set, or rejected if setting |
| 401 |
* the permission fails. |
| 402 |
*/ |
| 403 |
set_permission: function (params) { |
| 404 |
assertBidiIsEnabled(); |
| 405 |
return window.test_driver_internal.bidi.permissions.set_permission( |
| 406 |
params); |
| 407 |
} |
| 408 |
} |
| 409 |
}, |
| 410 |
|
| 411 |
/** |
| 412 |
* Set the context in which testharness.js is loaded |
| 413 |
* |
| 414 |
* @param {WindowProxy} context - the window containing testharness.js |
| 415 |
**/ |
| 416 |
set_test_context: function(context) { |
| 417 |
if (window.test_driver_internal.set_test_context) { |
| 418 |
window.test_driver_internal.set_test_context(context); |
| 419 |
} |
| 420 |
testharness_context = context; |
| 421 |
}, |
| 422 |
|
| 423 |
/** |
| 424 |
* postMessage to the context containing testharness.js |
| 425 |
* |
| 426 |
* @param {Object} msg - the data to POST |
| 427 |
**/ |
| 428 |
message_test: function(msg) { |
| 429 |
let target = testharness_context; |
| 430 |
if (testharness_context === null) { |
| 431 |
target = window; |
| 432 |
} |
| 433 |
target.postMessage(msg, "*"); |
| 434 |
}, |
| 435 |
|
| 436 |
/** |
| 437 |
* Trigger user interaction in order to grant additional privileges to |
| 438 |
* a provided function. |
| 439 |
* |
| 440 |
* See `Tracking user activation |
| 441 |
* <https://html.spec.whatwg.org/multipage/interaction.html#tracking-user-activation>`_. |
| 442 |
* |
| 443 |
* @example |
| 444 |
* var mediaElement = document.createElement('video'); |
| 445 |
* |
| 446 |
* test_driver.bless('initiate media playback', function () { |
| 447 |
* mediaElement.play(); |
| 448 |
* }); |
| 449 |
* |
| 450 |
* @param {String} intent - a description of the action which must be |
| 451 |
* triggered by user interaction |
| 452 |
* @param {Function} action - code requiring escalated privileges |
| 453 |
* @param {WindowProxy} context - Browsing context in which |
| 454 |
* to run the call, or null for the current |
| 455 |
* browsing context. |
| 456 |
* |
| 457 |
* @returns {Promise} fulfilled following user interaction and |
| 458 |
* execution of the provided `action` function; |
| 459 |
* rejected if interaction fails or the provided |
| 460 |
* function throws an error |
| 461 |
*/ |
| 462 |
bless: function(intent, action, context=null) { |
| 463 |
let contextDocument = context ? context.document : document; |
| 464 |
var button = contextDocument.createElement("button"); |
| 465 |
button.innerHTML = "This test requires user interaction.<br />" + |
| 466 |
"Please click here to allow " + intent + "."; |
| 467 |
button.id = "wpt-test-driver-bless-" + (idCounter += 1); |
| 468 |
const elem = contextDocument.body || contextDocument.documentElement; |
| 469 |
elem.appendChild(button); |
| 470 |
|
| 471 |
let wait_click = new Promise(resolve => button.addEventListener("click", resolve)); |
| 472 |
|
| 473 |
return test_driver.click(button) |
| 474 |
.then(() => wait_click) |
| 475 |
.then(() => { |
| 476 |
button.remove(); |
| 477 |
|
| 478 |
if (typeof action === "function") { |
| 479 |
return action(); |
| 480 |
} |
| 481 |
return null; |
| 482 |
}); |
| 483 |
}, |
| 484 |
|
| 485 |
/** |
| 486 |
* Triggers a user-initiated mouse click. |
| 487 |
* |
| 488 |
* If ``element`` isn't inside the viewport, it will be |
| 489 |
* scrolled into view before the click occurs. |
| 490 |
* |
| 491 |
* If ``element`` is from a different browsing context, the |
| 492 |
* command will be run in that context. |
| 493 |
* |
| 494 |
* Matches the behaviour of the `Element Click |
| 495 |
* <https://w3c.github.io/webdriver/#element-click>`_ |
| 496 |
* WebDriver command. |
| 497 |
* |
| 498 |
* **Note:** If the element to be clicked does not have a |
| 499 |
* unique ID, the document must not have any DOM mutations |
| 500 |
* made between the function being called and the promise |
| 501 |
* settling. |
| 502 |
* |
| 503 |
* @param {Element} element - element to be clicked |
| 504 |
* @returns {Promise} fulfilled after click occurs, or rejected in |
| 505 |
* the cases the WebDriver command errors |
| 506 |
*/ |
| 507 |
click: function(element) { |
| 508 |
if (!inView(element)) { |
| 509 |
element.scrollIntoView({behavior: "instant", |
| 510 |
block: "end", |
| 511 |
inline: "nearest"}); |
| 512 |
} |
| 513 |
|
| 514 |
var pointerInteractablePaintTree = getPointerInteractablePaintTree(element); |
| 515 |
if (pointerInteractablePaintTree.length === 0 || |
| 516 |
!element.contains(pointerInteractablePaintTree[0])) { |
| 517 |
return Promise.reject(new Error("element click intercepted error")); |
| 518 |
} |
| 519 |
|
| 520 |
var rect = element.getClientRects()[0]; |
| 521 |
var centerPoint = getInViewCenterPoint(rect); |
| 522 |
return window.test_driver_internal.click(element, |
| 523 |
{x: centerPoint[0], |
| 524 |
y: centerPoint[1]}); |
| 525 |
}, |
| 526 |
|
| 527 |
/** |
| 528 |
* Deletes all cookies. |
| 529 |
* |
| 530 |
* Matches the behaviour of the `Delete All Cookies |
| 531 |
* <https://w3c.github.io/webdriver/#delete-all-cookies>`_ |
| 532 |
* WebDriver command. |
| 533 |
* |
| 534 |
* @param {WindowProxy} context - Browsing context in which |
| 535 |
* to run the call, or null for the current |
| 536 |
* browsing context. |
| 537 |
* |
| 538 |
* @returns {Promise} fulfilled after cookies are deleted, or rejected in |
| 539 |
* the cases the WebDriver command errors |
| 540 |
*/ |
| 541 |
delete_all_cookies: function(context=null) { |
| 542 |
return window.test_driver_internal.delete_all_cookies(context); |
| 543 |
}, |
| 544 |
|
| 545 |
/** |
| 546 |
* Get details for all cookies in the current context. |
| 547 |
* See https://w3c.github.io/webdriver/#get-all-cookies |
| 548 |
* |
| 549 |
* @param {WindowProxy} context - Browsing context in which |
| 550 |
* to run the call, or null for the current |
| 551 |
* browsing context. |
| 552 |
* |
| 553 |
* @returns {Promise} Returns an array of cookies objects as defined in the spec: |
| 554 |
* https://w3c.github.io/webdriver/#cookies |
| 555 |
*/ |
| 556 |
get_all_cookies: function(context=null) { |
| 557 |
return window.test_driver_internal.get_all_cookies(context); |
| 558 |
}, |
| 559 |
|
| 560 |
/** |
| 561 |
* Get details for a cookie in the current context by name if it exists. |
| 562 |
* See https://w3c.github.io/webdriver/#get-named-cookie |
| 563 |
* |
| 564 |
* @param {String} name - The name of the cookie to get. |
| 565 |
* @param {WindowProxy} context - Browsing context in which |
| 566 |
* to run the call, or null for the current |
| 567 |
* browsing context. |
| 568 |
* |
| 569 |
* @returns {Promise} Returns the matching cookie as defined in the spec: |
| 570 |
* https://w3c.github.io/webdriver/#cookies |
| 571 |
* Rejected if no such cookie exists. |
| 572 |
*/ |
| 573 |
get_named_cookie: async function(name, context=null) { |
| 574 |
let cookie = await window.test_driver_internal.get_named_cookie(name, context); |
| 575 |
if (!cookie) { |
| 576 |
throw new Error("no such cookie"); |
| 577 |
} |
| 578 |
return cookie; |
| 579 |
}, |
| 580 |
|
| 581 |
/** |
| 582 |
* Get Computed Label for an element. |
| 583 |
* |
| 584 |
* This matches the behaviour of the |
| 585 |
* `Get Computed Label |
| 586 |
* <https://w3c.github.io/webdriver/#dfn-get-computed-label>`_ |
| 587 |
* WebDriver command. |
| 588 |
* |
| 589 |
* @param {Element} element |
| 590 |
* @returns {Promise} fulfilled after the computed label is returned, or |
| 591 |
* rejected in the cases the WebDriver command errors |
| 592 |
*/ |
| 593 |
get_computed_label: async function(element) { |
| 594 |
let label = await window.test_driver_internal.get_computed_label(element); |
| 595 |
return label; |
| 596 |
}, |
| 597 |
|
| 598 |
/** |
| 599 |
* Get Computed Role for an element. |
| 600 |
* |
| 601 |
* This matches the behaviour of the |
| 602 |
* `Get Computed Label |
| 603 |
* <https://w3c.github.io/webdriver/#dfn-get-computed-role>`_ |
| 604 |
* WebDriver command. |
| 605 |
* |
| 606 |
* @param {Element} element |
| 607 |
* @returns {Promise} fulfilled after the computed role is returned, or |
| 608 |
* rejected in the cases the WebDriver command errors |
| 609 |
*/ |
| 610 |
get_computed_role: async function(element) { |
| 611 |
let role = await window.test_driver_internal.get_computed_role(element); |
| 612 |
return role; |
| 613 |
}, |
| 614 |
|
| 615 |
/** |
| 616 |
* Send keys to an element. |
| 617 |
* |
| 618 |
* If ``element`` isn't inside the |
| 619 |
* viewport, it will be scrolled into view before the click |
| 620 |
* occurs. |
| 621 |
* |
| 622 |
* If ``element`` is from a different browsing context, the |
| 623 |
* command will be run in that context. The test must not depend |
| 624 |
* on the ``window.name`` property being unset on the target |
| 625 |
* window. |
| 626 |
* |
| 627 |
* To send special keys, send the respective key's codepoint, |
| 628 |
* as defined by `WebDriver |
| 629 |
* <https://w3c.github.io/webdriver/#keyboard-actions>`_. For |
| 630 |
* example, the "tab" key is represented as "``\uE004``". |
| 631 |
* |
| 632 |
* **Note:** these special-key codepoints are not necessarily |
| 633 |
* what you would expect. For example, <kbd>Esc</kbd> is the |
| 634 |
* invalid Unicode character ``\uE00C``, not the ``\u001B`` Escape |
| 635 |
* character from ASCII. |
| 636 |
* |
| 637 |
* This matches the behaviour of the |
| 638 |
* `Send Keys |
| 639 |
* <https://w3c.github.io/webdriver/#element-send-keys>`_ |
| 640 |
* WebDriver command. |
| 641 |
* |
| 642 |
* **Note:** If the element to be clicked does not have a |
| 643 |
* unique ID, the document must not have any DOM mutations |
| 644 |
* made between the function being called and the promise |
| 645 |
* settling. |
| 646 |
* |
| 647 |
* @param {Element} element - element to send keys to |
| 648 |
* @param {String} keys - keys to send to the element |
| 649 |
* @returns {Promise} fulfilled after keys are sent, or rejected in |
| 650 |
* the cases the WebDriver command errors |
| 651 |
*/ |
| 652 |
send_keys: function(element, keys) { |
| 653 |
if (!inView(element)) { |
| 654 |
element.scrollIntoView({behavior: "instant", |
| 655 |
block: "end", |
| 656 |
inline: "nearest"}); |
| 657 |
} |
| 658 |
|
| 659 |
return window.test_driver_internal.send_keys(element, keys); |
| 660 |
}, |
| 661 |
|
| 662 |
/** |
| 663 |
* Freeze the current page |
| 664 |
* |
| 665 |
* The freeze function transitions the page from the HIDDEN state to |
| 666 |
* the FROZEN state as described in `Lifecycle API for Web Pages |
| 667 |
* <https://github.com/WICG/page-lifecycle/blob/master/README.md>`_. |
| 668 |
* |
| 669 |
* @param {WindowProxy} context - Browsing context in which |
| 670 |
* to run the call, or null for the current |
| 671 |
* browsing context. |
| 672 |
* |
| 673 |
* @returns {Promise} fulfilled after the freeze request is sent, or rejected |
| 674 |
* in case the WebDriver command errors |
| 675 |
*/ |
| 676 |
freeze: function(context=null) { |
| 677 |
return window.test_driver_internal.freeze(); |
| 678 |
}, |
| 679 |
|
| 680 |
/** |
| 681 |
* Minimizes the browser window. |
| 682 |
* |
| 683 |
* Matches the behaviour of the `Minimize |
| 684 |
* <https://www.w3.org/TR/webdriver/#minimize-window>`_ |
| 685 |
* WebDriver command |
| 686 |
* |
| 687 |
* @param {WindowProxy} context - Browsing context in which |
| 688 |
* to run the call, or null for the current |
| 689 |
* browsing context. |
| 690 |
* |
| 691 |
* @returns {Promise} fulfilled with the previous `WindowRect |
| 692 |
* <https://www.w3.org/TR/webdriver/#dfn-windowrect-object>`_ |
| 693 |
* value, after the window is minimized. |
| 694 |
*/ |
| 695 |
minimize_window: function(context=null) { |
| 696 |
return window.test_driver_internal.minimize_window(context); |
| 697 |
}, |
| 698 |
|
| 699 |
/** |
| 700 |
* Restore the window from minimized/maximized state to a given rect. |
| 701 |
* |
| 702 |
* Matches the behaviour of the `Set Window Rect |
| 703 |
* <https://www.w3.org/TR/webdriver/#set-window-rect>`_ |
| 704 |
* WebDriver command |
| 705 |
* |
| 706 |
* @param {Object} rect - A `WindowRect |
| 707 |
* <https://www.w3.org/TR/webdriver/#dfn-windowrect-object>`_ |
| 708 |
* @param {WindowProxy} context - Browsing context in which |
| 709 |
* to run the call, or null for the current |
| 710 |
* browsing context. |
| 711 |
* |
| 712 |
* @returns {Promise} fulfilled after the window is restored to the given rect. |
| 713 |
*/ |
| 714 |
set_window_rect: function(rect, context=null) { |
| 715 |
return window.test_driver_internal.set_window_rect(rect, context); |
| 716 |
}, |
| 717 |
|
| 718 |
/** |
| 719 |
* Gets a rect with the size and position on the screen from the current window state. |
| 720 |
* |
| 721 |
* Matches the behaviour of the `Get Window Rect |
| 722 |
* <https://www.w3.org/TR/webdriver/#get-window-rect>`_ |
| 723 |
* WebDriver command |
| 724 |
* |
| 725 |
* @param {WindowProxy} context - Browsing context in which |
| 726 |
* to run the call, or null for the current |
| 727 |
* browsing context. |
| 728 |
* |
| 729 |
* @returns {Promise} fulfilled after the window rect is returned, or rejected |
| 730 |
* in cases the WebDriver command returns errors. Returns a |
| 731 |
* `WindowRect <https://www.w3.org/TR/webdriver/#dfn-windowrect-object>`_ |
| 732 |
*/ |
| 733 |
get_window_rect: function(context=null) { |
| 734 |
return window.test_driver_internal.get_window_rect(context); |
| 735 |
}, |
| 736 |
|
| 737 |
/** |
| 738 |
* Send a sequence of actions |
| 739 |
* |
| 740 |
* This function sends a sequence of actions to perform. |
| 741 |
* |
| 742 |
* Matches the behaviour of the `Actions |
| 743 |
* <https://w3c.github.io/webdriver/#actions>`_ feature in |
| 744 |
* WebDriver. |
| 745 |
* |
| 746 |
* Authors are encouraged to use the |
| 747 |
* :js:class:`test_driver.Actions` builder rather than |
| 748 |
* invoking this API directly. |
| 749 |
* |
| 750 |
* @param {Array} actions - an array of actions. The format is |
| 751 |
* the same as the actions property |
| 752 |
* of the `Perform Actions |
| 753 |
* <https://w3c.github.io/webdriver/#perform-actions>`_ |
| 754 |
* WebDriver command. Each element is |
| 755 |
* an object representing an input |
| 756 |
* source and each input source |
| 757 |
* itself has an actions property |
| 758 |
* detailing the behaviour of that |
| 759 |
* source at each timestep (or |
| 760 |
* tick). Authors are not expected to |
| 761 |
* construct the actions sequence by |
| 762 |
* hand, but to use the builder api |
| 763 |
* provided in testdriver-actions.js |
| 764 |
* @param {WindowProxy} context - Browsing context in which |
| 765 |
* to run the call, or null for the current |
| 766 |
* browsing context. |
| 767 |
* |
| 768 |
* @returns {Promise} fulfilled after the actions are performed, or rejected in |
| 769 |
* the cases the WebDriver command errors |
| 770 |
*/ |
| 771 |
action_sequence: function(actions, context=null) { |
| 772 |
return window.test_driver_internal.action_sequence(actions, context); |
| 773 |
}, |
| 774 |
|
| 775 |
/** |
| 776 |
* Generates a test report on the current page |
| 777 |
* |
| 778 |
* The generate_test_report function generates a report (to be |
| 779 |
* observed by ReportingObserver) for testing purposes. |
| 780 |
* |
| 781 |
* Matches the `Generate Test Report |
| 782 |
* <https://w3c.github.io/reporting/#generate-test-report-command>`_ |
| 783 |
* WebDriver command. |
| 784 |
* |
| 785 |
* @param {WindowProxy} context - Browsing context in which |
| 786 |
* to run the call, or null for the current |
| 787 |
* browsing context. |
| 788 |
* |
| 789 |
* @returns {Promise} fulfilled after the report is generated, or |
| 790 |
* rejected if the report generation fails |
| 791 |
*/ |
| 792 |
generate_test_report: function(message, context=null) { |
| 793 |
return window.test_driver_internal.generate_test_report(message, context); |
| 794 |
}, |
| 795 |
|
| 796 |
/** |
| 797 |
* Sets the state of a permission |
| 798 |
* |
| 799 |
* This function causes permission requests and queries for the status |
| 800 |
* of a certain permission type (e.g. "push", or "background-fetch") to |
| 801 |
* always return ``state``. |
| 802 |
* |
| 803 |
* Matches the `Set Permission |
| 804 |
* <https://w3c.github.io/permissions/#set-permission-command>`_ |
| 805 |
* WebDriver command. |
| 806 |
* |
| 807 |
* @example |
| 808 |
* await test_driver.set_permission({ name: "background-fetch" }, "denied"); |
| 809 |
* await test_driver.set_permission({ name: "push", userVisibleOnly: true }, "granted"); |
| 810 |
* |
| 811 |
* @param {PermissionDescriptor} descriptor - a `PermissionDescriptor |
| 812 |
* <https://w3c.github.io/permissions/#dom-permissiondescriptor>`_ |
| 813 |
* or derived object. |
| 814 |
* @param {PermissionState} state - a `PermissionState |
| 815 |
* <https://w3c.github.io/permissions/#dom-permissionstate>`_ |
| 816 |
* value. |
| 817 |
* @param {WindowProxy} context - Browsing context in which |
| 818 |
* to run the call, or null for the current |
| 819 |
* browsing context. |
| 820 |
* @returns {Promise} fulfilled after the permission is set, or rejected if setting the |
| 821 |
* permission fails |
| 822 |
*/ |
| 823 |
set_permission: function(descriptor, state, context=null) { |
| 824 |
let permission_params = { |
| 825 |
descriptor, |
| 826 |
state, |
| 827 |
}; |
| 828 |
return window.test_driver_internal.set_permission(permission_params, context); |
| 829 |
}, |
| 830 |
|
| 831 |
/** |
| 832 |
* Creates a virtual authenticator |
| 833 |
* |
| 834 |
* This function creates a virtual authenticator for use with |
| 835 |
* the U2F and WebAuthn APIs. |
| 836 |
* |
| 837 |
* Matches the `Add Virtual Authenticator |
| 838 |
* <https://w3c.github.io/webauthn/#sctn-automation-add-virtual-authenticator>`_ |
| 839 |
* WebDriver command. |
| 840 |
* |
| 841 |
* @param {Object} config - an `Authenticator Configuration |
| 842 |
* <https://w3c.github.io/webauthn/#authenticator-configuration>`_ |
| 843 |
* object |
| 844 |
* @param {WindowProxy} context - Browsing context in which |
| 845 |
* to run the call, or null for the current |
| 846 |
* browsing context. |
| 847 |
* |
| 848 |
* @returns {Promise} fulfilled after the authenticator is added, or |
| 849 |
* rejected in the cases the WebDriver command |
| 850 |
* errors. Returns the ID of the authenticator |
| 851 |
*/ |
| 852 |
add_virtual_authenticator: function(config, context=null) { |
| 853 |
return window.test_driver_internal.add_virtual_authenticator(config, context); |
| 854 |
}, |
| 855 |
|
| 856 |
/** |
| 857 |
* Removes a virtual authenticator |
| 858 |
* |
| 859 |
* This function removes a virtual authenticator that has been |
| 860 |
* created by :js:func:`add_virtual_authenticator`. |
| 861 |
* |
| 862 |
* Matches the `Remove Virtual Authenticator |
| 863 |
* <https://w3c.github.io/webauthn/#sctn-automation-remove-virtual-authenticator>`_ |
| 864 |
* WebDriver command. |
| 865 |
* |
| 866 |
* @param {String} authenticator_id - the ID of the authenticator to be |
| 867 |
* removed. |
| 868 |
* @param {WindowProxy} context - Browsing context in which |
| 869 |
* to run the call, or null for the current |
| 870 |
* browsing context. |
| 871 |
* |
| 872 |
* @returns {Promise} fulfilled after the authenticator is removed, or |
| 873 |
* rejected in the cases the WebDriver command |
| 874 |
* errors |
| 875 |
*/ |
| 876 |
remove_virtual_authenticator: function(authenticator_id, context=null) { |
| 877 |
return window.test_driver_internal.remove_virtual_authenticator(authenticator_id, context); |
| 878 |
}, |
| 879 |
|
| 880 |
/** |
| 881 |
* Adds a credential to a virtual authenticator |
| 882 |
* |
| 883 |
* Matches the `Add Credential |
| 884 |
* <https://w3c.github.io/webauthn/#sctn-automation-add-credential>`_ |
| 885 |
* WebDriver command. |
| 886 |
* |
| 887 |
* @param {String} authenticator_id - the ID of the authenticator |
| 888 |
* @param {Object} credential - A `Credential Parameters |
| 889 |
* <https://w3c.github.io/webauthn/#credential-parameters>`_ |
| 890 |
* object |
| 891 |
* @param {WindowProxy} context - Browsing context in which |
| 892 |
* to run the call, or null for the current |
| 893 |
* browsing context. |
| 894 |
* |
| 895 |
* @returns {Promise} fulfilled after the credential is added, or |
| 896 |
* rejected in the cases the WebDriver command |
| 897 |
* errors |
| 898 |
*/ |
| 899 |
add_credential: function(authenticator_id, credential, context=null) { |
| 900 |
return window.test_driver_internal.add_credential(authenticator_id, credential, context); |
| 901 |
}, |
| 902 |
|
| 903 |
/** |
| 904 |
* Gets all the credentials stored in an authenticator |
| 905 |
* |
| 906 |
* This function retrieves all the credentials (added via the U2F API, |
| 907 |
* WebAuthn, or the add_credential function) stored in a virtual |
| 908 |
* authenticator |
| 909 |
* |
| 910 |
* Matches the `Get Credentials |
| 911 |
* <https://w3c.github.io/webauthn/#sctn-automation-get-credentials>`_ |
| 912 |
* WebDriver command. |
| 913 |
* |
| 914 |
* @param {String} authenticator_id - the ID of the authenticator |
| 915 |
* @param {WindowProxy} context - Browsing context in which |
| 916 |
* to run the call, or null for the current |
| 917 |
* browsing context. |
| 918 |
* |
| 919 |
* @returns {Promise} fulfilled after the credentials are |
| 920 |
* returned, or rejected in the cases the |
| 921 |
* WebDriver command errors. Returns an |
| 922 |
* array of `Credential Parameters |
| 923 |
* <https://w3c.github.io/webauthn/#credential-parameters>`_ |
| 924 |
*/ |
| 925 |
get_credentials: function(authenticator_id, context=null) { |
| 926 |
return window.test_driver_internal.get_credentials(authenticator_id, context=null); |
| 927 |
}, |
| 928 |
|
| 929 |
/** |
| 930 |
* Remove a credential stored in an authenticator |
| 931 |
* |
| 932 |
* Matches the `Remove Credential |
| 933 |
* <https://w3c.github.io/webauthn/#sctn-automation-remove-credential>`_ |
| 934 |
* WebDriver command. |
| 935 |
* |
| 936 |
* @param {String} authenticator_id - the ID of the authenticator |
| 937 |
* @param {String} credential_id - the ID of the credential |
| 938 |
* @param {WindowProxy} context - Browsing context in which |
| 939 |
* to run the call, or null for the current |
| 940 |
* browsing context. |
| 941 |
* |
| 942 |
* @returns {Promise} fulfilled after the credential is removed, or |
| 943 |
* rejected in the cases the WebDriver command |
| 944 |
* errors. |
| 945 |
*/ |
| 946 |
remove_credential: function(authenticator_id, credential_id, context=null) { |
| 947 |
return window.test_driver_internal.remove_credential(authenticator_id, credential_id, context); |
| 948 |
}, |
| 949 |
|
| 950 |
/** |
| 951 |
* Removes all the credentials stored in a virtual authenticator |
| 952 |
* |
| 953 |
* Matches the `Remove All Credentials |
| 954 |
* <https://w3c.github.io/webauthn/#sctn-automation-remove-all-credentials>`_ |
| 955 |
* WebDriver command. |
| 956 |
* |
| 957 |
* @param {String} authenticator_id - the ID of the authenticator |
| 958 |
* @param {WindowProxy} context - Browsing context in which |
| 959 |
* to run the call, or null for the current |
| 960 |
* browsing context. |
| 961 |
* |
| 962 |
* @returns {Promise} fulfilled after the credentials are removed, or |
| 963 |
* rejected in the cases the WebDriver command |
| 964 |
* errors. |
| 965 |
*/ |
| 966 |
remove_all_credentials: function(authenticator_id, context=null) { |
| 967 |
return window.test_driver_internal.remove_all_credentials(authenticator_id, context); |
| 968 |
}, |
| 969 |
|
| 970 |
/** |
| 971 |
* Sets the User Verified flag on an authenticator |
| 972 |
* |
| 973 |
* Sets whether requests requiring user verification will succeed or |
| 974 |
* fail on a given virtual authenticator |
| 975 |
* |
| 976 |
* Matches the `Set User Verified |
| 977 |
* <https://w3c.github.io/webauthn/#sctn-automation-set-user-verified>`_ |
| 978 |
* WebDriver command. |
| 979 |
* |
| 980 |
* @param {String} authenticator_id - the ID of the authenticator |
| 981 |
* @param {boolean} uv - the User Verified flag |
| 982 |
* @param {WindowProxy} context - Browsing context in which |
| 983 |
* to run the call, or null for the current |
| 984 |
* browsing context. |
| 985 |
*/ |
| 986 |
set_user_verified: function(authenticator_id, uv, context=null) { |
| 987 |
return window.test_driver_internal.set_user_verified(authenticator_id, uv, context); |
| 988 |
}, |
| 989 |
|
| 990 |
/** |
| 991 |
* Sets the storage access rule for an origin when embedded |
| 992 |
* in a third-party context. |
| 993 |
* |
| 994 |
* Matches the `Set Storage Access |
| 995 |
* <https://privacycg.github.io/storage-access/#set-storage-access-command>`_ |
| 996 |
* WebDriver command. |
| 997 |
* |
| 998 |
* @param {String} origin - A third-party origin to block or allow. |
| 999 |
* May be "*" to indicate all origins. |
| 1000 |
* @param {String} embedding_origin - an embedding (first-party) origin |
| 1001 |
* on which {origin}'s access should |
| 1002 |
* be blocked or allowed. |
| 1003 |
* May be "*" to indicate all origins. |
| 1004 |
* @param {String} state - The storage access setting. |
| 1005 |
* Must be either "allowed" or "blocked". |
| 1006 |
* @param {WindowProxy} context - Browsing context in which |
| 1007 |
* to run the call, or null for the current |
| 1008 |
* browsing context. |
| 1009 |
* |
| 1010 |
* @returns {Promise} Fulfilled after the storage access rule has been |
| 1011 |
* set, or rejected if setting the rule fails. |
| 1012 |
*/ |
| 1013 |
set_storage_access: function(origin, embedding_origin, state, context=null) { |
| 1014 |
if (state !== "allowed" && state !== "blocked") { |
| 1015 |
throw new Error("storage access status must be 'allowed' or 'blocked'"); |
| 1016 |
} |
| 1017 |
const blocked = state === "blocked"; |
| 1018 |
return window.test_driver_internal.set_storage_access(origin, embedding_origin, blocked, context); |
| 1019 |
}, |
| 1020 |
|
| 1021 |
/** |
| 1022 |
* Sets the current transaction automation mode for Secure Payment |
| 1023 |
* Confirmation. |
| 1024 |
* |
| 1025 |
* This function places `Secure Payment |
| 1026 |
* Confirmation <https://w3c.github.io/secure-payment-confirmation>`_ into |
| 1027 |
* an automated 'autoAccept' or 'autoReject' mode, to allow testing |
| 1028 |
* without user interaction with the transaction UX prompt. |
| 1029 |
* |
| 1030 |
* Matches the `Set SPC Transaction Mode |
| 1031 |
* <https://w3c.github.io/secure-payment-confirmation/#sctn-automation-set-spc-transaction-mode>`_ |
| 1032 |
* WebDriver command. |
| 1033 |
* |
| 1034 |
* @example |
| 1035 |
* await test_driver.set_spc_transaction_mode("autoaccept"); |
| 1036 |
* test.add_cleanup(() => { |
| 1037 |
* return test_driver.set_spc_transaction_mode("none"); |
| 1038 |
* }); |
| 1039 |
* |
| 1040 |
* // Assumption: `request` is a PaymentRequest with a secure-payment-confirmation |
| 1041 |
* // payment method. |
| 1042 |
* const response = await request.show(); |
| 1043 |
* |
| 1044 |
* @param {String} mode - The `transaction mode |
| 1045 |
* <https://w3c.github.io/secure-payment-confirmation/#enumdef-transactionautomationmode>`_ |
| 1046 |
* to set. Must be one of "``none``", |
| 1047 |
* "``autoAccept``", or |
| 1048 |
* "``autoReject``". |
| 1049 |
* @param {WindowProxy} context - Browsing context in which |
| 1050 |
* to run the call, or null for the current |
| 1051 |
* browsing context. |
| 1052 |
* |
| 1053 |
* @returns {Promise} Fulfilled after the transaction mode has been set, |
| 1054 |
* or rejected if setting the mode fails. |
| 1055 |
*/ |
| 1056 |
set_spc_transaction_mode: function(mode, context=null) { |
| 1057 |
return window.test_driver_internal.set_spc_transaction_mode(mode, context); |
| 1058 |
}, |
| 1059 |
|
| 1060 |
/** |
| 1061 |
* Sets the current registration automation mode for Register Protocol Handlers. |
| 1062 |
* |
| 1063 |
* This function places `Register Protocol Handlers |
| 1064 |
* <https://html.spec.whatwg.org/multipage/system-state.html#custom-handlers>`_ into |
| 1065 |
* an automated 'autoAccept' or 'autoReject' mode, to allow testing |
| 1066 |
* without user interaction with the transaction UX prompt. |
| 1067 |
* |
| 1068 |
* Matches the `Set Register Protocol Handler Mode |
| 1069 |
* <https://html.spec.whatwg.org/multipage/system-state.html#set-rph-registration-mode>`_ |
| 1070 |
* WebDriver command. |
| 1071 |
* |
| 1072 |
* @example |
| 1073 |
* await test_driver.set_rph_registration_mode("autoAccept"); |
| 1074 |
* test.add_cleanup(() => { |
| 1075 |
* return test_driver.set_rph_registration_mode("none"); |
| 1076 |
* }); |
| 1077 |
* |
| 1078 |
* navigator.registerProtocolHandler('web+soup', 'soup?url=%s'); |
| 1079 |
* |
| 1080 |
* @param {String} mode - The `registration mode |
| 1081 |
* <https://html.spec.whatwg.org/multipage/system-state.html#registerprotocolhandler()-automation-mode>`_ |
| 1082 |
* to set. Must be one of "``none``", |
| 1083 |
* "``autoAccept``", or |
| 1084 |
* "``autoReject``". |
| 1085 |
* @param {WindowProxy} context - Browsing context in which |
| 1086 |
* to run the call, or null for the current |
| 1087 |
* browsing context. |
| 1088 |
* |
| 1089 |
* @returns {Promise} Fulfilled after the transaction mode has been set, |
| 1090 |
* or rejected if setting the mode fails. |
| 1091 |
*/ |
| 1092 |
set_rph_registration_mode: function(mode, context=null) { |
| 1093 |
return window.test_driver_internal.set_rph_registration_mode(mode, context); |
| 1094 |
}, |
| 1095 |
|
| 1096 |
/** |
| 1097 |
* Cancels the Federated Credential Management dialog |
| 1098 |
* |
| 1099 |
* Matches the `Cancel dialog |
| 1100 |
* <https://fedidcg.github.io/FedCM/#webdriver-canceldialog>`_ |
| 1101 |
* WebDriver command. |
| 1102 |
* |
| 1103 |
* @param {WindowProxy} context - Browsing context in which |
| 1104 |
* to run the call, or null for the current |
| 1105 |
* browsing context. |
| 1106 |
* |
| 1107 |
* @returns {Promise} Fulfilled after the dialog is canceled, or rejected |
| 1108 |
* in case the WebDriver command errors |
| 1109 |
*/ |
| 1110 |
cancel_fedcm_dialog: function(context=null) { |
| 1111 |
return window.test_driver_internal.cancel_fedcm_dialog(context); |
| 1112 |
}, |
| 1113 |
|
| 1114 |
/** |
| 1115 |
* Clicks a button on the Federated Credential Management dialog |
| 1116 |
* |
| 1117 |
* Matches the `Click dialog button |
| 1118 |
* <https://fedidcg.github.io/FedCM/#webdriver-clickdialogbutton>`_ |
| 1119 |
* WebDriver command. |
| 1120 |
* |
| 1121 |
* @param {String} dialog_button - String enum representing the dialog button to click. |
| 1122 |
* @param {WindowProxy} context - Browsing context in which |
| 1123 |
* to run the call, or null for the current |
| 1124 |
* browsing context. |
| 1125 |
* |
| 1126 |
* @returns {Promise} Fulfilled after the button is clicked, |
| 1127 |
* or rejected in case the WebDriver command errors |
| 1128 |
*/ |
| 1129 |
click_fedcm_dialog_button: function(dialog_button, context=null) { |
| 1130 |
return window.test_driver_internal.click_fedcm_dialog_button(dialog_button, context); |
| 1131 |
}, |
| 1132 |
|
| 1133 |
/** |
| 1134 |
* Selects an account from the Federated Credential Management dialog |
| 1135 |
* |
| 1136 |
* Matches the `Select account |
| 1137 |
* <https://fedidcg.github.io/FedCM/#webdriver-selectaccount>`_ |
| 1138 |
* WebDriver command. |
| 1139 |
* |
| 1140 |
* @param {number} account_index - Index of the account to select. |
| 1141 |
* @param {WindowProxy} context - Browsing context in which |
| 1142 |
* to run the call, or null for the current |
| 1143 |
* browsing context. |
| 1144 |
* |
| 1145 |
* @returns {Promise} Fulfilled after the account is selected, |
| 1146 |
* or rejected in case the WebDriver command errors |
| 1147 |
*/ |
| 1148 |
select_fedcm_account: function(account_index, context=null) { |
| 1149 |
return window.test_driver_internal.select_fedcm_account(account_index, context); |
| 1150 |
}, |
| 1151 |
|
| 1152 |
/** |
| 1153 |
* Gets the account list from the Federated Credential Management dialog |
| 1154 |
* |
| 1155 |
* Matches the `Account list |
| 1156 |
* <https://fedidcg.github.io/FedCM/#webdriver-accountlist>`_ |
| 1157 |
* WebDriver command. |
| 1158 |
* |
| 1159 |
* @param {WindowProxy} context - Browsing context in which |
| 1160 |
* to run the call, or null for the current |
| 1161 |
* browsing context. |
| 1162 |
* |
| 1163 |
* @returns {Promise} fulfilled after the account list is returned, or |
| 1164 |
* rejected in case the WebDriver command errors |
| 1165 |
*/ |
| 1166 |
get_fedcm_account_list: function(context=null) { |
| 1167 |
return window.test_driver_internal.get_fedcm_account_list(context); |
| 1168 |
}, |
| 1169 |
|
| 1170 |
/** |
| 1171 |
* Gets the title of the Federated Credential Management dialog |
| 1172 |
* |
| 1173 |
* Matches the `Get title |
| 1174 |
* <https://fedidcg.github.io/FedCM/#webdriver-gettitle>`_ |
| 1175 |
* WebDriver command. |
| 1176 |
* |
| 1177 |
* @param {WindowProxy} context - Browsing context in which |
| 1178 |
* to run the call, or null for the current |
| 1179 |
* browsing context. |
| 1180 |
* |
| 1181 |
* @returns {Promise} Fulfilled after the title is returned, or rejected |
| 1182 |
* in case the WebDriver command errors |
| 1183 |
*/ |
| 1184 |
get_fedcm_dialog_title: function(context=null) { |
| 1185 |
return window.test_driver_internal.get_fedcm_dialog_title(context); |
| 1186 |
}, |
| 1187 |
|
| 1188 |
/** |
| 1189 |
* Gets the type of the Federated Credential Management dialog |
| 1190 |
* |
| 1191 |
* Matches the `Get dialog type |
| 1192 |
* <https://fedidcg.github.io/FedCM/#webdriver-getdialogtype>`_ |
| 1193 |
* WebDriver command. |
| 1194 |
* |
| 1195 |
* @param {WindowProxy} context - Browsing context in which |
| 1196 |
* to run the call, or null for the current |
| 1197 |
* browsing context. |
| 1198 |
* |
| 1199 |
* @returns {Promise} Fulfilled after the dialog type is returned, or |
| 1200 |
* rejected in case the WebDriver command errors |
| 1201 |
*/ |
| 1202 |
get_fedcm_dialog_type: function(context=null) { |
| 1203 |
return window.test_driver_internal.get_fedcm_dialog_type(context); |
| 1204 |
}, |
| 1205 |
|
| 1206 |
/** |
| 1207 |
* Sets whether promise rejection delay is enabled for the Federated Credential Management dialog |
| 1208 |
* |
| 1209 |
* Matches the `Set delay enabled |
| 1210 |
* <https://fedidcg.github.io/FedCM/#webdriver-setdelayenabled>`_ |
| 1211 |
* WebDriver command. |
| 1212 |
* |
| 1213 |
* @param {boolean} enabled - Whether to delay FedCM promise rejection. |
| 1214 |
* @param {WindowProxy} context - Browsing context in which |
| 1215 |
* to run the call, or null for the current |
| 1216 |
* browsing context. |
| 1217 |
* |
| 1218 |
* @returns {Promise} Fulfilled after the delay has been enabled or disabled, |
| 1219 |
* or rejected in case the WebDriver command errors |
| 1220 |
*/ |
| 1221 |
set_fedcm_delay_enabled: function(enabled, context=null) { |
| 1222 |
return window.test_driver_internal.set_fedcm_delay_enabled(enabled, context); |
| 1223 |
}, |
| 1224 |
|
| 1225 |
/** |
| 1226 |
* Resets the Federated Credential Management dialog's cooldown |
| 1227 |
* |
| 1228 |
* Matches the `Reset cooldown |
| 1229 |
* <https://fedidcg.github.io/FedCM/#webdriver-resetcooldown>`_ |
| 1230 |
* WebDriver command. |
| 1231 |
* |
| 1232 |
* @param {WindowProxy} context - Browsing context in which |
| 1233 |
* to run the call, or null for the current |
| 1234 |
* browsing context. |
| 1235 |
* |
| 1236 |
* @returns {Promise} Fulfilled after the cooldown has been reset, |
| 1237 |
* or rejected in case the WebDriver command errors |
| 1238 |
*/ |
| 1239 |
reset_fedcm_cooldown: function(context=null) { |
| 1240 |
return window.test_driver_internal.reset_fedcm_cooldown(context); |
| 1241 |
}, |
| 1242 |
|
| 1243 |
/** |
| 1244 |
* Creates a virtual sensor for use with the Generic Sensors APIs. |
| 1245 |
* |
| 1246 |
* Matches the `Create Virtual Sensor |
| 1247 |
* <https://w3c.github.io/sensors/#create-virtual-sensor-command>`_ |
| 1248 |
* WebDriver command. |
| 1249 |
* |
| 1250 |
* Once created, a virtual sensor is available to all navigables under |
| 1251 |
* the same top-level traversable (i.e. all frames in the same page, |
| 1252 |
* regardless of origin). |
| 1253 |
* |
| 1254 |
* @param {String} sensor_type - A `virtual sensor type |
| 1255 |
* <https://w3c.github.io/sensors/#virtual-sensor-metadata-virtual-sensor-type>`_ |
| 1256 |
* such as "accelerometer". |
| 1257 |
* @param {Object} [sensor_params={}] - Optional parameters described |
| 1258 |
* in `Create Virtual Sensor |
| 1259 |
* <https://w3c.github.io/sensors/#create-virtual-sensor-command>`_. |
| 1260 |
* @param {WindowProxy} [context=null] - Browsing context in which to |
| 1261 |
* run the call, or null for the |
| 1262 |
* current browsing context. |
| 1263 |
* |
| 1264 |
* @returns {Promise} Fulfilled when virtual sensor is created. |
| 1265 |
* Rejected in case the WebDriver command errors out |
| 1266 |
* (including if a virtual sensor of the same type |
| 1267 |
* already exists). |
| 1268 |
*/ |
| 1269 |
create_virtual_sensor: function(sensor_type, sensor_params={}, context=null) { |
| 1270 |
return window.test_driver_internal.create_virtual_sensor(sensor_type, sensor_params, context); |
| 1271 |
}, |
| 1272 |
|
| 1273 |
/** |
| 1274 |
* Causes a virtual sensor to report a new reading to any connected |
| 1275 |
* platform sensor. |
| 1276 |
* |
| 1277 |
* Matches the `Update Virtual Sensor Reading |
| 1278 |
* <https://w3c.github.io/sensors/#update-virtual-sensor-reading-command>`_ |
| 1279 |
* WebDriver command. |
| 1280 |
* |
| 1281 |
* Note: The ``Promise`` it returns may fulfill before or after a |
| 1282 |
* "reading" event is fired. When using |
| 1283 |
* :js:func:`EventWatcher.wait_for`, it is necessary to take this into |
| 1284 |
* account: |
| 1285 |
* |
| 1286 |
* Note: New values may also be discarded due to the checks in `update |
| 1287 |
* latest reading |
| 1288 |
* <https://w3c.github.io/sensors/#update-latest-reading>`_. |
| 1289 |
* |
| 1290 |
* @example |
| 1291 |
* // Avoid races between EventWatcher and update_virtual_sensor(). |
| 1292 |
* // This assumes you are sure this reading will be processed (see |
| 1293 |
* // the example below otherwise). |
| 1294 |
* const reading = { x: 1, y: 2, z: 3 }; |
| 1295 |
* await Promise.all([ |
| 1296 |
* test_driver.update_virtual_sensor('gyroscope', reading), |
| 1297 |
* watcher.wait_for('reading') |
| 1298 |
* ]); |
| 1299 |
* |
| 1300 |
* @example |
| 1301 |
* // Do not wait forever if you are not sure the reading will be |
| 1302 |
* // processed. |
| 1303 |
* const readingPromise = watcher.wait_for('reading'); |
| 1304 |
* const timeoutPromise = new Promise(resolve => { |
| 1305 |
* t.step_timeout(() => resolve('TIMEOUT', 3000)) |
| 1306 |
* }); |
| 1307 |
* |
| 1308 |
* const reading = { x: 1, y: 2, z: 3 }; |
| 1309 |
* await test_driver.update_virtual_sensor('gyroscope', 'reading'); |
| 1310 |
* |
| 1311 |
* const value = |
| 1312 |
* await Promise.race([timeoutPromise, readingPromise]); |
| 1313 |
* if (value !== 'TIMEOUT') { |
| 1314 |
* // Do something. The "reading" event was fired. |
| 1315 |
* } |
| 1316 |
* |
| 1317 |
* @param {String} sensor_type - A `virtual sensor type |
| 1318 |
* <https://w3c.github.io/sensors/#virtual-sensor-metadata-virtual-sensor-type>`_ |
| 1319 |
* such as "accelerometer". |
| 1320 |
* @param {Object} reading - An Object describing a reading in a format |
| 1321 |
* dependent on ``sensor_type`` (e.g. ``{x: |
| 1322 |
* 1, y: 2, z: 3}`` or ``{ illuminance: 42 |
| 1323 |
* }``). |
| 1324 |
* @param {WindowProxy} [context=null] - Browsing context in which to |
| 1325 |
* run the call, or null for the |
| 1326 |
* current browsing context. |
| 1327 |
* |
| 1328 |
* @returns {Promise} Fulfilled after the reading update reaches the |
| 1329 |
* virtual sensor. Rejected in case the WebDriver |
| 1330 |
* command errors out (including if a virtual sensor |
| 1331 |
* of the given type does not exist). |
| 1332 |
*/ |
| 1333 |
update_virtual_sensor: function(sensor_type, reading, context=null) { |
| 1334 |
return window.test_driver_internal.update_virtual_sensor(sensor_type, reading, context); |
| 1335 |
}, |
| 1336 |
|
| 1337 |
/** |
| 1338 |
* Triggers the removal of a virtual sensor if it exists. |
| 1339 |
* |
| 1340 |
* Matches the `Delete Virtual Sensor |
| 1341 |
* <https://w3c.github.io/sensors/#delete-virtual-sensor-command>`_ |
| 1342 |
* WebDriver command. |
| 1343 |
* |
| 1344 |
* @param {String} sensor_type - A `virtual sensor type |
| 1345 |
* <https://w3c.github.io/sensors/#virtual-sensor-metadata-virtual-sensor-type>`_ |
| 1346 |
* such as "accelerometer". |
| 1347 |
* @param {WindowProxy} [context=null] - Browsing context in which to |
| 1348 |
* run the call, or null for the |
| 1349 |
* current browsing context. |
| 1350 |
* |
| 1351 |
* @returns {Promise} Fulfilled after the virtual sensor has been |
| 1352 |
* removed or if a sensor of the given type does not |
| 1353 |
* exist. Rejected in case the WebDriver command |
| 1354 |
* errors out. |
| 1355 |
|
| 1356 |
*/ |
| 1357 |
remove_virtual_sensor: function(sensor_type, context=null) { |
| 1358 |
return window.test_driver_internal.remove_virtual_sensor(sensor_type, context); |
| 1359 |
}, |
| 1360 |
|
| 1361 |
/** |
| 1362 |
* Returns information about a virtual sensor. |
| 1363 |
* |
| 1364 |
* Matches the `Get Virtual Sensor Information |
| 1365 |
* <https://w3c.github.io/sensors/#get-virtual-sensor-information-command>`_ |
| 1366 |
* WebDriver command. |
| 1367 |
* |
| 1368 |
* @param {String} sensor_type - A `virtual sensor type |
| 1369 |
* <https://w3c.github.io/sensors/#virtual-sensor-metadata-virtual-sensor-type>`_ |
| 1370 |
* such as "accelerometer". |
| 1371 |
* @param {WindowProxy} [context=null] - Browsing context in which to |
| 1372 |
* run the call, or null for the |
| 1373 |
* current browsing context. |
| 1374 |
* |
| 1375 |
* @returns {Promise} Fulfilled with an Object with the properties |
| 1376 |
* described in `Get Virtual Sensor Information |
| 1377 |
* <https://w3c.github.io/sensors/#get-virtual-sensor-information-command>`_. |
| 1378 |
* Rejected in case the WebDriver command errors out |
| 1379 |
* (including if a virtual sensor of the given type |
| 1380 |
* does not exist). |
| 1381 |
*/ |
| 1382 |
get_virtual_sensor_information: function(sensor_type, context=null) { |
| 1383 |
return window.test_driver_internal.get_virtual_sensor_information(sensor_type, context); |
| 1384 |
}, |
| 1385 |
|
| 1386 |
/** |
| 1387 |
* Overrides device posture set by hardware. |
| 1388 |
* |
| 1389 |
* Matches the `Set device posture |
| 1390 |
* <https://w3c.github.io/device-posture/#set-device-posture>`_ |
| 1391 |
* WebDriver command. |
| 1392 |
* |
| 1393 |
* @param {String} posture - A `DevicePostureType |
| 1394 |
* <https://w3c.github.io/device-posture/#dom-deviceposturetype>`_ |
| 1395 |
* either "continuous" or "folded". |
| 1396 |
* @param {WindowProxy} [context=null] - Browsing context in which to |
| 1397 |
* run the call, or null for the |
| 1398 |
* current browsing context. |
| 1399 |
* |
| 1400 |
* @returns {Promise} Fulfilled when device posture is set. |
| 1401 |
* Rejected in case the WebDriver command errors out |
| 1402 |
* (including if a device posture of the given type |
| 1403 |
* does not exist). |
| 1404 |
*/ |
| 1405 |
set_device_posture: function(posture, context=null) { |
| 1406 |
return window.test_driver_internal.set_device_posture(posture, context); |
| 1407 |
}, |
| 1408 |
|
| 1409 |
/** |
| 1410 |
* Removes device posture override and returns device posture control |
| 1411 |
* back to hardware. |
| 1412 |
* |
| 1413 |
* Matches the `Clear device posture |
| 1414 |
* <https://w3c.github.io/device-posture/#clear-device-posture>`_ |
| 1415 |
* WebDriver command. |
| 1416 |
* |
| 1417 |
* @param {WindowProxy} [context=null] - Browsing context in which to |
| 1418 |
* run the call, or null for the |
| 1419 |
* current browsing context. |
| 1420 |
* |
| 1421 |
* @returns {Promise} Fulfilled after the device posture override has |
| 1422 |
* been removed. Rejected in case the WebDriver |
| 1423 |
* command errors out. |
| 1424 |
*/ |
| 1425 |
clear_device_posture: function(context=null) { |
| 1426 |
return window.test_driver_internal.clear_device_posture(context); |
| 1427 |
}, |
| 1428 |
|
| 1429 |
/** |
| 1430 |
* Runs the `bounce tracking timer algorithm |
| 1431 |
* <https://privacycg.github.io/nav-tracking-mitigations/#bounce-tracking-timer>`_, |
| 1432 |
* which removes all hosts from the stateful bounce tracking map, without |
| 1433 |
* regard for the bounce tracking grace period and returns a list of the |
| 1434 |
* deleted hosts. |
| 1435 |
* |
| 1436 |
* Matches the `Run Bounce Tracking Mitigations |
| 1437 |
* <https://privacycg.github.io/nav-tracking-mitigations/#run-bounce-tracking-mitigations-command>`_ |
| 1438 |
* WebDriver command. |
| 1439 |
* |
| 1440 |
* @param {WindowProxy} [context=null] - Browsing context in which to |
| 1441 |
* run the call, or null for the |
| 1442 |
* current browsing context. |
| 1443 |
* @returns {Promise} Fulfilled after the bounce tracking timer |
| 1444 |
* algorithm has finished running. Returns an array |
| 1445 |
* of all hosts that were in the stateful bounce |
| 1446 |
* tracking map before deletion occurred. |
| 1447 |
*/ |
| 1448 |
run_bounce_tracking_mitigations: function (context = null) { |
| 1449 |
return window.test_driver_internal.run_bounce_tracking_mitigations(context); |
| 1450 |
}, |
| 1451 |
|
| 1452 |
/** |
| 1453 |
* Creates a virtual pressure source. |
| 1454 |
* |
| 1455 |
* Matches the `Create virtual pressure source |
| 1456 |
* <https://w3c.github.io/compute-pressure/#create-virtual-pressure-source>`_ |
| 1457 |
* WebDriver command. |
| 1458 |
* |
| 1459 |
* @param {String} source_type - A `virtual pressure source type |
| 1460 |
* <https://w3c.github.io/compute-pressure/#dom-pressuresource>`_ |
| 1461 |
* such as "cpu". |
| 1462 |
* @param {Object} [metadata={}] - Optional parameters described |
| 1463 |
* in `Create virtual pressure source |
| 1464 |
* <https://w3c.github.io/compute-pressure/#create-virtual-pressure-source>`_. |
| 1465 |
* @param {WindowProxy} [context=null] - Browsing context in which to |
| 1466 |
* run the call, or null for the |
| 1467 |
* current browsing context. |
| 1468 |
* |
| 1469 |
* @returns {Promise} Fulfilled when virtual pressure source is created. |
| 1470 |
* Rejected in case the WebDriver command errors out |
| 1471 |
* (including if a virtual pressure source of the |
| 1472 |
* same type already exists). |
| 1473 |
*/ |
| 1474 |
create_virtual_pressure_source: function(source_type, metadata={}, context=null) { |
| 1475 |
return window.test_driver_internal.create_virtual_pressure_source(source_type, metadata, context); |
| 1476 |
}, |
| 1477 |
|
| 1478 |
/** |
| 1479 |
* Causes a virtual pressure source to report a new reading. |
| 1480 |
* |
| 1481 |
* Matches the `Update virtual pressure source |
| 1482 |
* <https://w3c.github.io/compute-pressure/?experimental=1#update-virtual-pressure-source>`_ |
| 1483 |
* WebDriver command. |
| 1484 |
* |
| 1485 |
* @param {String} source_type - A `virtual pressure source type |
| 1486 |
* <https://w3c.github.io/compute-pressure/#dom-pressuresource>`_ |
| 1487 |
* such as "cpu". |
| 1488 |
* @param {String} sample - A `virtual pressure state |
| 1489 |
* <https://w3c.github.io/compute-pressure/#dom-pressurestate>`_ |
| 1490 |
* such as "critical". |
| 1491 |
* @param {number} own_contribution_estimate - Optional, A `virtual own contribution estimate` |
| 1492 |
* <https://w3c.github.io/compute-pressure/?experimental=1#the-owncontributionestimate-attribute>`_ |
| 1493 |
* @param {WindowProxy} [context=null] - Browsing context in which to |
| 1494 |
* run the call, or null for the |
| 1495 |
* current browsing context. |
| 1496 |
* |
| 1497 |
* @returns {Promise} Fulfilled after the reading update reaches the |
| 1498 |
* virtual pressure source. Rejected in case the |
| 1499 |
* WebDriver command errors out (including if a |
| 1500 |
* virtual pressure source of the given type does not |
| 1501 |
* exist). |
| 1502 |
*/ |
| 1503 |
update_virtual_pressure_source: function(source_type, sample, own_contribution_estimate, context=null) { |
| 1504 |
return window.test_driver_internal.update_virtual_pressure_source(source_type, sample, own_contribution_estimate, context); |
| 1505 |
}, |
| 1506 |
|
| 1507 |
/** |
| 1508 |
* Removes created virtual pressure source. |
| 1509 |
* |
| 1510 |
* Matches the `Delete virtual pressure source |
| 1511 |
* <https://w3c.github.io/compute-pressure/#delete-virtual-pressure-source>`_ |
| 1512 |
* WebDriver command. |
| 1513 |
* |
| 1514 |
* @param {String} source_type - A `virtual pressure source type |
| 1515 |
* <https://w3c.github.io/compute-pressure/#dom-pressuresource>`_ |
| 1516 |
* such as "cpu". |
| 1517 |
* @param {WindowProxy} [context=null] - Browsing context in which to |
| 1518 |
* run the call, or null for the |
| 1519 |
* current browsing context. |
| 1520 |
* |
| 1521 |
* @returns {Promise} Fulfilled after the virtual pressure source has |
| 1522 |
* been removed or if a pressure source of the given |
| 1523 |
* type does not exist. Rejected in case the |
| 1524 |
* WebDriver command errors out. |
| 1525 |
*/ |
| 1526 |
remove_virtual_pressure_source: function(source_type, context=null) { |
| 1527 |
return window.test_driver_internal.remove_virtual_pressure_source(source_type, context); |
| 1528 |
}, |
| 1529 |
|
| 1530 |
/** |
| 1531 |
* Sets which hashes are considered k-anonymous for the Protected |
| 1532 |
* Audience interest group with specified `owner` and `name`. |
| 1533 |
* |
| 1534 |
* Matches the `Set Protected Audience K-Anonymity |
| 1535 |
* <https://wicg.github.io/turtledove/#sctn-automation-set-protected-audience-k-anonymity> |
| 1536 |
* WebDriver command. |
| 1537 |
* |
| 1538 |
* @param {String} owner - Origin of the owner of the interest group |
| 1539 |
* to modify |
| 1540 |
* @param {String} name - Name of the interest group to modify |
| 1541 |
* @param {Array} hashes - An array of strings, each of which is a |
| 1542 |
* base64 ecoded hash to consider k-anonymous. |
| 1543 |
* |
| 1544 |
* @returns {Promise} Fulfilled after the k-anonymity status for the |
| 1545 |
* specified Protected Audience interest group has |
| 1546 |
* been updated. |
| 1547 |
* |
| 1548 |
*/ |
| 1549 |
set_protected_audience_k_anonymity: function(owner, name, hashes, context = null) { |
| 1550 |
return window.test_driver_internal.set_protected_audience_k_anonymity(owner, name, hashes, context); |
| 1551 |
}, |
| 1552 |
|
| 1553 |
/** |
| 1554 |
* Overrides the display features provided by the hardware so the viewport segments |
| 1555 |
* can be emulated. |
| 1556 |
* |
| 1557 |
* Matches the `Set display features |
| 1558 |
* <https://drafts.csswg.org/css-viewport/#set-display-features>`_ |
| 1559 |
* WebDriver command. |
| 1560 |
* |
| 1561 |
* @param {Array} features - An array of `DisplayFeatureOverride |
| 1562 |
* <https://drafts.csswg.org/css-viewport/#display-feature-override>`. |
| 1563 |
* @param {WindowProxy} [context=null] - Browsing context in which to |
| 1564 |
* run the call, or null for the |
| 1565 |
* current browsing context. |
| 1566 |
* |
| 1567 |
* @returns {Promise} Fulfilled when the display features are set. |
| 1568 |
* Rejected in case the WebDriver command errors out |
| 1569 |
* (including if the array is malformed). |
| 1570 |
*/ |
| 1571 |
set_display_features: function(features, context=null) { |
| 1572 |
return window.test_driver_internal.set_display_features(features, context); |
| 1573 |
}, |
| 1574 |
|
| 1575 |
/** |
| 1576 |
* Removes display features override and returns the control |
| 1577 |
* back to hardware. |
| 1578 |
* |
| 1579 |
* Matches the `Clear display features |
| 1580 |
* <https://drafts.csswg.org/css-viewport/#clear-display-features>`_ |
| 1581 |
* WebDriver command. |
| 1582 |
* |
| 1583 |
* @param {WindowProxy} [context=null] - Browsing context in which to |
| 1584 |
* run the call, or null for the |
| 1585 |
* current browsing context. |
| 1586 |
* |
| 1587 |
* @returns {Promise} Fulfilled after the display features override has |
| 1588 |
* been removed. Rejected in case the WebDriver |
| 1589 |
* command errors out. |
| 1590 |
*/ |
| 1591 |
clear_display_features: function(context=null) { |
| 1592 |
return window.test_driver_internal.clear_display_features(context); |
| 1593 |
} |
| 1594 |
}; |
| 1595 |
|
| 1596 |
window.test_driver_internal = { |
| 1597 |
/** |
| 1598 |
* This flag should be set to `true` by any code which implements the |
| 1599 |
* internal methods defined below for automation purposes. Doing so |
| 1600 |
* allows the library to signal failure immediately when an automated |
| 1601 |
* implementation of one of the methods is not available. |
| 1602 |
*/ |
| 1603 |
in_automation: false, |
| 1604 |
|
| 1605 |
bidi: { |
| 1606 |
bluetooth: { |
| 1607 |
handle_request_device_prompt: function() { |
| 1608 |
throw new Error( |
| 1609 |
'bidi.bluetooth.handle_request_device_prompt is not implemented by testdriver-vendor.js'); |
| 1610 |
}, |
| 1611 |
simulate_adapter: function () { |
| 1612 |
throw new Error( |
| 1613 |
"bidi.bluetooth.simulate_adapter is not implemented by testdriver-vendor.js"); |
| 1614 |
}, |
| 1615 |
simulate_preconnected_peripheral: function() { |
| 1616 |
throw new Error( |
| 1617 |
'bidi.bluetooth.simulate_preconnected_peripheral is not implemented by testdriver-vendor.js'); |
| 1618 |
}, |
| 1619 |
request_device_prompt_updated: { |
| 1620 |
async subscribe() { |
| 1621 |
throw new Error( |
| 1622 |
'bidi.bluetooth.request_device_prompt_updated.subscribe is not implemented by testdriver-vendor.js'); |
| 1623 |
}, |
| 1624 |
on() { |
| 1625 |
throw new Error( |
| 1626 |
'bidi.bluetooth.request_device_prompt_updated.on is not implemented by testdriver-vendor.js'); |
| 1627 |
} |
| 1628 |
} |
| 1629 |
}, |
| 1630 |
emulation: { |
| 1631 |
set_geolocation_override: function (params) { |
| 1632 |
throw new Error( |
| 1633 |
"bidi.emulation.set_geolocation_override is not implemented by testdriver-vendor.js"); |
| 1634 |
} |
| 1635 |
}, |
| 1636 |
log: { |
| 1637 |
entry_added: { |
| 1638 |
async subscribe() { |
| 1639 |
throw new Error( |
| 1640 |
"bidi.log.entry_added.subscribe is not implemented by testdriver-vendor.js"); |
| 1641 |
}, |
| 1642 |
on() { |
| 1643 |
throw new Error( |
| 1644 |
"bidi.log.entry_added.on is not implemented by testdriver-vendor.js"); |
| 1645 |
} |
| 1646 |
} |
| 1647 |
}, |
| 1648 |
permissions: { |
| 1649 |
async set_permission() { |
| 1650 |
throw new Error( |
| 1651 |
"bidi.permissions.set_permission() is not implemented by testdriver-vendor.js"); |
| 1652 |
} |
| 1653 |
} |
| 1654 |
}, |
| 1655 |
|
| 1656 |
async click(element, coords) { |
| 1657 |
if (this.in_automation) { |
| 1658 |
throw new Error("click() is not implemented by testdriver-vendor.js"); |
| 1659 |
} |
| 1660 |
|
| 1661 |
return new Promise(function(resolve, reject) { |
| 1662 |
element.addEventListener("click", resolve); |
| 1663 |
}); |
| 1664 |
}, |
| 1665 |
|
| 1666 |
async delete_all_cookies(context=null) { |
| 1667 |
throw new Error("delete_all_cookies() is not implemented by testdriver-vendor.js"); |
| 1668 |
}, |
| 1669 |
|
| 1670 |
async get_all_cookies(context=null) { |
| 1671 |
throw new Error("get_all_cookies() is not implemented by testdriver-vendor.js"); |
| 1672 |
}, |
| 1673 |
|
| 1674 |
async get_named_cookie(name, context=null) { |
| 1675 |
throw new Error("get_named_cookie() is not implemented by testdriver-vendor.js"); |
| 1676 |
}, |
| 1677 |
|
| 1678 |
async get_computed_role(element) { |
| 1679 |
throw new Error("get_computed_role is a testdriver.js function which cannot be run in this context."); |
| 1680 |
}, |
| 1681 |
|
| 1682 |
async get_computed_name(element) { |
| 1683 |
throw new Error("get_computed_name is a testdriver.js function which cannot be run in this context."); |
| 1684 |
}, |
| 1685 |
|
| 1686 |
async send_keys(element, keys) { |
| 1687 |
if (this.in_automation) { |
| 1688 |
throw new Error("send_keys() is not implemented by testdriver-vendor.js"); |
| 1689 |
} |
| 1690 |
|
| 1691 |
return new Promise(function(resolve, reject) { |
| 1692 |
var seen = ""; |
| 1693 |
|
| 1694 |
function remove() { |
| 1695 |
element.removeEventListener("keydown", onKeyDown); |
| 1696 |
} |
| 1697 |
|
| 1698 |
function onKeyDown(event) { |
| 1699 |
if (event.key.length > 1) { |
| 1700 |
return; |
| 1701 |
} |
| 1702 |
|
| 1703 |
seen += event.key; |
| 1704 |
|
| 1705 |
if (keys.indexOf(seen) !== 0) { |
| 1706 |
reject(new Error("Unexpected key sequence: " + seen)); |
| 1707 |
remove(); |
| 1708 |
} else if (seen === keys) { |
| 1709 |
resolve(); |
| 1710 |
remove(); |
| 1711 |
} |
| 1712 |
} |
| 1713 |
|
| 1714 |
element.addEventListener("keydown", onKeyDown); |
| 1715 |
}); |
| 1716 |
}, |
| 1717 |
|
| 1718 |
async freeze(context=null) { |
| 1719 |
throw new Error("freeze() is not implemented by testdriver-vendor.js"); |
| 1720 |
}, |
| 1721 |
|
| 1722 |
async minimize_window(context=null) { |
| 1723 |
throw new Error("minimize_window() is not implemented by testdriver-vendor.js"); |
| 1724 |
}, |
| 1725 |
|
| 1726 |
async set_window_rect(rect, context=null) { |
| 1727 |
throw new Error("set_window_rect() is not implemented by testdriver-vendor.js"); |
| 1728 |
}, |
| 1729 |
|
| 1730 |
async get_window_rect(context=null) { |
| 1731 |
throw new Error("get_window_rect() is not implemented by testdriver-vendor.js"); |
| 1732 |
}, |
| 1733 |
|
| 1734 |
async action_sequence(actions, context=null) { |
| 1735 |
throw new Error("action_sequence() is not implemented by testdriver-vendor.js"); |
| 1736 |
}, |
| 1737 |
|
| 1738 |
async generate_test_report(message, context=null) { |
| 1739 |
throw new Error("generate_test_report() is not implemented by testdriver-vendor.js"); |
| 1740 |
}, |
| 1741 |
|
| 1742 |
async set_permission(permission_params, context=null) { |
| 1743 |
throw new Error("set_permission() is not implemented by testdriver-vendor.js"); |
| 1744 |
}, |
| 1745 |
|
| 1746 |
async add_virtual_authenticator(config, context=null) { |
| 1747 |
throw new Error("add_virtual_authenticator() is not implemented by testdriver-vendor.js"); |
| 1748 |
}, |
| 1749 |
|
| 1750 |
async remove_virtual_authenticator(authenticator_id, context=null) { |
| 1751 |
throw new Error("remove_virtual_authenticator() is not implemented by testdriver-vendor.js"); |
| 1752 |
}, |
| 1753 |
|
| 1754 |
async add_credential(authenticator_id, credential, context=null) { |
| 1755 |
throw new Error("add_credential() is not implemented by testdriver-vendor.js"); |
| 1756 |
}, |
| 1757 |
|
| 1758 |
async get_credentials(authenticator_id, context=null) { |
| 1759 |
throw new Error("get_credentials() is not implemented by testdriver-vendor.js"); |
| 1760 |
}, |
| 1761 |
|
| 1762 |
async remove_credential(authenticator_id, credential_id, context=null) { |
| 1763 |
throw new Error("remove_credential() is not implemented by testdriver-vendor.js"); |
| 1764 |
}, |
| 1765 |
|
| 1766 |
async remove_all_credentials(authenticator_id, context=null) { |
| 1767 |
throw new Error("remove_all_credentials() is not implemented by testdriver-vendor.js"); |
| 1768 |
}, |
| 1769 |
|
| 1770 |
async set_user_verified(authenticator_id, uv, context=null) { |
| 1771 |
throw new Error("set_user_verified() is not implemented by testdriver-vendor.js"); |
| 1772 |
}, |
| 1773 |
|
| 1774 |
async set_storage_access(origin, embedding_origin, blocked, context=null) { |
| 1775 |
throw new Error("set_storage_access() is not implemented by testdriver-vendor.js"); |
| 1776 |
}, |
| 1777 |
|
| 1778 |
async set_spc_transaction_mode(mode, context=null) { |
| 1779 |
throw new Error("set_spc_transaction_mode() is not implemented by testdriver-vendor.js"); |
| 1780 |
}, |
| 1781 |
|
| 1782 |
set_rph_registration_mode: function(mode, context=null) { |
| 1783 |
return Promise.reject(new Error("unimplemented")); |
| 1784 |
}, |
| 1785 |
|
| 1786 |
async cancel_fedcm_dialog(context=null) { |
| 1787 |
throw new Error("cancel_fedcm_dialog() is not implemented by testdriver-vendor.js"); |
| 1788 |
}, |
| 1789 |
|
| 1790 |
async click_fedcm_dialog_button(dialog_button, context=null) { |
| 1791 |
throw new Error("click_fedcm_dialog_button() is not implemented by testdriver-vendor.js"); |
| 1792 |
}, |
| 1793 |
|
| 1794 |
async select_fedcm_account(account_index, context=null) { |
| 1795 |
throw new Error("select_fedcm_account() is not implemented by testdriver-vendor.js"); |
| 1796 |
}, |
| 1797 |
|
| 1798 |
async get_fedcm_account_list(context=null) { |
| 1799 |
throw new Error("get_fedcm_account_list() is not implemented by testdriver-vendor.js"); |
| 1800 |
}, |
| 1801 |
|
| 1802 |
async get_fedcm_dialog_title(context=null) { |
| 1803 |
throw new Error("get_fedcm_dialog_title() is not implemented by testdriver-vendor.js"); |
| 1804 |
}, |
| 1805 |
|
| 1806 |
async get_fedcm_dialog_type(context=null) { |
| 1807 |
throw new Error("get_fedcm_dialog_type() is not implemented by testdriver-vendor.js"); |
| 1808 |
}, |
| 1809 |
|
| 1810 |
async set_fedcm_delay_enabled(enabled, context=null) { |
| 1811 |
throw new Error("set_fedcm_delay_enabled() is not implemented by testdriver-vendor.js"); |
| 1812 |
}, |
| 1813 |
|
| 1814 |
async reset_fedcm_cooldown(context=null) { |
| 1815 |
throw new Error("reset_fedcm_cooldown() is not implemented by testdriver-vendor.js"); |
| 1816 |
}, |
| 1817 |
|
| 1818 |
async create_virtual_sensor(sensor_type, sensor_params, context=null) { |
| 1819 |
throw new Error("create_virtual_sensor() is not implemented by testdriver-vendor.js"); |
| 1820 |
}, |
| 1821 |
|
| 1822 |
async update_virtual_sensor(sensor_type, reading, context=null) { |
| 1823 |
throw new Error("update_virtual_sensor() is not implemented by testdriver-vendor.js"); |
| 1824 |
}, |
| 1825 |
|
| 1826 |
async remove_virtual_sensor(sensor_type, context=null) { |
| 1827 |
throw new Error("remove_virtual_sensor() is not implemented by testdriver-vendor.js"); |
| 1828 |
}, |
| 1829 |
|
| 1830 |
async get_virtual_sensor_information(sensor_type, context=null) { |
| 1831 |
throw new Error("get_virtual_sensor_information() is not implemented by testdriver-vendor.js"); |
| 1832 |
}, |
| 1833 |
|
| 1834 |
async set_device_posture(posture, context=null) { |
| 1835 |
throw new Error("set_device_posture() is not implemented by testdriver-vendor.js"); |
| 1836 |
}, |
| 1837 |
|
| 1838 |
async clear_device_posture(context=null) { |
| 1839 |
throw new Error("clear_device_posture() is not implemented by testdriver-vendor.js"); |
| 1840 |
}, |
| 1841 |
|
| 1842 |
async run_bounce_tracking_mitigations(context=null) { |
| 1843 |
throw new Error("run_bounce_tracking_mitigations() is not implemented by testdriver-vendor.js"); |
| 1844 |
}, |
| 1845 |
|
| 1846 |
async create_virtual_pressure_source(source_type, metadata={}, context=null) { |
| 1847 |
throw new Error("create_virtual_pressure_source() is not implemented by testdriver-vendor.js"); |
| 1848 |
}, |
| 1849 |
|
| 1850 |
async update_virtual_pressure_source(source_type, sample, own_contribution_estimate, context=null) { |
| 1851 |
throw new Error("update_virtual_pressure_source() is not implemented by testdriver-vendor.js"); |
| 1852 |
}, |
| 1853 |
|
| 1854 |
async remove_virtual_pressure_source(source_type, context=null) { |
| 1855 |
throw new Error("remove_virtual_pressure_source() is not implemented by testdriver-vendor.js"); |
| 1856 |
}, |
| 1857 |
|
| 1858 |
async set_protected_audience_k_anonymity(owner, name, hashes, context=null) { |
| 1859 |
throw new Error("set_protected_audience_k_anonymity() is not implemented by testdriver-vendor.js"); |
| 1860 |
}, |
| 1861 |
|
| 1862 |
async set_display_features(features, context=null) { |
| 1863 |
throw new Error("set_display_features() is not implemented by testdriver-vendor.js"); |
| 1864 |
}, |
| 1865 |
|
| 1866 |
async clear_display_features(context=null) { |
| 1867 |
throw new Error("clear_display_features() is not implemented by testdriver-vendor.js"); |
| 1868 |
} |
| 1869 |
}; |
| 1870 |
})(); |