summaryrefslogtreecommitdiffstats
path: root/toolkit/components/antitracking/bouncetrackingprotection/test/browser/browser_bouncetracking_schemes.js
diff options
context:
space:
mode:
Diffstat (limited to 'toolkit/components/antitracking/bouncetrackingprotection/test/browser/browser_bouncetracking_schemes.js')
-rw-r--r--toolkit/components/antitracking/bouncetrackingprotection/test/browser/browser_bouncetracking_schemes.js75
1 files changed, 75 insertions, 0 deletions
diff --git a/toolkit/components/antitracking/bouncetrackingprotection/test/browser/browser_bouncetracking_schemes.js b/toolkit/components/antitracking/bouncetrackingprotection/test/browser/browser_bouncetracking_schemes.js
new file mode 100644
index 0000000000..21b72cdc45
--- /dev/null
+++ b/toolkit/components/antitracking/bouncetrackingprotection/test/browser/browser_bouncetracking_schemes.js
@@ -0,0 +1,75 @@
+/* Any copyright is dedicated to the Public Domain.
+ https://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+let bounceTrackingProtection;
+
+add_setup(async function () {
+ bounceTrackingProtection = Cc[
+ "@mozilla.org/bounce-tracking-protection;1"
+ ].getService(Ci.nsIBounceTrackingProtection);
+ bounceTrackingProtection.clearAll();
+});
+
+async function testInteractWithSite(origin, expectRecorded) {
+ is(
+ bounceTrackingProtection.testGetUserActivationHosts({}).length,
+ 0,
+ "No user activation hosts initially"
+ );
+
+ let baseDomain;
+ let scheme;
+
+ await BrowserTestUtils.withNewTab(origin, async browser => {
+ baseDomain = browser.contentPrincipal.baseDomain;
+ scheme = browser.contentPrincipal.URI.scheme;
+
+ info(
+ `Trigger a user activation, which should ${
+ expectRecorded ? "" : "not "
+ }be recorded.`
+ );
+ // We intentionally turn off this a11y check, because the following click
+ // is purposefully sent on an arbitrary web content that is not expected
+ // to be tested by itself with the browser mochitests, therefore this rule
+ // check shall be ignored by a11y_checks suite.
+ AccessibilityUtils.setEnv({ mustHaveAccessibleRule: false });
+ await BrowserTestUtils.synthesizeMouseAtPoint(50, 50, {}, browser);
+ AccessibilityUtils.resetEnv();
+ });
+ if (expectRecorded) {
+ Assert.deepEqual(
+ bounceTrackingProtection
+ .testGetUserActivationHosts({})
+ .map(entry => entry.siteHost),
+ [baseDomain],
+ `User activation should be recorded for ${scheme} scheme.`
+ );
+ } else {
+ Assert.deepEqual(
+ bounceTrackingProtection.testGetUserActivationHosts({}),
+ [],
+ `User activation should not be recorded for ${scheme} scheme.`
+ );
+ }
+
+ bounceTrackingProtection.clearAll();
+}
+
+/**
+ * Test that we only record user activation for supported schemes.
+ */
+add_task(async function test_userActivationSchemes() {
+ // eslint-disable-next-line @microsoft/sdl/no-insecure-url
+ await testInteractWithSite("http://example.com", true);
+ await testInteractWithSite("https://example.com", true);
+
+ await testInteractWithSite("about:blank", false);
+ await testInteractWithSite("about:robots", false);
+ await testInteractWithSite(
+ "file://" + Services.dirsvc.get("TmpD", Ci.nsIFile).path,
+ false
+ );
+});