forked from Unity-Technologies/UnityCsReference
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebViewTestFunctions.cs
More file actions
138 lines (116 loc) · 4.03 KB
/
Copy pathWebViewTestFunctions.cs
File metadata and controls
138 lines (116 loc) · 4.03 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// Unity C# reference source
// Copyright (c) Unity Technologies. For terms of use, see
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
using System.Linq;
using Debug = UnityEngine.Debug;
namespace UnityEditor.Web
{
internal class WebViewTestFunctions
{
public int ReturnInt()
{
return 5;
}
public string ReturnString()
{
return "Five";
}
public bool ReturnBool()
{
return true;
}
public int[] ReturnNumberArray()
{
return new[] {1, 2, 3};
}
public string[] ReturnStringArray()
{
return new[] {"One", "Two", "Three"};
}
public bool[] ReturnBoolArray()
{
return new[] {true, false, true};
}
public TestObject ReturnObject()
{
TestObject testObject = new TestObject {NumberProperty = 5, StringProperty = "Five", BoolProperty = true};
return testObject;
}
public void AcceptInt(int passedInt)
{
Debug.Log("A value was passed from JS: " + passedInt);
}
public void AcceptString(string passedString)
{
Debug.Log("A value was passed from JS: " + passedString);
}
public void AcceptBool(bool passedBool)
{
Debug.Log("A value was passed from JS: " + passedBool);
}
public void AcceptIntArray(int[] passedArray)
{
Debug.Log("An array was passed from the JS. Array elements were:");
for (int i = 0; i <= passedArray.Length; i++)
{
Debug.Log("Element at index " + i + ": " + passedArray[i]);
}
}
public void AcceptStringArray(string[] passedArray)
{
Debug.Log("An array was passed from the JS. Array elements were:");
for (int i = 0; i <= passedArray.Length; i++)
{
Debug.Log("Element at index " + i + ": " + passedArray[i]);
}
}
public void AcceptBoolArray(bool[] passedArray)
{
Debug.Log("An array was passed from the JS. Array elements were:");
for (int i = 1; i <= passedArray.Length; i++)
{
Debug.Log("Element at index " + i + ": " + passedArray[i]);
}
}
public void AcceptTestObject(TestObject passedObject)
{
Debug.Log("An object was passed from the JS. Properties were:");
Debug.Log("StringProperty: " + passedObject.StringProperty);
Debug.Log("NumberProperty: " + passedObject.NumberProperty);
Debug.Log("BoolProperty: " + passedObject.BoolProperty);
}
//For testing function calls with no parameters or return value
public void VoidMethod(string logMessage)
{
Debug.Log("A method was called from the CEF: " + logMessage);
}
//For testing access control on CEF function calls
private string APrivateMethod(string input)
{
return "This method is private and not for CEF";
}
//For testing function calls that supply and expect an array of strings
public string[] ArrayReverse(string[] input)
{
var outputStrings = (string[])input.Reverse();
return outputStrings;
}
public void LogMessage(string message)
{
Debug.Log(message);
}
public static void RunTestScript(string path)
{
var url = "file:///" + path;
JSProxyMgr.GetInstance().AddGlobalObject("WebViewTestFunctions", new WebViewTestFunctions());
var window = WebViewEditorWindowTabs.Create<WebViewEditorWindowTabs>("Test Window", url, 0, 0, 0, 0);
window.OnBatchMode();
}
}
internal class TestObject
{
public string StringProperty { get; set; }
public int NumberProperty { get; set; }
public bool BoolProperty { get; set; }
}
}