Add pref to force WebGL context creation failure

The pref `webgl.testing.context_creation_error` will cause creation of a new WebGLRenderingContext to fail, iff set to true.
Also update test expectation of `context_creation_error.html` to pass.
This commit is contained in:
Benjamin Dahse 2017-06-06 19:18:40 +02:00
parent 2da8eb0342
commit c034d99880
5 changed files with 10 additions and 8 deletions

View file

@ -51,6 +51,7 @@ use net_traits::image::base::PixelFormat;
use net_traits::image_cache::ImageResponse;
use offscreen_gl_context::{GLContextAttributes, GLLimits};
use script_traits::ScriptMsg as ConstellationMsg;
use servo_config::prefs::PREFS;
use std::cell::Cell;
use std::collections::HashMap;
use webrender_traits;
@ -166,6 +167,10 @@ impl WebGLRenderingContext {
size: Size2D<i32>,
attrs: GLContextAttributes)
-> Result<WebGLRenderingContext, String> {
if let Some(true) = PREFS.get("webgl.testing.context_creation_error").as_boolean() {
return Err("WebGL context creation error forced by pref `webgl.testing.context_creation_error`".into());
}
let (sender, receiver) = ipc::channel().unwrap();
let constellation_chan = window.upcast::<GlobalScope>().constellation_chan();
constellation_chan.send(ConstellationMsg::CreateWebGLPaintThread(size, attrs, sender))

View file

@ -66,5 +66,6 @@
"shell.homepage": "https://servo.org",
"shell.keep_screen_on.enabled": false,
"shell.native-orientation": "both",
"shell.native-titlebar.enabled": true
"shell.native-titlebar.enabled": true,
"webgl.testing.context_creation_error": false
}

View file

@ -31668,7 +31668,7 @@
"support"
],
"mozilla/webgl/context_creation_error.html": [
"d6ffc0c4ea5671399d3c9b6440608b47c80699cf",
"583df4d3fb090862383338a50548b4afb333dd52",
"testharness"
],
"mozilla/webgl/draw_arrays_simple.html": [

View file

@ -1,5 +1,3 @@
[context_creation_error.html]
type: reftest
[WebGLContextEvent "webglcontextcreationerror" event]
expected: FAIL
prefs: ["webgl.testing.context_creation_error:true"]

View file

@ -14,9 +14,7 @@ async_test(function() {
"'statusMessage' should be a string, " + typeof(e.statusMessage) + " found");
}), false);
// TODO: Create a dummy function to fail the webgl context forcefully from js tests.
// Now that antialias doesn't throw an error, there isn't a way to force context creation errors.
var gl = canvas.getContext('webgl', { antialiasing: true });
var gl = canvas.getContext('webgl');
assert_false(!!gl, "WebGLContext creation succeeded, please update this test!");
});