dom/browser-element/mochitest/browserElement_DocumentFirstPaint.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/browser-element/mochitest/browserElement_DocumentFirstPaint.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,70 @@
     1.4 +/* Any copyright is dedicated to the public domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +// Bug 829486 - Add mozdocumentbrowserfirstpaint event.
     1.8 +"use strict";
     1.9 +
    1.10 +SimpleTest.waitForExplicitFinish();
    1.11 +browserElementTestHelpers.setEnabledPref(true);
    1.12 +browserElementTestHelpers.addPermission();
    1.13 +
    1.14 +var iframe;
    1.15 +
    1.16 +function runTestQueue(queue) {
    1.17 +  if (queue.length == 0) {
    1.18 +    SimpleTest.finish();
    1.19 +    return;
    1.20 +  }
    1.21 +
    1.22 +  var gotFirstPaint = false;
    1.23 +  var gotFirstLocationChange = false;
    1.24 +  var test = queue.shift();
    1.25 +
    1.26 +  function runNext() {
    1.27 +    iframe.removeEventListener('mozbrowserdocumentfirstpaint', documentfirstpainthandler);
    1.28 +    iframe.removeEventListener('mozbrowserloadend', loadendhandler);
    1.29 +    runTestQueue(queue);
    1.30 +  }
    1.31 +
    1.32 +  function documentfirstpainthandler(e) {
    1.33 +    ok(!gotFirstPaint, "Got firstpaint only once");
    1.34 +    gotFirstPaint = true;
    1.35 +    if (gotFirstLocationChange) {
    1.36 +      runNext();
    1.37 +    }
    1.38 +  }
    1.39 +
    1.40 +  function loadendhandler(e) {
    1.41 +    gotFirstLocationChange = true;
    1.42 +    if (gotFirstPaint) {
    1.43 +      runNext();
    1.44 +    }
    1.45 +  }
    1.46 +
    1.47 +  iframe.addEventListener('mozbrowserdocumentfirstpaint', documentfirstpainthandler);
    1.48 +  iframe.addEventListener('mozbrowserloadend', loadendhandler);
    1.49 +
    1.50 +  test();
    1.51 +}
    1.52 +
    1.53 +function testChangeLocation() {
    1.54 +  iframe.src = browserElementTestHelpers.emptyPage1 + "?2";
    1.55 +}
    1.56 +
    1.57 +function testReload() {
    1.58 +  iframe.reload();
    1.59 +}
    1.60 +
    1.61 +function testFirstLoad() {
    1.62 +  document.body.appendChild(iframe);
    1.63 +  iframe.src = browserElementTestHelpers.emptyPage1;
    1.64 +}
    1.65 +
    1.66 +function runTest() {
    1.67 +  iframe = document.createElement('iframe');
    1.68 +  SpecialPowers.wrap(iframe).mozbrowser = true;
    1.69 +
    1.70 +  runTestQueue([testFirstLoad, testReload, testChangeLocation]);
    1.71 +}
    1.72 +
    1.73 +addEventListener('testready', runTest);

mercurial