@@ -1711,7 +1711,8 @@ void main() {
1711
1711
});
1712
1712
group ('cameraFrameStream' , () {
1713
1713
testWidgets (
1714
- 'bytes is a multiple of 4' ,
1714
+ 'CameraImageData bytes is a multiple of 4 '
1715
+ 'when browser supports OffscreenCanvas' ,
1715
1716
(WidgetTester tester) async {
1716
1717
final VideoElement videoElement = getVideoElementWithBlankStream (
1717
1718
const Size (10 , 10 ),
@@ -1722,18 +1723,72 @@ void main() {
1722
1723
cameraService: cameraService,
1723
1724
)..videoElement = videoElement;
1724
1725
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
+
1725
1780
when (
1726
1781
() => cameraService.takeFrame (videoElement),
1727
1782
).thenAnswer (
1728
1783
(_) => CameraImageData (
1729
1784
format: const CameraImageFormat (
1730
- ImageFormatGroup .jpeg ,
1731
- raw: '' ,
1785
+ ImageFormatGroup .unknown ,
1786
+ raw: 0 ,
1732
1787
),
1733
1788
planes: < CameraImagePlane > [
1734
1789
CameraImagePlane (
1735
1790
bytes: Uint8List (32 ),
1736
- bytesPerRow: 0 ,
1791
+ bytesPerRow: videoElement.width * 4 ,
1737
1792
),
1738
1793
],
1739
1794
height: 10 ,
@@ -1754,7 +1809,6 @@ void main() {
1754
1809
),
1755
1810
);
1756
1811
},
1757
- timeout: const Timeout (Duration (seconds: 2 )),
1758
1812
);
1759
1813
});
1760
1814
});
0 commit comments