Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

test(photos):strengthen-raw-header-checks-and-remove-comments

Aswin Asok6761b64735e5
diff --git a/web/apps/photos/tests/raw-formats.test.ts b/web/apps/photos/tests/raw-formats.test.ts
index 41e89d0fd7..a270da6b6e 100644
--- a/web/apps/photos/tests/raw-formats.test.ts
+++ b/web/apps/photos/tests/raw-formats.test.ts
@@ -9,19 +9,14 @@ vi.mock("ente-base/log", () => ({
}));
vi.mock("ente-media/heic-convert", () => ({ heicToJPEG: vi.fn() }));
-// Keep this change scoped to the five selected camera RAW formats.
const rawExtensions = ["raf", "orf", "pef", "nrw", "srw"];
-// Intentionally unrecognized bytes exercise the filename fallback, not decoding.
const unknownBytes = new Uint8Array([0, 1, 2, 3]);
-// A minimal TIFF with an empty IFD. RAW files sharing this signature retain the
-// detected TIFF type; the native converter also needs their original filename.
const tiffBytes = new Uint8Array([
0x49, 0x49, 0x2a, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
]);
-// These recognizable headers exercise file-type rather than filename fallback.
const rawHeaders = [
{
extension: "orf",
@@ -41,8 +36,6 @@ describe("camera RAW format support", () => {
extension,
});
- // ML fallback and browser editing/casting checks use the filename
- // extension, independently of content-based type detection.
expect(needsJPEGConversion(extension.toUpperCase())).toBe(true);
const jpeg = new Blob(["converted"], { type: "image/jpeg" });
@@ -61,7 +54,7 @@ describe("camera RAW format support", () => {
test.each(rawHeaders)(
"converts content-detected $extension files",
async ({ extension, bytes }) => {
- const file = new File([bytes], `photo.${extension}`);
+ const file = new File([bytes], "photo.bin");
expect(await detectFileTypeInfo(file)).toMatchObject({ extension });
const jpeg = new Blob(["converted"], { type: "image/jpeg" });
const convertToJPEG = vi.fn().mockResolvedValue(jpeg);
diff --git a/web/packages/media/formats.ts b/web/packages/media/formats.ts
index 4633adfe10..872f05aaf7 100644
--- a/web/packages/media/formats.ts
+++ b/web/packages/media/formats.ts
@@ -1,6 +1,6 @@
-// Image extensions that browsers are unlikely to render, for which the desktop
-// app should attempt native JPEG conversion. RAW support depends on the
-// platform decoder and camera model.
+// Image extensions that the browser is unlikely to be able to render, but
+// which our desktop app should be able to convert to JPEG. Both conditions
+// must hold for an extension to be in this list.
const needsJPEGConversionExtensions = [
"arw",
"cr2",