This commit is contained in:
2025-01-17 13:10:42 +01:00
commit 4536213c91
15115 changed files with 1442174 additions and 0 deletions

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b5115ff20f1ea204dac14fa49c0e8f69
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,78 @@
using UnityEngine;
using UnityEditor.TestTools.CodeCoverage.Utils;
namespace UnityEditor.TestTools.CodeCoverage
{
internal class FolderDropDownMenu
{
GenericMenu m_Menu;
string m_Path;
string m_Message;
readonly CodeCoverageWindow m_Parent;
readonly FolderType m_FolderType;
static class Styles
{
public static readonly GUIContent ShowInExplorerLabel = EditorGUIUtility.TrTextContent("Open Containing Folder");
public static readonly GUIContent ChangeLocationLabel = EditorGUIUtility.TrTextContent("Change Location");
public static readonly GUIContent ResetToDefaultLabel = EditorGUIUtility.TrTextContent("Reset to Default Location");
}
public FolderDropDownMenu(CodeCoverageWindow parent, FolderType type)
{
m_Parent = parent;
m_FolderType = type;
}
private void PopulateMenu()
{
m_Menu = new GenericMenu();
m_Menu.AddItem(Styles.ShowInExplorerLabel, false, () => ShowInExplorer());
m_Menu.AddItem(Styles.ChangeLocationLabel, false, () => ChangeLocation());
if (m_Path.Equals(CoverageUtils.GetProjectPath()))
m_Menu.AddDisabledItem(Styles.ResetToDefaultLabel);
else
m_Menu.AddItem(Styles.ResetToDefaultLabel, false, () => ResetToDefault());
}
public void Show(Rect position, string folderPath, string message)
{
m_Path = folderPath;
m_Message = message;
PopulateMenu();
m_Menu.DropDown(position);
}
private void ShowInExplorer()
{
string path = m_FolderType == FolderType.Results ?
m_Parent.GetResultsRootFolder() :
m_Parent.GetReportHistoryFolder();
EditorUtility.RevealInFinder(path);
}
private void ChangeLocation()
{
string candidate = CoverageUtils.BrowseForDir(m_Path, m_Message);
if (m_FolderType == FolderType.Results)
m_Parent.SetCoverageLocation(candidate);
else
m_Parent.SetCoverageHistoryLocation(candidate);
m_Parent.LoseFocus();
}
private void ResetToDefault()
{
if (m_FolderType == FolderType.Results)
m_Parent.SetDefaultCoverageLocation();
else
m_Parent.SetDefaultCoverageHistoryLocation();
m_Parent.LoseFocus();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: efa0ff6842a348049864f8312e42ec4b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
namespace UnityEditor.TestTools.CodeCoverage
{
internal enum FolderType
{
Results = 0,
History = 1
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1f4b403c98301c44da49e4df4c5cb5b4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,90 @@
using UnityEngine;
using UnityEditor.IMGUI.Controls;
namespace UnityEditor.TestTools.CodeCoverage
{
class IncludedAssembliesPopupWindow : PopupWindowContent
{
readonly SearchField m_SearchField;
readonly IncludedAssembliesTreeView m_TreeView;
const float kWindowHeight = 221;
public float Width { get; set; }
static class Styles
{
public static readonly GUIContent SelectLabel = EditorGUIUtility.TrTextContent("Select:");
public static readonly GUIContent SelectAllButtonLabel = EditorGUIUtility.TrTextContent("All", "Click this to select and include all the assemblies in the project. This includes both the assemblies under the 'Assets' folder and packages.\n\nIf searching, it will apply only to the assemblies visible in the list.");
public static readonly GUIContent SelectAssetsButtonLabel = EditorGUIUtility.TrTextContent("Assets", "Click this to select and include only the assemblies under the 'Assets' folder.\n\nIf searching, it will apply only to the assemblies visible in the list.");
public static readonly GUIContent SelectPackagesButtonLabel = EditorGUIUtility.TrTextContent("Packages", "Click this to select and include only the Packages' assemblies.\n\nIf searching, it will apply only to the assemblies visible in the list.");
public static readonly GUIContent DeselectAllButtonLabel = EditorGUIUtility.TrTextContent("Deselect All", "Click this to deselect and exclude all the assemblies.\n\nIf searching, it will apply only to the assemblies visible in the list.");
}
public IncludedAssembliesPopupWindow(CodeCoverageWindow parent, string assembliesToInclude)
{
m_SearchField = new SearchField();
m_TreeView = new IncludedAssembliesTreeView(parent, assembliesToInclude);
}
public override void OnGUI(Rect rect)
{
const int border = 4;
const int topPadding = 12;
const int searchHeight = 20;
const int buttonHeight = 16;
const int remainTop = topPadding + searchHeight + buttonHeight + border + border;
float selectLabelWidth = EditorStyles.boldLabel.CalcSize(Styles.SelectLabel).x;
float selectAllWidth = EditorStyles.miniButton.CalcSize(Styles.SelectAllButtonLabel).x;
float selectAssetsWidth = EditorStyles.miniButton.CalcSize(Styles.SelectAssetsButtonLabel).x;
float selectPackagesWidth = EditorStyles.miniButton.CalcSize(Styles.SelectPackagesButtonLabel).x;
float deselectAllWidth = EditorStyles.miniButton.CalcSize(Styles.DeselectAllButtonLabel).x;
Rect searchRect = new Rect(border, topPadding, rect.width - border * 2, searchHeight);
Rect selectLabelRect = new Rect(border, topPadding + searchHeight + border, selectLabelWidth, searchHeight);
Rect selectAllRect = new Rect(border + selectLabelWidth + border, topPadding + searchHeight + border, selectAllWidth, buttonHeight);
Rect selectAssetsRect = new Rect(border + selectLabelWidth + border + selectAllWidth + border, topPadding + searchHeight + border, selectAssetsWidth, buttonHeight);
Rect selectPackagesRect = new Rect(border + selectLabelWidth + border + selectAllWidth + border + selectAssetsWidth + border, topPadding + searchHeight + border, selectPackagesWidth, buttonHeight);
Rect deselectAllRect = new Rect(rect.width - border - deselectAllWidth, topPadding + searchHeight + border, deselectAllWidth, buttonHeight);
Rect remainingRect = new Rect(border, remainTop, rect.width - border * 2, rect.height - remainTop - border);
m_TreeView.searchString = m_SearchField.OnGUI(searchRect, m_TreeView.searchString);
GUI.Label(selectLabelRect, Styles.SelectLabel, EditorStyles.boldLabel);
if (GUI.Button(selectAllRect, Styles.SelectAllButtonLabel, EditorStyles.miniButton))
{
m_TreeView.SelectAll();
}
if (GUI.Button(deselectAllRect, Styles.DeselectAllButtonLabel, EditorStyles.miniButton))
{
m_TreeView.DeselectAll();
}
if (GUI.Button(selectAssetsRect, Styles.SelectAssetsButtonLabel, EditorStyles.miniButton))
{
m_TreeView.SelectAssets();
}
if (GUI.Button(selectPackagesRect, Styles.SelectPackagesButtonLabel, EditorStyles.miniButton))
{
m_TreeView.SelectPackages();
}
m_TreeView.OnGUI(remainingRect);
}
public override Vector2 GetWindowSize()
{
return new Vector2(Mathf.Max(Width, m_TreeView.Width), kWindowHeight);
}
public override void OnOpen()
{
m_SearchField.SetFocus();
base.OnOpen();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b706bbc1f4c2d0c4d8c44630579b20cb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,184 @@
using UnityEditor.IMGUI.Controls;
using UnityEditor.Compilation;
using System.Text.RegularExpressions;
using System.Text;
using System.Linq;
using System;
using UnityEngine;
using UnityEditor.TestTools.CodeCoverage.Analytics;
namespace UnityEditor.TestTools.CodeCoverage
{
class IncludedAssembliesTreeView : TreeView
{
string m_AssembliesToInclude;
readonly CodeCoverageWindow m_Parent;
const float kCheckBoxWidth = 42f;
public float Width { get; set; } = 100f;
public IncludedAssembliesTreeView(CodeCoverageWindow parent, string assembliesToInclude)
: base(new TreeViewState())
{
m_AssembliesToInclude = assembliesToInclude;
m_Parent = parent;
showAlternatingRowBackgrounds = true;
showBorder = true;
Reload();
}
protected override bool CanMultiSelect(TreeViewItem item)
{
return false;
}
protected override TreeViewItem BuildRoot()
{
string[] includeAssemblyFilters = m_AssembliesToInclude.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
Regex[] includeAssemblies = includeAssemblyFilters
.Select(f => AssemblyFiltering.CreateFilterRegex(f))
.ToArray();
TreeViewItem root = new TreeViewItem(-1, -1);
bool developerMode = EditorPrefs.GetBool("DeveloperMode", false);
if (developerMode)
{
System.Reflection.Assembly[] assemblies = AssemblyFiltering.GetAllProjectAssembliesInternal();
int assembliesLength = assemblies.Length;
GUIContent textContent = new GUIContent();
for (int i = 0; i < assembliesLength; ++i)
{
System.Reflection.Assembly assembly = assemblies[i];
bool enabled = includeAssemblies.Any(f => f.IsMatch(assembly.GetName().Name.ToLowerInvariant()));
root.AddChild(new AssembliesTreeViewItem() { id = i + 1, displayName = assembly.GetName().Name, Enabled = enabled });
textContent.text = assembly.GetName().Name;
float itemWidth = TreeView.DefaultStyles.label.CalcSize(textContent).x + kCheckBoxWidth;
if (Width < itemWidth)
Width = itemWidth;
}
}
else
{
Assembly[] assemblies = AssemblyFiltering.GetAllProjectAssemblies();
int assembliesLength = assemblies.Length;
GUIContent textContent = new GUIContent();
for (int i = 0; i < assembliesLength; ++i)
{
Assembly assembly = assemblies[i];
bool enabled = includeAssemblies.Any(f => f.IsMatch(assembly.name.ToLowerInvariant()));
root.AddChild(new AssembliesTreeViewItem() { id = i + 1, displayName = assembly.name, Enabled = enabled });
textContent.text = assembly.name;
float itemWidth = TreeView.DefaultStyles.label.CalcSize(textContent).x + kCheckBoxWidth;
if (Width < itemWidth)
Width = itemWidth;
}
}
return root;
}
protected override void RowGUI(RowGUIArgs args)
{
AssembliesTreeViewItem item = args.item as AssembliesTreeViewItem;
EditorGUI.BeginChangeCheck();
bool enabled = EditorGUI.ToggleLeft(args.rowRect, args.label, item.Enabled);
if (EditorGUI.EndChangeCheck())
{
item.Enabled = enabled;
ApplyChanges();
}
}
public void SelectAll()
{
ToggleAll(true);
}
public void DeselectAll()
{
ToggleAll(false);
}
public void SelectAssets()
{
m_AssembliesToInclude = AssemblyFiltering.GetUserOnlyAssembliesString();
SelectFromString(m_AssembliesToInclude);
}
public void SelectPackages()
{
m_AssembliesToInclude = AssemblyFiltering.GetPackagesOnlyAssembliesString();
SelectFromString(m_AssembliesToInclude);
}
private void SelectFromString(string assembliesToInclude)
{
string[] includeAssemblyFilters = assembliesToInclude.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
Regex[] includeAssemblies = includeAssemblyFilters
.Select(f => AssemblyFiltering.CreateFilterRegex(f))
.ToArray();
foreach (var child in rootItem.children)
{
AssembliesTreeViewItem childItem = child as AssembliesTreeViewItem;
bool enabled = includeAssemblies.Any(f => f.IsMatch(childItem.displayName.ToLowerInvariant()));
if (searchString == null)
childItem.Enabled = enabled;
else if (DoesItemMatchSearch(child, searchString))
childItem.Enabled = enabled;
}
ApplyChanges();
}
private void ToggleAll(bool enabled)
{
foreach (var child in rootItem.children)
{
AssembliesTreeViewItem childItem = child as AssembliesTreeViewItem;
if (searchString == null)
childItem.Enabled = enabled;
else if (DoesItemMatchSearch(child, searchString))
childItem.Enabled = enabled;
}
ApplyChanges();
}
void ApplyChanges()
{
CoverageAnalytics.instance.CurrentCoverageEvent.updateAssembliesDialog = true;
StringBuilder sb = new StringBuilder();
foreach(var child in rootItem.children)
{
AssembliesTreeViewItem childItem = child as AssembliesTreeViewItem;
if (childItem.Enabled)
{
if (sb.Length > 0)
sb.Append(",");
sb.Append(childItem.displayName);
}
}
m_Parent.AssembliesToInclude = sb.ToString();
m_Parent.Repaint();
}
}
class AssembliesTreeViewItem : TreeViewItem
{
public bool Enabled { get; set; }
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c5a93638351266e418ccf0b46460a46e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
namespace UnityEditor.TestTools.CodeCoverage
{
internal enum PathFilterType
{
Include = 0,
Exclude = 1
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6e885c435119d8f4ebb060111a1fa3d8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,73 @@
using UnityEditor.TestTools.CodeCoverage.Analytics;
using UnityEngine;
namespace UnityEditor.TestTools.CodeCoverage
{
internal class PathToAddDropDownMenu
{
GenericMenu m_Menu;
string m_PathsToFilter;
readonly PathToAddHandler m_AddPathToIncludeHandler;
readonly PathToAddHandler m_AddPathToExcludeHandler;
readonly PathFilterType m_PathFilterType;
static class Styles
{
public static readonly GUIContent AddFolderLabel = EditorGUIUtility.TrTextContent("Add Folder");
public static readonly GUIContent AddFileLabel = EditorGUIUtility.TrTextContent("Add File");
}
public PathToAddDropDownMenu(CodeCoverageWindow parent, PathFilterType type)
{
m_PathFilterType = type;
m_AddPathToIncludeHandler = new PathToAddHandler(parent, PathFilterType.Include);
m_AddPathToExcludeHandler = new PathToAddHandler(parent, PathFilterType.Exclude);
}
private void PopulateMenu()
{
m_Menu = new GenericMenu();
m_Menu.AddItem(Styles.AddFolderLabel, false, () => AddFolder());
m_Menu.AddItem(Styles.AddFileLabel, false, () => AddFile());
}
public void Show(Rect position, string pathsToFilter)
{
m_PathsToFilter = pathsToFilter;
PopulateMenu();
m_Menu.DropDown(position);
}
private void AddFolder()
{
if (m_PathFilterType == PathFilterType.Include)
{
CoverageAnalytics.instance.CurrentCoverageEvent.selectAddFolder_IncludedPaths = true;
m_AddPathToIncludeHandler.BrowseForDir(m_PathsToFilter);
}
else
{
CoverageAnalytics.instance.CurrentCoverageEvent.selectAddFolder_ExcludedPaths = true;
m_AddPathToExcludeHandler.BrowseForDir(m_PathsToFilter);
}
}
private void AddFile()
{
if (m_PathFilterType == PathFilterType.Include)
{
CoverageAnalytics.instance.CurrentCoverageEvent.selectAddFile_IncludedPaths = true;
m_AddPathToIncludeHandler.BrowseForFile(m_PathsToFilter);
}
else
{
CoverageAnalytics.instance.CurrentCoverageEvent.selectAddFile_ExcludedPaths = true;
m_AddPathToExcludeHandler.BrowseForFile(m_PathsToFilter);
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e69bc8675774d1741834a4ff82846748
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,73 @@
using System.Linq;
using System;
using UnityEngine;
using UnityEditor.TestTools.CodeCoverage.Utils;
namespace UnityEditor.TestTools.CodeCoverage
{
internal class PathToAddHandler
{
string m_PathsToFilter;
readonly CodeCoverageWindow m_Parent;
readonly PathFilterType m_PathFilterType;
private readonly string kSelectIncludedDirectoryMessage = L10n.Tr($"Select directory to include");
private readonly string kSelectIncludedFileMessage = L10n.Tr("Select file to include");
private readonly string kSelectExcludedDirectoryMessage = L10n.Tr($"Select directory to exclude");
private readonly string kSelectExcludedFileMessage = L10n.Tr("Select file to exclude");
public PathToAddHandler(CodeCoverageWindow parent, PathFilterType type)
{
m_Parent = parent;
m_PathFilterType = type;
}
public void BrowseForDir(string pathsToFilter)
{
m_PathsToFilter = pathsToFilter;
string candidate = CoverageUtils.BrowseForDir(Application.dataPath, m_PathFilterType == PathFilterType.Include ? kSelectIncludedDirectoryMessage : kSelectExcludedDirectoryMessage);
if (CoverageUtils.IsValidFolder(candidate))
{
candidate = string.Concat(candidate, "/**");
UpdatePathToFilter(candidate);
}
}
public void BrowseForFile(string pathsToFilter)
{
m_PathsToFilter = pathsToFilter;
string candidate = CoverageUtils.BrowseForFile(Application.dataPath, m_PathFilterType == PathFilterType.Include ? kSelectIncludedFileMessage : kSelectExcludedFileMessage);
if (CoverageUtils.IsValidFile(candidate))
{
UpdatePathToFilter(candidate);
}
}
private void UpdatePathToFilter(string candidate)
{
string[] pathFilters = m_PathsToFilter.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
candidate = CoverageUtils.NormaliseFolderSeparators(candidate);
if (!pathFilters.Contains(candidate))
{
if (m_PathsToFilter.Length > 0)
m_PathsToFilter += ",";
m_PathsToFilter += candidate;
if (m_PathFilterType == PathFilterType.Include)
{
m_Parent.PathsToInclude = m_PathsToFilter;
}
else
{
m_Parent.PathsToExclude = m_PathsToFilter;
}
m_Parent.LoseFocus();
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6b5c2f62cdd9230479f2ad68d036975a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: