From 43a97878ce14b72f0981164f87f2e35e14151312 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:22:09 +0200 Subject: Adding upstream version 110.0.1. Signed-off-by: Daniel Baumann --- .../web-platform/tests/webrtc/tools/.eslintrc.js | 154 +++++++++++++++++++++ testing/web-platform/tests/webrtc/tools/README.md | 14 ++ .../webrtc/tools/codemod-peerconnection-addcleanup | 58 ++++++++ .../tests/webrtc/tools/html-codemod.js | 34 +++++ .../web-platform/tests/webrtc/tools/package.json | 16 +++ 5 files changed, 276 insertions(+) create mode 100644 testing/web-platform/tests/webrtc/tools/.eslintrc.js create mode 100644 testing/web-platform/tests/webrtc/tools/README.md create mode 100644 testing/web-platform/tests/webrtc/tools/codemod-peerconnection-addcleanup create mode 100644 testing/web-platform/tests/webrtc/tools/html-codemod.js create mode 100644 testing/web-platform/tests/webrtc/tools/package.json (limited to 'testing/web-platform/tests/webrtc/tools') diff --git a/testing/web-platform/tests/webrtc/tools/.eslintrc.js b/testing/web-platform/tests/webrtc/tools/.eslintrc.js new file mode 100644 index 0000000000..321f8e9a25 --- /dev/null +++ b/testing/web-platform/tests/webrtc/tools/.eslintrc.js @@ -0,0 +1,154 @@ +module.exports = { + rules: { + 'no-undef': 1, + 'no-unused-vars': 0 + }, + plugins: [ + 'html' + ], + env: { + browser: true, + es6: true + }, + globals: { + // testharness globals + test: true, + async_test: true, + promise_test: true, + IdlArray: true, + assert_true: true, + assert_false: true, + assert_equals: true, + assert_not_equals: true, + assert_array_equals: true, + assert_in_array: true, + assert_unreached: true, + assert_idl_attribute: true, + assert_own_property: true, + assert_greater_than: true, + assert_less_than: true, + assert_greater_than_equal: true, + assert_less_than_equal: true, + assert_approx_equals: true, + + + // WebRTC globals + RTCPeerConnection: true, + RTCRtpSender: true, + RTCRtpReceiver: true, + RTCRtpTransceiver: true, + RTCIceTransport: true, + RTCDtlsTransport: true, + RTCSctpTransport: true, + RTCDataChannel: true, + RTCCertificate: true, + RTCDTMFSender: true, + RTCError: true, + RTCTrackEvent: true, + RTCPeerConnectionIceEvent: true, + RTCDTMFToneChangeEvent: true, + RTCDataChannelEvent: true, + RTCRtpContributingSource: true, + RTCRtpSynchronizationSource: true, + + // dictionary-helper.js + assert_unsigned_int_field: true, + assert_int_field: true, + assert_string_field: true, + assert_number_field: true, + assert_boolean_field: true, + assert_array_field: true, + assert_dict_field: true, + assert_enum_field: true, + + assert_optional_unsigned_int_field: true, + assert_optional_int_field: true, + assert_optional_string_field: true, + assert_optional_number_field: true, + assert_optional_boolean_field: true, + assert_optional_array_field: true, + assert_optional_dict_field: true, + assert_optional_enum_field: true, + + // identity-helper.sub.js + parseAssertionResult: true, + getIdpDomains: true, + assert_rtcerror_rejection: true, + hostString: true, + + // RTCConfiguration-helper.js + config_test: true, + + // RTCDTMFSender-helper.js + createDtmfSender: true, + test_tone_change_events: true, + getTransceiver: true, + + // RTCPeerConnection-helper.js + countLine: true, + countAudioLine: true, + countVideoLine: true, + countApplicationLine: true, + similarMediaDescriptions: true, + assert_is_session_description: true, + isSimilarSessionDescription: true, + assert_session_desc_equals: true, + assert_session_desc_not_equals: true, + generateOffer: true, + generateAnswer: true, + test_state_change_event: true, + test_never_resolve: true, + exchangeIceCandidates: true, + exchangeOfferAnswer: true, + createDataChannelPair: true, + awaitMessage: true, + blobToArrayBuffer: true, + assert_equals_typed_array: true, + generateMediaStreamTrack: true, + getTrackFromUserMedia: true, + getUserMediaTracksAndStreams: true, + performOffer: true, + Resolver: true, + + // RTCRtpCapabilities-helper.js + validateRtpCapabilities: true, + validateCodecCapability: true, + validateHeaderExtensionCapability: true, + + // RTCRtpParameters-helper.js + validateSenderRtpParameters: true, + validateReceiverRtpParameters: true, + validateRtpParameters: true, + validateEncodingParameters: true, + validateRtcpParameters: true, + validateHeaderExtensionParameters: true, + validateCodecParameters: true, + + // RTCStats-helper.js + validateStatsReport: true, + assert_stats_report_has_stats: true, + findStatsFromReport: true, + getRequiredStats: true, + getStatsById: true, + validateIdField: true, + validateOptionalIdField: true, + validateRtcStats: true, + validateRtpStreamStats: true, + validateCodecStats: true, + validateReceivedRtpStreamStats: true, + validateInboundRtpStreamStats: true, + validateRemoteInboundRtpStreamStats: true, + validateSentRtpStreamStats: true, + validateOutboundRtpStreamStats: true, + validateRemoteOutboundRtpStreamStats: true, + validateContributingSourceStats: true, + validatePeerConnectionStats: true, + validateMediaStreamStats: true, + validateMediaStreamTrackStats: true, + validateDataChannelStats: true, + validateTransportStats: true, + validateIceCandidateStats: true, + validateIceCandidatePairStats: true, + validateCertificateStats: true, + } +} diff --git a/testing/web-platform/tests/webrtc/tools/README.md b/testing/web-platform/tests/webrtc/tools/README.md new file mode 100644 index 0000000000..68bc284fdf --- /dev/null +++ b/testing/web-platform/tests/webrtc/tools/README.md @@ -0,0 +1,14 @@ +WebRTC Tools +============ + +This directory contains a simple Node.js project to aid the development of +WebRTC tests. + +## Lint + +```bash +npm run lint +``` + +Does basic linting of the JavaScript code. Mainly for catching usage of +undefined variables. diff --git a/testing/web-platform/tests/webrtc/tools/codemod-peerconnection-addcleanup b/testing/web-platform/tests/webrtc/tools/codemod-peerconnection-addcleanup new file mode 100644 index 0000000000..920921d2e4 --- /dev/null +++ b/testing/web-platform/tests/webrtc/tools/codemod-peerconnection-addcleanup @@ -0,0 +1,58 @@ +/* a codemod for ensuring RTCPeerConnection is cleaned up in tests. + * For each `new RTCPeerConnection` add a + * `test.add_cleanup(() => pc.close())` + * Only applies in promise_tests if there is no add_cleanup in the + * test function body. + */ +export default function transformer(file, api) { + const j = api.jscodeshift; + return j(file.source) + // find each RTCPeerConnection constructor + .find(j.NewExpression, {callee: {type: 'Identifier', name: 'RTCPeerConnection'}}) + + // check it is inside a promise_test + .filter(path => { + // iterate parentPath until you find a CallExpression + let nextPath = path.parentPath; + while (nextPath && nextPath.value.type !== 'CallExpression') { + nextPath = nextPath.parentPath; + } + return nextPath && nextPath.value.callee.name === 'promise_test'; + }) + // check there is no add_cleanup in the function body + .filter(path => { + let nextPath = path.parentPath; + while (nextPath && nextPath.value.type !== 'CallExpression') { + nextPath = nextPath.parentPath; + } + const body = nextPath.value.arguments[0].body; + return j(body).find(j.Identifier, {name: 'add_cleanup'}).length === 0; + }) + .forEach(path => { + // iterate parentPath until you find a CallExpression + let nextPath = path.parentPath; + while (nextPath && nextPath.value.type !== 'CallExpression') { + nextPath = nextPath.parentPath; + } + const declaration = path.parentPath.parentPath.parentPath; + const pc = path.parentPath.value.id; + + declaration.insertAfter( + j.expressionStatement( + j.callExpression( + j.memberExpression( + nextPath.node.arguments[0].params[0], + j.identifier('add_cleanup') + ), + [j.arrowFunctionExpression([], + j.callExpression( + j.memberExpression(pc, j.identifier('close'), false), + [] + ) + )] + ) + ) + ); + }) + .toSource(); +}; diff --git a/testing/web-platform/tests/webrtc/tools/html-codemod.js b/testing/web-platform/tests/webrtc/tools/html-codemod.js new file mode 100644 index 0000000000..6a31e8c4c6 --- /dev/null +++ b/testing/web-platform/tests/webrtc/tools/html-codemod.js @@ -0,0 +1,34 @@ +/* + * extract script content from a series of html files, run a + * jscodeshift codemod on them and overwrite the original file. + * + * Usage: node html-codemod.js codemod-file list of files to process + */ +const { JSDOM } = require('jsdom'); +const fs = require('fs'); +const {execFileSync} = require('child_process'); + +const codemod = process.argv[2]; +const filenames = process.argv.slice(3); +filenames.forEach((filename) => { + const originalContent = fs.readFileSync(filename, 'utf-8'); + const dom = new JSDOM(originalContent); + const document = dom.window.document; + const scriptTags = document.querySelectorAll('script'); + const lastTag = scriptTags[scriptTags.length - 1]; + const script = lastTag.innerHTML; + if (!script) { + console.log('NO SCRIPT FOUND', filename); + return; + } + const scriptFilename = filename + '.codemod.js'; + const scriptFile = fs.writeFileSync(scriptFilename, script); + // exec jscodeshift + const output = execFileSync('./node_modules/.bin/jscodeshift', ['-t', codemod, scriptFilename]); + console.log(filename, output.toString()); // output jscodeshift output. + // read back file, resubstitute + const newScript = fs.readFileSync(scriptFilename, 'utf-8').toString(); + const modifiedContent = originalContent.split(script).join(newScript); + fs.writeFileSync(filename, modifiedContent); + fs.unlinkSync(scriptFilename); +}); diff --git a/testing/web-platform/tests/webrtc/tools/package.json b/testing/web-platform/tests/webrtc/tools/package.json new file mode 100644 index 0000000000..f26cfcc142 --- /dev/null +++ b/testing/web-platform/tests/webrtc/tools/package.json @@ -0,0 +1,16 @@ +{ + "name": "webrtc-testing-tools", + "version": "1.0.0", + "description": "Tools for WebRTC testing", + "scripts": { + "lint": "eslint -c .eslintrc.js ../*.html ../*.js" + }, + "devDependencies": { + "eslint": "^7.24.0", + "eslint-plugin-html": "^4.0.0", + "jscodeshift": "^0.5.1", + "jsdom": "^16.5.3" + }, + "license": "BSD", + "private": true +} -- cgit v1.2.3