OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library web_gl_test; | |
6 import 'package:unittest/unittest.dart'; | |
7 import 'package:unittest/html_individual_config.dart'; | |
8 import 'dart:html'; | 5 import 'dart:html'; |
9 import 'dart:typed_data'; | 6 import 'dart:typed_data'; |
10 import 'dart:web_gl'; | 7 import 'dart:web_gl'; |
11 import 'dart:web_gl' as gl; | 8 import 'dart:web_gl' as gl; |
12 | 9 |
| 10 import 'package:expect/minitest.dart'; |
| 11 |
13 // Test that WebGL is present in dart:web_gl API | 12 // Test that WebGL is present in dart:web_gl API |
14 | 13 |
| 14 final isRenderingContext = predicate((x) => x is RenderingContext); |
| 15 final isContextAttributes = predicate((x) => x is gl.ContextAttributes); |
| 16 |
15 main() { | 17 main() { |
16 useHtmlIndividualConfiguration(); | |
17 | |
18 group('supported', () { | 18 group('supported', () { |
19 test('supported', () { | 19 test('supported', () { |
20 expect(RenderingContext.supported, isTrue); | 20 expect(RenderingContext.supported, isTrue); |
21 }); | 21 }); |
22 }); | 22 }); |
23 | 23 |
24 group('functional', () { | 24 group('functional', () { |
25 test('unsupported fails', () { | 25 test('unsupported fails', () { |
26 var canvas = new CanvasElement(); | 26 var canvas = new CanvasElement(); |
27 var context = canvas.getContext3d(); | 27 var context = canvas.getContext3d(); |
28 if (RenderingContext.supported) { | 28 if (RenderingContext.supported) { |
29 expect(context, isNotNull); | 29 expect(context, isNotNull); |
30 expect(context, new isInstanceOf<RenderingContext>()); | 30 expect(context, isRenderingContext); |
31 } else { | 31 } else { |
32 expect(context, isNull); | 32 expect(context, isNull); |
33 } | 33 } |
34 }); | 34 }); |
35 | 35 |
36 if (RenderingContext.supported) { | 36 if (RenderingContext.supported) { |
37 test('simple', () { | 37 test('simple', () { |
38 var canvas = new CanvasElement(); | 38 var canvas = new CanvasElement(); |
39 var context = canvas.getContext('experimental-webgl'); | 39 var context = |
| 40 canvas.getContext('experimental-webgl') as gl.RenderingContext; |
40 var shader = context.createShader(gl.VERTEX_SHADER); | 41 var shader = context.createShader(gl.VERTEX_SHADER); |
41 context.shaderSource(shader, 'void main() { }'); | 42 context.shaderSource(shader, 'void main() { }'); |
42 context.compileShader(shader); | 43 context.compileShader(shader); |
43 var success = context.getShaderParameter(shader, gl.COMPILE_STATUS); | 44 var success = context.getShaderParameter(shader, gl.COMPILE_STATUS); |
44 expect(success, isTrue); | 45 expect(success, isTrue); |
45 }); | 46 }); |
46 | 47 |
47 test('getContext3d', () { | 48 test('getContext3d', () { |
48 var canvas = new CanvasElement(); | 49 var canvas = new CanvasElement(); |
49 var context = canvas.getContext3d(); | 50 var context = canvas.getContext3d(); |
50 expect(context, isNotNull); | 51 expect(context, isNotNull); |
51 expect(context, new isInstanceOf<RenderingContext>()); | 52 expect(context, isRenderingContext); |
52 | 53 |
53 context = canvas.getContext3d(depth: false); | 54 context = canvas.getContext3d(depth: false); |
54 expect(context, isNotNull); | 55 expect(context, isNotNull); |
55 expect(context, new isInstanceOf<RenderingContext>()); | 56 expect(context, isRenderingContext); |
56 }); | 57 }); |
57 | 58 |
58 test('texImage2D', () { | 59 test('texImage2D', () { |
59 var canvas = new CanvasElement(); | 60 var canvas = new CanvasElement(); |
60 var context = canvas.getContext3d(); | 61 var context = canvas.getContext3d(); |
61 var pixels = new Uint8List.fromList([0,0,3,255,0,0,0,0,0,0]); | 62 var pixels = new Uint8List.fromList([0,0,3,255,0,0,0,0,0,0]); |
62 context.texImage2DUntyped(1, 1, 1, 1, 10, 10, 1, 1, pixels); | 63 context.texImage2DUntyped(1, 1, 1, 1, 10, 10, 1, 1, pixels); |
63 | 64 |
64 canvas = new CanvasElement(); | 65 canvas = new CanvasElement(); |
65 document.body.children.add(canvas); | 66 document.body.children.add(canvas); |
(...skipping 22 matching lines...) Expand all Loading... |
88 context.texSubImage2DCanvas(1, 1, 1, 1, 1, 10, new CanvasElement()); | 89 context.texSubImage2DCanvas(1, 1, 1, 1, 1, 10, new CanvasElement()); |
89 context.texSubImage2DVideo(1, 1, 1, 1, 1, 10, new VideoElement()); | 90 context.texSubImage2DVideo(1, 1, 1, 1, 1, 10, new VideoElement()); |
90 }); | 91 }); |
91 | 92 |
92 test('getContextAttributes', () { | 93 test('getContextAttributes', () { |
93 var canvas = new CanvasElement(); | 94 var canvas = new CanvasElement(); |
94 var context = canvas.getContext3d(); | 95 var context = canvas.getContext3d(); |
95 var attributes = context.getContextAttributes(); | 96 var attributes = context.getContextAttributes(); |
96 | 97 |
97 expect(attributes, isNotNull); | 98 expect(attributes, isNotNull); |
98 expect(attributes, new isInstanceOf<gl.ContextAttributes>()); | 99 expect(attributes, isContextAttributes); |
99 | 100 |
100 expect(attributes.alpha, isBoolean); | 101 expect(attributes.alpha, isBoolean); |
101 expect(attributes.antialias, isBoolean); | 102 expect(attributes.antialias, isBoolean); |
102 expect(attributes.depth, isBoolean); | 103 expect(attributes.depth, isBoolean); |
103 expect(attributes.premultipliedAlpha, isBoolean); | 104 expect(attributes.premultipliedAlpha, isBoolean); |
104 expect(attributes.preserveDrawingBuffer, isBoolean); | 105 expect(attributes.preserveDrawingBuffer, isBoolean); |
105 expect(attributes.stencil, isBoolean); | 106 expect(attributes.stencil, isBoolean); |
106 }); | 107 }); |
107 } | 108 } |
108 }); | 109 }); |
109 } | 110 } |
110 | 111 |
111 Matcher isBoolean = anyOf(isTrue, isFalse); | 112 Matcher isBoolean = anyOf(isTrue, isFalse); |
OLD | NEW |