summaryrefslogtreecommitdiffstats
path: root/dom/browser-element/mochitest/browserElement_NextPaint.js
blob: 749a8efe3cc3d69154fe55fba28fdf279d37f1ef (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
/* Any copyright is dedicated to the public domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

// Bug 808231 - Add mozbrowsernextpaint event.
"use strict";

SimpleTest.waitForExplicitFinish();
browserElementTestHelpers.setEnabledPref(true);

function runTest() {
  var iframe = document.createElement('iframe');
  iframe.setAttribute('mozbrowser', 'true');
  document.body.appendChild(iframe);

  // Add a first listener that we'll remove shortly after.
  iframe.addNextPaintListener(wrongListener);

  var gotFirstNextPaintEvent = false;
  iframe.addNextPaintListener(function () {
    ok(!gotFirstNextPaintEvent, 'got the first nextpaint event');

    // Make sure we're only called once.
    gotFirstNextPaintEvent = true;

    iframe.addNextPaintListener(function () {
      info('got the second nextpaint event');
      SimpleTest.finish();
    });

    // Force the iframe to repaint.
    SimpleTest.executeSoon(() => iframe.src += '#next');
  });

  // Remove the first listener to make sure it's not called.
  iframe.removeNextPaintListener(wrongListener);
  iframe.src = 'file_browserElement_NextPaint.html';
}

function wrongListener() {
  ok(false, 'first listener should have been removed');
}

addEventListener('testready', runTest);