From a0f93ea87995036e8300f58fe6645fdb2ef66574 Mon Sep 17 00:00:00 2001 From: Andrew Datsenko Date: Tue, 5 Aug 2025 12:06:14 -0700 Subject: [PATCH] Add tests for crossOrigin (#53045) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/53045 Changelog: [Internal] Add tests for cross origin headers. Reviewed By: rubennorte Differential Revision: D79562333 fbshipit-source-id: ff8705b4e59c89bc48be29767bbdefbba9328534 --- .../Libraries/Image/__tests__/Image-itest.js | 88 ++++++++++++++----- 1 file changed, 67 insertions(+), 21 deletions(-) diff --git a/packages/react-native/Libraries/Image/__tests__/Image-itest.js b/packages/react-native/Libraries/Image/__tests__/Image-itest.js index 308fae655f8..d946941d444 100644 --- a/packages/react-native/Libraries/Image/__tests__/Image-itest.js +++ b/packages/react-native/Libraries/Image/__tests__/Image-itest.js @@ -19,31 +19,31 @@ import {Image} from 'react-native'; import ensureInstance from 'react-native/src/private/__tests__/utilities/ensureInstance'; import ReactNativeElement from 'react-native/src/private/webapis/dom/nodes/ReactNativeElement'; +const LOGO_SOURCE = {uri: 'https://reactnative.dev/img/tiny_logo.png'}; + describe('', () => { describe('props', () => { - it('renders an empty element when there are no props', () => { - const root = Fantom.createRoot(); + describe('empty props', () => { + // TODO T233552213: do not send empty source + it('renders an empty element when there are no props', () => { + const root = Fantom.createRoot(); - Fantom.runTask(() => { - root.render(); + Fantom.runTask(() => { + root.render(); + }); + + expect(root.getRenderedOutput().toJSX()).toEqual( + , + ); + + Fantom.runTask(() => { + root.render(); + }); + + expect(root.getRenderedOutput().toJSX()).toEqual( + , + ); }); - - expect( - root.getRenderedOutput({includeLayoutMetrics: true}).toJSX(), - ).toEqual( - , - ); }); describe('accessibility', () => { @@ -123,6 +123,52 @@ describe('', () => { ); }); }); + + describe('crossOrigin', () => { + it('does not set any headers in anonymous mode', () => { + const root = Fantom.createRoot(); + + Fantom.runTask(() => { + root.render(); + }); + + expect(root.getRenderedOutput({props: ['source']}).toJSX()).toEqual( + , + ); + + Fantom.runTask(() => { + root.render(); + }); + + expect(root.getRenderedOutput({props: ['source']}).toJSX()).toEqual( + , + ); + }); + + it('sets the "Access-Control-Allow-Credentials" header in "use-credentials" mode', () => { + const root = Fantom.createRoot(); + + Fantom.runTask(() => { + root.render( + , + ); + }); + + expect( + root.getRenderedOutput({props: ['source-header']}).toJSX(), + ).toEqual( + , + ); + }); + }); }); describe('ref', () => {