DesktopInputFieldTests.cs
2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
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()
{
#if UNITY_EDITOR
CreateInputFieldAsset(kPrefabPath);
#endif
}
[SetUp]
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>());
}
[TearDown]
public virtual void TearDown()
{
GUIUtility.systemCopyBuffer = null;
FontUpdateTracker.UntrackText(m_PrefabRoot.GetComponentInChildren<Text>());
GameObject.DestroyImmediate(m_PrefabRoot);
}
[OneTimeTearDown]
public void OnetimeTearDown()
{
#if UNITY_EDITOR
AssetDatabase.DeleteAsset(kPrefabPath);
#endif
}
[Test]
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);
}
[UnityTest]
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);
}
}
}