summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/webgl-mochitest/ensure-exts/ensure-ext.js
blob: 8d710139f357ee46cd0f66fdf615e3ca9496cff2 (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
'use strict';

function EnsureExt(extName, shouldHave=true) {
    EnsureExtFor('webgl', extName, shouldHave);
    EnsureExtFor('webgl2', extName, shouldHave);
}

function EnsureExtFor(contextType, extName, shouldHave=true) {
    var c = document.createElement('canvas');
    var gl = c.getContext(contextType);

    if (!gl) {
        todo(false, 'Failed to create context: ' + contextType);
        return;
    }

    var ext = gl.getExtension(extName);
    var haveText = ' have ' + contextType + ' extension ' + extName + '.';
    if (shouldHave) {
        ok(ext, 'Should' + haveText);
    } else {
        ok(!ext, 'Should not' + haveText);
    }
}

function Lastly_WithDraftExtsEnabled(func) {
    SimpleTest.waitForExplicitFinish();

    var fnEnsure = function() {
        func();
        SimpleTest.finish();
    };

    if ('SpecialPowers' in window) {
        var prefStateList = [
            ['webgl.enable-draft-extensions', true],
        ];
        var prefEnv = {'set': prefStateList};
        SpecialPowers.pushPrefEnv(prefEnv, fnEnsure);
    } else {
        console.log('Couldn\'t use SpecialPowers to enable draft extensions.');
        fnEnsure();
    }
}