tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

testdriver.js (135504B)


      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                 * Disables the bluetooth simulation with the given params. Matches the
    147                 * `bluetooth.disableSimulation <https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-disableSimulation-command>`_
    148                 * WebDriver BiDi command.
    149                 *
    150                 * @example
    151                 * await test_driver.bidi.bluetooth.disable_simulation();
    152                 *
    153                 * @param {object} params - Parameters for the command.
    154                 * @param {Context} [params.context] The optional context parameter specifies in
    155                 * which browsing context to disable the simulation for. If not provided, the
    156                 * current browsing context is used.
    157                 * @returns {Promise} fulfilled after the simulation is disabled, or rejected if
    158                 * the operation fails.
    159                 */
    160                disable_simulation: function (params) {
    161                    return window.test_driver_internal.bidi.bluetooth.disable_simulation(params);
    162                },
    163                /**
    164                 * Creates a simulated bluetooth peripheral with the given params.
    165                 * Matches the
    166                 * `bluetooth.simulatePreconnectedPeripheral <https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-simulateconnectedperipheral-command>`_
    167                 * WebDriver BiDi command.
    168                 *
    169                 * @example
    170                 * await test_driver.bidi.bluetooth.simulatePreconnectedPeripheral({
    171                 *     "address": "09:09:09:09:09:09",
    172                 *     "name": "Some Device",
    173                 *     "manufacturerData": [{key: 17, data: "AP8BAX8="}],
    174                 *     "knownServiceUuids": [
    175                 *          "12345678-1234-5678-9abc-def123456789",
    176                 *     ],
    177                 * });
    178                 *
    179                 * @param {object} params - Parameters for the command.
    180                 * @param {string} params.address - The address of the simulated
    181                 * bluetooth peripheral. Matches the
    182                 * `bluetooth.SimulatePreconnectedPeripheralParameters:address <https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-simulateconnectedperipheral-command>`_
    183                 * value.
    184                 * @param {string} params.name - The name of the simulated bluetooth
    185                 * peripheral. Matches the
    186                 * `bluetooth.SimulatePreconnectedPeripheralParameters:name <https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-simulateconnectedperipheral-command>`_
    187                 * value.
    188                 * @param {Array.ManufacturerData} params.manufacturerData - The manufacturerData of the
    189                 * simulated bluetooth peripheral. Matches the
    190                 * `bluetooth.SimulatePreconnectedPeripheralParameters:manufacturerData <https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-simulateconnectedperipheral-command>`_
    191                 * value.
    192                 * @param {string} params.knownServiceUuids - The knownServiceUuids of
    193                 * the simulated bluetooth peripheral. Matches the
    194                 * `bluetooth.SimulatePreconnectedPeripheralParameters:knownServiceUuids <https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-simulateconnectedperipheral-command>`_
    195                 * value.
    196                 * @param {Context} [params.context] The optional context parameter
    197                 * specifies in which browsing context the simulated bluetooth peripheral should be
    198                 * set. If not provided, the current browsing context is used.
    199                 * @returns {Promise} fulfilled after the simulated bluetooth peripheral is created
    200                 * and set, or rejected if the operation fails.
    201                 */
    202                simulate_preconnected_peripheral: function(params) {
    203                    return window.test_driver_internal.bidi.bluetooth
    204                        .simulate_preconnected_peripheral(params);
    205                },
    206                /**
    207                 * Simulates a GATT connection response for a given peripheral.
    208                 * Matches the `bluetooth.simulateGattConnectionResponse
    209                 * <https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-simulategattconnectionresponse-command>`_
    210                 * WebDriver BiDi command.
    211                 *
    212                 * @example
    213                 * await test_driver.bidi.bluetooth.simulate_gatt_connection_response({
    214                 *     "address": "09:09:09:09:09:09",
    215                 *     "code": 0x0
    216                 * });
    217                 *
    218                 * @param {object} params - Parameters for the command.
    219                 * @param {string} params.address - The address of the simulated
    220                 * bluetooth peripheral. Matches the
    221                 * `bluetooth.SimulateGattConnectionResponseParameters:peripheral <https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-simulategattconnectionresponse-command>`_
    222                 * value.
    223                 * @param {number} params.code - The response code for a GATT connection attempted.
    224                 * Matches the
    225                 * `bluetooth.SimulateGattConnectionResponseParameters:code <https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-simulategattconnectionresponse-command>`_
    226                 * value.
    227                 * @param {Context} [params.context] The optional context parameter specifies in
    228                 * which browsing context the GATT connection response should be simulated. If not
    229                 * provided, the current browsing context is used.
    230                 * @returns {Promise} fulfilled after the GATT connection response
    231                 * is simulated, or rejected if the operation fails.
    232                 */
    233                simulate_gatt_connection_response: function(params) {
    234                    return window.test_driver_internal.bidi.bluetooth
    235                        .simulate_gatt_connection_response(params);
    236                },
    237                /**
    238                 * Simulates a GATT disconnection for a given peripheral.
    239                 * Matches the `bluetooth.simulateGattDisconnection
    240                 * <https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-simulategattdisconnection-command>`_
    241                 * WebDriver BiDi command.
    242                 *
    243                 * @example
    244                 * await test_driver.bidi.bluetooth.simulate_gatt_disconnection({
    245                 *     "address": "09:09:09:09:09:09",
    246                 * });
    247                 *
    248                 * @param {object} params - Parameters for the command.
    249                 * @param {string} params.address - The address of the simulated
    250                 * bluetooth peripheral. Matches the
    251                 * `bluetooth.SimulateGattDisconnectionParameters:address <https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-simulategattdisconnection-command>`_
    252                 * value.
    253                 * @param {Context} [params.context] The optional context parameter specifies in
    254                 * which browsing context the GATT disconnection should be simulated. If not
    255                 * provided, the current browsing context is used.
    256                 * @returns {Promise} fulfilled after the GATT disconnection
    257                 * is simulated, or rejected if the operation fails.
    258                 */
    259                simulate_gatt_disconnection: function(params) {
    260                    return window.test_driver_internal.bidi.bluetooth
    261                        .simulate_gatt_disconnection(params);
    262                },
    263                /**
    264                 * Simulates a GATT service.
    265                 * Matches the `bluetooth.simulateService
    266                 * <https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-simulateservice-command>`_
    267                 * WebDriver BiDi command.
    268                 *
    269                 * @example
    270                 * await test_driver.bidi.bluetooth.simulate_service({
    271                 *     "address": "09:09:09:09:09:09",
    272                 *     "uuid": "0000180d-0000-1000-8000-00805f9b34fb",
    273                 *     "type": "add"
    274                 * });
    275                 *
    276                 * @param {object} params - Parameters for the command.
    277                 * @param {string} params.address - The address of the simulated bluetooth peripheral this service belongs to.
    278                 * Matches the
    279                 * `bluetooth.SimulateServiceParameters:address <https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-simulateservice-command>`_
    280                 * value.
    281                 * @param {string} params.uuid - The uuid of the simulated GATT service.
    282                 * Matches the
    283                 * `bluetooth.SimulateServiceParameters:address <https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-simulateservice-command>`_
    284                 * value.
    285                 * @param {string} params.type - The type of the GATT service simulation, either "add" or "remove".
    286                 * Matches the
    287                 * `bluetooth.SimulateServiceParameters:address <https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-simulateservice-command>`_
    288                 * value.
    289                 * @param {Context} [params.context] The optional context parameter specifies in
    290                 * which browsing context the GATT service should be simulated. If not
    291                 * provided, the current browsing context is used.
    292                 * @returns {Promise} fulfilled after the GATT service
    293                 * is simulated, or rejected if the operation fails.
    294                 */
    295                simulate_service: function(params) {
    296                    return window.test_driver_internal.bidi.bluetooth
    297                        .simulate_service(params);
    298                },
    299                /**
    300                 * Simulates a GATT characteristic.
    301                 * Matches the `bluetooth.simulateCharacteristic
    302                 * <https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-simulatecharacteristic-command>`_
    303                 * WebDriver BiDi command.
    304                 *
    305                 * @example
    306                 * await test_driver.bidi.bluetooth.simulate_characteristic({
    307                 *     "address": "09:09:09:09:09:09",
    308                 *    "serviceUuid": "0000180d-0000-1000-8000-00805f9b34fb",
    309                 *    "characteristicUuid": "00002a21-0000-1000-8000-00805f9b34fb",
    310                 *    "characteristicProperties": {
    311                 *      "read": true,
    312                 *      "write": true,
    313                 *      "notify": true
    314                 *    },
    315                 *    "type": "add"
    316                 * });
    317                 *
    318                 * @param {object} params - Parameters for the command.
    319                 * @param {string} params.address - The address of the simulated bluetooth peripheral the characterisitc belongs to.
    320                 * Matches the
    321                 * `bluetooth.SimulateCharacteristicParameters:address <https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-simulatecharacteristic-command>`_
    322                 * value.
    323                 * @param {string} params.serviceUuid - The uuid of the simulated GATT service the characterisitc belongs to.
    324                 * Matches the
    325                 * `bluetooth.SimulateCharacteristicParameters:address <https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-simulatecharacteristic-command>`_
    326                 * value.
    327                * @param {string} params.characteristicUuid - The uuid of the simulated GATT characteristic.
    328                * Matches the
    329                * `bluetooth.SimulateCharacteristicParameters:address <https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-simulatecharacteristic-command>`_
    330                * value.
    331                * @param {string} params.characteristicProperties - The properties of the simulated GATT characteristic.
    332                * Matches the
    333                * `bluetooth.SimulateCharacteristicParameters:address <https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-simulatecharacteristic-command>`_
    334                * value.
    335                * @param {string} params.type - The type of the GATT characterisitc simulation, either "add" or "remove".
    336                * Matches the
    337                * `bluetooth.SimulateCharacteristicParameters:address <https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-simulatecharacteristic-command>`_
    338                * value.
    339                * @param {Context} [params.context] The optional context parameter specifies in
    340                * which browsing context the GATT characteristic should be simulated. If not
    341                * provided, the current browsing context is used.
    342                * @returns {Promise} fulfilled after the GATT characteristic
    343                * is simulated, or rejected if the operation fails.
    344                */
    345                simulate_characteristic: function(params) {
    346                    return window.test_driver_internal.bidi.bluetooth
    347                        .simulate_characteristic(params);
    348                },
    349                /**
    350                 * Simulates a GATT characteristic response.
    351                 * Matches the `bluetooth.simulateCharacteristicResponse
    352                 * <https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-simulatecharacteristicresponse-command>`_
    353                 * WebDriver BiDi command.
    354                 *
    355                 * @example
    356                 * await test_driver.bidi.bluetooth.simulate_characteristic({
    357                 *     "address": "09:09:09:09:09:09",
    358                 *    "serviceUuid": "0000180d-0000-1000-8000-00805f9b34fb",
    359                 *    "characteristicUuid": "00002a21-0000-1000-8000-00805f9b34fb",
    360                 *    "type": "read",
    361                 *    "code": 0,
    362                 *    "data": [1, 2]
    363                 * });
    364                 *
    365                 * @param {object} params - Parameters for the command.
    366                 * @param {string} params.address - The address of the simulated
    367                 * bluetooth peripheral. Matches the
    368                 * `bluetooth.SimulateCharacteristicResponseParameters:address <https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-simulatecharacteristicresponse-command>`_
    369                 * value.
    370                 * @param {string} params.serviceUuid - The uuid of the simulated GATT service the characterisitc belongs to.
    371                 * Matches the
    372                 * `bluetooth.SimulateCharacteristicResponseParameters:address <https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-simulatecharacteristicresponse-command>`_
    373                 * value.
    374                * @param {string} params.characteristicUuid - The uuid of the simulated characteristic.
    375                * Matches the
    376                * `bluetooth.SimulateCharacteristicResponseParameters:address <https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-simulatecharacteristicresponse-command>`_
    377                * value.
    378                * @param {string} params.type - The type of the simulated GATT characteristic operation."
    379                * Can be "read", "write", "subscribe-to-notifications" or "unsubscribe-from-notifications".
    380                * Matches the
    381                * `bluetooth.SimulateCharacteristicResponseParameters:address <https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-simulatecharacteristicresponse-command>`_
    382                * value.
    383                * @param {string} params.code - The simulated GATT characteristic response code.
    384                * Matches the
    385                * `bluetooth.SimulateCharacteristicResponseParameters:address <https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-simulatecharacteristicresponse-command>`_
    386                * value.*
    387                * @param {string} params.data - The data along with the simulated GATT characteristic response.
    388                * Matches the
    389                * `bluetooth.SimulateCharacteristicResponseParameters:address <https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-simulatecharacteristicresponse-command>`_
    390                * value.**
    391                * @param {Context} [params.context] The optional context parameter specifies in
    392                * which browsing context the GATT characteristic belongs to. If not
    393                * provided, the current browsing context is used.
    394                * @returns {Promise} fulfilled after the GATT characteristic
    395                * is simulated, or rejected if the operation fails.
    396                */
    397                simulate_characteristic_response: function(params) {
    398                    return window.test_driver_internal.bidi.bluetooth
    399                        .simulate_characteristic_response(params);
    400                },
    401                /**
    402                 * Simulates a GATT descriptor.
    403                 * Matches the `bluetooth.simulateDescriptor
    404                 * <https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-simulatedescriptor-command>`_
    405                 * WebDriver BiDi command.
    406                 *
    407                 * @example
    408                 * await test_driver.bidi.bluetooth.simulate_descriptor({
    409                 *     "address": "09:09:09:09:09:09",
    410                 *    "serviceUuid": "0000180d-0000-1000-8000-00805f9b34fb",
    411                 *    "characteristicUuid": "00002a21-0000-1000-8000-00805f9b34fb",
    412                 *    "descriptorUuid": "00002901-0000-1000-8000-00805f9b34fb",
    413                 *    "type": "add"
    414                 * });
    415                 *
    416                 * @param {object} params - Parameters for the command.
    417                 * @param {string} params.address - The address of the simulated bluetooth peripheral the descriptor belongs to.
    418                 * Matches the
    419                 * `bluetooth.SimulateDescriptorParameters:address <https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-simulatedescriptor-command>`_
    420                 * value.
    421                 * @param {string} params.serviceUuid - The uuid of the simulated GATT service the descriptor belongs to.
    422                 * Matches the
    423                 * `bluetooth.SimulateDescriptorParameters:address <https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-simulatedescriptor-command>`_
    424                 * value.
    425                * @param {string} params.characteristicUuid - The uuid of the simulated GATT characterisitc the descriptor belongs to.
    426                 * Matches the
    427                * `bluetooth.SimulateDescriptorParameters:address <https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-simulatedescriptor-command>`_
    428                * value.
    429                * @param {string} params.descriptorUuid - The uuid of the simulated GATT descriptor.
    430                *  Matches the
    431                * `bluetooth.SimulateDescriptorParameters:address <https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-simulatedescriptor-command>`_
    432                * value.*
    433                * @param {string} params.type - The type of the GATT descriptor simulation, either "add" or "remove".
    434                * Matches the
    435                * `bluetooth.SimulateDescriptorParameters:address <https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-simulatedescriptor-command>`_
    436                * value.
    437                * @param {Context} [params.context] The optional context parameter specifies in
    438                * which browsing context the GATT descriptor should be simulated. If not
    439                * provided, the current browsing context is used.
    440                * @returns {Promise} fulfilled after the GATT descriptor
    441                * is simulated, or rejected if the operation fails.
    442                */
    443                simulate_descriptor: function(params) {
    444                    return window.test_driver_internal.bidi.bluetooth
    445                        .simulate_descriptor(params);
    446                },
    447                /**
    448                 * Simulates a GATT descriptor response.
    449                 * Matches the `bluetooth.simulateDescriptorResponse
    450                 * <https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-simulatedescriptorresponse-command>`_
    451                 * WebDriver BiDi command.
    452                 *
    453                 * @example
    454                 * await test_driver.bidi.bluetooth.simulate_descriptor_response({
    455                 *     "address": "09:09:09:09:09:09",
    456                 *    "serviceUuid": "0000180d-0000-1000-8000-00805f9b34fb",
    457                 *    "characteristicUuid": "00002a21-0000-1000-8000-00805f9b34fb",
    458                 *    "descriptorUuid": "00002901-0000-1000-8000-00805f9b34fb",
    459                 *    "type": "read",
    460                 *    "code": 0,
    461                 *    "data": [1, 2]
    462                 * });
    463                 *
    464                 * @param {object} params - Parameters for the command.
    465                 * @param {string} params.address - The address of the simulated bluetooth peripheral the descriptor belongs to.
    466                 * Matches the
    467                 * `bluetooth.SimulateDescriptorResponseParameters:address <https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-simulatedescriptorresponse-command>`_
    468                 * value.
    469                 * @param {string} params.serviceUuid - The uuid of the simulated GATT service the descriptor belongs to.
    470                 * Matches the
    471                 * `bluetooth.SimulateDescriptorResponseParameters:address <https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-simulatedescriptorresponse-command>`_
    472                 * value.
    473                 * @param {string} params.characteristicUuid - The uuid of the simulated GATT characterisitc the descriptor belongs to.
    474                 * Matches the
    475                 * `bluetooth.SimulateDescriptorResponseParameters:address <https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-simulatedescriptorresponse-command>`_
    476                 * value.
    477                * @param {string} params.descriptorUuid - The uuid of the simulated GATT descriptor.
    478                * Matches the
    479                * `bluetooth.SimulateDescriptorResponseParameters:address <https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-simulatedescriptorresponse-command>`_
    480                * value.
    481                * @param {string} params.type - The type of the simulated GATT descriptor operation.
    482                * Matches the
    483                * `bluetooth.SimulateDescriptorResponseParameters:address <https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-simulatedescriptorresponse-command>`_
    484                * value.
    485                * @param {string} params.code - The simulated GATT descriptor response code.
    486                * Matches the
    487                * `bluetooth.SimulateDescriptorResponseParameters:address <https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-simulatedescriptorresponse-command>`_
    488                * value.*
    489                * @param {string} params.data - The data along with the simulated GATT descriptor response.
    490                * Matches the
    491                * `bluetooth.SimulateDescriptorResponseParameters:address <https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-simulatedescriptorresponse-command>`_
    492                * value.**
    493                * @param {Context} [params.context] The optional context parameter specifies in
    494                * which browsing context the GATT descriptor belongs to. If not
    495                * provided, the current browsing context is used.
    496                * @returns {Promise} fulfilled after the GATT descriptor response
    497                * is simulated, or rejected if the operation fails.
    498                */
    499                simulate_descriptor_response: function(params) {
    500                    return window.test_driver_internal.bidi.bluetooth
    501                        .simulate_descriptor_response(params);
    502                },
    503                /**
    504                 * `bluetooth.RequestDevicePromptUpdatedParameters <https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-requestdevicepromptupdated-event>`_
    505                 * event.
    506                 */
    507                request_device_prompt_updated: {
    508                    /**
    509                     * @typedef {object} RequestDevicePromptUpdated
    510                     * `bluetooth.RequestDevicePromptUpdatedParameters <https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-requestdevicepromptupdated-event>`_
    511                     * event.
    512                     */
    513 
    514                    /**
    515                     * Subscribes to the event. Events will be emitted only if
    516                     * there is a subscription for the event. This method does
    517                     * not add actual listeners. To listen to the event, use the
    518                     * `on` or `once` methods. The buffered events will be
    519                     * emitted before the command promise is resolved.
    520                     *
    521                     * @param {object} [params] Parameters for the subscription.
    522                     * @param {null|Array.<(Context)>} [params.contexts] The
    523                     * optional contexts parameter specifies which browsing
    524                     * contexts to subscribe to the event on. It should be
    525                     * either an array of Context objects, or null. If null, the
    526                     * event will be subscribed to globally. If omitted, the
    527                     * event will be subscribed to on the current browsing
    528                     * context.
    529                     * @returns {Promise<(function(): Promise<void>)>} Callback
    530                     * for unsubscribing from the created subscription.
    531                     */
    532                    subscribe: async function(params = {}) {
    533                        assertBidiIsEnabled();
    534                        return window.test_driver_internal.bidi.bluetooth
    535                            .request_device_prompt_updated.subscribe(params);
    536                    },
    537                    /**
    538                     * Adds an event listener for the event.
    539                     *
    540                     * @param {function(RequestDevicePromptUpdated): void} callback The
    541                     * callback to be called when the event is emitted. The
    542                     * callback is called with the event object as a parameter.
    543                     * @returns {function(): void} A function that removes the
    544                     * added event listener when called.
    545                     */
    546                    on: function(callback) {
    547                        assertBidiIsEnabled();
    548                        return window.test_driver_internal.bidi.bluetooth
    549                            .request_device_prompt_updated.on(callback);
    550                    },
    551                    /**
    552                     * Adds an event listener for the event that is only called
    553                     * once and removed afterward.
    554                     *
    555                     * @return {Promise<RequestDevicePromptUpdated>} The promise which
    556                     * is resolved with the event object when the event is emitted.
    557                     */
    558                    once: function() {
    559                        assertBidiIsEnabled();
    560                        return new Promise(resolve => {
    561                            const remove_handler =
    562                                window.test_driver_internal.bidi.bluetooth
    563                                    .request_device_prompt_updated.on(event => {
    564                                    resolve(event);
    565                                    remove_handler();
    566                                });
    567                        });
    568                    },
    569                },
    570                /**
    571                 * `bluetooth.GattConnectionAttemptedParameters <https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-gattConnectionAttempted-event>`_
    572                 * event.
    573                 */
    574                gatt_connection_attempted: {
    575                    /**
    576                     * @typedef {object} GattConnectionAttempted
    577                     * `bluetooth.GattConnectionAttempted <https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-gattConnectionAttempted-event>`_
    578                     * event.
    579                     */
    580 
    581                    /**
    582                     * Subscribes to the event. Events will be emitted only if
    583                     * there is a subscription for the event. This method does
    584                     * not add actual listeners. To listen to the event, use the
    585                     * `on` or `once` methods. The buffered events will be
    586                     * emitted before the command promise is resolved.
    587                     *
    588                     * @param {object} [params] Parameters for the subscription.
    589                     * @param {null|Array.<(Context)>} [params.contexts] The
    590                     * optional contexts parameter specifies which browsing
    591                     * contexts to subscribe to the event on. It should be
    592                     * either an array of Context objects, or null. If null, the
    593                     * event will be subscribed to globally. If omitted, the
    594                     * event will be subscribed to on the current browsing
    595                     * context.
    596                     * @returns {Promise<(function(): Promise<void>)>} Callback
    597                     * for unsubscribing from the created subscription.
    598                     */
    599                    subscribe: async function(params = {}) {
    600                        assertBidiIsEnabled();
    601                        return window.test_driver_internal.bidi.bluetooth
    602                            .gatt_connection_attempted.subscribe(params);
    603                    },
    604                    /**
    605                     * Adds an event listener for the event.
    606                     *
    607                     * @param {function(GattConnectionAttempted): void} callback The
    608                     * callback to be called when the event is emitted. The
    609                     * callback is called with the event object as a parameter.
    610                     * @returns {function(): void} A function that removes the
    611                     * added event listener when called.
    612                     */
    613                    on: function(callback) {
    614                        assertBidiIsEnabled();
    615                        return window.test_driver_internal.bidi.bluetooth
    616                            .gatt_connection_attempted.on(callback);
    617                    },
    618                    /**
    619                     * Adds an event listener for the event that is only called
    620                     * once and removed afterward.
    621                     *
    622                     * @return {Promise<GattConnectionAttempted>} The promise which
    623                     * is resolved with the event object when the event is emitted.
    624                     */
    625                    once: function() {
    626                        assertBidiIsEnabled();
    627                        return new Promise(resolve => {
    628                            const remove_handler =
    629                                window.test_driver_internal.bidi.bluetooth
    630                                    .gatt_connection_attempted.on(event => {
    631                                    resolve(event);
    632                                    remove_handler();
    633                                });
    634                        });
    635                    },
    636                },
    637                /**
    638                 * `bluetooth.CharacteristicEventGeneratedParameters <https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-characteristiceventgenerated-event>`_
    639                 * event.
    640                 */
    641                characteristic_event_generated: {
    642                    /**
    643                     * @typedef {object} CharacteristicEventGenerated
    644                     * `bluetooth.CharacteristicEventGenerated <https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-characteristiceventgenerated-event>`_
    645                     * event.
    646                     */
    647 
    648                    /**
    649                     * Subscribes to the event. Events will be emitted only if
    650                     * there is a subscription for the event. This method does
    651                     * not add actual listeners. To listen to the event, use the
    652                     * `on` or `once` methods. The buffered events will be
    653                     * emitted before the command promise is resolved.
    654                     *
    655                     * @param {object} [params] Parameters for the subscription.
    656                     * @param {null|Array.<(Context)>} [params.contexts] The
    657                     * optional contexts parameter specifies which browsing
    658                     * contexts to subscribe to the event on. It should be
    659                     * either an array of Context objects, or null. If null, the
    660                     * event will be subscribed to globally. If omitted, the
    661                     * event will be subscribed to on the current browsing
    662                     * context.
    663                     * @returns {Promise<(function(): Promise<void>)>} Callback
    664                     * for unsubscribing from the created subscription.
    665                     */
    666                    subscribe: async function(params = {}) {
    667                        assertBidiIsEnabled();
    668                        return window.test_driver_internal.bidi.bluetooth
    669                            .characteristic_event_generated.subscribe(params);
    670                    },
    671                    /**
    672                     * Adds an event listener for the event.
    673                     *
    674                     * @param {function(CharacteristicEventGenerated): void} callback The
    675                     * callback to be called when the event is emitted. The
    676                     * callback is called with the event object as a parameter.
    677                     * @returns {function(): void} A function that removes the
    678                     * added event listener when called.
    679                     */
    680                    on: function(callback) {
    681                        assertBidiIsEnabled();
    682                        return window.test_driver_internal.bidi.bluetooth
    683                            .characteristic_event_generated.on(callback);
    684                    },
    685                    /**
    686                     * Adds an event listener for the event that is only called
    687                     * once and removed afterward.
    688                     *
    689                     * @return {Promise<CharacteristicEventGenerated>} The promise which
    690                     * is resolved with the event object when the event is emitted.
    691                     */
    692                    once: function() {
    693                        assertBidiIsEnabled();
    694                        return new Promise(resolve => {
    695                            const remove_handler =
    696                                window.test_driver_internal.bidi.bluetooth
    697                                    .characteristic_event_generated.on(event => {
    698                                    resolve(event);
    699                                    remove_handler();
    700                                });
    701                        });
    702                    },
    703                },
    704                /**
    705                 * `bluetooth.DescriptorEventGeneratedParameters <https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-descriptoreventgenerated-event>`_
    706                 * event.
    707                 */
    708                descriptor_event_generated: {
    709                    /**
    710                     * @typedef {object} DescriptorEventGenerated
    711                     * `bluetooth.DescriptorEventGenerated <https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-descriptoreventgenerated-event>`_
    712                     * event.
    713                     */
    714 
    715                    /**
    716                     * Subscribes to the event. Events will be emitted only if
    717                     * there is a subscription for the event. This method does
    718                     * not add actual listeners. To listen to the event, use the
    719                     * `on` or `once` methods. The buffered events will be
    720                     * emitted before the command promise is resolved.
    721                     *
    722                     * @param {object} [params] Parameters for the subscription.
    723                     * @param {null|Array.<(Context)>} [params.contexts] The
    724                     * optional contexts parameter specifies which browsing
    725                     * contexts to subscribe to the event on. It should be
    726                     * either an array of Context objects, or null. If null, the
    727                     * event will be subscribed to globally. If omitted, the
    728                     * event will be subscribed to on the current browsing
    729                     * context.
    730                     * @returns {Promise<(function(): Promise<void>)>} Callback
    731                     * for unsubscribing from the created subscription.
    732                     */
    733                    subscribe: async function(params = {}) {
    734                        assertBidiIsEnabled();
    735                        return window.test_driver_internal.bidi.bluetooth
    736                            .descriptor_event_generated.subscribe(params);
    737                    },
    738                    /**
    739                     * Adds an event listener for the event.
    740                     *
    741                     * @param {function(DescriptorEventGenerated): void} callback The
    742                     * callback to be called when the event is emitted. The
    743                     * callback is called with the event object as a parameter.
    744                     * @returns {function(): void} A function that removes the
    745                     * added event listener when called.
    746                     */
    747                    on: function(callback) {
    748                        assertBidiIsEnabled();
    749                        return window.test_driver_internal.bidi.bluetooth
    750                            .descriptor_event_generated.on(callback);
    751                    },
    752                    /**
    753                     * Adds an event listener for the event that is only called
    754                     * once and removed afterward.
    755                     *
    756                     * @return {Promise<DescriptorEventGenerated>} The promise which
    757                     * is resolved with the event object when the event is emitted.
    758                     */
    759                    once: function() {
    760                        assertBidiIsEnabled();
    761                        return new Promise(resolve => {
    762                            const remove_handler =
    763                                window.test_driver_internal.bidi.bluetooth
    764                                    .descriptor_event_generated.on(event => {
    765                                    resolve(event);
    766                                    remove_handler();
    767                                });
    768                        });
    769                    },
    770                }
    771            },
    772            /**
    773             * `speculation <https://wicg.github.io/nav-speculation/prefetch.html>`_ module.
    774             */
    775            speculation: {
    776                /**
    777                 * `speculation.PrefetchStatusUpdated <https://wicg.github.io/nav-speculation/prefetch.html#speculation-prefetchstatusupdated-event>`_
    778                 * event.
    779                 */
    780                prefetch_status_updated: {
    781                    /**
    782                     * @typedef {object} PrefetchStatusUpdated
    783                     * `speculation.PrefetchStatusUpdatedParameters <https://wicg.github.io/nav-speculation/prefetch.html#cddl-type-speculationprefetchstatusupdatedparameters>`_
    784                     * event.
    785                     */
    786 
    787                    /**
    788                     * Subscribes to the event. Events will be emitted only if
    789                     * there is a subscription for the event. This method does
    790                     * not add actual listeners. To listen to the event, use the
    791                     * `on` or `once` methods. The buffered events will be
    792                     * emitted before the command promise is resolved.
    793                     *
    794                     * @param {object} [params] Parameters for the subscription.
    795                     * @param {null|Array.<(Context)>} [params.contexts] The
    796                     * optional contexts parameter specifies which browsing
    797                     * contexts to subscribe to the event on. It should be
    798                     * either an array of Context objects, or null. If null, the
    799                     * event will be subscribed to globally. If omitted, the
    800                     * event will be subscribed to on the current browsing
    801                     * context.
    802                     * @returns {Promise<(function(): Promise<void>)>} Callback
    803                     * for unsubscribing from the created subscription.
    804                     */
    805                    subscribe: async function(params = {}) {
    806                        assertBidiIsEnabled();
    807                        return window.test_driver_internal.bidi.speculation
    808                            .prefetch_status_updated.subscribe(params);
    809                    },
    810                    /**
    811                     * Adds an event listener for the event.
    812                     *
    813                     * @param {function(PrefetchStatusUpdated): void} callback The
    814                     * callback to be called when the event is emitted. The
    815                     * callback is called with the event object as a parameter.
    816                     * @returns {function(): void} A function that removes the
    817                     * added event listener when called.
    818                     */
    819                    on: function(callback) {
    820                        assertBidiIsEnabled();
    821                        return window.test_driver_internal.bidi.speculation
    822                            .prefetch_status_updated.on(callback);
    823                    },
    824                    /**
    825                     * Adds an event listener for the event that is only called
    826                     * once and removed afterward.
    827                     *
    828                     * @return {Promise<PrefetchStatusUpdated>} The promise which
    829                     * is resolved with the event object when the event is emitted.
    830                     */
    831                    once: function() {
    832                        assertBidiIsEnabled();
    833                        return new Promise(resolve => {
    834                            const remove_handler =
    835                                window.test_driver_internal.bidi.speculation
    836                                    .prefetch_status_updated.on(event => {
    837                                    resolve(event);
    838                                    remove_handler();
    839                                });
    840                        });
    841                    }
    842                }
    843            },
    844            /**
    845             * `emulation <https://www.w3.org/TR/webdriver-bidi/#module-emulation>`_ module.
    846             */
    847            emulation: {
    848                /**
    849                 * Overrides the geolocation coordinates for the specified
    850                 * browsing contexts.
    851                 * Matches the `emulation.setGeolocationOverride
    852                 * <https://w3c.github.io/webdriver-bidi/#command-emulation-setGeolocationOverride>`_
    853                 * WebDriver BiDi command.
    854                 *
    855                 * @example
    856                 * await test_driver.bidi.emulation.set_geolocation_override({
    857                 *     coordinates: {
    858                 *         latitude: 52.51,
    859                 *         longitude: 13.39,
    860                 *         accuracy: 0.5,
    861                 *         altitude: 34,
    862                 *         altitudeAccuracy: 0.75,
    863                 *         heading: 180,
    864                 *         speed: 2.77
    865                 *     }
    866                 * });
    867                 *
    868                 * @param {object} params - Parameters for the command.
    869                 * @param {null|object} params.coordinates - The optional
    870                 * geolocation coordinates to set. Matches the
    871                 * `emulation.GeolocationCoordinates <https://w3c.github.io/webdriver-bidi/#commands-emulationsetgeolocationoverride>`_
    872                 * value. If null or omitted and the `params.error` is set, the
    873                 * emulation will be removed. Mutually exclusive with
    874                 * `params.error`.
    875                 * @param {object} params.error - The optional
    876                 * geolocation error to emulate. Matches the
    877                 * `emulation.GeolocationPositionError <https://w3c.github.io/webdriver-bidi/#commands-emulationsetgeolocationoverride>`_
    878                 * value. Mutually exclusive with `params.coordinates`.
    879                 * @param {null|Array.<(Context)>} [params.contexts] The
    880                 * optional contexts parameter specifies which browsing contexts
    881                 * to set the geolocation override on. It should be either an
    882                 * array of Context objects (window or browsing context id), or
    883                 * null. If null or omitted, the override will be set on the
    884                 * current browsing context.
    885                 * @returns {Promise<void>} Resolves when the geolocation
    886                 * override is successfully set.
    887                 */
    888                set_geolocation_override: function (params) {
    889                    // Ensure the bidi feature is enabled before calling the internal method
    890                    assertBidiIsEnabled();
    891                    return window.test_driver_internal.bidi.emulation.set_geolocation_override(
    892                        params);
    893                },
    894                /**
    895                 * Overrides the locale for the specified browsing contexts.
    896                 * Matches the `emulation.setLocaleOverride
    897                 * <https://www.w3.org/TR/webdriver-bidi/#commands-emulationsetlocaleoverride>`_
    898                 * WebDriver BiDi command.
    899                 *
    900                 * @example
    901                 * await test_driver.bidi.emulation.set_locale_override({
    902                 *     locale: 'de-DE'
    903                 * });
    904                 *
    905                 * @param {object} params - Parameters for the command.
    906                 * @param {null|string} params.locale - The optional
    907                 * locale to set.
    908                 * @param {null|Array.<(Context)>} [params.contexts] The
    909                 * optional contexts parameter specifies which browsing contexts
    910                 * to set the locale override on. It should be either an array
    911                 * of Context objects (window or browsing context id), or null.
    912                 * If null or omitted, the override will be set on the current
    913                 * browsing context.
    914                 * @returns {Promise<void>} Resolves when the locale override
    915                 * is successfully set.
    916                 */
    917                set_locale_override: function (params) {
    918                    assertBidiIsEnabled();
    919                    return window.test_driver_internal.bidi.emulation.set_locale_override(
    920                        params);
    921                },
    922                /**
    923                 * Overrides the screen orientation for the specified browsing
    924                 * contexts.
    925                 * Matches the `emulation.setScreenOrientationOverride
    926                 * <https://www.w3.org/TR/webdriver-bidi/#commands-emulationsetscreenorientationoverride>`_
    927                 * WebDriver BiDi command.
    928                 *
    929                 * @example
    930                 * await test_driver.bidi.emulation.set_screen_orientation_override({
    931                 *     screenOrientation: {
    932                 *         natural: 'portrait',
    933                 *         type: 'landscape-secondary'
    934                 *     }
    935                 * });
    936                 *
    937                 * @param {object} params - Parameters for the command.
    938                 * @param {null|object} params.screenOrientation - The optional
    939                 * screen orientation. Matches the
    940                 * `emulation.ScreenOrientation <https://www.w3.org/TR/webdriver-bidi/#cddl-type-emulationscreenorientation>`_
    941                 * type. If null or omitted, the override will be removed.
    942                 * @param {null|Array.<(Context)>} [params.contexts] The
    943                 * optional contexts parameter specifies which browsing contexts
    944                 * to set the screen orientation override on. It should be
    945                 * either an array of Context objects (window or browsing
    946                 * context id), or null. If null or omitted, the override will
    947                 * be set on the current browsing context.
    948                 * @returns {Promise<void>} Resolves when the screen orientation
    949                 * override is successfully set.
    950                 */
    951                set_screen_orientation_override: function (params) {
    952                    // Ensure the bidi feature is enabled before calling the internal method
    953                    assertBidiIsEnabled();
    954                    return window.test_driver_internal.bidi.emulation.set_screen_orientation_override(
    955                        params);
    956                },
    957            },
    958            /**
    959             * `log <https://www.w3.org/TR/webdriver-bidi/#module-log>`_ module.
    960             */
    961            log: {
    962                entry_added: {
    963                    /**
    964                     * @typedef {object} LogEntryAdded `log.entryAdded <https://www.w3.org/TR/webdriver-bidi/#event-log-entryAdded>`_ event.
    965                     */
    966 
    967                    /**
    968                     * Subscribes to the event. Events will be emitted only if
    969                     * there is a subscription for the event. This method does
    970                     * not add actual listeners. To listen to the event, use the
    971                     * `on` or `once` methods. The buffered events will be
    972                     * emitted before the command promise is resolved.
    973                     *
    974                     * @param {object} [params] Parameters for the subscription.
    975                     * @param {null|Array.<(Context)>} [params.contexts] The
    976                     * optional contexts parameter specifies which browsing
    977                     * contexts to subscribe to the event on. It should be
    978                     * either an array of Context objects, or null. If null, the
    979                     * event will be subscribed to globally. If omitted, the
    980                     * event will be subscribed to on the current browsing
    981                     * context.
    982                     * @returns {Promise<(function(): Promise<void>)>} Callback
    983                     * for unsubscribing from the created subscription.
    984                     */
    985                    subscribe: async function (params = {}) {
    986                        assertBidiIsEnabled();
    987                        return window.test_driver_internal.bidi.log.entry_added.subscribe(params);
    988                    },
    989                    /**
    990                     * Adds an event listener for the event.
    991                     *
    992                     * @param {function(LogEntryAdded): void} callback The
    993                     * callback to be called when the event is emitted. The
    994                     * callback is called with the event object as a parameter.
    995                     * @returns {function(): void} A function that removes the
    996                     * added event listener when called.
    997                     */
    998                    on: function (callback) {
    999                        assertBidiIsEnabled();
   1000                        return window.test_driver_internal.bidi.log.entry_added.on(callback);
   1001                    },
   1002                    /**
   1003                     * Adds an event listener for the event that is only called
   1004                     * once and removed afterward.
   1005                     *
   1006                     * @return {Promise<LogEntryAdded>} The promise which is resolved
   1007                     * with the event object when the event is emitted.
   1008                     */
   1009                    once: function () {
   1010                        assertBidiIsEnabled();
   1011                        return new Promise(resolve => {
   1012                            const remove_handler = window.test_driver_internal.bidi.log.entry_added.on(
   1013                                event => {
   1014                                    resolve(event);
   1015                                    remove_handler();
   1016                                });
   1017                        });
   1018                    },
   1019                }
   1020            },
   1021            /**
   1022             * `permissions <https://www.w3.org/TR/permissions/>`_ module.
   1023             */
   1024            permissions: {
   1025                /**
   1026                 * Sets the state of a permission
   1027                 *
   1028                 * This function causes permission requests and queries for the status
   1029                 * of a certain permission type (e.g. "push", or "background-fetch") to
   1030                 * always return ``state`` for the specific origin.
   1031                 *
   1032                 * Matches the `permissions.setPermission <https://w3c.github.io/permissions/#webdriver-bidi-command-permissions-setPermission>`_
   1033                 * WebDriver BiDi command.
   1034                 *
   1035                 * @example
   1036                 * await test_driver.bidi.permissions.set_permission({
   1037                 *     {name: "geolocation"},
   1038                 *     state: "granted",
   1039                 * });
   1040                 *
   1041                 * @param {object} params - Parameters for the command.
   1042                 * @param {PermissionDescriptor} params.descriptor - a `PermissionDescriptor
   1043                 *                               <https://w3c.github.io/permissions/#dom-permissiondescriptor>`_
   1044                 *                               or derived object.
   1045                 * @param {PermissionState} params.state - a `PermissionState
   1046                 *                          <https://w3c.github.io/permissions/#dom-permissionstate>`_
   1047                 *                          value.
   1048                 * @param {string} [params.origin] - an optional top-level `origin` string to set the
   1049                 *                 permission for. If omitted, the permission is set for the
   1050                 *                 current window's origin.
   1051                 * @param {string} [params.embeddedOrigin] - an optional embedded `origin` string to set the
   1052                 *                 permission for. If omitted, the top-level `origin` is used as the
   1053                 *                 embedded origin.
   1054                 * @returns {Promise} fulfilled after the permission is set, or rejected if setting
   1055                 *                    the permission fails.
   1056                 */
   1057                set_permission: function (params) {
   1058                    assertBidiIsEnabled();
   1059                    return window.test_driver_internal.bidi.permissions.set_permission(
   1060                        params);
   1061                }
   1062            }
   1063        },
   1064 
   1065        /**
   1066         * Set the context in which testharness.js is loaded
   1067         *
   1068         * @param {WindowProxy} context - the window containing testharness.js
   1069         **/
   1070        set_test_context: function(context) {
   1071          if (window.test_driver_internal.set_test_context) {
   1072            window.test_driver_internal.set_test_context(context);
   1073          }
   1074          testharness_context = context;
   1075        },
   1076 
   1077        /**
   1078         * postMessage to the context containing testharness.js
   1079         *
   1080         * @param {Object} msg - the data to POST
   1081         **/
   1082        message_test: function(msg) {
   1083            let target = testharness_context;
   1084            if (testharness_context === null) {
   1085                target = window;
   1086            }
   1087            target.postMessage(msg, "*");
   1088        },
   1089 
   1090        /**
   1091         * Trigger user interaction in order to grant additional privileges to
   1092         * a provided function.
   1093         *
   1094         * See `Tracking user activation
   1095         * <https://html.spec.whatwg.org/multipage/interaction.html#tracking-user-activation>`_.
   1096         *
   1097         * @example
   1098         * var mediaElement = document.createElement('video');
   1099         *
   1100         * test_driver.bless('initiate media playback', function () {
   1101         *   mediaElement.play();
   1102         * });
   1103         *
   1104         * @param {String} intent - a description of the action which must be
   1105         *                          triggered by user interaction
   1106         * @param {Function} action - code requiring escalated privileges
   1107         * @param {WindowProxy} context - Browsing context in which
   1108         *                                to run the call, or null for the current
   1109         *                                browsing context.
   1110         *
   1111         * @returns {Promise} fulfilled following user interaction and
   1112         *                    execution of the provided `action` function;
   1113         *                    rejected if interaction fails or the provided
   1114         *                    function throws an error
   1115         */
   1116        bless: function(intent, action, context=null) {
   1117            let contextDocument = context ? context.document : document;
   1118            var button = contextDocument.createElement("button");
   1119            button.innerHTML = "This test requires user interaction.<br />" +
   1120                "Please click here to allow " + intent + ".";
   1121            button.id = "wpt-test-driver-bless-" + (idCounter += 1);
   1122            const elem = contextDocument.body || contextDocument.documentElement;
   1123            elem.appendChild(button);
   1124 
   1125            let wait_click = new Promise(resolve => button.addEventListener("click", resolve));
   1126 
   1127            return test_driver.click(button)
   1128                .then(() => wait_click)
   1129                .then(() => {
   1130                    button.remove();
   1131 
   1132                    if (typeof action === "function") {
   1133                        return action();
   1134                    }
   1135                    return null;
   1136                });
   1137        },
   1138 
   1139        /**
   1140         * Triggers a user-initiated mouse click.
   1141         *
   1142         * If ``element`` isn't inside the viewport, it will be
   1143         * scrolled into view before the click occurs.
   1144         *
   1145         * If ``element`` is from a different browsing context, the
   1146         * command will be run in that context.
   1147         *
   1148         * Matches the behaviour of the `Element Click
   1149         * <https://w3c.github.io/webdriver/#element-click>`_
   1150         * WebDriver command.
   1151         *
   1152         * **Note:** If the element to be clicked does not have a
   1153         * unique ID, the document must not have any DOM mutations
   1154         * made between the function being called and the promise
   1155         * settling.
   1156         *
   1157         * @param {Element} element - element to be clicked
   1158         * @returns {Promise} fulfilled after click occurs, or rejected in
   1159         *                    the cases the WebDriver command errors
   1160         */
   1161        click: function(element) {
   1162            if (!inView(element)) {
   1163                element.scrollIntoView({behavior: "instant",
   1164                                        block: "end",
   1165                                        inline: "nearest"});
   1166            }
   1167 
   1168            var pointerInteractablePaintTree = getPointerInteractablePaintTree(element);
   1169            if (pointerInteractablePaintTree.length === 0 ||
   1170                !element.contains(pointerInteractablePaintTree[0])) {
   1171                return Promise.reject(new Error("element click intercepted error"));
   1172            }
   1173 
   1174            var rect = element.getClientRects()[0];
   1175            var centerPoint = getInViewCenterPoint(rect);
   1176            return window.test_driver_internal.click(element,
   1177                                                     {x: centerPoint[0],
   1178                                                      y: centerPoint[1]});
   1179        },
   1180 
   1181        /**
   1182         * Deletes all cookies.
   1183         *
   1184         * Matches the behaviour of the `Delete All Cookies
   1185         * <https://w3c.github.io/webdriver/#delete-all-cookies>`_
   1186         * WebDriver command.
   1187         *
   1188         * @param {WindowProxy} context - Browsing context in which
   1189         *                                to run the call, or null for the current
   1190         *                                browsing context.
   1191         *
   1192         * @returns {Promise} fulfilled after cookies are deleted, or rejected in
   1193         *                    the cases the WebDriver command errors
   1194         */
   1195        delete_all_cookies: function(context=null) {
   1196            return window.test_driver_internal.delete_all_cookies(context);
   1197        },
   1198 
   1199        /**
   1200         * Get details for all cookies in the current context.
   1201         * See https://w3c.github.io/webdriver/#get-all-cookies
   1202         *
   1203         * @param {WindowProxy} context - Browsing context in which
   1204         *                                to run the call, or null for the current
   1205         *                                browsing context.
   1206         *
   1207         * @returns {Promise} Returns an array of cookies objects as defined in the spec:
   1208         *                    https://w3c.github.io/webdriver/#cookies
   1209         */
   1210        get_all_cookies: function(context=null) {
   1211            return window.test_driver_internal.get_all_cookies(context);
   1212        },
   1213 
   1214        /**
   1215         * Get details for a cookie in the current context by name if it exists.
   1216         * See https://w3c.github.io/webdriver/#get-named-cookie
   1217         *
   1218         * @param {String} name - The name of the cookie to get.
   1219         * @param {WindowProxy} context - Browsing context in which
   1220         *                                to run the call, or null for the current
   1221         *                                browsing context.
   1222         *
   1223         * @returns {Promise} Returns the matching cookie as defined in the spec:
   1224         *                    https://w3c.github.io/webdriver/#cookies
   1225         *                    Rejected if no such cookie exists.
   1226         */
   1227         get_named_cookie: async function(name, context=null) {
   1228            let cookie = await window.test_driver_internal.get_named_cookie(name, context);
   1229            if (!cookie) {
   1230                throw new Error("no such cookie");
   1231            }
   1232            return cookie;
   1233        },
   1234 
   1235        /**
   1236         * Get Computed Label for an element.
   1237         *
   1238         * This matches the behaviour of the
   1239         * `Get Computed Label
   1240         * <https://w3c.github.io/webdriver/#dfn-get-computed-label>`_
   1241         * WebDriver command.
   1242         *
   1243         * @param {Element} element
   1244         * @returns {Promise} fulfilled after the computed label is returned, or
   1245         *                    rejected in the cases the WebDriver command errors
   1246         */
   1247        get_computed_label: async function(element) {
   1248            let label = await window.test_driver_internal.get_computed_label(element);
   1249            return label;
   1250        },
   1251 
   1252        /**
   1253         * Get Computed Role for an element.
   1254         *
   1255         * This matches the behaviour of the
   1256         * `Get Computed Label
   1257         * <https://w3c.github.io/webdriver/#dfn-get-computed-role>`_
   1258         * WebDriver command.
   1259         *
   1260         * @param {Element} element
   1261         * @returns {Promise} fulfilled after the computed role is returned, or
   1262         *                    rejected in the cases the WebDriver command errors
   1263         */
   1264        get_computed_role: async function(element) {
   1265            let role = await window.test_driver_internal.get_computed_role(element);
   1266            return role;
   1267        },
   1268 
   1269        /**
   1270         * Send keys to an element.
   1271         *
   1272         * If ``element`` isn't inside the
   1273         * viewport, it will be scrolled into view before the click
   1274         * occurs.
   1275         *
   1276         * If ``element`` is from a different browsing context, the
   1277         * command will be run in that context. The test must not depend
   1278         * on the ``window.name`` property being unset on the target
   1279         * window.
   1280         *
   1281         * To send special keys, send the respective key's codepoint,
   1282         * as defined by `WebDriver
   1283         * <https://w3c.github.io/webdriver/#keyboard-actions>`_.  For
   1284         * example, the "tab" key is represented as "``\uE004``".
   1285         *
   1286         * **Note:** these special-key codepoints are not necessarily
   1287         * what you would expect. For example, <kbd>Esc</kbd> is the
   1288         * invalid Unicode character ``\uE00C``, not the ``\u001B`` Escape
   1289         * character from ASCII.
   1290         *
   1291         * This matches the behaviour of the
   1292         * `Send Keys
   1293         * <https://w3c.github.io/webdriver/#element-send-keys>`_
   1294         * WebDriver command.
   1295         *
   1296         * **Note:** If the element to be clicked does not have a
   1297         * unique ID, the document must not have any DOM mutations
   1298         * made between the function being called and the promise
   1299         * settling.
   1300         *
   1301         * @param {Element} element - element to send keys to
   1302         * @param {String} keys - keys to send to the element
   1303         * @returns {Promise} fulfilled after keys are sent, or rejected in
   1304         *                    the cases the WebDriver command errors
   1305         */
   1306        send_keys: function(element, keys) {
   1307            if (!inView(element)) {
   1308                element.scrollIntoView({behavior: "instant",
   1309                                        block: "end",
   1310                                        inline: "nearest"});
   1311            }
   1312 
   1313            return window.test_driver_internal.send_keys(element, keys);
   1314        },
   1315 
   1316        /**
   1317         * Freeze the current page
   1318         *
   1319         * The freeze function transitions the page from the HIDDEN state to
   1320         * the FROZEN state as described in `Lifecycle API for Web Pages
   1321         * <https://github.com/WICG/page-lifecycle/blob/master/README.md>`_.
   1322         *
   1323         * @param {WindowProxy} context - Browsing context in which
   1324         *                                to run the call, or null for the current
   1325         *                                browsing context.
   1326         *
   1327         * @returns {Promise} fulfilled after the freeze request is sent, or rejected
   1328         *                    in case the WebDriver command errors
   1329         */
   1330        freeze: function(context=null) {
   1331            return window.test_driver_internal.freeze();
   1332        },
   1333 
   1334        /**
   1335         * Minimizes the browser window.
   1336         *
   1337         * Matches the behaviour of the `Minimize
   1338         * <https://www.w3.org/TR/webdriver/#minimize-window>`_
   1339         * WebDriver command
   1340         *
   1341         * @param {WindowProxy} context - Browsing context in which
   1342         *                                to run the call, or null for the current
   1343         *                                browsing context.
   1344         *
   1345         * @returns {Promise} fulfilled with the previous `WindowRect
   1346         *                    <https://www.w3.org/TR/webdriver/#dfn-windowrect-object>`_
   1347         *                    value, after the window is minimized.
   1348         */
   1349        minimize_window: function(context=null) {
   1350            return window.test_driver_internal.minimize_window(context);
   1351        },
   1352 
   1353        /**
   1354         * Restore the window from minimized/maximized state to a given rect.
   1355         *
   1356         * Matches the behaviour of the `Set Window Rect
   1357         * <https://www.w3.org/TR/webdriver/#set-window-rect>`_
   1358         * WebDriver command
   1359         *
   1360         * @param {Object} rect - A `WindowRect
   1361         *                        <https://www.w3.org/TR/webdriver/#dfn-windowrect-object>`_
   1362         * @param {WindowProxy} context - Browsing context in which
   1363         *                                to run the call, or null for the current
   1364         *                                browsing context.
   1365         *
   1366         * @returns {Promise} fulfilled after the window is restored to the given rect.
   1367         */
   1368        set_window_rect: function(rect, context=null) {
   1369            return window.test_driver_internal.set_window_rect(rect, context);
   1370        },
   1371 
   1372        /**
   1373         * Gets a rect with the size and position on the screen from the current window state.
   1374         *
   1375         * Matches the behaviour of the `Get Window Rect
   1376         * <https://www.w3.org/TR/webdriver/#get-window-rect>`_
   1377         * WebDriver command
   1378         *
   1379         * @param {WindowProxy} context - Browsing context in which
   1380         *                                to run the call, or null for the current
   1381         *                                browsing context.
   1382         *
   1383         * @returns {Promise} fulfilled after the window rect is returned, or rejected
   1384         * in cases the WebDriver command returns errors. Returns a
   1385         * `WindowRect <https://www.w3.org/TR/webdriver/#dfn-windowrect-object>`_
   1386         */
   1387        get_window_rect: function(context=null) {
   1388            return window.test_driver_internal.get_window_rect(context);
   1389        },
   1390 
   1391        /**
   1392         * Send a sequence of actions
   1393         *
   1394         * This function sends a sequence of actions to perform.
   1395         *
   1396         * Matches the behaviour of the `Actions
   1397         * <https://w3c.github.io/webdriver/#actions>`_ feature in
   1398         * WebDriver.
   1399         *
   1400         * Authors are encouraged to use the
   1401         * :js:class:`test_driver.Actions` builder rather than
   1402         * invoking this API directly.
   1403         *
   1404         * @param {Array} actions - an array of actions. The format is
   1405         *                          the same as the actions property
   1406         *                          of the `Perform Actions
   1407         *                          <https://w3c.github.io/webdriver/#perform-actions>`_
   1408         *                          WebDriver command. Each element is
   1409         *                          an object representing an input
   1410         *                          source and each input source
   1411         *                          itself has an actions property
   1412         *                          detailing the behaviour of that
   1413         *                          source at each timestep (or
   1414         *                          tick). Authors are not expected to
   1415         *                          construct the actions sequence by
   1416         *                          hand, but to use the builder api
   1417         *                          provided in testdriver-actions.js
   1418         * @param {WindowProxy} context - Browsing context in which
   1419         *                                to run the call, or null for the current
   1420         *                                browsing context.
   1421         *
   1422         * @returns {Promise} fulfilled after the actions are performed, or rejected in
   1423         *                    the cases the WebDriver command errors
   1424         */
   1425        action_sequence: function(actions, context=null) {
   1426            return window.test_driver_internal.action_sequence(actions, context);
   1427        },
   1428 
   1429        /**
   1430         * Generates a test report on the current page
   1431         *
   1432         * The generate_test_report function generates a report (to be
   1433         * observed by ReportingObserver) for testing purposes.
   1434         *
   1435         * Matches the `Generate Test Report
   1436         * <https://w3c.github.io/reporting/#generate-test-report-command>`_
   1437         * WebDriver command.
   1438         *
   1439         * @param {WindowProxy} context - Browsing context in which
   1440         *                                to run the call, or null for the current
   1441         *                                browsing context.
   1442         *
   1443         * @returns {Promise} fulfilled after the report is generated, or
   1444         *                    rejected if the report generation fails
   1445         */
   1446        generate_test_report: function(message, context=null) {
   1447            return window.test_driver_internal.generate_test_report(message, context);
   1448        },
   1449 
   1450        /**
   1451         * Sets the state of a permission
   1452         *
   1453         * This function causes permission requests and queries for the status
   1454         * of a certain permission type (e.g. "push", or "background-fetch") to
   1455         * always return ``state``.
   1456         *
   1457         * Matches the `Set Permission
   1458         * <https://w3c.github.io/permissions/#set-permission-command>`_
   1459         * WebDriver command.
   1460         *
   1461         * @example
   1462         * await test_driver.set_permission({ name: "background-fetch" }, "denied");
   1463         * await test_driver.set_permission({ name: "push", userVisibleOnly: true }, "granted");
   1464         *
   1465         * @param {PermissionDescriptor} descriptor - a `PermissionDescriptor
   1466         *                              <https://w3c.github.io/permissions/#dom-permissiondescriptor>`_
   1467         *                              or derived object.
   1468         * @param {PermissionState} state - a `PermissionState
   1469         *                          <https://w3c.github.io/permissions/#dom-permissionstate>`_
   1470         *                          value.
   1471         * @param {WindowProxy} context - Browsing context in which
   1472         *                                to run the call, or null for the current
   1473         *                                browsing context.
   1474         * @returns {Promise} fulfilled after the permission is set, or rejected if setting the
   1475         *                    permission fails
   1476         */
   1477        set_permission: function(descriptor, state, context=null) {
   1478            let permission_params = {
   1479              descriptor,
   1480              state,
   1481            };
   1482            return window.test_driver_internal.set_permission(permission_params, context);
   1483        },
   1484 
   1485        /**
   1486         * Creates a virtual authenticator
   1487         *
   1488         * This function creates a virtual authenticator for use with
   1489         * the U2F and WebAuthn APIs.
   1490         *
   1491         * Matches the `Add Virtual Authenticator
   1492         * <https://w3c.github.io/webauthn/#sctn-automation-add-virtual-authenticator>`_
   1493         * WebDriver command.
   1494         *
   1495         * @param {Object} config - an `Authenticator Configuration
   1496         *                          <https://w3c.github.io/webauthn/#authenticator-configuration>`_
   1497         *                          object
   1498         * @param {WindowProxy} context - Browsing context in which
   1499         *                                to run the call, or null for the current
   1500         *                                browsing context.
   1501         *
   1502         * @returns {Promise} fulfilled after the authenticator is added, or
   1503         *                    rejected in the cases the WebDriver command
   1504         *                    errors. Returns the ID of the authenticator
   1505         */
   1506        add_virtual_authenticator: function(config, context=null) {
   1507            return window.test_driver_internal.add_virtual_authenticator(config, context);
   1508        },
   1509 
   1510        /**
   1511         * Removes a virtual authenticator
   1512         *
   1513         * This function removes a virtual authenticator that has been
   1514         * created by :js:func:`add_virtual_authenticator`.
   1515         *
   1516         * Matches the `Remove Virtual Authenticator
   1517         * <https://w3c.github.io/webauthn/#sctn-automation-remove-virtual-authenticator>`_
   1518         * WebDriver command.
   1519         *
   1520         * @param {String} authenticator_id - the ID of the authenticator to be
   1521         *                                    removed.
   1522         * @param {WindowProxy} context - Browsing context in which
   1523         *                                to run the call, or null for the current
   1524         *                                browsing context.
   1525         *
   1526         * @returns {Promise} fulfilled after the authenticator is removed, or
   1527         *                    rejected in the cases the WebDriver command
   1528         *                    errors
   1529         */
   1530        remove_virtual_authenticator: function(authenticator_id, context=null) {
   1531            return window.test_driver_internal.remove_virtual_authenticator(authenticator_id, context);
   1532        },
   1533 
   1534        /**
   1535         * Adds a credential to a virtual authenticator
   1536         *
   1537         * Matches the `Add Credential
   1538         * <https://w3c.github.io/webauthn/#sctn-automation-add-credential>`_
   1539         * WebDriver command.
   1540         *
   1541         * @param {String} authenticator_id - the ID of the authenticator
   1542         * @param {Object} credential - A `Credential Parameters
   1543         *                              <https://w3c.github.io/webauthn/#credential-parameters>`_
   1544         *                              object
   1545         * @param {WindowProxy} context - Browsing context in which
   1546         *                                to run the call, or null for the current
   1547         *                                browsing context.
   1548         *
   1549         * @returns {Promise} fulfilled after the credential is added, or
   1550         *                    rejected in the cases the WebDriver command
   1551         *                    errors
   1552         */
   1553        add_credential: function(authenticator_id, credential, context=null) {
   1554            return window.test_driver_internal.add_credential(authenticator_id, credential, context);
   1555        },
   1556 
   1557        /**
   1558         * Gets all the credentials stored in an authenticator
   1559         *
   1560         * This function retrieves all the credentials (added via the U2F API,
   1561         * WebAuthn, or the add_credential function) stored in a virtual
   1562         * authenticator
   1563         *
   1564         * Matches the `Get Credentials
   1565         * <https://w3c.github.io/webauthn/#sctn-automation-get-credentials>`_
   1566         * WebDriver command.
   1567         *
   1568         * @param {String} authenticator_id - the ID of the authenticator
   1569         * @param {WindowProxy} context - Browsing context in which
   1570         *                                to run the call, or null for the current
   1571         *                                browsing context.
   1572         *
   1573         * @returns {Promise} fulfilled after the credentials are
   1574         *                    returned, or rejected in the cases the
   1575         *                    WebDriver command errors. Returns an
   1576         *                    array of `Credential Parameters
   1577         *                    <https://w3c.github.io/webauthn/#credential-parameters>`_
   1578         */
   1579        get_credentials: function(authenticator_id, context=null) {
   1580            return window.test_driver_internal.get_credentials(authenticator_id, context=null);
   1581        },
   1582 
   1583        /**
   1584         * Remove a credential stored in an authenticator
   1585         *
   1586         * Matches the `Remove Credential
   1587         * <https://w3c.github.io/webauthn/#sctn-automation-remove-credential>`_
   1588         * WebDriver command.
   1589         *
   1590         * @param {String} authenticator_id - the ID of the authenticator
   1591         * @param {String} credential_id - the ID of the credential
   1592         * @param {WindowProxy} context - Browsing context in which
   1593         *                                to run the call, or null for the current
   1594         *                                browsing context.
   1595         *
   1596         * @returns {Promise} fulfilled after the credential is removed, or
   1597         *                    rejected in the cases the WebDriver command
   1598         *                    errors.
   1599         */
   1600        remove_credential: function(authenticator_id, credential_id, context=null) {
   1601            return window.test_driver_internal.remove_credential(authenticator_id, credential_id, context);
   1602        },
   1603 
   1604        /**
   1605         * Removes all the credentials stored in a virtual authenticator
   1606         *
   1607         * Matches the `Remove All Credentials
   1608         * <https://w3c.github.io/webauthn/#sctn-automation-remove-all-credentials>`_
   1609         * WebDriver command.
   1610         *
   1611         * @param {String} authenticator_id - the ID of the authenticator
   1612         * @param {WindowProxy} context - Browsing context in which
   1613         *                                to run the call, or null for the current
   1614         *                                browsing context.
   1615         *
   1616         * @returns {Promise} fulfilled after the credentials are removed, or
   1617         *                    rejected in the cases the WebDriver command
   1618         *                    errors.
   1619         */
   1620        remove_all_credentials: function(authenticator_id, context=null) {
   1621            return window.test_driver_internal.remove_all_credentials(authenticator_id, context);
   1622        },
   1623 
   1624        /**
   1625         * Sets the User Verified flag on an authenticator
   1626         *
   1627         * Sets whether requests requiring user verification will succeed or
   1628         * fail on a given virtual authenticator
   1629         *
   1630         * Matches the `Set User Verified
   1631         * <https://w3c.github.io/webauthn/#sctn-automation-set-user-verified>`_
   1632         * WebDriver command.
   1633         *
   1634         * @param {String} authenticator_id - the ID of the authenticator
   1635         * @param {boolean} uv - the User Verified flag
   1636         * @param {WindowProxy} context - Browsing context in which
   1637         *                                to run the call, or null for the current
   1638         *                                browsing context.
   1639         */
   1640        set_user_verified: function(authenticator_id, uv, context=null) {
   1641            return window.test_driver_internal.set_user_verified(authenticator_id, uv, context);
   1642        },
   1643 
   1644        /**
   1645         * Sets the storage access rule for an origin when embedded
   1646         * in a third-party context.
   1647         *
   1648         * Matches the `Set Storage Access
   1649         * <https://privacycg.github.io/storage-access/#set-storage-access-command>`_
   1650         * WebDriver command.
   1651         *
   1652         * @param {String} origin - A third-party origin to block or allow.
   1653         *                          May be "*" to indicate all origins.
   1654         * @param {String} embedding_origin - an embedding (first-party) origin
   1655         *                                    on which {origin}'s access should
   1656         *                                    be blocked or allowed.
   1657         *                                    May be "*" to indicate all origins.
   1658         * @param {String} state - The storage access setting.
   1659         *                         Must be either "allowed" or "blocked".
   1660         * @param {WindowProxy} context - Browsing context in which
   1661         *                                to run the call, or null for the current
   1662         *                                browsing context.
   1663         *
   1664         * @returns {Promise} Fulfilled after the storage access rule has been
   1665         *                    set, or rejected if setting the rule fails.
   1666         */
   1667        set_storage_access: function(origin, embedding_origin, state, context=null) {
   1668            if (state !== "allowed" && state !== "blocked") {
   1669                throw new Error("storage access status must be 'allowed' or 'blocked'");
   1670            }
   1671            const blocked = state === "blocked";
   1672            return window.test_driver_internal.set_storage_access(origin, embedding_origin, blocked, context);
   1673        },
   1674 
   1675        /**
   1676         * Sets the current transaction automation mode for Secure Payment
   1677         * Confirmation.
   1678         *
   1679         * This function places `Secure Payment
   1680         * Confirmation <https://w3c.github.io/secure-payment-confirmation>`_ into
   1681         * an automated 'autoAccept' or 'autoReject' mode, to allow testing
   1682         * without user interaction with the transaction UX prompt.
   1683         *
   1684         * Matches the `Set SPC Transaction Mode
   1685         * <https://w3c.github.io/secure-payment-confirmation/#sctn-automation-set-spc-transaction-mode>`_
   1686         * WebDriver command.
   1687         *
   1688         * @example
   1689         * await test_driver.set_spc_transaction_mode("autoaccept");
   1690         * test.add_cleanup(() => {
   1691         *   return test_driver.set_spc_transaction_mode("none");
   1692         * });
   1693         *
   1694         * // Assumption: `request` is a PaymentRequest with a secure-payment-confirmation
   1695         * // payment method.
   1696         * const response = await request.show();
   1697         *
   1698         * @param {String} mode - The `transaction mode
   1699         *                        <https://w3c.github.io/secure-payment-confirmation/#enumdef-transactionautomationmode>`_
   1700         *                        to set. Must be one of "``none``",
   1701         *                        "``autoAccept``", or
   1702         *                        "``autoReject``".
   1703         * @param {WindowProxy} context - Browsing context in which
   1704         *                                to run the call, or null for the current
   1705         *                                browsing context.
   1706         *
   1707         * @returns {Promise} Fulfilled after the transaction mode has been set,
   1708         *                    or rejected if setting the mode fails.
   1709         */
   1710        set_spc_transaction_mode: function(mode, context=null) {
   1711          return window.test_driver_internal.set_spc_transaction_mode(mode, context);
   1712        },
   1713 
   1714        /**
   1715         * Sets the current registration automation mode for Register Protocol Handlers.
   1716         *
   1717         * This function places `Register Protocol Handlers
   1718         * <https://html.spec.whatwg.org/multipage/system-state.html#custom-handlers>`_ into
   1719         * an automated 'autoAccept' or 'autoReject' mode, to allow testing
   1720         * without user interaction with the transaction UX prompt.
   1721         *
   1722         * Matches the `Set Register Protocol Handler Mode
   1723         * <https://html.spec.whatwg.org/multipage/system-state.html#set-rph-registration-mode>`_
   1724         * WebDriver command.
   1725         *
   1726         * @example
   1727         * await test_driver.set_rph_registration_mode("autoAccept");
   1728         * test.add_cleanup(() => {
   1729         *   return test_driver.set_rph_registration_mode("none");
   1730         * });
   1731         *
   1732         * navigator.registerProtocolHandler('web+soup', 'soup?url=%s');
   1733         *
   1734         * @param {String} mode - The `registration mode
   1735         *                        <https://html.spec.whatwg.org/multipage/system-state.html#registerprotocolhandler()-automation-mode>`_
   1736         *                        to set. Must be one of "``none``",
   1737         *                        "``autoAccept``", or
   1738         *                        "``autoReject``".
   1739         * @param {WindowProxy} context - Browsing context in which
   1740         *                                to run the call, or null for the current
   1741         *                                browsing context.
   1742         *
   1743         * @returns {Promise} Fulfilled after the transaction mode has been set,
   1744         *                    or rejected if setting the mode fails.
   1745         */
   1746        set_rph_registration_mode: function(mode, context=null) {
   1747          return window.test_driver_internal.set_rph_registration_mode(mode, context);
   1748        },
   1749 
   1750        /**
   1751         * Cancels the Federated Credential Management dialog
   1752         *
   1753         * Matches the `Cancel dialog
   1754         * <https://fedidcg.github.io/FedCM/#webdriver-canceldialog>`_
   1755         * WebDriver command.
   1756         *
   1757         * @param {WindowProxy} context - Browsing context in which
   1758         *                                to run the call, or null for the current
   1759         *                                browsing context.
   1760         *
   1761         * @returns {Promise} Fulfilled after the dialog is canceled, or rejected
   1762         *                    in case the WebDriver command errors
   1763         */
   1764        cancel_fedcm_dialog: function(context=null) {
   1765            return window.test_driver_internal.cancel_fedcm_dialog(context);
   1766        },
   1767 
   1768        /**
   1769         * Clicks a button on the Federated Credential Management dialog
   1770         *
   1771         * Matches the `Click dialog button
   1772         * <https://fedidcg.github.io/FedCM/#webdriver-clickdialogbutton>`_
   1773         * WebDriver command.
   1774         *
   1775         * @param {String} dialog_button - String enum representing the dialog button to click.
   1776         * @param {WindowProxy} context - Browsing context in which
   1777         *                                to run the call, or null for the current
   1778         *                                browsing context.
   1779         *
   1780         * @returns {Promise} Fulfilled after the button is clicked,
   1781         *                    or rejected in case the WebDriver command errors
   1782         */
   1783        click_fedcm_dialog_button: function(dialog_button, context=null) {
   1784          return window.test_driver_internal.click_fedcm_dialog_button(dialog_button, context);
   1785        },
   1786 
   1787        /**
   1788         * Selects an account from the Federated Credential Management dialog
   1789         *
   1790         * Matches the `Select account
   1791         * <https://fedidcg.github.io/FedCM/#webdriver-selectaccount>`_
   1792         * WebDriver command.
   1793         *
   1794         * @param {number} account_index - Index of the account to select.
   1795         * @param {WindowProxy} context - Browsing context in which
   1796         *                                to run the call, or null for the current
   1797         *                                browsing context.
   1798         *
   1799         * @returns {Promise} Fulfilled after the account is selected,
   1800         *                    or rejected in case the WebDriver command errors
   1801         */
   1802        select_fedcm_account: function(account_index, context=null) {
   1803          return window.test_driver_internal.select_fedcm_account(account_index, context);
   1804        },
   1805 
   1806        /**
   1807         * Gets the account list from the Federated Credential Management dialog
   1808         *
   1809         * Matches the `Account list
   1810         * <https://fedidcg.github.io/FedCM/#webdriver-accountlist>`_
   1811         * WebDriver command.
   1812         *
   1813         * @param {WindowProxy} context - Browsing context in which
   1814         *                                to run the call, or null for the current
   1815         *                                browsing context.
   1816         *
   1817         * @returns {Promise} fulfilled after the account list is returned, or
   1818         *                    rejected in case the WebDriver command errors
   1819         */
   1820        get_fedcm_account_list: function(context=null) {
   1821          return window.test_driver_internal.get_fedcm_account_list(context);
   1822        },
   1823 
   1824        /**
   1825         * Gets the title of the Federated Credential Management dialog
   1826         *
   1827         * Matches the `Get title
   1828         * <https://fedidcg.github.io/FedCM/#webdriver-gettitle>`_
   1829         * WebDriver command.
   1830         *
   1831         * @param {WindowProxy} context - Browsing context in which
   1832         *                                to run the call, or null for the current
   1833         *                                browsing context.
   1834         *
   1835         * @returns {Promise} Fulfilled after the title is returned, or rejected
   1836         *                    in case the WebDriver command errors
   1837         */
   1838        get_fedcm_dialog_title: function(context=null) {
   1839          return window.test_driver_internal.get_fedcm_dialog_title(context);
   1840        },
   1841 
   1842        /**
   1843         * Gets the type of the Federated Credential Management dialog
   1844         *
   1845         * Matches the `Get dialog type
   1846         * <https://fedidcg.github.io/FedCM/#webdriver-getdialogtype>`_
   1847         * WebDriver command.
   1848         *
   1849         * @param {WindowProxy} context - Browsing context in which
   1850         *                                to run the call, or null for the current
   1851         *                                browsing context.
   1852         *
   1853         * @returns {Promise} Fulfilled after the dialog type is returned, or
   1854         *                    rejected in case the WebDriver command errors
   1855         */
   1856        get_fedcm_dialog_type: function(context=null) {
   1857          return window.test_driver_internal.get_fedcm_dialog_type(context);
   1858        },
   1859 
   1860        /**
   1861         * Sets whether promise rejection delay is enabled for the Federated Credential Management dialog
   1862         *
   1863         * Matches the `Set delay enabled
   1864         * <https://fedidcg.github.io/FedCM/#webdriver-setdelayenabled>`_
   1865         * WebDriver command.
   1866         *
   1867         * @param {boolean} enabled - Whether to delay FedCM promise rejection.
   1868         * @param {WindowProxy} context - Browsing context in which
   1869         *                                to run the call, or null for the current
   1870         *                                browsing context.
   1871         *
   1872         * @returns {Promise} Fulfilled after the delay has been enabled or disabled,
   1873         *                    or rejected in case the WebDriver command errors
   1874         */
   1875        set_fedcm_delay_enabled: function(enabled, context=null) {
   1876          return window.test_driver_internal.set_fedcm_delay_enabled(enabled, context);
   1877        },
   1878 
   1879        /**
   1880         * Resets the Federated Credential Management dialog's cooldown
   1881         *
   1882         * Matches the `Reset cooldown
   1883         * <https://fedidcg.github.io/FedCM/#webdriver-resetcooldown>`_
   1884         * WebDriver command.
   1885         *
   1886         * @param {WindowProxy} context - Browsing context in which
   1887         *                                to run the call, or null for the current
   1888         *                                browsing context.
   1889         *
   1890         * @returns {Promise} Fulfilled after the cooldown has been reset,
   1891         *                    or rejected in case the WebDriver command errors
   1892         */
   1893        reset_fedcm_cooldown: function(context=null) {
   1894          return window.test_driver_internal.reset_fedcm_cooldown(context);
   1895        },
   1896 
   1897        /**
   1898         * Creates a virtual sensor for use with the Generic Sensors APIs.
   1899         *
   1900         * Matches the `Create Virtual Sensor
   1901         * <https://w3c.github.io/sensors/#create-virtual-sensor-command>`_
   1902         * WebDriver command.
   1903         *
   1904         * Once created, a virtual sensor is available to all navigables under
   1905         * the same top-level traversable (i.e. all frames in the same page,
   1906         * regardless of origin).
   1907         *
   1908         * @param {String} sensor_type - A `virtual sensor type
   1909         *                               <https://w3c.github.io/sensors/#virtual-sensor-metadata-virtual-sensor-type>`_
   1910         *                               such as "accelerometer".
   1911         * @param {Object} [sensor_params={}] - Optional parameters described
   1912         *                                     in `Create Virtual Sensor
   1913         *                                     <https://w3c.github.io/sensors/#create-virtual-sensor-command>`_.
   1914         * @param {WindowProxy} [context=null] - Browsing context in which to
   1915         *                                       run the call, or null for the
   1916         *                                       current browsing context.
   1917         *
   1918         * @returns {Promise} Fulfilled when virtual sensor is created.
   1919         *                    Rejected in case the WebDriver command errors out
   1920         *                    (including if a virtual sensor of the same type
   1921         *                    already exists).
   1922         */
   1923        create_virtual_sensor: function(sensor_type, sensor_params={}, context=null) {
   1924          return window.test_driver_internal.create_virtual_sensor(sensor_type, sensor_params, context);
   1925        },
   1926 
   1927        /**
   1928         * Causes a virtual sensor to report a new reading to any connected
   1929         * platform sensor.
   1930         *
   1931         * Matches the `Update Virtual Sensor Reading
   1932         * <https://w3c.github.io/sensors/#update-virtual-sensor-reading-command>`_
   1933         * WebDriver command.
   1934         *
   1935         * Note: The ``Promise`` it returns may fulfill before or after a
   1936         * "reading" event is fired. When using
   1937         * :js:func:`EventWatcher.wait_for`, it is necessary to take this into
   1938         * account:
   1939         *
   1940         * Note: New values may also be discarded due to the checks in `update
   1941         * latest reading
   1942         * <https://w3c.github.io/sensors/#update-latest-reading>`_.
   1943         *
   1944         * @example
   1945         * // Avoid races between EventWatcher and update_virtual_sensor().
   1946         * // This assumes you are sure this reading will be processed (see
   1947         * // the example below otherwise).
   1948         * const reading = { x: 1, y: 2, z: 3 };
   1949         * await Promise.all([
   1950         *   test_driver.update_virtual_sensor('gyroscope', reading),
   1951         *   watcher.wait_for('reading')
   1952         * ]);
   1953         *
   1954         * @example
   1955         * // Do not wait forever if you are not sure the reading will be
   1956         * // processed.
   1957         * const readingPromise = watcher.wait_for('reading');
   1958         * const timeoutPromise = new Promise(resolve => {
   1959         *     t.step_timeout(() => resolve('TIMEOUT', 3000))
   1960         * });
   1961         *
   1962         * const reading = { x: 1, y: 2, z: 3 };
   1963         * await test_driver.update_virtual_sensor('gyroscope', 'reading');
   1964         *
   1965         * const value =
   1966         *     await Promise.race([timeoutPromise, readingPromise]);
   1967         * if (value !== 'TIMEOUT') {
   1968         *   // Do something. The "reading" event was fired.
   1969         * }
   1970         *
   1971         * @param {String} sensor_type - A `virtual sensor type
   1972         *                               <https://w3c.github.io/sensors/#virtual-sensor-metadata-virtual-sensor-type>`_
   1973         *                               such as "accelerometer".
   1974         * @param {Object} reading - An Object describing a reading in a format
   1975         *                           dependent on ``sensor_type`` (e.g. ``{x:
   1976         *                           1, y: 2, z: 3}`` or ``{ illuminance: 42
   1977         *                           }``).
   1978         * @param {WindowProxy} [context=null] - Browsing context in which to
   1979         *                                       run the call, or null for the
   1980         *                                       current browsing context.
   1981         *
   1982         * @returns {Promise} Fulfilled after the reading update reaches the
   1983         *                    virtual sensor. Rejected in case the WebDriver
   1984         *                    command errors out (including if a virtual sensor
   1985         *                    of the given type does not exist).
   1986         */
   1987        update_virtual_sensor: function(sensor_type, reading, context=null) {
   1988          return window.test_driver_internal.update_virtual_sensor(sensor_type, reading, context);
   1989        },
   1990 
   1991        /**
   1992         * Triggers the removal of a virtual sensor if it exists.
   1993         *
   1994         * Matches the `Delete Virtual Sensor
   1995         * <https://w3c.github.io/sensors/#delete-virtual-sensor-command>`_
   1996         * WebDriver command.
   1997         *
   1998         * @param {String} sensor_type - A `virtual sensor type
   1999         *                               <https://w3c.github.io/sensors/#virtual-sensor-metadata-virtual-sensor-type>`_
   2000         *                               such as "accelerometer".
   2001         * @param {WindowProxy} [context=null] - Browsing context in which to
   2002         *                                       run the call, or null for the
   2003         *                                       current browsing context.
   2004         *
   2005         * @returns {Promise} Fulfilled after the virtual sensor has been
   2006         *                    removed or if a sensor of the given type does not
   2007         *                    exist. Rejected in case the WebDriver command
   2008         *                    errors out.
   2009 
   2010         */
   2011        remove_virtual_sensor: function(sensor_type, context=null) {
   2012          return window.test_driver_internal.remove_virtual_sensor(sensor_type, context);
   2013        },
   2014 
   2015        /**
   2016         * Returns information about a virtual sensor.
   2017         *
   2018         * Matches the `Get Virtual Sensor Information
   2019         * <https://w3c.github.io/sensors/#get-virtual-sensor-information-command>`_
   2020         * WebDriver command.
   2021         *
   2022         * @param {String} sensor_type - A `virtual sensor type
   2023         *                               <https://w3c.github.io/sensors/#virtual-sensor-metadata-virtual-sensor-type>`_
   2024         *                               such as "accelerometer".
   2025         * @param {WindowProxy} [context=null] - Browsing context in which to
   2026         *                                       run the call, or null for the
   2027         *                                       current browsing context.
   2028         *
   2029         * @returns {Promise} Fulfilled with an Object with the properties
   2030         *                    described in `Get Virtual Sensor Information
   2031         *                    <https://w3c.github.io/sensors/#get-virtual-sensor-information-command>`_.
   2032         *                    Rejected in case the WebDriver command errors out
   2033         *                    (including if a virtual sensor of the given type
   2034         *                    does not exist).
   2035         */
   2036        get_virtual_sensor_information: function(sensor_type, context=null) {
   2037            return window.test_driver_internal.get_virtual_sensor_information(sensor_type, context);
   2038        },
   2039 
   2040        /**
   2041         * Overrides device posture set by hardware.
   2042         *
   2043         * Matches the `Set device posture
   2044         * <https://w3c.github.io/device-posture/#set-device-posture>`_
   2045         * WebDriver command.
   2046         *
   2047         * @param {String} posture - A `DevicePostureType
   2048         *                           <https://w3c.github.io/device-posture/#dom-deviceposturetype>`_
   2049         *                           either "continuous" or "folded".
   2050         * @param {WindowProxy} [context=null] - Browsing context in which to
   2051         *                                       run the call, or null for the
   2052         *                                       current browsing context.
   2053         *
   2054         * @returns {Promise} Fulfilled when device posture is set.
   2055         *                    Rejected in case the WebDriver command errors out
   2056         *                    (including if a device posture of the given type
   2057         *                    does not exist).
   2058         */
   2059        set_device_posture: function(posture, context=null) {
   2060            return window.test_driver_internal.set_device_posture(posture, context);
   2061        },
   2062 
   2063        /**
   2064         * Removes device posture override and returns device posture control
   2065         * back to hardware.
   2066         *
   2067         * Matches the `Clear device posture
   2068         * <https://w3c.github.io/device-posture/#clear-device-posture>`_
   2069         * WebDriver command.
   2070         *
   2071         * @param {WindowProxy} [context=null] - Browsing context in which to
   2072         *                                       run the call, or null for the
   2073         *                                       current browsing context.
   2074         *
   2075         * @returns {Promise} Fulfilled after the device posture override has
   2076         *                    been removed. Rejected in case the WebDriver
   2077         *                    command errors out.
   2078         */
   2079        clear_device_posture: function(context=null) {
   2080            return window.test_driver_internal.clear_device_posture(context);
   2081        },
   2082 
   2083        /**
   2084         * Runs the `bounce tracking timer algorithm
   2085         * <https://privacycg.github.io/nav-tracking-mitigations/#bounce-tracking-timer>`_,
   2086         * which removes all hosts from the stateful bounce tracking map, without
   2087         * regard for the bounce tracking grace period and returns a list of the
   2088         * deleted hosts.
   2089         *
   2090         * Matches the `Run Bounce Tracking Mitigations
   2091         * <https://privacycg.github.io/nav-tracking-mitigations/#run-bounce-tracking-mitigations-command>`_
   2092         * WebDriver command.
   2093         *
   2094         * @param {WindowProxy} [context=null] - Browsing context in which to
   2095         *                                       run the call, or null for the
   2096         *                                       current browsing context.
   2097         * @returns {Promise} Fulfilled after the bounce tracking timer
   2098         *                    algorithm has finished running. Returns an array
   2099         *                    of all hosts that were in the stateful bounce
   2100         *                    tracking map before deletion occurred.
   2101         */
   2102        run_bounce_tracking_mitigations: function (context = null) {
   2103            return window.test_driver_internal.run_bounce_tracking_mitigations(context);
   2104        },
   2105 
   2106        /**
   2107         * Creates a virtual pressure source.
   2108         *
   2109         * Matches the `Create virtual pressure source
   2110         * <https://w3c.github.io/compute-pressure/#create-virtual-pressure-source>`_
   2111         * WebDriver command.
   2112         *
   2113         * @param {String} source_type - A `virtual pressure source type
   2114         *                               <https://w3c.github.io/compute-pressure/#dom-pressuresource>`_
   2115         *                               such as "cpu".
   2116         * @param {Object} [metadata={}] - Optional parameters described
   2117         *                                 in `Create virtual pressure source
   2118         *                                 <https://w3c.github.io/compute-pressure/#create-virtual-pressure-source>`_.
   2119         * @param {WindowProxy} [context=null] - Browsing context in which to
   2120         *                                       run the call, or null for the
   2121         *                                       current browsing context.
   2122         *
   2123         * @returns {Promise} Fulfilled when virtual pressure source is created.
   2124         *                    Rejected in case the WebDriver command errors out
   2125         *                    (including if a virtual pressure source of the
   2126         *                    same type already exists).
   2127         */
   2128        create_virtual_pressure_source: function(source_type, metadata={}, context=null) {
   2129            return window.test_driver_internal.create_virtual_pressure_source(source_type, metadata, context);
   2130        },
   2131 
   2132        /**
   2133         * Causes a virtual pressure source to report a new reading.
   2134         *
   2135         * Matches the `Update virtual pressure source
   2136         * <https://w3c.github.io/compute-pressure/?experimental=1#update-virtual-pressure-source>`_
   2137         * WebDriver command.
   2138         *
   2139         * @param {String} source_type - A `virtual pressure source type
   2140         *                               <https://w3c.github.io/compute-pressure/#dom-pressuresource>`_
   2141         *                               such as "cpu".
   2142         * @param {String} sample - A `virtual pressure state
   2143         *                          <https://w3c.github.io/compute-pressure/#dom-pressurestate>`_
   2144         *                          such as "critical".
   2145         * @param {number} own_contribution_estimate - Optional, A `virtual own contribution estimate`
   2146         *                          <https://w3c.github.io/compute-pressure/?experimental=1#the-owncontributionestimate-attribute>`_
   2147         * @param {WindowProxy} [context=null] - Browsing context in which to
   2148         *                                       run the call, or null for the
   2149         *                                       current browsing context.
   2150         *
   2151         * @returns {Promise} Fulfilled after the reading update reaches the
   2152         *                    virtual pressure source. Rejected in case the
   2153         *                    WebDriver command errors out (including if a
   2154         *                    virtual pressure source of the given type does not
   2155         *                    exist).
   2156         */
   2157        update_virtual_pressure_source: function(source_type, sample, own_contribution_estimate, context=null) {
   2158            return window.test_driver_internal.update_virtual_pressure_source(source_type, sample, own_contribution_estimate, context);
   2159        },
   2160 
   2161        /**
   2162         * Removes created virtual pressure source.
   2163         *
   2164         * Matches the `Delete virtual pressure source
   2165         * <https://w3c.github.io/compute-pressure/#delete-virtual-pressure-source>`_
   2166         * WebDriver command.
   2167         *
   2168         * @param {String} source_type - A `virtual pressure source type
   2169         *                               <https://w3c.github.io/compute-pressure/#dom-pressuresource>`_
   2170         *                               such as "cpu".
   2171         * @param {WindowProxy} [context=null] - Browsing context in which to
   2172         *                                       run the call, or null for the
   2173         *                                       current browsing context.
   2174         *
   2175         * @returns {Promise} Fulfilled after the virtual pressure source has
   2176         *                    been removed or if a pressure source of the given
   2177         *                    type does not exist. Rejected in case the
   2178         *                    WebDriver command errors out.
   2179         */
   2180        remove_virtual_pressure_source: function(source_type, context=null) {
   2181            return window.test_driver_internal.remove_virtual_pressure_source(source_type, context);
   2182        },
   2183 
   2184        /**
   2185         * Sets which hashes are considered k-anonymous for the Protected
   2186         * Audience interest group with specified `owner` and `name`.
   2187         *
   2188         * Matches the `Set Protected Audience K-Anonymity
   2189         * <https://wicg.github.io/turtledove/#sctn-automation-set-protected-audience-k-anonymity>
   2190         * WebDriver command.
   2191         *
   2192         *  @param {String} owner - Origin of the owner of the interest group
   2193         *                          to modify
   2194         *  @param {String} name -  Name of the interest group to modify
   2195         *  @param {Array} hashes - An array of strings, each of which is a
   2196         *                          base64 ecoded hash to consider k-anonymous.
   2197         *
   2198         *  @returns {Promise} Fulfilled after the k-anonymity status for the
   2199         *                     specified Protected Audience interest group has
   2200         *                     been updated.
   2201         *
   2202         */
   2203        set_protected_audience_k_anonymity: function(owner, name, hashes, context = null) {
   2204            return window.test_driver_internal.set_protected_audience_k_anonymity(owner, name, hashes, context);
   2205        },
   2206 
   2207        /**
   2208         * Overrides the display features provided by the hardware so the viewport segments
   2209         * can be emulated.
   2210         *
   2211         * Matches the `Set display features
   2212         * <https://drafts.csswg.org/css-viewport/#set-display-features>`_
   2213         * WebDriver command.
   2214         *
   2215         * @param {Array} features - An array of `DisplayFeatureOverride
   2216         *                           <https://drafts.csswg.org/css-viewport/#display-feature-override>`.
   2217         * @param {WindowProxy} [context=null] - Browsing context in which to
   2218         *                                       run the call, or null for the
   2219         *                                       current browsing context.
   2220         *
   2221         * @returns {Promise} Fulfilled when the display features are set.
   2222         *                    Rejected in case the WebDriver command errors out
   2223         *                    (including if the array is malformed).
   2224         */
   2225        set_display_features: function(features, context=null) {
   2226            return window.test_driver_internal.set_display_features(features, context);
   2227        },
   2228 
   2229        /**
   2230         * Removes display features override and returns the control
   2231         * back to hardware.
   2232         *
   2233         * Matches the `Clear display features
   2234         * <https://drafts.csswg.org/css-viewport/#clear-display-features>`_
   2235         * WebDriver command.
   2236         *
   2237         * @param {WindowProxy} [context=null] - Browsing context in which to
   2238         *                                       run the call, or null for the
   2239         *                                       current browsing context.
   2240         *
   2241         * @returns {Promise} Fulfilled after the display features override has
   2242         *                    been removed. Rejected in case the WebDriver
   2243         *                    command errors out.
   2244         */
   2245        clear_display_features: function(context=null) {
   2246            return window.test_driver_internal.clear_display_features(context);
   2247        },
   2248 
   2249        /**
   2250         * Gets the current globally-applied privacy control status
   2251         *
   2252         * @returns {Promise} Fulfils with an object with boolean property `gpc`
   2253         *                    that encodes the current "do not sell or share"
   2254         *                    signal the browser is configured to convey.
   2255         */
   2256        get_global_privacy_control: function() {
   2257            return window.test_driver_internal.get_global_privacy_control();
   2258        },
   2259 
   2260        /**
   2261         * Gets the current globally-applied privacy control status
   2262         *
   2263         * @param {bool} newValue - The a boolean that is true if the browers
   2264         *                          should convey a "do not sell or share" signal
   2265         *                          and false otherwise
   2266         *
   2267         * @returns {Promise} Fulfils with an object with boolean property `gpc`
   2268         *                    that encodes the new "do not sell or share"
   2269         *                    after applying the new value.
   2270         */
   2271        set_global_privacy_control: function(newValue) {
   2272            return window.test_driver_internal.set_global_privacy_control(newValue);
   2273        },
   2274 
   2275        /**
   2276         * Installs a WebExtension.
   2277         *
   2278         * Matches the `Install WebExtension
   2279         * <https://github.com/w3c/webextensions/blob/main/specification/webdriver-classic.bs>`_
   2280         * WebDriver command.
   2281         *
   2282         * @param {Object} params - Parameters for loading the extension.
   2283         * @param {String} params.type - A type such as "path", "archivePath", or "base64".
   2284         *
   2285         * @param {String} params.path - The path to the extension's resources if type "path" or "archivePath" is specified.
   2286         *
   2287         * @param {String} params.value - The base64 encoded value of the extension's resources if type "base64" is specified.
   2288         *
   2289         * @returns {Promise} Returns the extension identifier as defined in the spec.
   2290         *                    Rejected if the extension fails to load.
   2291         */
   2292        install_web_extension: function(params) {
   2293            return window.test_driver_internal.install_web_extension(params);
   2294        },
   2295 
   2296        /**
   2297         * Uninstalls a WebExtension.
   2298         *
   2299         * Matches the `Uninstall WebExtension
   2300         * <https://github.com/w3c/webextensions/blob/main/specification/webdriver-classic.bs>`_
   2301         * WebDriver command.
   2302         *
   2303         * @param {String} extension_id - The extension identifier.
   2304         *
   2305         * @returns {Promise} Fulfilled after the extension has been removed.
   2306         *                    Rejected in case the WebDriver command errors out.
   2307         */
   2308        uninstall_web_extension: function(extension_id) {
   2309            return window.test_driver_internal.uninstall_web_extension(extension_id);
   2310        }
   2311    };
   2312 
   2313    window.test_driver_internal = {
   2314        /**
   2315         * This flag should be set to `true` by any code which implements the
   2316         * internal methods defined below for automation purposes. Doing so
   2317         * allows the library to signal failure immediately when an automated
   2318         * implementation of one of the methods is not available.
   2319         */
   2320        in_automation: false,
   2321 
   2322        bidi: {
   2323            bluetooth: {
   2324                handle_request_device_prompt: function() {
   2325                    throw new Error(
   2326                        'bidi.bluetooth.handle_request_device_prompt is not implemented by testdriver-vendor.js');
   2327                },
   2328                simulate_adapter: function () {
   2329                    throw new Error(
   2330                        "bidi.bluetooth.simulate_adapter is not implemented by testdriver-vendor.js");
   2331                },
   2332                disable_simulation: function () {
   2333                    throw new Error(
   2334                        "bidi.bluetooth.disable_simulation is not implemented by testdriver-vendor.js");
   2335                },
   2336                simulate_preconnected_peripheral: function() {
   2337                    throw new Error(
   2338                        'bidi.bluetooth.simulate_preconnected_peripheral is not implemented by testdriver-vendor.js');
   2339                },
   2340                request_device_prompt_updated: {
   2341                    async subscribe() {
   2342                        throw new Error(
   2343                            'bidi.bluetooth.request_device_prompt_updated.subscribe is not implemented by testdriver-vendor.js');
   2344                    },
   2345                    on() {
   2346                        throw new Error(
   2347                            'bidi.bluetooth.request_device_prompt_updated.on is not implemented by testdriver-vendor.js');
   2348                    }
   2349                },
   2350                gatt_connection_attempted: {
   2351                    async subscribe() {
   2352                        throw new Error(
   2353                            'bidi.bluetooth.gatt_connection_attempted.subscribe is not implemented by testdriver-vendor.js');
   2354                    },
   2355                    on() {
   2356                        throw new Error(
   2357                            'bidi.bluetooth.gatt_connection_attempted.on is not implemented by testdriver-vendor.js');
   2358                    }
   2359                },
   2360                characteristic_event_generated: {
   2361                    async subscribe() {
   2362                        throw new Error(
   2363                            'bidi.bluetooth.characteristic_event_generated.subscribe is not implemented by testdriver-vendor.js');
   2364                    },
   2365                    on() {
   2366                        throw new Error(
   2367                            'bidi.bluetooth.characteristic_event_generated.on is not implemented by testdriver-vendor.js');
   2368                    }
   2369                },
   2370                descriptor_event_generated: {
   2371                    async subscribe() {
   2372                        throw new Error(
   2373                            'bidi.bluetooth.descriptor_event_generated.subscribe is not implemented by testdriver-vendor.js');
   2374                    },
   2375                    on() {
   2376                        throw new Error(
   2377                            'bidi.bluetooth.descriptor_event_generated.on is not implemented by testdriver-vendor.js');
   2378                    }
   2379                }
   2380            },
   2381            emulation: {
   2382                set_geolocation_override: function (params) {
   2383                    throw new Error(
   2384                        "bidi.emulation.set_geolocation_override is not implemented by testdriver-vendor.js");
   2385                },
   2386                set_locale_override: function (params) {
   2387                    throw new Error(
   2388                        "bidi.emulation.set_locale_override is not implemented by testdriver-vendor.js");
   2389                },
   2390                set_screen_orientation_override: function (params) {
   2391                    throw new Error(
   2392                        "bidi.emulation.set_screen_orientation_override is not implemented by testdriver-vendor.js");
   2393                }
   2394            },
   2395            log: {
   2396                entry_added: {
   2397                    async subscribe() {
   2398                        throw new Error(
   2399                            "bidi.log.entry_added.subscribe is not implemented by testdriver-vendor.js");
   2400                    },
   2401                    on() {
   2402                        throw new Error(
   2403                            "bidi.log.entry_added.on is not implemented by testdriver-vendor.js");
   2404                    }
   2405                }
   2406            },
   2407            permissions: {
   2408                async set_permission() {
   2409                    throw new Error(
   2410                        "bidi.permissions.set_permission() is not implemented by testdriver-vendor.js");
   2411                }
   2412            },
   2413            speculation: {
   2414                prefetch_status_updated: {
   2415                    async subscribe() {
   2416                        throw new Error(
   2417                            'bidi.speculation.prefetch_status_updated.subscribe is not implemented by testdriver-vendor.js');
   2418                    },
   2419                    on() {
   2420                        throw new Error(
   2421                            'bidi.speculation.prefetch_status_updated.on is not implemented by testdriver-vendor.js');
   2422                    }
   2423                },
   2424            }
   2425        },
   2426 
   2427        async click(element, coords) {
   2428            if (this.in_automation) {
   2429                throw new Error("click() is not implemented by testdriver-vendor.js");
   2430            }
   2431 
   2432            return new Promise(function(resolve, reject) {
   2433                element.addEventListener("click", resolve);
   2434            });
   2435        },
   2436 
   2437        async delete_all_cookies(context=null) {
   2438            throw new Error("delete_all_cookies() is not implemented by testdriver-vendor.js");
   2439        },
   2440 
   2441        async get_all_cookies(context=null) {
   2442            throw new Error("get_all_cookies() is not implemented by testdriver-vendor.js");
   2443        },
   2444 
   2445        async get_named_cookie(name, context=null) {
   2446            throw new Error("get_named_cookie() is not implemented by testdriver-vendor.js");
   2447        },
   2448 
   2449        async get_computed_role(element) {
   2450            throw new Error("get_computed_role is a testdriver.js function which cannot be run in this context.");
   2451        },
   2452 
   2453        async get_computed_name(element) {
   2454            throw new Error("get_computed_name is a testdriver.js function which cannot be run in this context.");
   2455        },
   2456 
   2457        async send_keys(element, keys) {
   2458            if (this.in_automation) {
   2459                throw new Error("send_keys() is not implemented by testdriver-vendor.js");
   2460            }
   2461 
   2462            return new Promise(function(resolve, reject) {
   2463                var seen = "";
   2464 
   2465                function remove() {
   2466                    element.removeEventListener("keydown", onKeyDown);
   2467                }
   2468 
   2469                function onKeyDown(event) {
   2470                    if (event.key.length > 1) {
   2471                        return;
   2472                    }
   2473 
   2474                    seen += event.key;
   2475 
   2476                    if (keys.indexOf(seen) !== 0) {
   2477                        reject(new Error("Unexpected key sequence: " + seen));
   2478                        remove();
   2479                    } else if (seen === keys) {
   2480                        resolve();
   2481                        remove();
   2482                    }
   2483                }
   2484 
   2485                element.addEventListener("keydown", onKeyDown);
   2486            });
   2487        },
   2488 
   2489        async freeze(context=null) {
   2490            throw new Error("freeze() is not implemented by testdriver-vendor.js");
   2491        },
   2492 
   2493        async minimize_window(context=null) {
   2494            throw new Error("minimize_window() is not implemented by testdriver-vendor.js");
   2495        },
   2496 
   2497        async set_window_rect(rect, context=null) {
   2498            throw new Error("set_window_rect() is not implemented by testdriver-vendor.js");
   2499        },
   2500 
   2501        async get_window_rect(context=null) {
   2502            throw new Error("get_window_rect() is not implemented by testdriver-vendor.js");
   2503        },
   2504 
   2505        async action_sequence(actions, context=null) {
   2506            throw new Error("action_sequence() is not implemented by testdriver-vendor.js");
   2507        },
   2508 
   2509        async generate_test_report(message, context=null) {
   2510            throw new Error("generate_test_report() is not implemented by testdriver-vendor.js");
   2511        },
   2512 
   2513        async set_permission(permission_params, context=null) {
   2514            throw new Error("set_permission() is not implemented by testdriver-vendor.js");
   2515        },
   2516 
   2517        async add_virtual_authenticator(config, context=null) {
   2518            throw new Error("add_virtual_authenticator() is not implemented by testdriver-vendor.js");
   2519        },
   2520 
   2521        async remove_virtual_authenticator(authenticator_id, context=null) {
   2522            throw new Error("remove_virtual_authenticator() is not implemented by testdriver-vendor.js");
   2523        },
   2524 
   2525        async add_credential(authenticator_id, credential, context=null) {
   2526            throw new Error("add_credential() is not implemented by testdriver-vendor.js");
   2527        },
   2528 
   2529        async get_credentials(authenticator_id, context=null) {
   2530            throw new Error("get_credentials() is not implemented by testdriver-vendor.js");
   2531        },
   2532 
   2533        async remove_credential(authenticator_id, credential_id, context=null) {
   2534            throw new Error("remove_credential() is not implemented by testdriver-vendor.js");
   2535        },
   2536 
   2537        async remove_all_credentials(authenticator_id, context=null) {
   2538            throw new Error("remove_all_credentials() is not implemented by testdriver-vendor.js");
   2539        },
   2540 
   2541        async set_user_verified(authenticator_id, uv, context=null) {
   2542            throw new Error("set_user_verified() is not implemented by testdriver-vendor.js");
   2543        },
   2544 
   2545        async set_storage_access(origin, embedding_origin, blocked, context=null) {
   2546            throw new Error("set_storage_access() is not implemented by testdriver-vendor.js");
   2547        },
   2548 
   2549        async set_spc_transaction_mode(mode, context=null) {
   2550            throw new Error("set_spc_transaction_mode() is not implemented by testdriver-vendor.js");
   2551        },
   2552 
   2553        set_rph_registration_mode: function(mode, context=null) {
   2554            return Promise.reject(new Error("unimplemented"));
   2555        },
   2556 
   2557        async cancel_fedcm_dialog(context=null) {
   2558            throw new Error("cancel_fedcm_dialog() is not implemented by testdriver-vendor.js");
   2559        },
   2560 
   2561        async click_fedcm_dialog_button(dialog_button, context=null) {
   2562            throw new Error("click_fedcm_dialog_button() is not implemented by testdriver-vendor.js");
   2563        },
   2564 
   2565        async select_fedcm_account(account_index, context=null) {
   2566            throw new Error("select_fedcm_account() is not implemented by testdriver-vendor.js");
   2567        },
   2568 
   2569        async get_fedcm_account_list(context=null) {
   2570            throw new Error("get_fedcm_account_list() is not implemented by testdriver-vendor.js");
   2571        },
   2572 
   2573        async get_fedcm_dialog_title(context=null) {
   2574            throw new Error("get_fedcm_dialog_title() is not implemented by testdriver-vendor.js");
   2575        },
   2576 
   2577        async get_fedcm_dialog_type(context=null) {
   2578            throw new Error("get_fedcm_dialog_type() is not implemented by testdriver-vendor.js");
   2579        },
   2580 
   2581        async set_fedcm_delay_enabled(enabled, context=null) {
   2582            throw new Error("set_fedcm_delay_enabled() is not implemented by testdriver-vendor.js");
   2583        },
   2584 
   2585        async reset_fedcm_cooldown(context=null) {
   2586            throw new Error("reset_fedcm_cooldown() is not implemented by testdriver-vendor.js");
   2587        },
   2588 
   2589        async create_virtual_sensor(sensor_type, sensor_params, context=null) {
   2590            throw new Error("create_virtual_sensor() is not implemented by testdriver-vendor.js");
   2591        },
   2592 
   2593        async update_virtual_sensor(sensor_type, reading, context=null) {
   2594            throw new Error("update_virtual_sensor() is not implemented by testdriver-vendor.js");
   2595        },
   2596 
   2597        async remove_virtual_sensor(sensor_type, context=null) {
   2598            throw new Error("remove_virtual_sensor() is not implemented by testdriver-vendor.js");
   2599        },
   2600 
   2601        async get_virtual_sensor_information(sensor_type, context=null) {
   2602            throw new Error("get_virtual_sensor_information() is not implemented by testdriver-vendor.js");
   2603        },
   2604 
   2605        async set_device_posture(posture, context=null) {
   2606            throw new Error("set_device_posture() is not implemented by testdriver-vendor.js");
   2607        },
   2608 
   2609        async clear_device_posture(context=null) {
   2610            throw new Error("clear_device_posture() is not implemented by testdriver-vendor.js");
   2611        },
   2612 
   2613        async run_bounce_tracking_mitigations(context=null) {
   2614            throw new Error("run_bounce_tracking_mitigations() is not implemented by testdriver-vendor.js");
   2615        },
   2616 
   2617        async create_virtual_pressure_source(source_type, metadata={}, context=null) {
   2618            throw new Error("create_virtual_pressure_source() is not implemented by testdriver-vendor.js");
   2619        },
   2620 
   2621        async update_virtual_pressure_source(source_type, sample, own_contribution_estimate, context=null) {
   2622            throw new Error("update_virtual_pressure_source() is not implemented by testdriver-vendor.js");
   2623        },
   2624 
   2625        async remove_virtual_pressure_source(source_type, context=null) {
   2626            throw new Error("remove_virtual_pressure_source() is not implemented by testdriver-vendor.js");
   2627        },
   2628 
   2629        async set_protected_audience_k_anonymity(owner, name, hashes, context=null) {
   2630            throw new Error("set_protected_audience_k_anonymity() is not implemented by testdriver-vendor.js");
   2631        },
   2632 
   2633        async set_display_features(features, context=null) {
   2634            throw new Error("set_display_features() is not implemented by testdriver-vendor.js");
   2635        },
   2636 
   2637        async clear_display_features(context=null) {
   2638            throw new Error("clear_display_features() is not implemented by testdriver-vendor.js");
   2639        },
   2640 
   2641        async set_global_privacy_control(newValue) {
   2642            throw new Error("set_global_privacy_control() is not implemented by testdriver-vendor.js");
   2643        },
   2644 
   2645        async get_global_privacy_control() {
   2646            throw new Error("get_global_privacy_control() is not implemented by testdriver-vendor.js");
   2647        }
   2648    };
   2649 })();