using System; using System.Collections; using UnityEngine; namespace UnityEditor.TestTools.TestRunner.TestRun.Tasks { internal class PerformUndoTask : TestTaskBase { private const double warningThreshold = 1000; internal Action RevertAllDownToGroup = Undo.RevertAllDownToGroup; internal Action LogWarning = Debug.LogWarning; internal Action DisplayProgressBar = EditorUtility.DisplayProgressBar; internal Action ClearProgressBar = EditorUtility.ClearProgressBar; internal Func TimeNow = () => DateTime.Now; public override IEnumerator Execute(TestJobData testJobData) { if (testJobData.undoGroup < 0) { yield break; } DisplayProgressBar("Undo", "Reverting changes to the scene", 0); var undoStartTime = TimeNow(); RevertAllDownToGroup(testJobData.undoGroup); var timeDelta = TimeNow() - undoStartTime; if (timeDelta.TotalMilliseconds >= warningThreshold) { LogWarning($"Undo after editor test run took {timeDelta.Seconds} second{(timeDelta.Seconds == 1 ? "" : "s")}."); } ClearProgressBar(); } } }