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

NetworkImage does not throw NetworkImageLoadException in widget tests on chrome platform #44370

Open
CaseyHillers opened this issue Nov 7, 2019 · 4 comments
Labels
a: error message Error messages from the Flutter framework a: tests "flutter test", flutter_test, or one of our tests engine flutter/engine repository. See also e: labels. found in release: 3.7 Found to occur in 3.7 found in release: 3.9 Found to occur in 3.9 has reproducible steps The issue has been confirmed reproducible and is ready to work on P2 Important issues not at the top of the work list platform-web Web applications specifically team-web Owned by Web platform team triaged-web Triaged by Web platform team

Comments

@CaseyHillers
Copy link
Contributor

Steps to Reproduce

  1. Pump a NetworkImage widget in a widget test
await tester.pumpWidget(NetworkImage(/* an image url */);
  1. An NetworkImageLoadException should be thrown (in the default test platform), but on the Chrome platform no exception is thrown.

Target Platform: Web
Target OS version/browser: Chrome
Devices:

Logs

Analyzing app_flutter...                                                

   info • Unused import: 'dart:ui' • lib/generated_plugin_registrant.dart:4:8 • unused_import

1 issue found. (ran in 2.0s)
[✓] Flutter (Channel master, v1.10.15-pre.378, on Linux, locale en_US.UTF-8)
    • Flutter version 1.10.15-pre.378 at /usr/local/google/home/chillers/flutter
    • Framework revision bf45897f13 (6 days ago), 2019-11-01 11:30:58 -0700
    • Engine revision 8ea19b1c76
    • Dart version 2.6.0 (build 2.6.0-dev.8.2 bbe2ac28c9)

 
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
    • Android SDK at /usr/local/google/home/chillers/Android/Sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-stable, build-tools 29.0.2
    • Java binary at: /opt/android-studio-with-blaze-3.4/jre/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b16-5323222)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at google-chrome

[!] Android Studio (version 3.4)
    • Android Studio at /opt/android-studio-with-blaze-3.4
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b16-5323222)

[✓] IntelliJ IDEA Ultimate Edition (version 2019.1)
    • IntelliJ at /opt/intellij-ue-2019.1
    • Flutter plugin version 39.0.2
    • Dart plugin version 191.8423

[✓] VS Code (version 1.39.2)
    • VS Code at /usr/share/code
    • Flutter extension version 3.6.0

[✓] Connected device (2 available)
    • Chrome     • chrome     • web-javascript • Google Chrome 78.0.3904.97
    • Web Server • web-server • web-javascript • Flutter Tools

! Doctor found issues in 1 category.
@CaseyHillers CaseyHillers added the platform-web Web applications specifically label Nov 7, 2019
@yjbanov yjbanov added this to the Near-term Goals milestone Nov 7, 2019
@yjbanov yjbanov added the engine flutter/engine repository. See also e: labels. label Nov 7, 2019
@CaseyHillers
Copy link
Contributor Author

I did a little digging into this. I think we need to have https://github.com/flutter/engine/blob/master/lib/web_ui/lib/src/engine/html_image_codec.dart#L46-L50 throw the exception. However, Chrome does not support for onerror on an image element.

@kf6gpe kf6gpe added the P1 High-priority issues at the top of the work list label May 29, 2020
@kf6gpe kf6gpe modified the milestone: Near-term Goals Jun 1, 2020
@yjbanov yjbanov added P2 Important issues not at the top of the work list and removed P1 High-priority issues at the top of the work list labels Jun 16, 2020
@kf6gpe kf6gpe modified the milestone: [DEPRECATED] Near-term Goals Jul 7, 2020
@kf6gpe kf6gpe removed this from the [DEPRECATED] Near-term Goals milestone Jul 22, 2020
@Hixie Hixie removed this from the None milestone Aug 17, 2020
@TahaTesser
Copy link
Member

I can reproduce the issue
When running the same test on android device and chrome, chrome doesn't throw any exception

code sample
// This is a basic Flutter widget test.
//
// To perform an interaction with a widget in your test, use the WidgetTester
// utility that Flutter provides. For example, you can send tap and scroll
// gestures. You can also use WidgetTester to find child widgets in the widget
// tree, read text, and verify that the values of widget properties are correct.

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

import 'package:master_flutter/main.dart';

void main() {
  testWidgets('Counter increments smoke test', (WidgetTester tester) async {
    // Build our app and trigger a frame.
    await tester.pumpWidget(Image.network('src'));

    // Verify that our counter starts at 0.
  });
}
tahatesser@Tahas-MacBook-Pro master_flutter % flutterm run -d chrome test/widget_test.dart
Launching test/widget_test.dart on Chrome in debug mode...
Waiting for connection from debug service on Chrome...             16.4s
Debug service listening on ws://127.0.0.1:51238/Wwcbg6wOaRA=/ws

Running with unsound null safety
For more information see https://dart.dev/null-safety/unsound-null-safety

Warning: Flutter's support for web development is not stable yet and hasn't
been thoroughly tested in production environments.
For more information see https://flutter.dev/web

🔥  To hot restart changes while running, press "r" or "R".
For a more detailed help message, press "h". To quit, press "q".
00:00 +0: Counter increments smoke test
00:00 +1: All tests passed!
flutter doctor -v
[✓] Flutter (Channel master, 1.25.0-5.0.pre.45, on macOS 11.0.1 20B29 darwin-x64, locale en-GB)
    • Flutter version 1.25.0-5.0.pre.45 at /Users/tahatesser/Code/flutter_master
    • Framework revision 81e1f7d1ed (11 hours ago), 2020-12-02 17:19:57 -0800
    • Engine revision 20caf54969
    • Dart version 2.12.0 (build 2.12.0-76.0.dev)

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
    • Android SDK at /Users/tahatesser/Code/sdk
    • Platform android-30, build-tools 30.0.2
    • ANDROID_HOME = /Users/tahatesser/Code/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 12.2)
    • Xcode at /Volumes/Extreme/Xcode.app/Contents/Developer
    • Xcode 12.2, Build version 12B45b
    • CocoaPods version 1.10.0

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 4.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)

[✓] VS Code (version 1.51.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.16.0

[✓] Connected device (5 available)
    • IN2011 (mobile)      • c9d8ee0c                  • android-arm64  • Android 11 (API 30)
    • Taha’s iPad (mobile) • 00008020-000255113EE8402E • ios            • iOS 14.2
    • macOS (desktop)      • macos                     • darwin-x64     • macOS 11.0.1 20B29 darwin-x64
    • Web Server (web)     • web-server                • web-javascript • Flutter Tools
    • Chrome (web)         • chrome                    • web-javascript • Google Chrome 87.0.4280.88

• No issues found!

@TahaTesser TahaTesser added found in release: 1.25 Found to occur in 1.25 has reproducible steps The issue has been confirmed reproducible and is ready to work on a: error message Error messages from the Flutter framework a: tests "flutter test", flutter_test, or one of our tests labels Dec 3, 2020
@technolion
Copy link

This seems to be similar or the same issue as #60239
Should these issues be merged?

@huycozy
Copy link
Member

huycozy commented Mar 16, 2023

I see there is a different exception when running tests on this issue, using sample code at #44370 (comment).

  • Unit test: NetworkImageLoadException
  • Integration test: ImageCodecException
flutter unit test output
══╡ EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE ╞════════════════════════════════════════════════════
The following NetworkImageLoadException was thrown resolving an image codec:
HTTP request failed, statusCode: 400,
file:///Users/huynq/Documents/NEVERCODE.IO/RepoduceProjects/reproduce_issues/src

When the exception was thrown, this was the stack:
#0      NetworkImage._loadAsync (package:flutter/src/painting/_network_image_io.dart:135:9)
<asynchronous suspension>
<asynchronous suspension>
(elided one frame from package:stack_trace)

Image provider: NetworkImage("src", scale: 1.0)
Image key: NetworkImage("src", scale: 1.0)
════════════════════════════════════════════════════════════════════════════════════════════════════
Warning: At least one test in this suite creates an HttpClient. When
running a test suite that uses TestWidgetsFlutterBinding, all HTTP
requests will return status code 400, and no network request will
actually be made. Any test expecting a real network connection and
status code will fail.
To test code that needs an HttpClient, provide your own HttpClient
implementation to the code under test, so that your test can
consistently provide a testable response to the code under test.

Test failed. See exception logs above.
The test description was: Counter increments smoke test
integration test output
➜  reproduce_issues flutterm drive --driver=test_driver/integration_test_driver.dart --target=integration_test/test_networkimage_44370.dart -d web-server
Resolving dependencies... (2.8s)
  async 2.10.0 (2.11.0 available)
  cached_network_image 3.2.1 (3.2.3 available)
  cached_network_image_platform_interface 1.0.0 (2.0.0 available)
  cached_network_image_web 1.0.1 (1.0.2 available)
  flutter_lints 1.0.4 (2.0.1 available)
  lints 1.0.1 (2.0.1 available)
  material_color_utilities 0.2.0 (0.3.0 available)
  win32 3.1.3 (4.1.1 available)
Got dependencies!
Launching integration_test/test_networkimage_44370.dart on Web Server in debug mode...
Waiting for connection from debug service on Web Server...         28.0s
integration_test/test_networkimage_44370.dart is being served at http://localhost:54620
The web-server device requires the Dart Debug Chrome extension for debugging. Consider using the Chrome or Edge devices for an improved development workflow.
Failure Details:
Failure in method: Counter increments smoke test
══╡ EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE ╞═════════════════
The following ImageCodecException was thrown resolving an image
codec:
Failed to detect image file format using the file header.
File header was [0x3c 0x21 0x44 0x4f 0x43 0x54 0x59 0x50 0x45
0x20].
Image source: encoded image bytes

When the exception was thrown, this was the stack:
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 288:49  throw_
lib/_engine/engine/canvaskit/image_web_codecs.dart 56:7                       create
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 84:54            runBody
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 123:5            _async
lib/_engine/engine/canvaskit/image_web_codecs.dart 41:46                      create
lib/_engine/engine/canvaskit/image.dart 14:34                                 skiaInstantiateImageCodec
lib/_engine/engine/canvaskit/renderer.dart 197:15                             instantiateImageCodec
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 84:54            runBody
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 123:5            _async
lib/_engine/engine/canvaskit/renderer.dart 192:41                             instantiateImageCodec
lib/ui/painting.dart 501:28                                                   instantiateImageCodecWithSize
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 84:54            runBody
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 123:5            _async
lib/ui/painting.dart 496:44                                                   instantiateImageCodecWithSize
packages/flutter/src/painting/binding.dart.js 86:17                           instantiateImageCodecWithSize
packages/flutter/src/painting/_network_image_web.dart.js 401:20               _loadAsync
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 45:50            <fn>
dart-sdk/lib/async/zone.dart 1406:47                                          _rootRunUnary
dart-sdk/lib/async/zone.dart 1307:19                                          runUnary
dart-sdk/lib/async/future_impl.dart 147:18                                    handleValue
dart-sdk/lib/async/future_impl.dart 784:44                                    handleValueCallback
dart-sdk/lib/async/future_impl.dart 813:13                                    _propagateToListeners
dart-sdk/lib/async/future_impl.dart 584:5                                     [_completeWithValue]
dart-sdk/lib/async/future_impl.dart 657:7                                     <fn>
dart-sdk/lib/async/zone.dart 1398:13                                          _rootRun
dart-sdk/lib/async/zone.dart 1300:19                                          run
dart-sdk/lib/async/zone.dart 1208:7                                           runGuarded
dart-sdk/lib/async/zone.dart 1248:23                                          callback
dart-sdk/lib/async/schedule_microtask.dart 40:11                              _microtaskLoop
dart-sdk/lib/async/schedule_microtask.dart 49:5                               _startMicrotaskLoop
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 177:15           <fn>

Image provider: NetworkImage("src", scale: 1)
Image key: NetworkImage("src", scale: 1)
═════════════════════════════════════════════════════════════════

end of failure 1



Application finished.
flutter doctor -v (stable and master)
[✓] Flutter (Channel stable, 3.7.7, on macOS 13.0.1 22A400 darwin-x64, locale en-EE)
    • Flutter version 3.7.7 on channel stable at /Users/huynq/Documents/GitHub/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 2ad6cd72c0 (10 hours ago), 2023-03-08 09:41:59 -0800
    • Engine revision 1837b5be5f
    • Dart version 2.19.4
    • DevTools version 2.20.1

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/huynq/Library/Android/sdk
    • Platform android-33, build-tools 31.0.0
    • ANDROID_HOME = /Users/huynq/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14B47b
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[!] Android Studio
    • Android Studio at /Applications/Android Studio Preview.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    ✗ Unable to find bundled Java version.
    • Try updating or re-installing Android Studio.

[✓] Android Studio (version 2022.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301)

[✓] IntelliJ IDEA Community Edition (version 2022.1.1)
    • IntelliJ at /Users/huynq/Library/Application Support/JetBrains/Toolbox/apps/IDEA-C/ch-0/221.5591.52/IntelliJ IDEA CE.app
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart

[✓] VS Code (version 1.76.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.60.0

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-x64     • macOS 13.0.1 22A400 darwin-x64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 110.0.5481.177

[✓] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 1 category.
[!] Flutter (Channel master, 3.9.0-8.0.pre.19, on macOS 13.0.1 22A400 darwin-x64, locale en-VN)
    • Flutter version 3.9.0-8.0.pre.19 on channel master at /Users/huynq/Documents/GitHub/flutter_master
    ! Warning: `flutter` on your path resolves to /Users/huynq/Documents/GitHub/flutter/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/huynq/Documents/GitHub/flutter_master. Consider adding /Users/huynq/Documents/GitHub/flutter_master/bin to the front of your path.
    ! Warning: `dart` on your path resolves to /Users/huynq/Documents/GitHub/flutter/bin/dart, which is not inside your current Flutter SDK checkout at /Users/huynq/Documents/GitHub/flutter_master. Consider adding /Users/huynq/Documents/GitHub/flutter_master/bin to the front of your path.
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision d043c93e1a (2 hours ago), 2023-03-15 21:44:10 -0400
    • Engine revision 903ea2eabc
    • Dart version 3.0.0 (build 3.0.0-322.0.dev)
    • DevTools version 2.22.2
    • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/huynq/Library/Android/sdk
    • Platform android-33, build-tools 31.0.0
    • ANDROID_HOME = /Users/huynq/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14B47b
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301)

[✓] IntelliJ IDEA Community Edition (version 2022.1.1)
    • IntelliJ at /Users/huynq/Library/Application Support/JetBrains/Toolbox/apps/IDEA-C/ch-0/221.5591.52/IntelliJ IDEA CE.app
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart

[✓] VS Code (version 1.76.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.60.0

[✓] Connected device (4 available)
    • SM T225 (mobile)       • R9JT3004VRJ                          • android-arm64  • Android 13 (API 33)
    • iPhone 14 Pro (mobile) • AB2EBB55-6852-40A7-9A12-057128370920 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-16-1 (simulator)
    • macOS (desktop)        • macos                                • darwin-x64     • macOS 13.0.1 22A400 darwin-x64
    • Chrome (web)           • chrome                               • web-javascript • Google Chrome 111.0.5563.64

[✓] Network resources
    • All expected network resources are available.

! Doctor found issues in 1 category.

Updating the label for further insights!

@huycozy huycozy added found in release: 3.7 Found to occur in 3.7 found in release: 3.9 Found to occur in 3.9 and removed found in release: 1.25 Found to occur in 1.25 labels Mar 16, 2023
@flutter-triage-bot flutter-triage-bot bot added multiteam-retriage-candidate team-web Owned by Web platform team triaged-web Triaged by Web platform team labels Jul 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a: error message Error messages from the Flutter framework a: tests "flutter test", flutter_test, or one of our tests engine flutter/engine repository. See also e: labels. found in release: 3.7 Found to occur in 3.7 found in release: 3.9 Found to occur in 3.9 has reproducible steps The issue has been confirmed reproducible and is ready to work on P2 Important issues not at the top of the work list platform-web Web applications specifically team-web Owned by Web platform team triaged-web Triaged by Web platform team
Projects
None yet
Development

No branches or pull requests

7 participants