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

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

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

mercurial