Skip to content

Add debugNetworkImageHttpClientProvider - #32857

Merged
tvolkert merged 4 commits into
flutter:masterfrom
tvolkert:testing
May 20, 2019
Merged

tvolkert merged 4 commits into
flutter:masterfrom
tvolkert:testing

Conversation

@tvolkert

Copy link
Copy Markdown
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.

#32374
@tvolkert
tvolkert requested a review from goderbauer May 17, 2019 00:32
@tvolkert

Copy link
Copy Markdown
Contributor Author

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

@tp

tp commented May 17, 2019

Copy link
Copy Markdown

@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
Copy Markdown
Contributor Author

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

@jonahwilliams

Copy link
Copy Markdown
Contributor

You can provide a specific HttpClient using HttpOverrides

@tvolkert

Copy link
Copy Markdown
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
@tvolkert tvolkert mentioned this pull request May 18, 2019
8 of 9 tasks
Comment thread packages/flutter/lib/src/painting/debug.dart Outdated
Comment thread packages/flutter/lib/src/painting/image_provider.dart Outdated
Comment thread packages/flutter/lib/src/painting/image_provider.dart Outdated
Comment thread packages/flutter/lib/src/painting/debug.dart Outdated
@goderbauer

Copy link
Copy Markdown
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.

@goderbauer goderbauer left a comment

Copy link
Copy Markdown
Member

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
@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.

6 participants