Closed Bug 1016482 Opened 11 years ago Closed 6 years ago

2d.pattern.image.broken test seems to pass intermittently

Categories

(Core :: Graphics: Canvas2D, defect)

x86_64
Linux
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla75
Tracking Status
firefox75 --- fixed

People

(Reporter: jgraham, Assigned: bzbarsky)

Details

Attachments

(2 files)

To reproduce you may need to check out the web-platform-tests locally, and run the server, as described in the README.md file [1]. When run locally http://web-platform.test:8000/2dcontext/fill-and-stroke-styles/2d.pattern.image.broken.html seems to flip between passing and failing. When run on w3c-test.org this doesn't happen, presumably because of the increased latency. This suggests some kind of race condition in the loading code. (that also suggests that this might not be a canvas bug. But a good fix might be to make this test always pass, which might be possible without fixing the underlying race since, presumably, the image is always known to be broken when createPattern is called). [1] https://github.com/w3c/web-platform-tests

At this point, this test is just wrong. Per spec at https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-createpattern a unusable image means null is returned, which is what we do.

This appears to be the portion of the HTML Standard which is being relied on for the expectation for an exception being thrown re "Broken" https://html.spec.whatwg.org/multipage/images.html#img-error (see https://bugzilla.mozilla.org/show_bug.cgi?id=1614225)

However, Firefox throws no such error. null is returned.

    var img = new Image;
    img.src = "data:,";
    img.onerror = e => {
      console.log(e);
      const canvas = document.createElement("canvas");
      const ctx = canvas.getContext("2d");
      try {
        console.dir(ctx.createPattern(img, "repeat"));
      } catch (e) {
        console.error(e);
      }
    }

The same code at Chromium 81 does throw an exception

DOMException: Failed to execute 'createPattern' on 'CanvasRenderingContext2D': Source image is in the 'broken' state.
    at Image.img.onerror (<anonymous>:8:25)

The conclusion reached here is that

  • the image used in WPT is not "Broken" enough to throw an error at modern browsers, though does log this error (Fatal error reading PNG image file: IDAT: CRC error) at Ristretto Image Viewer at *nix.
  • Firefox returns null, then stops.
  • Chromium does not return null and throws the exception per "Broken" part of the specification.

meaning the browsers, Firefox and Chromium, respectively, have some parts of implementation correct, yet not all parts, and the implementations are not consistent at all, making testing if not difficult, a trial and error to compose a single test that outputs the expected result for each browser.

If there is any ambiguity in the specification as to which part is controlling, or if the "Broken" part of specification is controlling at all

https://bugzilla.mozilla.org/show_bug.cgi?id=1614225#c7

It does not seem clear to me on the definition of broken image as it applies to this testcase for reasons I outlined in comment 3 (https://bugzilla.mozilla.org/show_bug.cgi?id=1614225#c3).

perhaps now is a time that can adjust both the specification and the televant test.

Per spec, createPattern never throws InvalidStateError. It can return null if
the image is not usable (as here) or throw SyntaxError if the second arg is not
a recognized value, but that's it.

Assignee: nobody → bzbarsky
Status: NEW → ASSIGNED

(In reply to Boris Zbarsky [:bzbarsky, bz on IRC] from comment #1)

At this point, this test is just wrong. Per spec at https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-createpattern a unusable image means null is returned, which is what we do.

In fact, following the link from "checking the usability"

To check the usability of the image argument, where image is a CanvasImageSource object, run these steps:

Switch on image:

HTMLOrSVGImageElement
If image's current request's state is broken, then throw an "InvalidStateError" DOMException.

Firefox behaviour is not in conformance with the HTML Standard.

According to the processsing model at step 1. the InvalidStateError exception should be thrown before null is returned at step 2.

Searched for though did not locate this bug before filing https://bugzilla.mozilla.org/show_bug.cgi?id=1614225 which is probably a duplicate of this bug.

(In reply to Boris Zbarsky [:bzbarsky, bz on IRC] from comment #5)

Created attachment 9126974 [details]
Bug 1016482. Fix broken createPattern test.

Per spec, createPattern never throws InvalidStateError. It can return null if
the image is not usable (as here) or throw SyntaxError if the second arg is not
a recognized value, but that's it.

This

_assertSame(ctx.createPattern(img, 'repeat'), null, "ctx.createPattern(img, 'repeat')", "null");

is wrong per the specification section that you are referring to.

If image's current request's state is broken, then throw an "InvalidStateError" DOMException.

The change at https://phabricator.services.mozilla.com/D63030 for WPT test essentially is hiding the Firefox bug for handling usability of the image at https://html.spec.whatwg.org/multipage/canvas.html#check-the-usability-of-the-image-argument. Not a viable resolution to the bug or the test.

the image used in WPT is not "Broken" enough to throw an error at modern browsers

Ah, indeed. I was specifically talking about the image in question in this test, which does not lead to a "current request's state is broken" state, because the image has a valid header (including size information) and it's just the image data that's not decodable. So it falls into the "image is not fully decodable" case. See definitions of the states at https://html.spec.whatwg.org/multipage/images.html#img-req-state

So for this specific image, my test fix is correct. I will correct the commit message to make this clear.

For the 'data:,' case, I would have expected it to fall into the "broken" case. I'll take a look at that later, but it's not this bug, not this bug's testcase, and not a duplicate of this bug...

Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/21833 for changes under testing/web-platform/tests
Upstream web-platform-tests status checks passed, PR will merge once commit reaches central.

I'll take a look at that later, but it's not this bug, not this bug's testcase, and not a duplicate of this bug...

And to be clear, I reopened bug 1614225 to track that.

Status: ASSIGNED → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla75
Upstream PR merged by moz-wptsync-bot
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: