2022-06-17 11:03:29 +00:00
|
|
|
/*
|
|
|
|
Copyright 2022 The Matrix.org Foundation C.I.C.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2023-02-13 11:39:16 +00:00
|
|
|
import React, { ComponentProps } from "react";
|
|
|
|
import { IContent, MatrixEvent } from "matrix-js-sdk/src/matrix";
|
2022-12-12 11:24:14 +00:00
|
|
|
import { render, RenderResult } from "@testing-library/react";
|
2022-06-17 11:03:29 +00:00
|
|
|
|
|
|
|
import MatrixClientContext from "../../../../src/contexts/MatrixClientContext";
|
|
|
|
import { RoomPermalinkCreator } from "../../../../src/utils/permalinks/Permalinks";
|
|
|
|
import { MediaEventHelper } from "../../../../src/utils/MediaEventHelper";
|
2022-12-12 11:24:14 +00:00
|
|
|
import { getMockClientWithEventEmitter } from "../../../test-utils";
|
|
|
|
import MVideoBody from "../../../../src/components/views/messages/MVideoBody";
|
2022-06-17 11:03:29 +00:00
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
jest.mock("../../../../src/customisations/Media", () => {
|
|
|
|
return {
|
|
|
|
mediaFromContent: () => {
|
|
|
|
return { isEncrypted: false };
|
|
|
|
},
|
|
|
|
};
|
|
|
|
});
|
2022-06-17 11:03:29 +00:00
|
|
|
|
|
|
|
describe("MVideoBody", () => {
|
2022-12-12 11:24:14 +00:00
|
|
|
it("does not crash when given a portrait image", () => {
|
2022-06-17 11:03:29 +00:00
|
|
|
// Check for an unreliable crash caused by a fractional-sized
|
|
|
|
// image dimension being used for a CanvasImageData.
|
2022-11-18 09:16:11 +00:00
|
|
|
const { asFragment } = makeMVideoBody(720, 1280);
|
|
|
|
expect(asFragment()).toMatchSnapshot();
|
2022-06-17 11:03:29 +00:00
|
|
|
// If we get here, we did not crash.
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-11-18 09:16:11 +00:00
|
|
|
function makeMVideoBody(w: number, h: number): RenderResult {
|
2023-02-13 11:39:16 +00:00
|
|
|
const content: IContent = {
|
2022-06-17 11:03:29 +00:00
|
|
|
info: {
|
|
|
|
"w": w,
|
|
|
|
"h": h,
|
|
|
|
"mimetype": "video/mp4",
|
|
|
|
"size": 2495675,
|
|
|
|
"thumbnail_file": {
|
|
|
|
url: "",
|
|
|
|
key: { alg: "", key_ops: [], kty: "", k: "", ext: true },
|
|
|
|
iv: "",
|
|
|
|
hashes: {},
|
|
|
|
v: "",
|
|
|
|
},
|
|
|
|
"thumbnail_info": { mimetype: "" },
|
|
|
|
"xyz.amorgan.blurhash": "TrGl6bofof~paxWC?bj[oL%2fPj]",
|
|
|
|
},
|
|
|
|
url: "http://example.com",
|
|
|
|
};
|
|
|
|
|
|
|
|
const event = new MatrixEvent({
|
|
|
|
content,
|
|
|
|
});
|
|
|
|
|
2023-02-13 11:39:16 +00:00
|
|
|
const defaultProps: ComponentProps<typeof MVideoBody> = {
|
2022-06-17 11:03:29 +00:00
|
|
|
mxEvent: event,
|
|
|
|
highlights: [],
|
2022-12-12 11:24:14 +00:00
|
|
|
highlightLink: "",
|
2022-06-17 11:03:29 +00:00
|
|
|
onHeightChanged: jest.fn(),
|
|
|
|
onMessageAllowed: jest.fn(),
|
|
|
|
permalinkCreator: {} as RoomPermalinkCreator,
|
|
|
|
mediaEventHelper: { media: { isEncrypted: false } } as MediaEventHelper,
|
|
|
|
};
|
|
|
|
|
|
|
|
const mockClient = getMockClientWithEventEmitter({
|
|
|
|
mxcUrlToHttp: jest.fn(),
|
|
|
|
});
|
|
|
|
|
2022-11-18 09:16:11 +00:00
|
|
|
return render(
|
|
|
|
<MatrixClientContext.Provider value={mockClient}>
|
|
|
|
<MVideoBody {...defaultProps} />
|
|
|
|
</MatrixClientContext.Provider>,
|
|
|
|
);
|
2022-06-17 11:03:29 +00:00
|
|
|
}
|