summaryrefslogtreecommitdiffstats
path: root/browser/base/content/test/protectionsUI/browser_protectionsUI_animation.js
blob: 2d11bd5b259eb24c0f193d22d1d7218ec420c20e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

const TRACKING_PAGE =
  "http://tracking.example.org/browser/browser/base/content/test/protectionsUI/trackingPage.html";
const BENIGN_PAGE =
  "http://tracking.example.org/browser/browser/base/content/test/protectionsUI/benignPage.html";
const TP_PREF = "privacy.trackingprotection.enabled";
const PREFER_REDUCED_MOTION_PREF = "ui.prefersReducedMotion";
const DTSCBN_PREF = "dom.testing.sync-content-blocking-notifications";

// Test that the shield icon animation can be controlled by the cosmetic
// animations pref and that one of the icons is visible in each case.
add_task(async function testShieldAnimation() {
  await UrlClassifierTestUtils.addTestTrackers();
  Services.prefs.setBoolPref(TP_PREF, true);
  Services.prefs.setBoolPref(DTSCBN_PREF, true);

  let tab = (gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser));

  let animationIcon = document.getElementById(
    "tracking-protection-icon-animatable-image"
  );
  let noAnimationIcon = document.getElementById("tracking-protection-icon");

  Services.prefs.setIntPref(PREFER_REDUCED_MOTION_PREF, 0);
  await Promise.all([
    promiseTabLoadEvent(tab, TRACKING_PAGE),
    waitForContentBlockingEvent(2, tab.linkedBrowser.ownerGlobal),
  ]);
  ok(
    BrowserTestUtils.is_hidden(noAnimationIcon),
    "the default icon is hidden when animations are enabled"
  );
  ok(
    BrowserTestUtils.is_visible(animationIcon),
    "the animated icon is shown when animations are enabled"
  );

  await promiseTabLoadEvent(tab, BENIGN_PAGE);
  ok(BrowserTestUtils.is_hidden(animationIcon), "the animated icon is hidden");
  ok(
    BrowserTestUtils.is_visible(noAnimationIcon),
    "the default icon is visible"
  );

  Services.prefs.setIntPref(PREFER_REDUCED_MOTION_PREF, 1);
  await Promise.all([
    promiseTabLoadEvent(tab, TRACKING_PAGE),
    waitForContentBlockingEvent(2, tab.linkedBrowser.ownerGlobal),
  ]);

  // We will only show the last frame of the animation when the animation is
  // disable. So, the animated icon would be shown but the default icon
  // wouldn't.
  ok(
    BrowserTestUtils.is_hidden(noAnimationIcon),
    "the default icon is hidden when animations are disabled"
  );
  ok(
    BrowserTestUtils.is_visible(animationIcon),
    "the animated icon is shown when animations are disabled"
  );

  gBrowser.removeCurrentTab();
  Services.prefs.clearUserPref(PREFER_REDUCED_MOTION_PREF);
  Services.prefs.clearUserPref(TP_PREF);
  Services.prefs.clearUserPref(DTSCBN_PREF);
  UrlClassifierTestUtils.cleanupTestTrackers();
});