Skip to content

Test/web camera release review feedback - #1

Open
snodnipper wants to merge 3 commits into
apptreesoftware:fix/web-release-camera-tracksfrom
snodnipper:test/web-camera-release-review-feedback
Open

snodnipper wants to merge 3 commits into
apptreesoftware:fix/web-release-camera-tracksfrom
snodnipper:test/web-camera-release-review-feedback

Conversation

@snodnipper

Copy link
Copy Markdown

Follow-up to juliansteenbakker#1779, addressing @navaronbracke's nine review comments on the tests, plus one gap found in the start path while doing so.

Review feedback

  • The duplicated MediaStream helpers and start options move to test/web/utils/media_stream_test_utils.dart, shared by both web tests.
  • getUserMedia and BarcodeDetector are stubbed through extension type bindings instead of eval. Restoring uses delete, which exposes the native MediaDevices.prototype.getUserMedia again, or leaves BarcodeDetector absent on browsers that never had it (so isSupported() feature detection stays honest). createJSInteropWrapper doesn't fit here: it returns a plain object, never a constructor, so it cannot stand in for BarcodeDetector, and navigator.mediaDevices is a getter-only accessor, so a wrapper can't be assigned there. I verified that new on a .toJS function raises the Dart error under both dart2js and dart2wasm.
  • The dispose-during-start test now asserts directly that the disposed controller does not hold the camera session, through a @visibleForTesting platformSessionOwner getter next to the existing resetPlatformSessionOwner(). The behavioural check (the next controller's dispose reaches the platform) is kept. The unused stopCalls counter is gone.
  • The teardown expectations have reasons, and the stop-twice test asserts that the second stop() completes.
  • allLive / allEnded now fail on a stream with no tracks instead of passing vacuously.
  • awaitCall() no longer busy-waits. If getUserMedia is never called, it fails after 5s with a TestFailure instead of hanging until the runner's 30s timeout.

Start-path gap

start() awaits the reader's library load (a real script load for zxing-wasm) before calling getUserMedia, with no teardown check in between. A scanner stopped in that window still prompted for permission and briefly lit the camera before the post-acquire check released it. start() now checks the teardown generation immediately before acquiring the camera. A new test fails without the fix (getUserMedia is called once) and passes with it.

Verified

  • flutter test: 386 passed.
  • test/web/polling_barcode_reader_stop_test.dart and test/web/mobile_scanner_web_start_teardown_test.dart pass in Chrome under dart2js and --wasm.
  • Swapping develop's lib/ back in fails every new test.
  • test/web/web_library_versions_test.dart fails under --platform chrome on develop too (it reads package.json from disk). That failure is unrelated.

Related: juliansteenbakker#1778

Checklist

  • The PR title follows Conventional Commits (e.g. feat: ..., fix: ..., chore: ...) — this is required by CI and drives the automated changelog/release.
  • (Optional) Each individual commit also follows Conventional Commits — if so, we'll merge with a real merge commit to preserve your full history; otherwise we'll squash the PR into one commit.
  • Tests were added or updated, if applicable.
  • Documentation (README.md) was updated, if applicable.

- Move the duplicated MediaStream helpers and start options into
  test/web/utils/media_stream_test_utils.dart, shared by both web tests.
- Stub getUserMedia and BarcodeDetector through extension type bindings
  instead of eval().
- Assert the disposed controller does not hold the camera session, via a
  @VisibleForTesting platformSessionOwner getter, and drop the unused
  stopCalls counter.
- Add reasons to the stop() teardown expectations, and assert that a
  second PollingBarcodeReader.stop() completes without throwing.
- allLive/allEnded no longer pass vacuously on a stream without tracks.
awaitCall() busy-waited, so a start that never reached getUserMedia hung
until the runner's 30s timeout with no message. It now waits on a
completer and fails after 5s with a TestFailure naming the missing call.
start() awaits the reader's library load (a real script load for
zxing-wasm) before calling getUserMedia, with no teardown check between.
A scanner dismissed in that window still prompted for permission and
briefly lit the camera before the post-acquire check released it.

Check the teardown generation immediately before acquiring the camera,
and cover it with a test that fails when getUserMedia is reached.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant