dom/browser-element/mochitest/browserElement_DocumentFirstPaint.js

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

     1 /* Any copyright is dedicated to the public domain.
     2    http://creativecommons.org/publicdomain/zero/1.0/ */
     4 // Bug 829486 - Add mozdocumentbrowserfirstpaint event.
     5 "use strict";
     7 SimpleTest.waitForExplicitFinish();
     8 browserElementTestHelpers.setEnabledPref(true);
     9 browserElementTestHelpers.addPermission();
    11 var iframe;
    13 function runTestQueue(queue) {
    14   if (queue.length == 0) {
    15     SimpleTest.finish();
    16     return;
    17   }
    19   var gotFirstPaint = false;
    20   var gotFirstLocationChange = false;
    21   var test = queue.shift();
    23   function runNext() {
    24     iframe.removeEventListener('mozbrowserdocumentfirstpaint', documentfirstpainthandler);
    25     iframe.removeEventListener('mozbrowserloadend', loadendhandler);
    26     runTestQueue(queue);
    27   }
    29   function documentfirstpainthandler(e) {
    30     ok(!gotFirstPaint, "Got firstpaint only once");
    31     gotFirstPaint = true;
    32     if (gotFirstLocationChange) {
    33       runNext();
    34     }
    35   }
    37   function loadendhandler(e) {
    38     gotFirstLocationChange = true;
    39     if (gotFirstPaint) {
    40       runNext();
    41     }
    42   }
    44   iframe.addEventListener('mozbrowserdocumentfirstpaint', documentfirstpainthandler);
    45   iframe.addEventListener('mozbrowserloadend', loadendhandler);
    47   test();
    48 }
    50 function testChangeLocation() {
    51   iframe.src = browserElementTestHelpers.emptyPage1 + "?2";
    52 }
    54 function testReload() {
    55   iframe.reload();
    56 }
    58 function testFirstLoad() {
    59   document.body.appendChild(iframe);
    60   iframe.src = browserElementTestHelpers.emptyPage1;
    61 }
    63 function runTest() {
    64   iframe = document.createElement('iframe');
    65   SpecialPowers.wrap(iframe).mozbrowser = true;
    67   runTestQueue([testFirstLoad, testReload, testChangeLocation]);
    68 }
    70 addEventListener('testready', runTest);

mercurial