From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- .../tests/common/subset-tests-by-key.js | 83 ++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 testing/web-platform/tests/common/subset-tests-by-key.js (limited to 'testing/web-platform/tests/common/subset-tests-by-key.js') diff --git a/testing/web-platform/tests/common/subset-tests-by-key.js b/testing/web-platform/tests/common/subset-tests-by-key.js new file mode 100644 index 0000000000..483017a644 --- /dev/null +++ b/testing/web-platform/tests/common/subset-tests-by-key.js @@ -0,0 +1,83 @@ +(function() { + var subTestKeyPattern = null; + var match; + var collectKeys = false; + var collectCounts = false; + var keys = {}; + var exclude = false; + if (location.search) { + match = /(?:^\?|&)(include|exclude)=([^&]+)?/.exec(location.search); + if (match) { + subTestKeyPattern = new RegExp(`^${match[2]}$`); + if (match[1] === 'exclude') { + exclude = true; + } + } + // Below is utility code to generate for copy/paste into tests. + // Sample usage: + // test.html?get-keys + match = /(?:^\?|&)get-keys(&get-counts)?(?:&|$)/.exec(location.search); + if (match) { + collectKeys = true; + if (match[1]) { + collectCounts = true; + } + add_completion_callback(() => { + var metas = []; + var template = ''; + if (collectCounts) { + template += ' '; + } + for (var key in keys) { + var meta = template.replace("%s", key); + if (collectCounts) { + meta = meta.replace("%s", keys[key]); + } + metas.push(meta); + } + var pre = document.createElement('pre'); + pre.textContent = metas.join('\n') + '\n'; + document.body.insertBefore(pre, document.body.firstChild); + document.getSelection().selectAllChildren(pre); + }); + } + } + /** + * Check if `key` is in the subset specified in the URL. + * @param {string} key + * @returns {boolean} + */ + function shouldRunSubTest(key) { + if (key && subTestKeyPattern) { + var found = subTestKeyPattern.test(key); + if (exclude) { + return !found; + } + return found; + } + return true; + } + /** + * Only test a subset of tests with `?include=Foo` or `?exclude=Foo` in the URL. + * Can be used together with `` + * Sample usage: + * for (const test of tests) { + * subsetTestByKey("Foo", async_test, test.fn, test.name); + * } + */ + function subsetTestByKey(key, testFunc, ...args) { + if (collectKeys) { + if (collectCounts && key in keys) { + keys[key]++; + } else { + keys[key] = 1; + } + } + if (shouldRunSubTest(key)) { + return testFunc(...args); + } + return null; + } + self.shouldRunSubTest = shouldRunSubTest; + self.subsetTestByKey = subsetTestByKey; +})(); -- cgit v1.2.3