using NUnit.Framework;
using UnityEngine;
using UnityEngine.UI;
namespace jeanf.universalplayer.tests
{
///
/// While the XR display keeps running, the engine treats every game camera as a
/// stereo camera: its target is the eye texture and its viewport the eye size, so a
/// flat HDRP render lands stretched in the Game view with a strip of the other eye.
/// The presenter takes the camera off the eye texture (a window-sized render
/// texture is never XR) and shows it through a screen-space overlay, which the
/// engine draws on the window itself.
///
public class FlatViewPresenterTests
{
private GameObject _root;
private Camera _camera;
private FlatViewPresenter _presenter;
[SetUp]
public void SetUp()
{
_root = new GameObject("FlatViewPresenterTest");
_camera = new GameObject("Camera").AddComponent();
_camera.transform.SetParent(_root.transform);
_camera.enabled = false;
_presenter = _root.AddComponent();
}
[TearDown]
public void TearDown()
{
Object.DestroyImmediate(_root);
}
[Test]
public void Begin_RendersTheCameraIntoAWindowSizedTexture()
{
_presenter.Begin(_camera);
Assert.That(_presenter.IsPresenting, Is.True);
Assert.That(_camera.targetTexture, Is.SameAs(_presenter.Target),
"The flat camera must render off the XR eye texture, into the presenter's own target.");
Assert.That(new Vector2Int(_presenter.Target.width, _presenter.Target.height), Is.EqualTo(FlatViewPresenter.WindowSize),
"The target must be the window size so the flat picture keeps the window's aspect.");
}
[Test]
public void Begin_ShowsTheTextureThroughAnOverlayThatNeverBlocksUi()
{
_presenter.Begin(_camera);
var canvas = _root.GetComponentInChildren