dom/browser-element/mochitest/priority/test_WebGLContextLost.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/browser-element/mochitest/priority/test_WebGLContextLost.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,100 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +Test that calling setVisible('false') and then sending a low-memory
     1.8 +notification causes a WebGL context loss event.
     1.9 +-->
    1.10 +<head>
    1.11 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.12 +  <script type="application/javascript" src="../browserElementTestHelpers.js"></script>
    1.13 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.14 +</head>
    1.15 +<body>
    1.16 +
    1.17 +<script type="application/javascript;version=1.7">
    1.18 +"use strict";
    1.19 +
    1.20 +SimpleTest.waitForExplicitFinish();
    1.21 +browserElementTestHelpers.setEnabledPref(true);
    1.22 +browserElementTestHelpers.addPermission();
    1.23 +browserElementTestHelpers.enableProcessPriorityManager();
    1.24 +
    1.25 +function runTest() {
    1.26 +  var iframe = document.createElement('iframe');
    1.27 +  iframe.setAttribute('mozbrowser', true);
    1.28 +  iframe.src = 'file_WebGLContextLost.html';
    1.29 +
    1.30 +  // We use this to ensure that we don't call SimpleTest.finish() twice.
    1.31 +  var finished = false;
    1.32 +  function finishOnce() {
    1.33 +    if (!finished) {
    1.34 +      SimpleTest.finish();
    1.35 +      finished = true;
    1.36 +    }
    1.37 +  }
    1.38 +
    1.39 +  expectMozbrowserEvent(iframe, 'error').then(function(e) {
    1.40 +    if (finished) {
    1.41 +      // We don't care if the frame dies after the test finishes.
    1.42 +      return;
    1.43 +    }
    1.44 +    todo(false, "child process is crashing; this probably indicates that " +
    1.45 +         "something is wrong with WebGL in child processes on your machine.");
    1.46 +    is(e.detail.type, 'fatal');
    1.47 +  }).then(finishOnce);
    1.48 +
    1.49 +  var childID = null;
    1.50 +  expectOnlyOneProcessCreated().then(function(chid) {
    1.51 +    childID = chid;
    1.52 +    return Promise.all(
    1.53 +      [expectPriorityChange(childID, 'FOREGROUND'),
    1.54 +       expectMozbrowserEvent(iframe, 'loadend'),
    1.55 +       expectMozbrowserEvent(iframe, 'showmodalprompt').then(function(e) {
    1.56 +         is(e.detail.message, 'ready');
    1.57 +       })
    1.58 +     ]);
    1.59 +  }).then(function() {
    1.60 +    // Fire a low-memory notification once the process goes into the background
    1.61 +    // due to the setVisible(false) call below.
    1.62 +    expectPriorityChange(childID, 'BACKGROUND').then(function() {
    1.63 +      SimpleTest.executeSoon(function() {
    1.64 +        var os = SpecialPowers.Cc["@mozilla.org/observer-service;1"]
    1.65 +                              .getService(SpecialPowers.Ci.nsIObserverService);
    1.66 +        os.notifyObservers(null, "memory-pressure", "low-memory");
    1.67 +        ok(true, 'Successfully notified observers.');
    1.68 +      });
    1.69 +    });
    1.70 +
    1.71 +    // This test isn't the only possible source of a low-memory notification; the
    1.72 +    // browser can fire one whenever it likes.  So it's fine if we lose the
    1.73 +    // WebGL context before we fire the low-memory notification ourself.
    1.74 +
    1.75 +    var p = expectMozbrowserEvent(iframe, 'showmodalprompt').then(function(e) {
    1.76 +      is(e.detail.message, 'webglcontextlost');
    1.77 +    });
    1.78 +
    1.79 +    iframe.setVisible(false);
    1.80 +    return p;
    1.81 +  }).then(finishOnce);
    1.82 +
    1.83 +  document.body.appendChild(iframe);
    1.84 +}
    1.85 +
    1.86 +addEventListener('testready', function() {
    1.87 +  // At the time this test was written, webgl was blocklisted inside child
    1.88 +  // processes on desktop Linux.  The issue is that we spawn a child process to
    1.89 +  // read driver info, but we only did this on the main prrocess.  Child
    1.90 +  // processes never read the driver info themselves, nor do they get it from
    1.91 +  // their parent, so they refuse to start up WebGL.
    1.92 +  //
    1.93 +  // This isn't a problem on B2G because we force WebGL on there.  But it
    1.94 +  // obviously makes this test difficult.  bjacob says forcing WebGL on here
    1.95 +  // shouldn't hurt things, and anyway this setting mirrors what we do on B2G,
    1.96 +  // which is what we're trying to test!
    1.97 +  SpecialPowers.pushPrefEnv({set: [["webgl.force-enabled", true]]},
    1.98 +                            runTest);
    1.99 +});
   1.100 +
   1.101 +</script>
   1.102 +</body>
   1.103 +</html>

mercurial