dom/browser-element/mochitest/browserElement_VisibilityChange.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/browser-element/mochitest/browserElement_VisibilityChange.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,43 @@
     1.4 +/* Any copyright is dedicated to the public domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +// Test that the onmozbrowservisibilitychange event works.
     1.8 +'use strict';
     1.9 +
    1.10 +SimpleTest.waitForExplicitFinish();
    1.11 +browserElementTestHelpers.setEnabledPref(true);
    1.12 +browserElementTestHelpers.addPermission();
    1.13 +
    1.14 +var iframe1 = null;
    1.15 +function runTest() {
    1.16 +  iframe1 = document.createElement('iframe');
    1.17 +  SpecialPowers.wrap(iframe1).mozbrowser = true;
    1.18 +  document.body.appendChild(iframe1);
    1.19 +
    1.20 +  iframe1.src = 'data:text/html,<html><head><title>Title</title></head><body></body></html>';
    1.21 +  checkVisibilityFalse();
    1.22 +}
    1.23 +
    1.24 +function checkVisibilityFalse() {
    1.25 +  iframe1.addEventListener('mozbrowservisibilitychange', function onvisibilitychange(e) {
    1.26 +    iframe1.removeEventListener(e.type, onvisibilitychange);
    1.27 +
    1.28 +    is(e.detail.visible, false, 'Visibility should be false');
    1.29 +    checkVisibilityTrue();
    1.30 +  });
    1.31 +
    1.32 +  iframe1.setVisible(false);
    1.33 +}
    1.34 +
    1.35 +function checkVisibilityTrue() {
    1.36 +  iframe1.addEventListener('mozbrowservisibilitychange', function onvisibilitychange(e) {
    1.37 +    iframe1.removeEventListener(e.type, onvisibilitychange);
    1.38 +
    1.39 +    is(e.detail.visible, true, 'Visibility should be true');
    1.40 +    SimpleTest.finish();
    1.41 +  });
    1.42 +
    1.43 +  iframe1.setVisible(true);
    1.44 +}
    1.45 +
    1.46 +addEventListener('testready', runTest);

mercurial