tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

getContextAttributes.html (4290B)


      1 <!DOCTYPE html>
      2 <!-- This test should be kept in sync with the element version of this test (so long as the element
      3 offscreen context attribute APIs remain identical). -->
      4 <script src="/resources/testharness.js"></script>
      5 <script src="/resources/testharnessreport.js"></script>
      6 
      7 <script>
      8 
      9 var testScenarios = [
     10    // defaults
     11    {testDescription: "Test default offscreen context creation attributes",
     12        canvasContextAttributes: {},
     13        expectedContextAttributes: {
     14            alpha: true,
     15            desynchronized: false,
     16            willReadFrequently: false,
     17            colorSpace: "srgb",
     18            colorType:"unorm8"}},
     19    // alpha
     20    {testDescription: "Test offscreen context creation attributes alpha: true",
     21        canvasContextAttributes: {alpha: true},
     22        expectedContextAttributes: {alpha: true}},
     23    {testDescription: "Test offscreen context creation attributes alpha: false",
     24        canvasContextAttributes: {alpha: false},
     25        expectedContextAttributes: {alpha: false}},
     26    // colorSpace
     27    {testDescription: "Test offscreen context creation attributes colorSpace: 'srgb'",
     28        canvasContextAttributes: {colorSpace: "srgb"},
     29        expectedContextAttributes: {colorSpace: "srgb"}},
     30    {testDescription: "Test offscreen context creation attributes colorSpace: 'display-p3'",
     31        canvasContextAttributes: {colorSpace: "display-p3"},
     32        expectedContextAttributes: {colorSpace: "display-p3"}},
     33    // desynchronized
     34    {testDescription: "Test offscreen context creation attributes desynchronized: true",
     35        canvasContextAttributes: {desynchronized: true},
     36        expectedContextAttributes: {desynchronized: true}},
     37    {testDescription: "Test offscreen context creation attributes desynchronized: false",
     38        canvasContextAttributes: {desynchronized: false},
     39        expectedContextAttributes: {desynchronized: false}},
     40    // willReadFrequently
     41    {testDescription: "Test offscreen context creation attributes willReadFrequently: true",
     42        canvasContextAttributes: {willReadFrequently: true},
     43        expectedContextAttributes: {willReadFrequently: true}},
     44    {testDescription: "Test offscreen context creation attributes willReadFrequently: false",
     45        canvasContextAttributes: {willReadFrequently: false},
     46        expectedContextAttributes: {willReadFrequently: false}},
     47    // colorType
     48    {testDescription: "Test context creation attributes colorType: unorm8",
     49        canvasContextAttributes: {colorType: "unorm8"},
     50        expectedContextAttributes: {colorType: "unorm8"}},
     51    {testDescription: "Test context creation attributes colorType: float16",
     52        canvasContextAttributes: {colorType: "float16"},
     53        expectedContextAttributes: {colorType: "float16"}},
     54 ];
     55 
     56 function runTestScenario(canvas, testScenario) {
     57    var t = test(function() {
     58        var ctx = canvas.getContext('2d', testScenario.canvasContextAttributes);
     59        var contextAttributes = ctx.getContextAttributes();
     60        if (testScenario.expectedContextAttributes.alpha !== undefined) {
     61            assert_equals(contextAttributes.alpha,
     62                testScenario.expectedContextAttributes.alpha);
     63        }
     64        if (testScenario.expectedContextAttributes.colorSpace !== undefined) {
     65            assert_equals(contextAttributes.colorSpace,
     66                testScenario.expectedContextAttributes.colorSpace);
     67        }
     68        if (testScenario.expectedContextAttributes.desynchronized !== undefined) {
     69            assert_equals(contextAttributes.desynchronized,
     70                testScenario.expectedContextAttributes.desynchronized);
     71        }
     72        if (testScenario.expectedContextAttributes.willReadFrequently !== undefined) {
     73            assert_equals(contextAttributes.willReadFrequently,
     74                testScenario.expectedContextAttributes.willReadFrequently);
     75        }
     76        if (testScenario.expectedContextAttributes.colorType !== undefined) {
     77            assert_equals(contextAttributes.colorType,
     78                testScenario.expectedContextAttributes.colorType);
     79        }
     80    }, testScenario.testDescription);
     81 }
     82 
     83 function runAllTests() {
     84    for (var i = 0; i < testScenarios.length; i++) {
     85        runTestScenario(new OffscreenCanvas(100, 100), testScenarios[i]);
     86    }
     87 }
     88 
     89 runAllTests();
     90 </script>