dom/browser-element/mochitest/browserElement_SetVisibleFrames.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/browser-element/mochitest/browserElement_SetVisibleFrames.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,101 @@
     1.4 +/* Any copyright is dedicated to the public domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +// Bug 762939 - Test that visibility propagates down properly through
     1.8 +// hierarchies of <iframe mozbrowser>.
     1.9 +//
    1.10 +// In this test, we modify the parent's visibility and check that the child's
    1.11 +// visibility is changed as appopriate.  We test modifying the child's
    1.12 +// visibility in a separate testcase.
    1.13 +
    1.14 +"use strict";
    1.15 +
    1.16 +SimpleTest.waitForExplicitFinish();
    1.17 +browserElementTestHelpers.setEnabledPref(true);
    1.18 +browserElementTestHelpers.addPermission();
    1.19 +
    1.20 +var iframe;
    1.21 +
    1.22 +function runTest() {
    1.23 +  var principal = SpecialPowers.wrap(document).nodePrincipal;
    1.24 +  SpecialPowers.addPermission("browser", true, { url: SpecialPowers.wrap(principal.URI).spec,
    1.25 +                                                 appId: principal.appId,
    1.26 +                                                 isInBrowserElement: true });
    1.27 +
    1.28 +  iframe = document.createElement('iframe');
    1.29 +  SpecialPowers.wrap(iframe).mozbrowser = true;
    1.30 +
    1.31 +  // Our test involves three <iframe mozbrowser>'s, parent, child1, and child2.
    1.32 +  // child1 and child2 are contained inside parent.  child1 is visibile, and
    1.33 +  // child2 is not.
    1.34 +  //
    1.35 +  // For the purposes of this test, we want there to be a process barrier
    1.36 +  // between child{1,2} and parent.  Therefore parent must be a non-remote
    1.37 +  // <iframe mozbrowser>, until bug 761935 is resolved and we can have nested
    1.38 +  // content processes.
    1.39 +  iframe.remote = false;
    1.40 +
    1.41 +  iframe.addEventListener('mozbrowsershowmodalprompt', checkMessage);
    1.42 +  expectMessage('parent:ready', test1);
    1.43 +
    1.44 +  document.body.appendChild(iframe);
    1.45 +  iframe.src = 'file_browserElement_SetVisibleFrames_Outer.html';
    1.46 +}
    1.47 +
    1.48 +function test1() {
    1.49 +  expectMessage('child1:hidden', getVisibleTest1);
    1.50 +  iframe.setVisible(false);
    1.51 +}
    1.52 +
    1.53 +function getVisibleTest1() {
    1.54 +  iframe.getVisible().onsuccess = function(evt) {
    1.55 +    ok(evt.target.result === false, 'getVisible shows a hidden frame');
    1.56 +    test2();
    1.57 +  };
    1.58 +}
    1.59 +
    1.60 +function test2() {
    1.61 +  expectMessage('child1:visible', getVisibleTest2);
    1.62 +  iframe.setVisible(true);
    1.63 +}
    1.64 +
    1.65 +function getVisibleTest2() {
    1.66 +  iframe.getVisible().onsuccess = function(evt) {
    1.67 +    ok(evt.target.result === true, 'getVisible shows a displayed frame');
    1.68 +    finish();
    1.69 +  };
    1.70 +}
    1.71 +
    1.72 +function finish() {
    1.73 +  // We need to remove this listener because when this test finishes and the
    1.74 +  // iframe containing this document is navigated, we'll fire a
    1.75 +  // visibilitychange(false) event on all child iframes.  That's OK and
    1.76 +  // expected, but if we don't remove our listener, then we'll end up causing
    1.77 +  // the /next/ test to fail!
    1.78 +  iframe.removeEventListener('mozbrowsershowmodalprompt', checkMessage);
    1.79 +
    1.80 +  var principal = SpecialPowers.wrap(document).nodePrincipal;
    1.81 +  SpecialPowers.removePermission("browser", { url: SpecialPowers.wrap(principal.URI).spec,
    1.82 +                                              appId: principal.appId,
    1.83 +                                              isInBrowserElement: true });
    1.84 +
    1.85 +  SimpleTest.finish();
    1.86 +}
    1.87 +
    1.88 +var expectedMsg = null;
    1.89 +var expectedMsgCallback = null;
    1.90 +function expectMessage(msg, next) {
    1.91 +  expectedMsg = msg;
    1.92 +  expectedMsgCallback = next;
    1.93 +}
    1.94 +
    1.95 +function checkMessage(e) {
    1.96 +  var msg = e.detail.message;
    1.97 +  is(msg, expectedMsg);
    1.98 +  if (msg == expectedMsg) {
    1.99 +    expectedMsg = null;
   1.100 +    SimpleTest.executeSoon(function() { expectedMsgCallback() });
   1.101 +  }
   1.102 +}
   1.103 +
   1.104 +addEventListener('testready', runTest);

mercurial