Skip to content

Commit d7b7d5c

Browse files
committed
[camera_web] test: camera frame stream test cases for with and without OffscreenCanvas in camera test
1 parent a0cd373 commit d7b7d5c

File tree

1 file changed

+59
-5
lines changed

1 file changed

+59
-5
lines changed

packages/camera/camera_web/example/integration_test/camera_test.dart

Lines changed: 59 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1711,7 +1711,8 @@ void main() {
17111711
});
17121712
group('cameraFrameStream', () {
17131713
testWidgets(
1714-
'bytes is a multiple of 4',
1714+
'CameraImageData bytes is a multiple of 4 '
1715+
'when browser supports OffscreenCanvas',
17151716
(WidgetTester tester) async {
17161717
final VideoElement videoElement = getVideoElementWithBlankStream(
17171718
const Size(10, 10),
@@ -1722,18 +1723,72 @@ void main() {
17221723
cameraService: cameraService,
17231724
)..videoElement = videoElement;
17241725

1726+
when(() => cameraService.hasPropertyOffScreenCanvas()).thenReturn(
1727+
true,
1728+
);
1729+
1730+
when(
1731+
() => cameraService.takeFrame(videoElement),
1732+
).thenAnswer(
1733+
(_) => CameraImageData(
1734+
format: const CameraImageFormat(
1735+
ImageFormatGroup.unknown,
1736+
raw: 0,
1737+
),
1738+
planes: <CameraImagePlane>[
1739+
CameraImagePlane(
1740+
bytes: Uint8List(32),
1741+
bytesPerRow: videoElement.width * 4,
1742+
),
1743+
],
1744+
height: 10,
1745+
width: 10,
1746+
),
1747+
);
1748+
1749+
final CameraImageData cameraImageData =
1750+
await camera.cameraFrameStream().first;
1751+
expect(
1752+
cameraImageData,
1753+
equals(
1754+
isA<CameraImageData>().having(
1755+
(CameraImageData e) => e.planes.first.bytes.length % 4,
1756+
'bytes',
1757+
equals(0),
1758+
),
1759+
),
1760+
);
1761+
},
1762+
);
1763+
testWidgets(
1764+
'CameraImageData bytes is a multiple of 4 '
1765+
'when browser does not supports OffscreenCanvas',
1766+
(WidgetTester tester) async {
1767+
final VideoElement videoElement = getVideoElementWithBlankStream(
1768+
const Size(10, 10),
1769+
);
1770+
1771+
final Camera camera = Camera(
1772+
textureId: textureId,
1773+
cameraService: cameraService,
1774+
)..videoElement = videoElement;
1775+
1776+
when(() => cameraService.hasPropertyOffScreenCanvas()).thenReturn(
1777+
false,
1778+
);
1779+
17251780
when(
17261781
() => cameraService.takeFrame(videoElement),
17271782
).thenAnswer(
17281783
(_) => CameraImageData(
17291784
format: const CameraImageFormat(
1730-
ImageFormatGroup.jpeg,
1731-
raw: '',
1785+
ImageFormatGroup.unknown,
1786+
raw: 0,
17321787
),
17331788
planes: <CameraImagePlane>[
17341789
CameraImagePlane(
17351790
bytes: Uint8List(32),
1736-
bytesPerRow: 0,
1791+
bytesPerRow: videoElement.width * 4,
17371792
),
17381793
],
17391794
height: 10,
@@ -1754,7 +1809,6 @@ void main() {
17541809
),
17551810
);
17561811
},
1757-
timeout: const Timeout(Duration(seconds: 2)),
17581812
);
17591813
});
17601814
});

0 commit comments

Comments
 (0)