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