summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/mixed-content/generic
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/tests/mixed-content/generic
parentInitial commit. (diff)
downloadfirefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz
firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/mixed-content/generic')
-rw-r--r--testing/web-platform/tests/mixed-content/generic/sanity-checker.js53
-rw-r--r--testing/web-platform/tests/mixed-content/generic/test-case.sub.js61
2 files changed, 114 insertions, 0 deletions
diff --git a/testing/web-platform/tests/mixed-content/generic/sanity-checker.js b/testing/web-platform/tests/mixed-content/generic/sanity-checker.js
new file mode 100644
index 0000000000..55a103adf0
--- /dev/null
+++ b/testing/web-platform/tests/mixed-content/generic/sanity-checker.js
@@ -0,0 +1,53 @@
+// The SanityChecker is used in debug mode to identify problems with the
+// structure of the testsuite and to force early test failures.
+// In release mode it is mocked out to do nothing.
+function SanityChecker() {}
+
+SanityChecker.prototype.checkScenario = function(scenario, resourceInvoker) {
+ // Check if scenario is valid.
+ test(function() {
+ var expectedFields = SPEC_JSON["test_expansion_schema"];
+
+ for (var field in expectedFields) {
+ if (field == "expansion")
+ continue
+
+ assert_own_property(scenario, field,
+ "The scenario should contain field '" + field + "'.")
+
+ var expectedFieldList = expectedFields[field];
+ if (!expectedFieldList.hasOwnProperty('length')) {
+ var expectedFieldList = [];
+ for (var key in expectedFields[field]) {
+ expectedFieldList = expectedFieldList.concat(expectedFields[field][key])
+ }
+ }
+ assert_in_array(scenario[field], expectedFieldList,
+ "Scenario's " + field + " is one of: " +
+ expectedFieldList.join(", ")) + "."
+ }
+
+ // Check if the protocol is matched.
+ assert_equals(scenario["source_scheme"] + ":", location.protocol,
+ "Protocol of the test page should match the scenario.")
+
+ assert_own_property(resourceInvoker, scenario.subresource,
+ "Subresource should be supported");
+
+ }, "[MixedContentTestCase] The test scenario should be valid.");
+}
+
+// For easier debugging runs, we can fail a test earlier.
+SanityChecker.prototype.setFailTimeout = function(test, timeout) {
+ // Due to missing implementations, tests time out, so we fail them early.
+ // TODO(kristijanburnik): Once WPT rolled in:
+ // https://github.com/w3c/testharness.js/pull/127
+ // Refactor to make use of step_timeout.
+ setTimeout(function() {
+ test.step(function() {
+ assert_equals(test.phase, test.phases.COMPLETE,
+ "Expected test to complete.");
+ test.done();
+ })
+ }, timeout || 1000);
+}
diff --git a/testing/web-platform/tests/mixed-content/generic/test-case.sub.js b/testing/web-platform/tests/mixed-content/generic/test-case.sub.js
new file mode 100644
index 0000000000..bfb02a0e61
--- /dev/null
+++ b/testing/web-platform/tests/mixed-content/generic/test-case.sub.js
@@ -0,0 +1,61 @@
+/**
+ * @fileoverview Test case for mixed-content in web-platform-tests.
+ * @author burnik@google.com (Kristijan Burnik)
+ */
+
+/**
+ * MixedContentTestCase exercises all the tests for checking browser behavior
+ * when resources regarded as mixed-content are requested. A single run covers
+ * only a single scenario.
+ * @param {object} scenario A JSON describing the test arrangement and
+ * expectation(s). Refer to /mixed-content/spec.src.json for details.
+ * @param {string} description The test scenario verbose description.
+ * @param {SanityChecker} sanityChecker Instance of an object used to check the
+ * running scenario. Useful in debug mode. See ./sanity-checker.js.
+ * Run {@code ./tools/generate.py -h} for info on test generating modes.
+ * @return {object} Object wrapping the start method used to run the test.
+ */
+function TestCase(scenarios, sanityChecker) {
+ function runTest(scenario) {
+ sanityChecker.checkScenario(scenario, subresourceMap);
+
+ const urls = getRequestURLs(scenario.subresource,
+ scenario.origin,
+ scenario.redirection);
+ const checkResult = _ => {
+ // Send request to check if the key has been torn down.
+ return xhrRequest(urls.assertUrl)
+ .then(assertResult => {
+ // Now check if the value has been torn down. If it's still there,
+ // we have blocked the request to mixed-content.
+ assert_equals(assertResult.status, scenario.expectation,
+ "The resource request should be '" + scenario.expectation + "'.");
+ });
+ };
+
+ /** @type {Subresource} */
+ const subresource = {
+ subresourceType: scenario.subresource,
+ url: urls.testUrl,
+ policyDeliveries: scenario.subresource_policy_deliveries,
+ };
+
+ promise_test(() => {
+ return xhrRequest(urls.announceUrl)
+ // Send out the real resource request.
+ // This should tear down the key if it's not blocked.
+ .then(_ => invokeRequest(subresource, scenario.source_context_list))
+ // We check the key state, regardless of whether the main request
+ // succeeded or failed.
+ .then(checkResult, checkResult);
+ }, scenario.test_description);
+ } // runTest
+
+ function runTests() {
+ for (const scenario of scenarios) {
+ runTest(scenario);
+ }
+ }
+
+ return {start: runTests};
+}