Auto merge of #15821 - montrivo:ImDataConstructors, r=Ms2ger

Implement ImageData constructors #15671 -- 1

<!-- Please describe your changes on the following line: -->
Implement ImageData constructors
* new constructors in the imagedata.rs file
* modification of the ImageData::new method
* new method ImageData::from_vec
* new wpt test file imagedata.html

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes affect #15671  (github issue number if applicable).

<!-- Either: -->
- [X] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/15821)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-03-15 02:23:48 -07:00 committed by GitHub
commit 5bfa87a8e2
7 changed files with 156 additions and 19 deletions

View file

@ -0,0 +1,4 @@
[2d.imageData.object.ctor.html]
type: testharness
[ImageData does not have a usable constructor]
expected: FAIL

View file

@ -92591,6 +92591,12 @@
{}
]
],
"html/semantics/embedded-content/the-canvas-element/imagedata.html": [
[
"/html/semantics/embedded-content/the-canvas-element/imagedata.html",
{}
]
],
"html/semantics/embedded-content/the-canvas-element/initial.colour.html": [
[
"/html/semantics/embedded-content/the-canvas-element/initial.colour.html",
@ -175580,6 +175586,10 @@
"38b6f3c5707b360427854b82054d86f5364dc0b8",
"testharness"
],
"html/semantics/embedded-content/the-canvas-element/imagedata.html": [
"e685ab0d76bdd1b60a5d6f1e2126ea1a89db97d1",
"testharness"
],
"html/semantics/embedded-content/the-canvas-element/initial.colour.html": [
"22ddb77f5a18a19edc409d36532120f852bfbc57",
"testharness"

View file

@ -4116,9 +4116,6 @@
[TextMetrics interface: attribute ideographicBaseline]
expected: FAIL
[ImageData interface object length]
expected: FAIL
[DrawingStyle interface: existence and properties of interface object]
expected: FAIL

View file

@ -1,8 +1,5 @@
[interfaces.worker.html]
type: testharness
[ImageData interface object length]
expected: FAIL
[Path2D interface: existence and properties of interface object]
expected: FAIL

View file

@ -0,0 +1,58 @@
<!doctype html>
<meta charset="utf-8">
<title>ImageData Tests</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
test(function() {
assert_throws("IndexSizeError", function() {
new ImageData(0, 1);
});
}, "ImageData(w, h), width cannot be 0");
test(function() {
assert_throws("IndexSizeError", function() {
new ImageData(1, 0);
});
}, "ImageData(w, h), height cannot be 0");
test(function() {
var imageData = new ImageData(2, 3);
assert_equals(imageData.width, 2);
assert_equals(imageData.height, 3);
assert_equals(imageData.data.length, 24);
assert_true(imageData.data instanceof Uint8ClampedArray);
}, "ImageData(w, h), exposed attributes check");
test(function() {
assert_throws("InvalidStateError", function() {
new ImageData(new Uint8ClampedArray(3), 1);
});
}, "ImageData(buffer, w), the buffer size must be a multiple of 4");
test(function() {
assert_throws("IndexSizeError", function() {
new ImageData(new Uint8ClampedArray(16), 3);
});
}, "ImageData(buffer, w), buffer size must be a multiple of the image width");
test(function() {
assert_throws("IndexSizeError", function() {
new ImageData(new Uint8ClampedArray(16), 4, 3);
});
}, "ImageData(buffer, w, h), buffer.lenght == 4 * w * h must be true");
test(function() {
assert_throws(new TypeError(), function() {
new ImageData(new Int8Array(1), 1);
});
}, "ImageData(buffer, w, opt h), Uint8ClampedArray argument type check");
test(function() {
var imageData = new ImageData(new Uint8ClampedArray(24), 2);
assert_equals(imageData.width, 2);
assert_equals(imageData.height, 3);
assert_equals(imageData.data.length, 24);
assert_true(imageData.data instanceof Uint8ClampedArray);
}, "ImageData(buffer, w, opt h), exposed attributes check");
</script>