Maze / Library /PackageCache /com.unity.ugui@1.0.0 /Tests /Runtime /InputField /DesktopInputFieldTests.cs
| using System; | |
| using System.Linq; | |
| using NUnit.Framework; | |
| using UnityEngine; | |
| using UnityEngine.EventSystems; | |
| using UnityEngine.TestTools; | |
| using System.Collections; | |
| using System.IO; | |
| using UnityEditor; | |
| using UnityEngine.UI; | |
| using System.Reflection; | |
| namespace InputfieldTests | |
| { | |
| public class DesktopInputFieldTests : BaseInputFieldTests, IPrebuildSetup | |
| { | |
| protected const string kPrefabPath = "Assets/Resources/DesktopInputFieldPrefab.prefab"; | |
| public void Setup() | |
| { | |
| CreateInputFieldAsset(kPrefabPath); | |
| } | |
| [] | |
| public virtual void TestSetup() | |
| { | |
| m_PrefabRoot = UnityEngine.Object.Instantiate(Resources.Load("DesktopInputFieldPrefab")) as GameObject; | |
| FieldInfo inputModule = typeof(EventSystem).GetField("m_CurrentInputModule", BindingFlags.NonPublic | BindingFlags.Instance); | |
| inputModule.SetValue(m_PrefabRoot.GetComponentInChildren<EventSystem>(), m_PrefabRoot.GetComponentInChildren<FakeInputModule>()); | |
| } | |
| [] | |
| public virtual void TearDown() | |
| { | |
| GUIUtility.systemCopyBuffer = null; | |
| FontUpdateTracker.UntrackText(m_PrefabRoot.GetComponentInChildren<Text>()); | |
| GameObject.DestroyImmediate(m_PrefabRoot); | |
| } | |
| [] | |
| public void OnetimeTearDown() | |
| { | |
| AssetDatabase.DeleteAsset(kPrefabPath); | |
| } | |
| [] | |
| public void FocusOnPointerClickWithLeftButton() | |
| { | |
| InputField inputField = m_PrefabRoot.GetComponentInChildren<InputField>(); | |
| PointerEventData data = new PointerEventData(m_PrefabRoot.GetComponentInChildren<EventSystem>()); | |
| data.button = PointerEventData.InputButton.Left; | |
| inputField.OnPointerClick(data); | |
| MethodInfo lateUpdate = typeof(InputField).GetMethod("LateUpdate", BindingFlags.NonPublic | BindingFlags.Instance); | |
| lateUpdate.Invoke(inputField, null); | |
| Assert.IsTrue(inputField.isFocused); | |
| } | |
| [] | |
| public IEnumerator DoesNotFocusOnPointerClickWithRightOrMiddleButton() | |
| { | |
| InputField inputField = m_PrefabRoot.GetComponentInChildren<InputField>(); | |
| PointerEventData data = new PointerEventData(m_PrefabRoot.GetComponentInChildren<EventSystem>()); | |
| data.button = PointerEventData.InputButton.Middle; | |
| inputField.OnPointerClick(data); | |
| yield return null; | |
| data.button = PointerEventData.InputButton.Right; | |
| inputField.OnPointerClick(data); | |
| yield return null; | |
| Assert.IsFalse(inputField.isFocused); | |
| } | |
| } | |
| } | |