Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add debugNetworkImageHttpClientProvider #32857

Merged
merged 4 commits into from May 20, 2019
Merged

Conversation

tvolkert
Copy link
Contributor

Description

Currently, the fact that NetworkImage uses a static HttpClient
makes it impossible to properly test, as a mock in one test will
be reused in another test. This change fixes that.

Related Issues

#32374

Tests

This change is about preparing for tests that will land in a follow-on
PR - existing tests were restructured in this PR, but no new tests were added
(yet).

Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I signed the [CLA].
  • I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement].
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

  • Yes, this is a breaking change (Please read [Handling breaking changes]). Replace this with a link to the e-mail where you asked for input on this proposed change.
  • No, this is not a breaking change.

Currently, the fact that NetworkImage uses a static HttpClient
makes it impossible to properly test, as a mock in one test will
be reused in another test. This change fixes that.

flutter#32374
@tvolkert
Copy link
Contributor Author

This change depends on #32853, since otherwise we'd receive compressed bytes after consolidation.

@tp
Copy link

tp commented May 17, 2019

@tvolkert Is there a chance to extend this provide a specific HttpClient just for the NetworkImage?

In our testing we have a "record" mode (with --update-goldens) where we'd like to have most API calls go through and have images mocked with a placeholder.

With the approach introduces here, we'd still have to write a rather smart HTTP client mock that in recording mode returns fallback images for some requests (from NetworkImage) and allows others to pass through, and then in non-update mode forbids all outgoing requests but returns the fallback data again for the images.

@tvolkert
Copy link
Contributor Author

@tp yep that makes sense. I'll update this PR shortly.

@jonahwilliams
Copy link
Member

You can provide a specific HttpClient using HttpOverrides

@tvolkert
Copy link
Contributor Author

@jonahwilliams yes, but allowing debug builds direct access to the creation of the client does simplify things a lot (including the tests).

@tvolkert tvolkert changed the title Add debugNetworkImageUseFreshHttpClient Add debugNetworkImageHttpClientProvider May 17, 2019
@Piinks Piinks added a: images Loading, displaying, rendering images framework flutter/packages/flutter repository. See also f: labels. labels May 17, 2019
packages/flutter/lib/src/painting/debug.dart Outdated Show resolved Hide resolved
packages/flutter/lib/src/painting/image_provider.dart Outdated Show resolved Hide resolved
packages/flutter/lib/src/painting/image_provider.dart Outdated Show resolved Hide resolved
packages/flutter/lib/src/painting/debug.dart Outdated Show resolved Hide resolved
@goderbauer
Copy link
Member

no new tests were added (yet).

You could add a test to verify that NetworkImage actually uses the HttpClient from debugNetworkImageHttpClientProvider if it is set.

Copy link
Member

@goderbauer goderbauer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@tvolkert tvolkert merged commit 2b15b24 into flutter:master May 20, 2019
@tvolkert tvolkert deleted the testing branch May 20, 2019 23:33
kiku-jw pushed a commit to kiku-jw/flutter that referenced this pull request Jun 14, 2019
Currently, the fact that NetworkImage uses a static HttpClient
makes it impossible to properly test, as a mock in one test will
be reused in another test. This change fixes that.

flutter#32374
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a: images Loading, displaying, rendering images framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants