summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/webappapis/timers/missing-timeout-setinterval.any.js
blob: 33a1cc073c8c1f7ebfaa7edc32a65293a1a5f713 (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
function timeout_trampoline(t, timeout, message) {
  t.step_timeout(function() {
    // Yield in case we managed to be called before the second interval callback.
    t.step_timeout(function() {
      assert_unreached(message);
    }, timeout);
  }, timeout);
}

async_test(function(t) {
  let ctr = 0;
  let h = setInterval(t.step_func(function() {
    if (++ctr == 2) {
      clearInterval(h);
      t.done();
      return;
    }
  }) /* no interval */);

  timeout_trampoline(t, 100, "Expected setInterval callback to be called two times");
}, "Calling setInterval with no interval should be the same as if called with 0 interval");

async_test(function(t) {
  let ctr = 0;
  let h = setInterval(t.step_func(function() {
    if (++ctr == 2) {
      clearInterval(h);
      t.done();
      return;
    }
  }),  undefined);

  timeout_trampoline(t, 100, "Expected setInterval callback to be called two times");
}, "Calling setInterval with undefined interval should be the same as if called with 0 interval");