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

changeset 2
7e26c7da4463
equal deleted inserted replaced
-1:000000000000 0:c532920aea8e
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 Test that calling setVisible('false') and then sending a low-memory
5 notification causes a WebGL context loss event.
6 -->
7 <head>
8 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
9 <script type="application/javascript" src="../browserElementTestHelpers.js"></script>
10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
11 </head>
12 <body>
13
14 <script type="application/javascript;version=1.7">
15 "use strict";
16
17 SimpleTest.waitForExplicitFinish();
18 browserElementTestHelpers.setEnabledPref(true);
19 browserElementTestHelpers.addPermission();
20 browserElementTestHelpers.enableProcessPriorityManager();
21
22 function runTest() {
23 var iframe = document.createElement('iframe');
24 iframe.setAttribute('mozbrowser', true);
25 iframe.src = 'file_WebGLContextLost.html';
26
27 // We use this to ensure that we don't call SimpleTest.finish() twice.
28 var finished = false;
29 function finishOnce() {
30 if (!finished) {
31 SimpleTest.finish();
32 finished = true;
33 }
34 }
35
36 expectMozbrowserEvent(iframe, 'error').then(function(e) {
37 if (finished) {
38 // We don't care if the frame dies after the test finishes.
39 return;
40 }
41 todo(false, "child process is crashing; this probably indicates that " +
42 "something is wrong with WebGL in child processes on your machine.");
43 is(e.detail.type, 'fatal');
44 }).then(finishOnce);
45
46 var childID = null;
47 expectOnlyOneProcessCreated().then(function(chid) {
48 childID = chid;
49 return Promise.all(
50 [expectPriorityChange(childID, 'FOREGROUND'),
51 expectMozbrowserEvent(iframe, 'loadend'),
52 expectMozbrowserEvent(iframe, 'showmodalprompt').then(function(e) {
53 is(e.detail.message, 'ready');
54 })
55 ]);
56 }).then(function() {
57 // Fire a low-memory notification once the process goes into the background
58 // due to the setVisible(false) call below.
59 expectPriorityChange(childID, 'BACKGROUND').then(function() {
60 SimpleTest.executeSoon(function() {
61 var os = SpecialPowers.Cc["@mozilla.org/observer-service;1"]
62 .getService(SpecialPowers.Ci.nsIObserverService);
63 os.notifyObservers(null, "memory-pressure", "low-memory");
64 ok(true, 'Successfully notified observers.');
65 });
66 });
67
68 // This test isn't the only possible source of a low-memory notification; the
69 // browser can fire one whenever it likes. So it's fine if we lose the
70 // WebGL context before we fire the low-memory notification ourself.
71
72 var p = expectMozbrowserEvent(iframe, 'showmodalprompt').then(function(e) {
73 is(e.detail.message, 'webglcontextlost');
74 });
75
76 iframe.setVisible(false);
77 return p;
78 }).then(finishOnce);
79
80 document.body.appendChild(iframe);
81 }
82
83 addEventListener('testready', function() {
84 // At the time this test was written, webgl was blocklisted inside child
85 // processes on desktop Linux. The issue is that we spawn a child process to
86 // read driver info, but we only did this on the main prrocess. Child
87 // processes never read the driver info themselves, nor do they get it from
88 // their parent, so they refuse to start up WebGL.
89 //
90 // This isn't a problem on B2G because we force WebGL on there. But it
91 // obviously makes this test difficult. bjacob says forcing WebGL on here
92 // shouldn't hurt things, and anyway this setting mirrors what we do on B2G,
93 // which is what we're trying to test!
94 SpecialPowers.pushPrefEnv({set: [["webgl.force-enabled", true]]},
95 runTest);
96 });
97
98 </script>
99 </body>
100 </html>

mercurial