public void WhenLoadPathUsesHttp_AndInsecureHttpAllowed_BuildSucceeds()
        {
#if UNITY_2022_1_OR_NEWER
            InsecureHttpOption oldHttpOption = PlayerSettings.insecureHttpOption;
            PlayerSettings.insecureHttpOption = InsecureHttpOption.AlwaysAllowed;

            string remoteLoadPathId  = Settings.profileSettings.GetProfileDataByName(AddressableAssetSettings.kRemoteLoadPath).Id;
            string oldRemoteLoadPath = Settings.profileSettings.GetValueById(Settings.activeProfileId, remoteLoadPathId);
            Settings.profileSettings.SetValue(Settings.activeProfileId, AddressableAssetSettings.kRemoteLoadPath, "http://insecureconnection/");

            AddressableAssetGroup assetGroup = Settings.CreateGroup("InsecureConnections", false, false, false, null, typeof(BundledAssetGroupSchema));
            assetGroup.GetSchema <BundledAssetGroupSchema>().BuildPath.SetVariableById(Settings, Settings.profileSettings.GetProfileDataByName(AddressableAssetSettings.kRemoteBuildPath).Id);
            assetGroup.GetSchema <BundledAssetGroupSchema>().LoadPath.SetVariableById(Settings, Settings.profileSettings.GetProfileDataByName(AddressableAssetSettings.kRemoteLoadPath).Id);

            string assetPath = Path.Combine(TestFolder, "insecureConnectionsTest.prefab");
            PrefabUtility.SaveAsPrefabAsset(new GameObject(), assetPath);
            Settings.CreateOrMoveEntry(AssetDatabase.AssetPathToGUID(assetPath), assetGroup, false, false);

            var             context = new AddressablesDataBuilderInput(Settings);
            BuildScriptBase db      = (BuildScriptBase)Settings.DataBuilders.Find(x => x.GetType() == typeof(BuildScriptPackedMode));
            db.BuildData <AddressablesPlayerBuildResult>(context);
            LogAssert.NoUnexpectedReceived();

            Settings.RemoveGroup(assetGroup);
            Settings.profileSettings.SetValue(Settings.activeProfileId, AddressableAssetSettings.kRemoteLoadPath, oldRemoteLoadPath);
            AssetDatabase.DeleteAsset(assetPath);
            PlayerSettings.insecureHttpOption = oldHttpOption;
#else
            Assert.Ignore($"Skipping test {nameof(WhenLoadPathUsesHttp_AndInsecureHttpAllowed_BuildSucceeds)}.");
#endif
        }
        public void WhenLoadPathUsesHttp_AndInsecureHttpNotAllowed_BuildLogsWarning()
        {
#if UNITY_2022_1_OR_NEWER
            InsecureHttpOption oldHttpOption = PlayerSettings.insecureHttpOption;
            PlayerSettings.insecureHttpOption = InsecureHttpOption.NotAllowed;

            string remoteLoadPathId  = Settings.profileSettings.GetProfileDataByName(AddressableAssetSettings.kRemoteLoadPath).Id;
            string oldRemoteLoadPath = Settings.profileSettings.GetValueById(Settings.activeProfileId, remoteLoadPathId);
            Settings.profileSettings.SetValue(Settings.activeProfileId, AddressableAssetSettings.kRemoteLoadPath, "http://insecureconnection/");

            AddressableAssetGroup assetGroup = Settings.CreateGroup("InsecureConnections", false, false, false, null, typeof(BundledAssetGroupSchema));
            assetGroup.GetSchema <BundledAssetGroupSchema>().BuildPath.SetVariableById(Settings, Settings.profileSettings.GetProfileDataByName(AddressableAssetSettings.kRemoteBuildPath).Id);
            assetGroup.GetSchema <BundledAssetGroupSchema>().LoadPath.SetVariableById(Settings, Settings.profileSettings.GetProfileDataByName(AddressableAssetSettings.kRemoteLoadPath).Id);

            string assetPath = Path.Combine(TestFolder, "insecureConnectionsTest.prefab");
            PrefabUtility.SaveAsPrefabAsset(new GameObject(), assetPath);
            Settings.CreateOrMoveEntry(AssetDatabase.AssetPathToGUID(assetPath), assetGroup, false, false);

            var             context = new AddressablesDataBuilderInput(Settings);
            BuildScriptBase db      = (BuildScriptBase)Settings.DataBuilders.Find(x => x.GetType() == typeof(BuildScriptPackedMode));
            db.BuildData <AddressablesPlayerBuildResult>(context);
            LogAssert.Expect(LogType.Warning, $"Addressable group {assetGroup.Name} uses insecure http for its load path.  To allow http connections for UnityWebRequests, change your settings in Edit > Project Settings > Player > Other Settings > Configuration > Allow downloads over HTTP.");

            Settings.RemoveGroup(assetGroup);
            Settings.profileSettings.SetValue(Settings.activeProfileId, AddressableAssetSettings.kRemoteLoadPath, oldRemoteLoadPath);
            AssetDatabase.DeleteAsset(assetPath);
            PlayerSettings.insecureHttpOption = oldHttpOption;
#else
            Assert.Ignore($"Skipping test {nameof(WhenLoadPathUsesHttp_AndInsecureHttpNotAllowed_BuildLogsWarning)}.");
#endif
        }
        public void AddressablesCleanCachedData_ClearsData()
        {
            //Setup
            Settings.BuildPlayerContentImpl();

            //Check after each clean that the data is not built
            foreach (ScriptableObject so in Settings.DataBuilders)
            {
                BuildScriptBase db = so as BuildScriptBase;
                Settings.CleanPlayerContentImpl(db);
                Assert.IsFalse(db.IsDataBuilt());
            }
        }
        public void AddressablesClearCachedData_DoesNotThrowError()
        {
            //individual clean paths
            foreach (ScriptableObject so in Settings.DataBuilders)
            {
                BuildScriptBase db = so as BuildScriptBase;
                Assert.DoesNotThrow(() => Settings.CleanPlayerContentImpl(db));
            }

            //Clean all path
            Assert.DoesNotThrow(() => Settings.CleanPlayerContentImpl());

            //Cleanup
            Settings.BuildPlayerContentImpl();
        }
        public void AddressablesCleanAllCachedData_ClearsAllData()
        {
            //Setup
            Settings.BuildPlayerContentImpl();

            //Clean ALL data builders
            Settings.CleanPlayerContentImpl();

            //Check none have data built
            foreach (ScriptableObject so in Settings.DataBuilders)
            {
                BuildScriptBase db = so as BuildScriptBase;
                Assert.IsFalse(db.IsDataBuilt());
            }
        }
        public void BuildScriptBaseWriteBuildLog_WhenDirectoryDoesNotExist_DirectoryCreated()
        {
            string dirName = "SomeTestDir";
            string logFile = Path.Combine(dirName, "AddressablesBuildTEP.json");

            try
            {
                BuildLog log = new BuildLog();
                BuildScriptBase.WriteBuildLog(log, dirName);
                FileAssert.Exists(logFile);
            }
            finally
            {
                Directory.Delete(dirName, true);
            }
        }
        public void WhenBundleLocalCatalogEnabled_BuildScriptPacked_DoesNotCreatePerformanceLogReport()
        {
            string logPath = $"Library/com.unity.addressables/aa/{PlatformMappingService.GetPlatformPathSubFolder()}/buildlogtep.json";

            if (File.Exists(logPath))
            {
                File.Delete(logPath);
            }

            Settings.BundleLocalCatalog = true;

            var             context = new AddressablesDataBuilderInput(Settings);
            BuildScriptBase db      = (BuildScriptBase)Settings.DataBuilders.Find(x => x.GetType() == typeof(BuildScriptPackedMode));

            Assert.IsFalse(File.Exists(logPath)); // make sure file does not exist before build

            var res = db.BuildData <AddressablesPlayerBuildResult>(context);

            Assert.IsFalse(File.Exists(logPath));
        }