mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 04:16:51 +00:00
Make CanvasPixelArray pretent to be Uint8ClampedArray
Eventually CanvasPixelArray will go away. Review URL: https://chromiumcodereview.appspot.com//10207033 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@6922 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
parent
1fe42965f9
commit
a8f78a5273
|
@ -6,25 +6,19 @@
|
|||
dom/DOMIsolatesTest: Fail # error: cannot resolve spawnDomIsolate
|
||||
dom/RequestAnimationFrameTest: Skip # Async test hangs.
|
||||
html/RequestAnimationFrameTest: Skip # Async test hangs.
|
||||
dom/IndexedDB3Test: Fail # Uncaught TypeError: Object #<IDBCursorWithValue> has no method 'continueFunction'
|
||||
dom/IndexedDB4Test: Fail # Uncaught TypeError: Object #<IDBCursorWithValue> has no method 'continueFunction'
|
||||
dom/IsolatesTest: Skip # Timeout because leg does not support web workers.
|
||||
dom/TypedArrays1Test: Fail # dart2js doesn't support is checks with generic types.
|
||||
|
||||
[ $compiler == dart2js && $runtime == drt ]
|
||||
|
||||
# Unknown error - should investigate.
|
||||
html/html_tests: Fail
|
||||
|
||||
# DOM errors.
|
||||
dom/WindowOpenTest: Fail # TypeError: Object [object Window] has no method 'close$0'
|
||||
dom/HTMLElementTest: Fail # TypeError: Object #<HTMLDivElement> has no method 'get$dataset'
|
||||
|
||||
|
||||
# We don't support is checks with generic types.
|
||||
dom/TypedArrays1Test: Fail # Expect.isTrue(false) fails.
|
||||
|
||||
dom/IsolatesTest: Skip # Timeout because leg does not support web workers.
|
||||
|
||||
dom/IndexedDB2Test: Fail # Uncaught error
|
||||
dom/IndexedDB3Test: Fail # Uncaught TypeError: Object #<IDBCursorWithValue> has no method 'continueFunction'
|
||||
dom/IndexedDB4Test: Fail # Uncaught TypeError: Object #<IDBCursorWithValue> has no method 'continueFunction'
|
||||
|
||||
[ $compiler == dart2js && $runtime == none ]
|
||||
*: Fail, Pass # TODO(ahe): Triage these tests.
|
||||
|
|
|
@ -35,7 +35,6 @@ dom/WindowOpenTest: Fail
|
|||
|
||||
[ $runtime == dartium || $runtime == chrome || $runtime == ie || $runtime == safari || $runtime == ff || $runtime == opera ]
|
||||
dom/HistoryTest: Fail
|
||||
dom/InstanceOfTest: Skip # Temporary skipped due to recent changes in IDL.
|
||||
|
||||
[ $runtime == chrome || $runtime == ie || $runtime == safari || $runtime == ff || $runtime == opera ]
|
||||
dom/ImplementationTest: Fail
|
||||
|
|
62
client/tests/client/dom/CanvasPixelArrayTypeAliasTest.dart
Normal file
62
client/tests/client/dom/CanvasPixelArrayTypeAliasTest.dart
Normal file
|
@ -0,0 +1,62 @@
|
|||
#library('CanvasTest');
|
||||
#import('../../../../lib/unittest/unittest.dart');
|
||||
#import('../../../../lib/unittest/dom_config.dart');
|
||||
#import('dart:dom');
|
||||
|
||||
// We have aliased the legacy type CanvasPixelArray with the new type
|
||||
// Uint8ClampedArray by mapping the CanvasPixelArray type tag to
|
||||
// Uint8ClampedArray. It is not a perfect match since CanvasPixelArray is
|
||||
// missing the ArrayBufferView members. These should appear to be null.
|
||||
|
||||
Object confuseType(x) => [1, x, [x], 's'] [1]; // returns 'x'
|
||||
|
||||
main() {
|
||||
HTMLCanvasElement canvas;
|
||||
CanvasRenderingContext2D context;
|
||||
int width = 100;
|
||||
int height = 100;
|
||||
|
||||
canvas = document.createElement('canvas');
|
||||
canvas.setAttribute('width', '$width');
|
||||
canvas.setAttribute('height', '$height');
|
||||
document.body.appendChild(canvas);
|
||||
|
||||
context = canvas.getContext('2d');
|
||||
|
||||
useDomConfiguration();
|
||||
|
||||
test('CreateImageData', () {
|
||||
ImageData image = context.createImageData(canvas.width,
|
||||
canvas.height);
|
||||
Uint8ClampedArray data = image.data;
|
||||
// It is legal for the dart2js compiler to believe the type of the native
|
||||
// ImageData.data and elides the check, so check the type explicitly:
|
||||
Expect.isTrue(confuseType(data) is Uint8ClampedArray);
|
||||
|
||||
Expect.equals(40000, data.length);
|
||||
checkPixel(data, 0, [0, 0, 0, 0]);
|
||||
checkPixel(data, width * height - 1, [0, 0, 0, 0]);
|
||||
|
||||
data[100] = 200;
|
||||
Expect.equals(200, data[100]);
|
||||
});
|
||||
|
||||
test('PutImageData', () {
|
||||
ImageData data = context.getImageData(0, 0, width, height);
|
||||
data.data[0] = 25;
|
||||
data.data[3] = 255;
|
||||
context.putImageData(data, 0, 0);
|
||||
|
||||
data = context.getImageData(0, 0, width, height);
|
||||
Expect.equals(25, data.data[0]);
|
||||
Expect.equals(255, data.data[3]);
|
||||
});
|
||||
}
|
||||
|
||||
void checkPixel(Uint8ClampedArray data, int offset, List<int> rgba)
|
||||
{
|
||||
offset *= 4;
|
||||
for (var i = 0; i < 4; ++i) {
|
||||
Expect.equals(rgba[i], data[offset + i]);
|
||||
}
|
||||
}
|
62
client/tests/client/html/CanvasPixelArrayTypeAliasTest.dart
Normal file
62
client/tests/client/html/CanvasPixelArrayTypeAliasTest.dart
Normal file
|
@ -0,0 +1,62 @@
|
|||
#library('CanvasTest');
|
||||
#import('../../../../lib/unittest/unittest.dart');
|
||||
#import('../../../../lib/unittest/html_config.dart');
|
||||
#import('dart:html');
|
||||
|
||||
// We have aliased the legacy type CanvasPixelArray with the new type
|
||||
// Uint8ClampedArray by mapping the CanvasPixelArray type tag to
|
||||
// Uint8ClampedArray. It is not a perfect match since CanvasPixelArray is
|
||||
// missing the ArrayBufferView members. These should appear to be null.
|
||||
|
||||
Object confuseType(x) => [1, x, [x], 's'] [1];
|
||||
|
||||
main() {
|
||||
CanvasElement canvas;
|
||||
CanvasRenderingContext2D context;
|
||||
int width = 100;
|
||||
int height = 100;
|
||||
|
||||
canvas = new Element.tag('canvas');
|
||||
canvas.width = width;
|
||||
canvas.height = height;
|
||||
document.body.nodes.add(canvas);
|
||||
|
||||
context = canvas.getContext('2d');
|
||||
|
||||
useHtmlConfiguration();
|
||||
|
||||
test('CreateImageData', () {
|
||||
ImageData image = context.createImageData(canvas.width,
|
||||
canvas.height);
|
||||
Uint8ClampedArray data = image.data;
|
||||
// It is legal for the dart2js compiler to believe the type of the native
|
||||
// ImageData.data and elides the check, so check the type explicitly:
|
||||
Expect.isTrue(confuseType(data) is Uint8ClampedArray);
|
||||
|
||||
Expect.equals(40000, data.length);
|
||||
checkPixel(data, 0, [0, 0, 0, 0]);
|
||||
checkPixel(data, width * height - 1, [0, 0, 0, 0]);
|
||||
|
||||
data[100] = 200;
|
||||
Expect.equals(200, data[100]);
|
||||
});
|
||||
|
||||
test('PutImageData', () {
|
||||
ImageData data = context.getImageData(0, 0, width, height);
|
||||
data.data[0] = 25;
|
||||
data.data[3] = 255;
|
||||
context.putImageData(data, 0, 0);
|
||||
|
||||
data = context.getImageData(0, 0, width, height);
|
||||
Expect.equals(25, data.data[0]);
|
||||
Expect.equals(255, data.data[3]);
|
||||
});
|
||||
}
|
||||
|
||||
void checkPixel(Uint8ClampedArray data, int offset, List<int> rgba)
|
||||
{
|
||||
offset *= 4;
|
||||
for (var i = 0; i < 4; ++i) {
|
||||
Expect.equals(rgba[i], data[offset + i]);
|
||||
}
|
||||
}
|
|
@ -5,6 +5,7 @@
|
|||
String typeNameInChrome(obj) {
|
||||
String name = JS('String', "#.constructor.name", obj);
|
||||
if (name == 'Window') return 'DOMWindow';
|
||||
if (name == 'CanvasPixelArray') return 'Uint8ClampedArray';
|
||||
return name;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue