Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #library('InstanceOfTest'); | 1 #library('InstanceOfTest'); |
| 2 #import('../../pkg/unittest/unittest.dart'); | 2 #import('../../pkg/unittest/unittest.dart'); |
| 3 #import('../../pkg/unittest/html_config.dart'); | 3 #import('../../pkg/unittest/html_config.dart'); |
| 4 #import('dart:html'); | 4 #import('dart:html'); |
| 5 | 5 |
| 6 main() { | 6 main() { |
| 7 CanvasElement canvas; | 7 CanvasElement canvas; |
| 8 | 8 |
| 9 canvas = new Element.tag('canvas'); | 9 canvas = new Element.tag('canvas'); |
| 10 canvas.attributes['width'] = 100; | 10 canvas.attributes['width'] = 100; |
| 11 canvas.attributes['height'] = 100; | 11 canvas.attributes['height'] = 100; |
| 12 document.body.nodes.add(canvas); | 12 document.body.nodes.add(canvas); |
| 13 | 13 |
| 14 var isCanvasRenderingContext = | |
| 15 new isInstanceOf<CanvasRenderingContext>('CanvasRenderingContext'); | |
| 16 var isCanvasRenderingContext2D = | |
| 17 new isInstanceOf<CanvasRenderingContext2D>('CanvasRenderingContext2D'); | |
| 18 var isElement = new isInstanceOf<Element>('Element'); | |
| 19 var isCanvasElement = new isInstanceOf<CanvasElement>('CanvasElement'); | |
| 20 var isImageData = new isInstanceOf<ImageData>('ImageData'); | |
| 21 //var isCanvasPixelArray = | |
| 22 // new isInstanceOf<CanvasPixelArray>('CanvasPixelArray'); | |
| 23 var isUint8ClampedArray = | |
| 24 new isInstanceOf<Uint8ClampedArray>('Uint8ClampedArray'); | |
| 25 | |
| 26 // TODO(gram): A number of tests here have a commenteded out version that | |
| 27 // uses the matchers above. As dart2js returns true for is/is! regardless | |
|
Siggi Cherem (dart-lang)
2012/10/26 00:44:51
that's what I was worried about. then below: wont
gram
2012/10/26 22:26:27
Yes, for now, these will always pass in dart2js. I
| |
| 28 // of arguments these don't work if they use isNot. For now those are | |
| 29 // written in a different way but should ultimately be replaced by the | |
| 30 // commented-out versions. These have been marked with //* to distinguish | |
| 31 // from tests that were already commented out. | |
| 14 useHtmlConfiguration(); | 32 useHtmlConfiguration(); |
| 15 test('Instanceof', () { | 33 test('Instanceof', () { |
| 16 Expect.isFalse(canvas is CanvasRenderingContext); | 34 //* expect(canvas, isNot(isCanvasRenderingContext)); |
| 17 Expect.isFalse(canvas is CanvasRenderingContext2D); | 35 expect(canvas is! CanvasRenderingContext, isTrue); |
| 18 Expect.isTrue(canvas is Element); | 36 //* expect(canvas, isNot(isCanvasRenderingContext2D)); |
| 19 Expect.isTrue(canvas is CanvasElement); | 37 expect(canvas is! CanvasRenderingContext2D, isTrue); |
| 20 Expect.isFalse(canvas is ImageData); | 38 expect(canvas, isElement); |
| 21 // Expect.isFalse(canvas is CanvasPixelArray); | 39 expect(canvas, isCanvasElement); |
| 40 //* expect(canvas, isNot(isImageData)); | |
| 41 expect(canvas is! ImageData, isTrue); | |
| 42 // expect(canvas, isNot(isCanvasPixelArray)); | |
| 22 | 43 |
| 23 CanvasRenderingContext2D context = canvas.getContext('2d'); | 44 CanvasRenderingContext2D context = canvas.getContext('2d'); |
| 24 Expect.isTrue(context is CanvasRenderingContext); | 45 expect(context, isCanvasRenderingContext); |
| 25 Expect.isTrue(context is CanvasRenderingContext2D); | 46 expect(context, isCanvasRenderingContext2D); |
| 26 Expect.isFalse(context is Element); | 47 //* expect(context, isNot(isElement)); |
| 27 Expect.isFalse(context is CanvasElement); | 48 expect(context is! Element, isTrue); |
| 28 Expect.isFalse(context is ImageData); | 49 //* expect(context, isNot(isCanvasElement)); |
| 29 // Expect.isFalse(context is CanvasPixelArray); | 50 expect(context is! CanvasElement, isTrue); |
| 51 //* expect(context, isNot(isImageData)); | |
| 52 expect(context is! ImageData, isTrue); | |
| 53 // expect(context, isNot(isCanvasPixelArray)); | |
| 30 | 54 |
| 31 // FIXME(b/5286633): Interface injection type check workaround. | 55 // FIXME(b/5286633): Interface injection type check workaround. |
| 32 var image = context.createImageData(canvas.width as Dynamic, | 56 var image = context.createImageData(canvas.width as Dynamic, |
| 33 canvas.height as Dynamic); | 57 canvas.height as Dynamic); |
| 34 Expect.isFalse(image is CanvasRenderingContext); | 58 //* expect(image, isNot(isCanvasRenderingContext)); |
| 35 Expect.isFalse(image is CanvasRenderingContext2D); | 59 expect(image is! CanvasRenderingContext, isTrue); |
| 36 Expect.isFalse(image is Element); | 60 //* expect(image, isNot(isCanvasRenderingContext2D)); |
| 37 Expect.isFalse(image is CanvasElement); | 61 expect(image is! CanvasRenderingContext2D, isTrue); |
| 38 Expect.isTrue(image is ImageData); | 62 //* expect(image, isNot(isElement)); |
| 39 // Expect.isFalse(image is CanvasPixelArray); | 63 expect(image is! Element, isTrue); |
| 64 //* expect(image, isNot(isCanvasElement)); | |
| 65 expect(image is! CanvasElement, isTrue); | |
| 66 expect(image, isImageData); | |
| 67 // expect(image, isNot(isCanvasPixelArray)); | |
| 40 | 68 |
| 41 // Include CanvasPixelArray since constructor and prototype are not | 69 // Include CanvasPixelArray since constructor and prototype are not |
| 42 // available until one is created. | 70 // available until one is created. |
| 43 var bytes = image.data; | 71 var bytes = image.data; |
| 44 Expect.isFalse(bytes is CanvasRenderingContext); | 72 //* expect(bytes, isNot(isCanvasRenderingContext)); |
| 45 Expect.isFalse(bytes is CanvasRenderingContext2D); | 73 expect(bytes is! CanvasRenderingContext, isTrue); |
| 46 Expect.isFalse(bytes is Element); | 74 //* expect(bytes, isNot(isCanvasRenderingContext2D)); |
| 47 Expect.isFalse(bytes is CanvasElement); | 75 expect(bytes is! CanvasRenderingContext2D, isTrue); |
| 48 Expect.isFalse(bytes is ImageData); | 76 //* expect(bytes, isNot(isElement)); |
| 49 Expect.isTrue(bytes is Uint8ClampedArray); | 77 expect(bytes is! Element, isTrue); |
| 78 //* expect(bytes, isNot(isCanvasElement)); | |
| 79 expect(bytes is! CanvasElement, isTrue); | |
| 80 //* expect(bytes, isNot(isImageData)); | |
| 81 expect(bytes is! ImageData, isTrue); | |
| 82 expect(bytes, isUint8ClampedArray); | |
| 50 | 83 |
| 51 // FIXME: Ensure this is an SpanElement when we next update | 84 // FIXME: Ensure this is an SpanElement when we next update |
| 52 // WebKit IDL. | 85 // WebKit IDL. |
| 53 var span = new Element.tag('span'); | 86 var span = new Element.tag('span'); |
| 54 Expect.isTrue(span is Element); | 87 expect(span, isElement); |
| 55 }); | 88 }); |
| 56 } | 89 } |
| OLD | NEW |