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

// Bug 829486 - Add mozdocumentbrowserfirstpaint event.
"use strict";

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

var iframe;

function runTestQueue(queue) {
  if (queue.length == 0) {
    SimpleTest.finish();
    return;
  }

  var gotFirstPaint = false;
  var gotFirstLocationChange = false;
  var test = queue.shift();

  function runNext() {
    iframe.removeEventListener('mozbrowserdocumentfirstpaint', documentfirstpainthandler);
    iframe.removeEventListener('mozbrowserloadend', loadendhandler);
    runTestQueue(queue);
  }

  function documentfirstpainthandler(e) {
    ok(!gotFirstPaint, "Got firstpaint only once");
    gotFirstPaint = true;
    if (gotFirstLocationChange) {
      runNext();
    }
  }

  function loadendhandler(e) {
    gotFirstLocationChange = true;
    if (gotFirstPaint) {
      runNext();
    }
  }

  iframe.addEventListener('mozbrowserdocumentfirstpaint', documentfirstpainthandler);
  iframe.addEventListener('mozbrowserloadend', loadendhandler);

  test();
}

function testChangeLocation() {
  iframe.src = browserElementTestHelpers.emptyPage1 + "?2";
}

function testReload() {
  iframe.reload();
}

function testFirstLoad() {
  document.body.appendChild(iframe);
  iframe.src = browserElementTestHelpers.emptyPage1;
}

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

  runTestQueue([testFirstLoad, testReload, testChangeLocation]);
}

addEventListener('testready', runTest);