commit c80ee4f8e66950d59a9f2ccd4b5c79fbaa2e8736
parent 58ec314162bea1fdda7650c5e821191bd654e14f
Author: Tom Ritter <tom@mozilla.com>
Date: Wed, 17 Dec 2025 17:44:38 +0000
Bug 1976287: Tests for WebGL Sanitize r=timhuang
Differential Revision: https://phabricator.services.mozilla.com/D276178
Diffstat:
4 files changed, 196 insertions(+), 0 deletions(-)
diff --git a/dom/canvas/test/webgl-mochitest/mochitest.toml b/dom/canvas/test/webgl-mochitest/mochitest.toml
@@ -279,6 +279,12 @@ skip-if = [
"os == 'android'", # bug 865443- seperate suite - the non_conf* tests pass except for one on armv6 tests
]
+["test_webgl_vendor_sanitize_fpp.html"]
+
+["test_webgl_vendor_sanitize_fpp_explicit.html"]
+
+["test_webgl_vendor_sanitize_rfp.html"]
+
["test_webglcontextcreationerror.html"]
["test_without_index_validation.html"]
diff --git a/dom/canvas/test/webgl-mochitest/test_webgl_vendor_sanitize_fpp.html b/dom/canvas/test/webgl-mochitest/test_webgl_vendor_sanitize_fpp.html
@@ -0,0 +1,69 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>WebGL Vendor Sanitize with FPP - Vendor should be sanitized</title>
+<script src="/tests/SimpleTest/SimpleTest.js"></script>
+<script>
+/* global SimpleTest SpecialPowers */
+SimpleTest.waitForExplicitFinish();
+document.addEventListener("DOMContentLoaded", async function() {
+ // Enable FPP with WebGLVendorSanitize
+ await SpecialPowers.pushPrefEnv({
+ set: [
+ ["privacy.fingerprintingProtection", true],
+ ["privacy.fingerprintingProtection.overrides", "+WebGLVendorSanitize"],
+ ["privacy.resistFingerprinting", false]
+ ]
+ });
+
+ let canvas = document.body.appendChild(document.createElement("canvas"));
+ if (!canvas) {
+ SimpleTest.ok(false, "Cannot create canvas");
+ SimpleTest.finish();
+ return;
+ }
+
+ let gl = canvas.getContext("webgl");
+ if (!gl) {
+ SimpleTest.ok(false, "Cannot get WebGL context");
+ SimpleTest.finish();
+ return;
+ }
+
+ // Try to get the WEBGL_debug_renderer_info extension
+ let ext = gl.getExtension("WEBGL_debug_renderer_info");
+ if (!ext) {
+ SimpleTest.ok(false, "WEBGL_debug_renderer_info extension should be available with FPP");
+ SimpleTest.finish();
+ return;
+ }
+
+ // With FPP and WebGLVendorSanitize enabled, the vendor should be sanitized
+ // to one of the known values
+ let vendor = gl.getParameter(ext.UNMASKED_VENDOR_WEBGL);
+
+ // List of valid sanitized vendor strings
+ const validVendors = [
+ "NVIDIA Corporation",
+ "Intel",
+ "AMD",
+ "Qualcomm",
+ "ARM",
+ "Apple",
+ "Samsung",
+ "Mesa",
+ "Microsoft",
+ "VMware",
+ "Google",
+ "Other"
+ ];
+
+ SimpleTest.ok(validVendors.includes(vendor),
+ "UNMASKED_VENDOR_WEBGL should be sanitized to one of the known values. Got: " + vendor);
+
+ // Verify it's NOT "Mozilla" (which would indicate WebGLRenderInfo is active)
+ SimpleTest.isnot(vendor, "Mozilla",
+ "UNMASKED_VENDOR_WEBGL should be sanitized, not 'Mozilla' (WebGLRenderInfo not active)");
+
+ SimpleTest.finish();
+});
+</script>
diff --git a/dom/canvas/test/webgl-mochitest/test_webgl_vendor_sanitize_fpp_explicit.html b/dom/canvas/test/webgl-mochitest/test_webgl_vendor_sanitize_fpp_explicit.html
@@ -0,0 +1,70 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>WebGL Vendor Sanitize with FPP (explicit) - Vendor should be sanitized</title>
+<script src="/tests/SimpleTest/SimpleTest.js"></script>
+<script>
+/* global SimpleTest SpecialPowers */
+SimpleTest.waitForExplicitFinish();
+document.addEventListener("DOMContentLoaded", async function() {
+ // Enable FPP with explicit -AllTargets,+WebGLVendorSanitize
+ // This ensures only WebGLVendorSanitize is active, nothing else
+ await SpecialPowers.pushPrefEnv({
+ set: [
+ ["privacy.fingerprintingProtection", true],
+ ["privacy.fingerprintingProtection.overrides", "-AllTargets,+WebGLVendorSanitize"],
+ ["privacy.resistFingerprinting", false]
+ ]
+ });
+
+ let canvas = document.body.appendChild(document.createElement("canvas"));
+ if (!canvas) {
+ SimpleTest.ok(false, "Cannot create canvas");
+ SimpleTest.finish();
+ return;
+ }
+
+ let gl = canvas.getContext("webgl");
+ if (!gl) {
+ SimpleTest.ok(false, "Cannot get WebGL context");
+ SimpleTest.finish();
+ return;
+ }
+
+ // Try to get the WEBGL_debug_renderer_info extension
+ let ext = gl.getExtension("WEBGL_debug_renderer_info");
+ if (!ext) {
+ SimpleTest.ok(false, "WEBGL_debug_renderer_info extension should be available with FPP");
+ SimpleTest.finish();
+ return;
+ }
+
+ // With FPP and WebGLVendorSanitize enabled, the vendor should be sanitized
+ // to one of the known values
+ let vendor = gl.getParameter(ext.UNMASKED_VENDOR_WEBGL);
+
+ // List of valid sanitized vendor strings
+ const validVendors = [
+ "NVIDIA Corporation",
+ "Intel",
+ "AMD",
+ "Qualcomm",
+ "ARM",
+ "Apple",
+ "Samsung",
+ "Mesa",
+ "Microsoft",
+ "VMware",
+ "Google",
+ "Other"
+ ];
+
+ SimpleTest.ok(validVendors.includes(vendor),
+ "UNMASKED_VENDOR_WEBGL should be sanitized to one of the known values. Got: " + vendor);
+
+ // Verify it's NOT "Mozilla" (which would indicate WebGLRenderInfo is active)
+ SimpleTest.isnot(vendor, "Mozilla",
+ "UNMASKED_VENDOR_WEBGL should be sanitized, not 'Mozilla' (WebGLRenderInfo not active)");
+
+ SimpleTest.finish();
+});
+</script>
diff --git a/dom/canvas/test/webgl-mochitest/test_webgl_vendor_sanitize_rfp.html b/dom/canvas/test/webgl-mochitest/test_webgl_vendor_sanitize_rfp.html
@@ -0,0 +1,51 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>WebGL Vendor Sanitize with RFP - WebGLRenderInfo takes precedence</title>
+<script src="/tests/SimpleTest/SimpleTest.js"></script>
+<script>
+/* global SimpleTest SpecialPowers */
+SimpleTest.waitForExplicitFinish();
+document.addEventListener("DOMContentLoaded", async function() {
+ // Enable RFP - WebGLRenderInfo should take precedence over WebGLVendorSanitize
+ await SpecialPowers.pushPrefEnv({
+ set: [
+ ["privacy.resistFingerprinting", true],
+ ["privacy.fingerprintingProtection", true],
+ ["privacy.fingerprintingProtection.overrides", "+WebGLVendorSanitize"],
+ ]
+ });
+
+ let canvas = document.body.appendChild(document.createElement("canvas"));
+ if (!canvas) {
+ SimpleTest.ok(false, "Cannot create canvas");
+ SimpleTest.finish();
+ return;
+ }
+
+ let gl = canvas.getContext("webgl");
+ if (!gl) {
+ SimpleTest.ok(false, "Cannot get WebGL context");
+ SimpleTest.finish();
+ return;
+ }
+
+ // Try to get the WEBGL_debug_renderer_info extension
+ let ext = gl.getExtension("WEBGL_debug_renderer_info");
+ if (!ext) {
+ SimpleTest.ok(false, "WEBGL_debug_renderer_info extension should be available with RFP");
+ SimpleTest.finish();
+ return;
+ }
+
+ // With RFP enabled, WebGLRenderInfo takes precedence
+ // The vendor should be "Mozilla", NOT a sanitized value
+ let vendor = gl.getParameter(ext.UNMASKED_VENDOR_WEBGL);
+ SimpleTest.is(vendor, "Mozilla", "UNMASKED_VENDOR_WEBGL should be 'Mozilla' with RFP enabled (WebGLRenderInfo precedence)");
+
+ // Also check renderer for completeness
+ let renderer = gl.getParameter(ext.UNMASKED_RENDERER_WEBGL);
+ SimpleTest.is(renderer, "Mozilla", "UNMASKED_RENDERER_WEBGL should be 'Mozilla' with RFP enabled");
+
+ SimpleTest.finish();
+});
+</script>