summaryrefslogtreecommitdiffstats
path: root/dom/browser-element/mochitest/priority/test_WebGLContextLost.html
blob: 383506ec6e328eb677b3a045ccecac10bcc7924b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<!DOCTYPE HTML>
<html>
<!--
Test that calling setVisible('false') and then sending a low-memory
notification causes a WebGL context loss event.
-->
<head>
  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <script type="application/javascript" src="../browserElementTestHelpers.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>

<script type="application/javascript;version=1.7">
"use strict";

SimpleTest.waitForExplicitFinish();
browserElementTestHelpers.setEnabledPref(true);
browserElementTestHelpers.addPermission();
browserElementTestHelpers.enableProcessPriorityManager();

function runTest() {
  var iframe = document.createElement('iframe');
  iframe.setAttribute('mozbrowser', true);
  iframe.src = 'file_WebGLContextLost.html';

  // We use this to ensure that we don't call SimpleTest.finish() twice.
  var finished = false;
  function finishOnce() {
    if (!finished) {
      SimpleTest.finish();
      finished = true;
    }
  }

  expectMozbrowserEvent(iframe, 'error').then(function(e) {
    if (finished) {
      // We don't care if the frame dies after the test finishes.
      return;
    }
    todo(false, "child process is crashing; this probably indicates that " +
         "something is wrong with WebGL in child processes on your machine.");
    is(e.detail.type, 'fatal');
  }).then(finishOnce);

  var childID = null;
  Promise.all([
    expectOnlyOneProcessCreated('FOREGROUND').then(function(chid) {
      childID = chid;
    }),
    expectMozbrowserEvent(iframe, 'loadend'),
    expectMozbrowserEvent(iframe, 'showmodalprompt').then(function(e) {
      is(e.detail.message, 'ready');
    })
  ]).then(function() {
    // Fire a low-memory notification once the process goes into the background
    // due to the setVisible(false) call below.
    expectPriorityChange(childID, 'BACKGROUND').then(function() {
      SimpleTest.executeSoon(function() {
        var os = SpecialPowers.Cc["@mozilla.org/observer-service;1"]
                              .getService(SpecialPowers.Ci.nsIObserverService);
        os.notifyObservers(null, "memory-pressure", "low-memory");
        ok(true, 'Successfully notified observers.');
      });
    });

    // This test isn't the only possible source of a low-memory notification; the
    // browser can fire one whenever it likes.  So it's fine if we lose the
    // WebGL context before we fire the low-memory notification ourself.

    var p = expectMozbrowserEvent(iframe, 'showmodalprompt').then(function(e) {
      is(e.detail.message, 'webglcontextlost');
    });

    iframe.setVisible(false);
    return p;
  }).then(finishOnce);

  document.body.appendChild(iframe);
}

addEventListener('testready', function() {
  // At the time this test was written, webgl was blocklisted inside child
  // processes on desktop Linux.  The issue is that we spawn a child process to
  // read driver info, but we only did this on the main prrocess.  Child
  // processes never read the driver info themselves, nor do they get it from
  // their parent, so they refuse to start up WebGL.
  //
  // This isn't a problem on B2G because we force WebGL on there.  But it
  // obviously makes this test difficult.  bjacob says forcing WebGL on here
  // shouldn't hurt things, and anyway this setting mirrors what we do on B2G,
  // which is what we're trying to test!
  SpecialPowers.pushPrefEnv({set: [["webgl.force-enabled", true]]},
                            runTest);
});

</script>
</body>
</html>