summaryrefslogtreecommitdiffstats
path: root/browser/base/content/test/about/browser_aboutStopReload.js
blob: 21507509bcb32ca34258b49eb477affdb5469c21 (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
async function waitForNoAnimation(elt) {
  return TestUtils.waitForCondition(() => !elt.hasAttribute("animate"));
}

async function getAnimatePromise(elt) {
  return BrowserTestUtils.waitForAttribute("animate", elt).then(() =>
    Assert.ok(true, `${elt.id} should animate`)
  );
}

function stopReloadMutationCallback() {
  Assert.ok(
    false,
    "stop-reload's animate attribute should not have been mutated"
  );
}

// Force-enable the animation
gReduceMotionOverride = false;

add_task(async function checkDontShowStopOnNewTab() {
  let stopReloadContainer = document.getElementById("stop-reload-button");
  let stopReloadContainerObserver = new MutationObserver(
    stopReloadMutationCallback
  );

  await waitForNoAnimation(stopReloadContainer);
  stopReloadContainerObserver.observe(stopReloadContainer, {
    attributeFilter: ["animate"],
  });
  let tab = await BrowserTestUtils.openNewForegroundTab({
    gBrowser,
    opening: "about:robots",
    waitForStateStop: true,
  });
  BrowserTestUtils.removeTab(tab);

  Assert.ok(
    true,
    "Test finished: stop-reload does not animate when navigating to local URI on new tab"
  );
  stopReloadContainerObserver.disconnect();
});

add_task(async function checkDontShowStopFromLocalURI() {
  let stopReloadContainer = document.getElementById("stop-reload-button");
  let stopReloadContainerObserver = new MutationObserver(
    stopReloadMutationCallback
  );

  let tab = await BrowserTestUtils.openNewForegroundTab({
    gBrowser,
    opening: "about:robots",
    waitForStateStop: true,
  });
  await waitForNoAnimation(stopReloadContainer);
  stopReloadContainerObserver.observe(stopReloadContainer, {
    attributeFilter: ["animate"],
  });
  BrowserTestUtils.startLoadingURIString(tab.linkedBrowser, "about:mozilla");
  BrowserTestUtils.removeTab(tab);

  Assert.ok(
    true,
    "Test finished: stop-reload does not animate when navigating between local URIs"
  );
  stopReloadContainerObserver.disconnect();
});

add_task(async function checkDontShowStopFromNonLocalURI() {
  let stopReloadContainer = document.getElementById("stop-reload-button");
  let stopReloadContainerObserver = new MutationObserver(
    stopReloadMutationCallback
  );

  let tab = await BrowserTestUtils.openNewForegroundTab({
    gBrowser,
    opening: "https://example.com",
    waitForStateStop: true,
  });
  await waitForNoAnimation(stopReloadContainer);
  stopReloadContainerObserver.observe(stopReloadContainer, {
    attributeFilter: ["animate"],
  });
  BrowserTestUtils.startLoadingURIString(tab.linkedBrowser, "about:mozilla");
  BrowserTestUtils.removeTab(tab);

  Assert.ok(
    true,
    "Test finished: stop-reload does not animate when navigating to local URI from non-local URI"
  );
  stopReloadContainerObserver.disconnect();
});

add_task(async function checkDoShowStopOnNewTab() {
  let stopReloadContainer = document.getElementById("stop-reload-button");
  let reloadButton = document.getElementById("reload-button");
  let stopPromise = BrowserTestUtils.waitForAttribute(
    "displaystop",
    reloadButton
  );

  await waitForNoAnimation(stopReloadContainer);

  let tab = await BrowserTestUtils.openNewForegroundTab({
    gBrowser,
    opening: "https://example.com",
    waitForStateStop: true,
  });
  await stopPromise;
  await waitForNoAnimation(stopReloadContainer);
  BrowserTestUtils.removeTab(tab);

  info(
    "Test finished: stop-reload shows stop when navigating to non-local URI during tab opening"
  );
});

add_task(async function checkAnimateStopOnTabAfterTabFinishesOpening() {
  let stopReloadContainer = document.getElementById("stop-reload-button");

  await waitForNoAnimation(stopReloadContainer);
  let tab = await BrowserTestUtils.openNewForegroundTab({
    gBrowser,
    waitForStateStop: true,
  });
  await TestUtils.waitForCondition(() => {
    info(
      "Waiting for tabAnimationsInProgress to equal 0, currently " +
        gBrowser.tabAnimationsInProgress
    );
    return !gBrowser.tabAnimationsInProgress;
  });
  let animatePromise = getAnimatePromise(stopReloadContainer);
  BrowserTestUtils.startLoadingURIString(
    tab.linkedBrowser,
    "https://example.com"
  );
  await animatePromise;
  BrowserTestUtils.removeTab(tab);

  info(
    "Test finished: stop-reload animates when navigating to non-local URI on new tab after tab has opened"
  );
});

add_task(async function checkDoShowStopFromLocalURI() {
  let stopReloadContainer = document.getElementById("stop-reload-button");

  await waitForNoAnimation(stopReloadContainer);
  let tab = await BrowserTestUtils.openNewForegroundTab({
    gBrowser,
    opening: "about:robots",
    waitForStateStop: true,
  });
  await TestUtils.waitForCondition(() => {
    info(
      "Waiting for tabAnimationsInProgress to equal 0, currently " +
        gBrowser.tabAnimationsInProgress
    );
    return !gBrowser.tabAnimationsInProgress;
  });
  let animatePromise = getAnimatePromise(stopReloadContainer);
  BrowserTestUtils.startLoadingURIString(
    tab.linkedBrowser,
    "https://example.com"
  );
  await animatePromise;
  await waitForNoAnimation(stopReloadContainer);
  BrowserTestUtils.removeTab(tab);

  info(
    "Test finished: stop-reload animates when navigating to non-local URI from local URI"
  );
});