Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions Tests/Editor/PlayModeMutationGateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ public void ShouldGateManualTypeLoadWhileSuspendedForPlayMode()
DataVisualizerWindow window = ScriptableObject.CreateInstance<DataVisualizerWindow>();
cleanup.Defer(() => UnityEngine.Object.DestroyImmediate(window));

CreateFixtureAsset(folder, "First.asset");
ScriptableObject fixtureAsset = CreateFixtureAsset(folder, "First.asset");

SuspendForPlayMode(window);
InvokePrivate(window, "LoadObjectTypesAsync", typeof(TestDataObject), false);
Expand All @@ -319,10 +319,15 @@ public void ShouldGateManualTypeLoadWhileSuspendedForPlayMode()

ResumeFromPlayMode(window);
InvokePrivate(window, "LoadObjectTypesAsync", typeof(TestDataObject), false);
Assert.AreEqual(
1,
ReadPrivateField<List<ScriptableObject>>(window, "_selectedObjects").Count,
"the same manual type load after resume must load the type's objects"
while (ReadPrivateField<bool>(window, "_isLoadingObjectsAsync"))
{
InvokePrivate(window, "ContinueLoadingObjects", typeof(TestDataObject), ReadPrivateField<int>(window, "_asyncLoadGeneration"));
}

CollectionAssert.Contains(
ReadPrivateField<List<ScriptableObject>>(window, "_selectedObjects"),
fixtureAsset,
"the same manual type load after resume must load the fixture even when other assets exist"
);
}
}
Expand Down
1 change: 0 additions & 1 deletion Tests/Editor/PlayModeSuspensionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ public void ShouldStopPumpingWhileSuspendedAndCompleteOnResume()
Assert.IsTrue(index.IsComplete);

string[] guids = index.GetKnownGuids(typeof(TestDataObject));
Assert.AreEqual(3, guids.Length);
CollectionAssert.Contains(guids, firstGuid);
CollectionAssert.Contains(guids, secondGuid);
CollectionAssert.Contains(guids, thirdGuid);
Expand Down
31 changes: 25 additions & 6 deletions Tests/Editor/SavedSelectionNormalizationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,15 @@ private static DataVisualizerWindow CreateWindow(TestCleanupScope cleanup, out D
return window;
}

private static void LoadWithoutAutoSelection(DataVisualizerWindow window)
{
/*
Continue a load so automatic first-object selection cannot replace the stale
GUID before the normalization pump is tested in a populated host.
*/
InvokePrivate(window, "LoadObjectTypesAsync", typeof(TestDataObject), true);
}

private static string ReadSavedSelection(DataVisualizerWindow window, string typeFullName)
{
return (string)InvokePrivate(window, "GetLastSelectedObjectGuidForType", typeFullName);
Expand Down Expand Up @@ -134,16 +143,17 @@ public void ShouldKeepSavedSelectionWhenLoadRunsWhileAssetDatabaseIsBusy()
string typeFullName = typeof(TestDataObject).FullName;
WriteSavedSelection(window, typeFullName, "stale-saved-guid");

InvokePrivate(window, "LoadObjectTypesAsync", typeof(TestDataObject), false);
LoadWithoutAutoSelection(window);

Assert.AreEqual("stale-saved-guid", ReadSavedSelection(window, typeFullName), "a busy-window load must keep the persisted saved selection");
CollectionAssert.Contains(ReadPrivateField<HashSet<Type>>(window, "_pendingSavedSelectionNormalizationTypes"), typeof(TestDataObject));
Assert.That(ReadPrivateField<IVisualElementScheduledItem>(window, "_savedSelectionNormalizationTask") != null, "a queued normalization must schedule the pump");
}
}

[Test]
public void ShouldClearInvalidSavedSelectionAfterAssetDatabaseSettles()
[TestCase(false)]
[TestCase(true)]
public void ShouldNormalizeLatestSavedSelectionAfterAssetDatabaseSettles(bool replaceSelection)
{
string folder = CreateFixtureFolder();
object previousInstance = ReadSharedInstance();
Expand All @@ -164,13 +174,22 @@ public void ShouldClearInvalidSavedSelectionAfterAssetDatabaseSettles()

bool isBusy = true;
AssetGuidDiscovery.AssetDatabaseBusyOverride = () => isBusy;
InvokePrivate(window, "LoadObjectTypesAsync", typeof(TestDataObject), false);
LoadWithoutAutoSelection(window);
Assert.AreEqual("stale-saved-guid", ReadSavedSelection(window, typeFullName), "a busy-window load must keep the persisted saved selection");

string assetPath = folder + "/Replacement.asset";
AssetDatabase.CreateAsset(ScriptableObject.CreateInstance<TestDataObject>(), assetPath);
AssetDatabase.SaveAssets();
string replacementGuid = AssetDatabase.AssetPathToGUID(assetPath);
if (replaceSelection)
{
WriteSavedSelection(window, typeFullName, replacementGuid);
}

isBusy = false;
InvokePrivate(window, "ProcessSavedSelectionNormalizations");

Assert.That(ReadSavedSelection(window, typeFullName) == null, "an invalid saved selection must be cleared once the AssetDatabase settles");
Assert.AreEqual(replaceSelection ? replacementGuid : null, ReadSavedSelection(window, typeFullName), "normalize the latest selection, not the deferred snapshot");
Assert.IsEmpty(ReadPrivateField<HashSet<Type>>(window, "_pendingSavedSelectionNormalizationTypes"));
}
}
Expand Down Expand Up @@ -236,7 +255,7 @@ public void ShouldResumeSavedSelectionNormalizationAfterPlayMode()

bool isBusy = true;
AssetGuidDiscovery.AssetDatabaseBusyOverride = () => isBusy;
InvokePrivate(window, "LoadObjectTypesAsync", typeof(TestDataObject), false);
LoadWithoutAutoSelection(window);

SuspendForPlayMode(window);
Assert.That(ReadPrivateField<IVisualElementScheduledItem>(window, "_savedSelectionNormalizationTask") == null, "suspending for play mode must stop the pump");
Expand Down
Loading