| | 1 | | using DCL; |
| | 2 | | using DCL.Helpers; |
| | 3 | | using DCL.Components; |
| | 4 | | using DCL.Models; |
| | 5 | | using NUnit.Framework; |
| | 6 | | using System.Collections; |
| | 7 | | using DCL.Components.Video.Plugin; |
| | 8 | | using UnityEngine; |
| | 9 | | using UnityEngine.TestTools; |
| | 10 | | using DCL.Controllers; |
| | 11 | | using Newtonsoft.Json; |
| | 12 | |
|
| | 13 | | namespace Tests |
| | 14 | | { |
| | 15 | | public class VideoTests : IntegrationTestSuite_Legacy |
| | 16 | | { |
| | 17 | | protected override IEnumerator SetUp() |
| | 18 | | { |
| 11 | 19 | | yield return base.SetUp(); |
| 11 | 20 | | DCLVideoTexture.isTest = true; |
| 11 | 21 | | } |
| | 22 | |
|
| | 23 | | protected override IEnumerator TearDown() |
| | 24 | | { |
| 11 | 25 | | sceneController.enabled = true; |
| 11 | 26 | | return base.TearDown(); |
| | 27 | | } |
| | 28 | |
|
| | 29 | | [UnityTest] |
| | 30 | | public IEnumerator VideoTextureIsCreatedCorrectly() |
| | 31 | | { |
| 1 | 32 | | DCLVideoTexture videoTexture = CreateDCLVideoTexture(scene, "it-wont-load-during-test"); |
| 1 | 33 | | yield return videoTexture.routine; |
| 1 | 34 | | Assert.IsTrue(videoTexture.attachedMaterials.Count == 0, "DCLVideoTexture started with attachedMaterials != |
| 1 | 35 | | } |
| | 36 | |
|
| | 37 | | [UnityTest] |
| | 38 | | public IEnumerator VideoTextureReplaceOtherTextureCorrectly() |
| | 39 | | { |
| 1 | 40 | | DCLVideoTexture videoTexture = CreateDCLVideoTexture(scene, "it-wont-load-during-test"); |
| 1 | 41 | | yield return videoTexture.routine; |
| 1 | 42 | | Assert.IsTrue(videoTexture.attachedMaterials.Count == 0, "DCLVideoTexture started with attachedMaterials != |
| | 43 | |
|
| 1 | 44 | | DCLTexture dclTexture = TestHelpers.CreateDCLTexture( |
| | 45 | | scene, |
| | 46 | | TestAssetsUtils.GetPath() + "/Images/atlas.png", |
| | 47 | | DCLTexture.BabylonWrapMode.CLAMP, |
| | 48 | | FilterMode.Bilinear); |
| | 49 | |
|
| 1 | 50 | | yield return dclTexture.routine; |
| | 51 | |
|
| 1 | 52 | | BasicMaterial mat = TestHelpers.SharedComponentCreate<BasicMaterial, BasicMaterial.Model> |
| | 53 | | (scene, CLASS_ID.BASIC_MATERIAL, |
| | 54 | | new BasicMaterial.Model |
| | 55 | | { |
| | 56 | | texture = dclTexture.id |
| | 57 | | }); |
| | 58 | |
|
| 1 | 59 | | yield return mat.routine; |
| | 60 | |
|
| 1 | 61 | | yield return TestHelpers.SharedComponentUpdate<BasicMaterial, BasicMaterial.Model>(mat, new BasicMaterial.Mo |
| | 62 | |
|
| 1 | 63 | | Assert.IsTrue(videoTexture.attachedMaterials.Count == 1, $"did DCLVideoTexture attach to material? {videoTex |
| 1 | 64 | | } |
| | 65 | |
|
| | 66 | | [UnityTest] |
| | 67 | | public IEnumerator VideoTextureIsAttachedAndDetachedCorrectly() |
| | 68 | | { |
| 1 | 69 | | DCLVideoTexture videoTexture = CreateDCLVideoTexture(scene, "it-wont-load-during-test"); |
| 1 | 70 | | yield return videoTexture.routine; |
| 1 | 71 | | Assert.IsTrue(videoTexture.attachedMaterials.Count == 0, "DCLVideoTexture started with attachedMaterials != |
| | 72 | |
|
| 1 | 73 | | BasicMaterial mat2 = TestHelpers.SharedComponentCreate<BasicMaterial, BasicMaterial.Model> |
| | 74 | | (scene, CLASS_ID.BASIC_MATERIAL, |
| | 75 | | new BasicMaterial.Model |
| | 76 | | { |
| | 77 | | texture = videoTexture.id |
| | 78 | | }); |
| | 79 | |
|
| 1 | 80 | | yield return mat2.routine; |
| | 81 | |
|
| 1 | 82 | | Assert.IsTrue(videoTexture.attachedMaterials.Count == 1, $"did DCLVideoTexture attach to material? {videoTex |
| | 83 | |
|
| | 84 | | // TEST: DCLVideoTexture detach on material disposed |
| 1 | 85 | | mat2.Dispose(); |
| 1 | 86 | | Assert.IsTrue(videoTexture.attachedMaterials.Count == 0, $"did DCLVideoTexture detach from material? {videoT |
| | 87 | |
|
| 1 | 88 | | videoTexture.Dispose(); |
| | 89 | |
|
| 1 | 90 | | yield return null; |
| 1 | 91 | | Assert.IsTrue(videoTexture.texture == null, "DCLVideoTexture didn't dispose correctly?"); |
| 1 | 92 | | } |
| | 93 | |
|
| | 94 | | [UnityTest] |
| | 95 | | public IEnumerator VideoTextureVisibleStateIsSetCorrectlyWhenAddedToAMaterialNotAttachedToShape() |
| | 96 | | { |
| 1 | 97 | | DCLVideoTexture videoTexture = CreateDCLVideoTexture(scene, "it-wont-load-during-test"); |
| 1 | 98 | | yield return videoTexture.routine; |
| | 99 | |
|
| 1 | 100 | | var ent1 = TestHelpers.CreateSceneEntity(scene); |
| 1 | 101 | | BasicMaterial ent1Mat = TestHelpers.SharedComponentCreate<BasicMaterial, BasicMaterial.Model>(scene, CLASS_I |
| 1 | 102 | | TestHelpers.SharedComponentAttach(ent1Mat, ent1); |
| 1 | 103 | | yield return ent1Mat.routine; |
| | 104 | |
|
| 1 | 105 | | Assert.IsTrue(!videoTexture.isVisible, "DCLVideoTexture should not be visible without a shape"); |
| 1 | 106 | | } |
| | 107 | |
|
| | 108 | | [UnityTest] |
| | 109 | | public IEnumerator VideoTextureVisibleStateIsSetCorrectly() |
| | 110 | | { |
| 1 | 111 | | DCLVideoTexture videoTexture = CreateDCLVideoTexture(scene, "it-wont-load-during-test"); |
| 1 | 112 | | yield return videoTexture.routine; |
| | 113 | |
|
| 1 | 114 | | var ent1 = TestHelpers.CreateSceneEntity(scene); |
| 1 | 115 | | BasicMaterial ent1Mat = TestHelpers.SharedComponentCreate<BasicMaterial, BasicMaterial.Model>(scene, CLASS_I |
| 1 | 116 | | TestHelpers.SharedComponentAttach(ent1Mat, ent1); |
| 1 | 117 | | yield return ent1Mat.routine; |
| | 118 | |
|
| 1 | 119 | | BoxShape ent1Shape = TestHelpers.SharedComponentCreate<BoxShape, BoxShape.Model>(scene, CLASS_ID.BOX_SHAPE, |
| 1 | 120 | | yield return ent1Shape.routine; |
| | 121 | |
|
| 1 | 122 | | TestHelpers.SharedComponentAttach(ent1Shape, ent1); |
| 1 | 123 | | yield return new WaitForAllMessagesProcessed(); |
| 1 | 124 | | Assert.IsTrue(videoTexture.isVisible, "DCLVideoTexture should be visible"); |
| | 125 | |
|
| 1 | 126 | | yield return TestHelpers.SharedComponentUpdate<BoxShape, BoxShape.Model>(ent1Shape, new BoxShape.Model() { v |
| 1 | 127 | | yield return new WaitForAllMessagesProcessed(); |
| | 128 | |
|
| 1 | 129 | | Assert.IsTrue(!videoTexture.isVisible, "DCLVideoTexture should not be visible "); |
| 1 | 130 | | } |
| | 131 | |
|
| | 132 | | [UnityTest] |
| | 133 | | public IEnumerator VideoTextureVisibleStateIsSetCorrectlyWhenAddedToAlreadyAttachedMaterial() |
| | 134 | | { |
| 1 | 135 | | DCLVideoTexture videoTexture = CreateDCLVideoTexture(scene, "it-wont-load-during-test"); |
| 1 | 136 | | yield return videoTexture.routine; |
| | 137 | |
|
| 1 | 138 | | var ent1 = TestHelpers.CreateSceneEntity(scene); |
| 1 | 139 | | BasicMaterial ent1Mat = TestHelpers.SharedComponentCreate<BasicMaterial, BasicMaterial.Model>(scene, CLASS_I |
| 1 | 140 | | TestHelpers.SharedComponentAttach(ent1Mat, ent1); |
| 1 | 141 | | yield return ent1Mat.routine; |
| | 142 | |
|
| 1 | 143 | | BoxShape ent1Shape = TestHelpers.SharedComponentCreate<BoxShape, BoxShape.Model>(scene, CLASS_ID.BOX_SHAPE, |
| 1 | 144 | | yield return ent1Shape.routine; |
| | 145 | |
|
| 1 | 146 | | TestHelpers.SharedComponentAttach(ent1Shape, ent1); |
| | 147 | |
|
| 1 | 148 | | yield return TestHelpers.SharedComponentUpdate<BasicMaterial, BasicMaterial.Model>(ent1Mat, new BasicMateria |
| 1 | 149 | | yield return new WaitForAllMessagesProcessed(); |
| 1 | 150 | | Assert.IsTrue(videoTexture.isVisible, "DCLVideoTexture should be visible"); |
| | 151 | |
|
| 1 | 152 | | yield return TestHelpers.SharedComponentUpdate<BoxShape, BoxShape.Model>(ent1Shape, new BoxShape.Model() { v |
| 1 | 153 | | yield return new WaitForAllMessagesProcessed(); |
| | 154 | |
|
| 1 | 155 | | Assert.IsTrue(!videoTexture.isVisible, "DCLVideoTexture should not be visible "); |
| 1 | 156 | | } |
| | 157 | |
|
| | 158 | | [UnityTest] |
| | 159 | | public IEnumerator VideoTextureVisibleStateIsSetCorrectlyWhenEntityIsRemoved() |
| | 160 | | { |
| 1 | 161 | | DCLVideoTexture videoTexture = CreateDCLVideoTexture(scene, "it-wont-load-during-test"); |
| 1 | 162 | | yield return videoTexture.routine; |
| | 163 | |
|
| 1 | 164 | | var ent1 = TestHelpers.CreateSceneEntity(scene); |
| 1 | 165 | | BasicMaterial ent1Mat = TestHelpers.SharedComponentCreate<BasicMaterial, BasicMaterial.Model>(scene, CLASS_I |
| 1 | 166 | | TestHelpers.SharedComponentAttach(ent1Mat, ent1); |
| 1 | 167 | | yield return ent1Mat.routine; |
| | 168 | |
|
| 1 | 169 | | BoxShape ent1Shape = TestHelpers.SharedComponentCreate<BoxShape, BoxShape.Model>(scene, CLASS_ID.BOX_SHAPE, |
| 1 | 170 | | yield return ent1Shape.routine; |
| | 171 | |
|
| 1 | 172 | | TestHelpers.SharedComponentAttach(ent1Shape, ent1); |
| 1 | 173 | | yield return new WaitForAllMessagesProcessed(); |
| 1 | 174 | | Assert.IsTrue(videoTexture.isVisible, "DCLVideoTexture should be visible"); |
| | 175 | |
|
| 1 | 176 | | scene.RemoveEntity(ent1.entityId, true); |
| 1 | 177 | | yield return new WaitForAllMessagesProcessed(); |
| | 178 | |
|
| 1 | 179 | | Assert.IsTrue(!videoTexture.isVisible, "DCLVideoTexture should not be visible "); |
| 1 | 180 | | } |
| | 181 | |
|
| | 182 | | [UnityTest] |
| | 183 | | public IEnumerator VolumeWhenVideoCreatedWithNoUserInScene() |
| | 184 | | { |
| | 185 | | // We disable SceneController monobehaviour to avoid its current scene id update |
| 1 | 186 | | sceneController.enabled = false; |
| | 187 | |
|
| | 188 | | // Set current scene as a different one |
| 1 | 189 | | CommonScriptableObjects.sceneID.Set("unexistent-scene"); |
| | 190 | |
|
| 1 | 191 | | DCLVideoTexture videoTexture = CreateDCLVideoTexture(scene, "it-wont-load-during-test"); |
| 1 | 192 | | yield return videoTexture.routine; |
| | 193 | |
|
| 1 | 194 | | var ent1 = TestHelpers.CreateSceneEntity(scene); |
| 1 | 195 | | BasicMaterial ent1Mat = TestHelpers.SharedComponentCreate<BasicMaterial, BasicMaterial.Model>(scene, CLASS_I |
| 1 | 196 | | TestHelpers.SharedComponentAttach(ent1Mat, ent1); |
| 1 | 197 | | yield return ent1Mat.routine; |
| | 198 | |
|
| 1 | 199 | | BoxShape ent1Shape = TestHelpers.SharedComponentCreate<BoxShape, BoxShape.Model>(scene, CLASS_ID.BOX_SHAPE, |
| 1 | 200 | | yield return ent1Shape.routine; |
| | 201 | |
|
| 1 | 202 | | TestHelpers.SharedComponentAttach(ent1Shape, ent1); |
| 1 | 203 | | yield return new WaitForAllMessagesProcessed(); |
| | 204 | |
|
| | 205 | | // Check the volume |
| 1 | 206 | | Assert.AreEqual(0f, videoTexture.texturePlayer.volume); |
| 1 | 207 | | } |
| | 208 | |
|
| | 209 | | [UnityTest] |
| | 210 | | public IEnumerator VolumeWhenVideoCreatedWithUserInScene() |
| | 211 | | { |
| | 212 | | // We disable SceneController monobehaviour to avoid its current scene id update |
| 1 | 213 | | sceneController.enabled = false; |
| | 214 | |
|
| | 215 | | // Set current scene with this scene's id |
| 1 | 216 | | CommonScriptableObjects.sceneID.Set(scene.sceneData.id); |
| | 217 | |
|
| 1 | 218 | | DCLVideoTexture videoTexture = CreateDCLVideoTexture(scene, "it-wont-load-during-test"); |
| 1 | 219 | | yield return videoTexture.routine; |
| | 220 | |
|
| 1 | 221 | | var ent1 = TestHelpers.CreateSceneEntity(scene); |
| 1 | 222 | | BasicMaterial ent1Mat = TestHelpers.SharedComponentCreate<BasicMaterial, BasicMaterial.Model>(scene, CLASS_I |
| 1 | 223 | | TestHelpers.SharedComponentAttach(ent1Mat, ent1); |
| 1 | 224 | | yield return ent1Mat.routine; |
| | 225 | |
|
| 1 | 226 | | BoxShape ent1Shape = TestHelpers.SharedComponentCreate<BoxShape, BoxShape.Model>(scene, CLASS_ID.BOX_SHAPE, |
| 1 | 227 | | yield return ent1Shape.routine; |
| | 228 | |
|
| 1 | 229 | | TestHelpers.SharedComponentAttach(ent1Shape, ent1); |
| 1 | 230 | | yield return new WaitForAllMessagesProcessed(); |
| | 231 | |
|
| | 232 | | // Check the volume |
| 1 | 233 | | Assert.AreEqual(videoTexture.GetVolume(), videoTexture.texturePlayer.volume); |
| 1 | 234 | | } |
| | 235 | |
|
| | 236 | | [UnityTest] |
| | 237 | | public IEnumerator VolumeIsMutedWhenUserLeavesScene() |
| | 238 | | { |
| | 239 | | // We disable SceneController monobehaviour to avoid its current scene id update |
| 1 | 240 | | sceneController.enabled = false; |
| | 241 | |
|
| | 242 | | // Set current scene with this scene's id |
| 1 | 243 | | CommonScriptableObjects.sceneID.Set(scene.sceneData.id); |
| 1 | 244 | | yield return null; |
| | 245 | |
|
| 1 | 246 | | DCLVideoTexture videoTexture = CreateDCLVideoTexture(scene, "it-wont-load-during-test"); |
| 1 | 247 | | yield return videoTexture.routine; |
| | 248 | |
|
| 1 | 249 | | var ent1 = TestHelpers.CreateSceneEntity(scene); |
| 1 | 250 | | BasicMaterial ent1Mat = TestHelpers.SharedComponentCreate<BasicMaterial, BasicMaterial.Model>(scene, CLASS_I |
| 1 | 251 | | TestHelpers.SharedComponentAttach(ent1Mat, ent1); |
| 1 | 252 | | yield return ent1Mat.routine; |
| | 253 | |
|
| 1 | 254 | | BoxShape ent1Shape = TestHelpers.SharedComponentCreate<BoxShape, BoxShape.Model>(scene, CLASS_ID.BOX_SHAPE, |
| 1 | 255 | | yield return ent1Shape.routine; |
| | 256 | |
|
| 1 | 257 | | TestHelpers.SharedComponentAttach(ent1Shape, ent1); |
| 1 | 258 | | yield return new WaitForAllMessagesProcessed(); |
| | 259 | |
|
| | 260 | | // Set current scene as a different one |
| 1 | 261 | | CommonScriptableObjects.sceneID.Set("unexistent-scene"); |
| | 262 | |
|
| | 263 | | // to force the video player to update its volume |
| 1 | 264 | | CommonScriptableObjects.playerCoords.Set(new Vector2Int(666, 666)); |
| | 265 | |
|
| 1 | 266 | | yield return null; |
| | 267 | |
|
| | 268 | | // Check the volume |
| 1 | 269 | | Assert.AreEqual(0f, videoTexture.texturePlayer.volume); |
| 1 | 270 | | } |
| | 271 | |
|
| | 272 | | [UnityTest] |
| | 273 | | public IEnumerator VolumeIsUnmutedWhenUserEntersScene() |
| | 274 | | { |
| | 275 | | // We disable SceneController monobehaviour to avoid its current scene id update |
| 1 | 276 | | sceneController.enabled = false; |
| | 277 | |
|
| | 278 | | // Set current scene as a different one |
| 1 | 279 | | CommonScriptableObjects.sceneID.Set("unexistent-scene"); |
| | 280 | |
|
| 1 | 281 | | DCLVideoTexture videoTexture = CreateDCLVideoTexture(scene, "it-wont-load-during-test"); |
| 1 | 282 | | yield return videoTexture.routine; |
| | 283 | |
|
| 1 | 284 | | var ent1 = TestHelpers.CreateSceneEntity(scene); |
| 1 | 285 | | BasicMaterial ent1Mat = TestHelpers.SharedComponentCreate<BasicMaterial, BasicMaterial.Model>(scene, CLASS_I |
| 1 | 286 | | TestHelpers.SharedComponentAttach(ent1Mat, ent1); |
| 1 | 287 | | yield return ent1Mat.routine; |
| | 288 | |
|
| 1 | 289 | | BoxShape ent1Shape = TestHelpers.SharedComponentCreate<BoxShape, BoxShape.Model>(scene, CLASS_ID.BOX_SHAPE, |
| 1 | 290 | | yield return ent1Shape.routine; |
| | 291 | |
|
| 1 | 292 | | TestHelpers.SharedComponentAttach(ent1Shape, ent1); |
| 1 | 293 | | yield return new WaitForAllMessagesProcessed(); |
| | 294 | |
|
| | 295 | | // Set current scene with this scene's id |
| 1 | 296 | | CommonScriptableObjects.sceneID.Set(scene.sceneData.id); |
| | 297 | |
|
| | 298 | | // to force the video player to update its volume |
| 1 | 299 | | CommonScriptableObjects.playerCoords.Set(new Vector2Int(666, 666)); |
| | 300 | |
|
| 1 | 301 | | yield return null; |
| | 302 | |
|
| | 303 | | // Check the volume |
| 1 | 304 | | Assert.AreEqual(videoTexture.GetVolume(), videoTexture.texturePlayer.volume); |
| 1 | 305 | | } |
| | 306 | |
|
| | 307 | | static DCLVideoClip CreateDCLVideoClip(ParcelScene scn, string url) |
| | 308 | | { |
| 11 | 309 | | return TestHelpers.SharedComponentCreate<DCLVideoClip, DCLVideoClip.Model> |
| | 310 | | ( |
| | 311 | | scn, |
| | 312 | | DCL.Models.CLASS_ID.VIDEO_CLIP, |
| | 313 | | new DCLVideoClip.Model |
| | 314 | | { |
| | 315 | | url = url |
| | 316 | | } |
| | 317 | | ); |
| | 318 | | } |
| | 319 | |
|
| | 320 | | static DCLVideoTexture CreateDCLVideoTexture(ParcelScene scn, DCLVideoClip clip) |
| | 321 | | { |
| 11 | 322 | | return TestHelpers.SharedComponentCreate<DCLVideoTexture, DCLVideoTexture.Model> |
| | 323 | | ( |
| | 324 | | scn, |
| | 325 | | DCL.Models.CLASS_ID.VIDEO_TEXTURE, |
| | 326 | | new DCLVideoTexture.Model |
| | 327 | | { |
| | 328 | | videoClipId = clip.id |
| | 329 | | } |
| | 330 | | ); |
| | 331 | | } |
| | 332 | |
|
| 11 | 333 | | static DCLVideoTexture CreateDCLVideoTexture(ParcelScene scn, string url) { return CreateDCLVideoTexture(scn, Cr |
| | 334 | | } |
| | 335 | | } |