Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(717)

Unified Diff: third_party/WebKit/LayoutTests/external/wpt/streams/generate-test-wrappers.js

Issue 2642393002: Import wpt@40665266227e475bc4a56884247d8c09d78dfb6a (Closed)
Patch Set: rebaseline-cl Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/LayoutTests/external/wpt/streams/generate-test-wrappers.js
diff --git a/third_party/WebKit/LayoutTests/external/wpt/streams/generate-test-wrappers.js b/third_party/WebKit/LayoutTests/external/wpt/streams/generate-test-wrappers.js
new file mode 100644
index 0000000000000000000000000000000000000000..0803eefc807b16b1d03b457190b8fe56b6673799
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/external/wpt/streams/generate-test-wrappers.js
@@ -0,0 +1,102 @@
+"use strict";
+// Usage: `node generate-test-wrappers.js js-filename1.js [js-filename2.js ...]` will generate:
+// - js-filename1.https.html
+// - js-filename1.sharedworker.html
+// - js-filename1.dedicatedworker.html
+// - js-filename1.serviceworker.html
+// (for each passed filename)
+//
+// It will turn any importScripts inside the .js file into <script>s in the browser context wrapper.
+//
+// This could become obsolete if all of the following happen:
+// - https://github.com/w3c/web-platform-tests/issues/4210 gets fixed, allowing .any.js to work with all four contexts
+// - We find some way to include scripts (<script>/importScripts) in .any.js files
+// - Chrome becomes able to run .any.js tests on its infrastructure
+// (https://bugs.chromium.org/p/chromium/issues/detail?id=653514)
+
+const fs = require("fs");
+const path = require("path");
+
+for (const arg of process.argv.slice(2)) {
+ generateWrapper(arg);
+}
+
+function generateWrapper(jsFilename) {
+ const importedScriptFilenames = findImportedScriptFilenames(jsFilename);
+ const importedScriptTags = importedScriptFilenames
+ .map(filename => `<script src="${filename}"></script>`)
+ .join('\n');
+
+ const basename = path.basename(jsFilename);
+ const noExtension = path.basename(jsFilename, '.js');
+
+ const outputs = {
+ https: `<!DOCTYPE html>
+<meta charset="utf-8">
+<title>${basename} browser context wrapper file</title>
+
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+
+${importedScriptTags}
+
+<script src="${basename}"></script>
+`,
+ dedicatedworker: `<!DOCTYPE html>
+<meta charset="utf-8">
+<title>${basename} dedicated worker wrapper file</title>
+
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+
+<script>
+'use strict';
+fetch_tests_from_worker(new Worker('${basename}'));
+</script>
+`,
+ sharedworker: `<!DOCTYPE html>
+<meta charset="utf-8">
+<title>${basename} shared worker wrapper file</title>
+
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+
+<script>
+'use strict';
+fetch_tests_from_worker(new SharedWorker('${basename}'));
+</script>
+`,
+ serviceworker: `<!DOCTYPE html>
+<meta charset="utf-8">
+<title>${basename} service worker wrapper file</title>
+
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/service-workers/service-worker/resources/test-helpers.sub.js"></script>
+
+<script>
+'use strict';
+service_worker_test('${basename}', 'Service worker test setup');
+</script>
+`
+ };
+
+ for (const [key, value] of Object.entries(outputs)) {
+ const destFilename = path.resolve(path.dirname(jsFilename), `${noExtension}.${key}.html`);
+ fs.writeFileSync(destFilename, value, { encoding: 'utf-8' });
+ }
+}
+
+function findImportedScriptFilenames(inputFilename) {
+ const scriptContents = fs.readFileSync(inputFilename, { encoding: 'utf-8' });
+
+ const regExp = /self\.importScripts\('([^']+)'\);/g;
+
+ let result = [];
+ let match;
+ while (match = regExp.exec(scriptContents)) {
+ result.push(match[1]);
+ }
+
+ return result.filter(x => x !== '/resources/testharness.js');
+}

Powered by Google App Engine
This is Rietveld 408576698