Skip to content

Commit e5fe026

Browse files
authored
Merge pull request #67 from SourcePointUSA/DIA-4326-usnat-accept-reject-all-usnat-ui-test
DIA-4326 usnat accept, reject all in PM + UI test, programmatic RejectAll + UI test
2 parents 6bb55b3 + cd7d471 commit e5fe026

File tree

19 files changed

+306
-12
lines changed

19 files changed

+306
-12
lines changed

Assets/ConsentManagementProvider/Plugins/iOS/Source/SwiftBridge.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,18 @@ import UIKit
203203
self.callbacks.RunCallback(callbackType: .OnErrorCallback, arg: "Library was not initialized correctly!")
204204
}
205205
}
206+
207+
@objc public func rejectAll(campaignType: Int) {
208+
guard let campaign = CAMPAIGN_TYPE(rawValue: campaignType) else {
209+
self.callbacks.RunCallback(callbackType: .OnErrorCallback, arg: "Wrong `campaignType` on `rejectAll` call!")
210+
return
211+
}
212+
if let consentManager = consentManager {
213+
consentManager.rejectAll(campaignType: convertBridgeCampaignToNative(campaign: campaign))
214+
} else {
215+
self.callbacks.RunCallback(callbackType: .OnErrorCallback, arg: "Library was not initialized correctly!")
216+
}
217+
}
206218
}
207219

208220
// MARK: - SPDelegate implementation
@@ -315,6 +327,15 @@ public class CallbackSwift {
315327
}
316328

317329
// MARK: - Util
330+
internal func convertBridgeCampaignToNative(campaign: SwiftBridge.CAMPAIGN_TYPE) -> SPCampaignType {
331+
switch campaign {
332+
case .GDPR: return SPCampaignType.gdpr
333+
case .IOS14: return SPCampaignType.ios14
334+
case .CCPA: return SPCampaignType.ccpa
335+
case .USNAT: return SPCampaignType.usnat
336+
}
337+
}
338+
318339
public func printLog(_ items: Any..., separator: String = " ", terminator: String = "\n") {
319340
Swift.print("CMP SWIFT LOG:",items)
320341
}

Assets/ConsentManagementProvider/Plugins/iOS/Source/Unity.mm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ void _deleteCustomConsentGDPR()
9393
[swiftBridge deleteCustomConsentGDPR];
9494
}
9595

96+
void _rejectAll(int campaignType)
97+
{
98+
[swiftBridge rejectAllWithCampaignType:campaignType];
99+
}
100+
96101
void _addVendor(char* vendor)
97102
{
98103
[swiftBridge addCustomVendorWithVendor:_getString(vendor)];

Assets/ConsentManagementProvider/Scripts/facade/CMP.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ public void DeleteCustomConsentGDPR(
121121
legIntCategories: legIntCategories,
122122
onSuccessDelegate: onSuccessDelegate);
123123

124+
public void RejectAll(CAMPAIGN_TYPE campaignType) => ConcreteInstance.RejectAll(campaignType);
125+
124126
public SpConsents GetSpConsents() => ConcreteInstance.GetSpConsents();
125127

126128
public GdprConsent GetCustomConsent() => ConcreteInstance.GetCustomConsent();
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
3+
namespace ConsentManagementProvider
4+
{
5+
public static class CMPTestUtils
6+
{
7+
public static void LoadPrivacyManager(
8+
string campaignType,
9+
string pmId)
10+
{
11+
CAMPAIGN_TYPE type = (CAMPAIGN_TYPE)Int32.Parse(campaignType);
12+
CMP.ConcreteInstance.LoadPrivacyManager(
13+
campaignType: type,
14+
pmId: pmId);
15+
}
16+
}
17+
}

Assets/ConsentManagementProvider/Scripts/facade/CMPTestUtils.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/ConsentManagementProvider/Scripts/interface/ISpSdk.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ void Initialize(
1717
void LoadPrivacyManager(CAMPAIGN_TYPE campaignType, string pmId, PRIVACY_MANAGER_TAB tab = PRIVACY_MANAGER_TAB.DEFAULT);
1818
void CustomConsentGDPR(string[] vendors, string[] categories, string[] legIntCategories, Action<GdprConsent> onSuccessDelegate);
1919
void DeleteCustomConsentGDPR(string[] vendors, string[] categories, string[] legIntCategories, Action<GdprConsent> onSuccessDelegate);
20+
void RejectAll(CAMPAIGN_TYPE campaignType);
2021
SpConsents GetSpConsents();
2122
GdprConsent GetCustomConsent();
2223
void ClearAllData();

Assets/ConsentManagementProvider/Scripts/wrapper/Android/ConsentWrapperAndroid.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ public void DeleteCustomConsentGDPR(string[] vendors, string[] categories, strin
122122
consentLib.Call("deleteCustomConsentTo", vendors, categories, legIntCategories, customConsentClient);
123123
}
124124

125+
public void RejectAll(CAMPAIGN_TYPE campaignType) => consentLib.Call("rejectAll", constructor.ConstructCampaignType(campaignType));
126+
125127
public SpConsents GetSpConsents()
126128
{
127129
if (spClient != null)

Assets/ConsentManagementProvider/Scripts/wrapper/UnityEditor/ConsentWrapperEditor.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ public void CustomConsentGDPR(string[] vendors, string[] categories, string[] le
2525
public void DeleteCustomConsentGDPR(string[] vendors, string[] categories, string[] legIntCategories, Action<GdprConsent> onSuccessDelegate) =>
2626
Debug.LogWarning("Emulating DeleteCustomConsentGDPR call.. Sourcepoint CMP works only for real Android/iOS devices, not the Unity Editor.");
2727

28+
public void RejectAll(CAMPAIGN_TYPE campaignType) =>
29+
Debug.LogWarning($"Emulating RejectAll call for {campaignType}... " +
30+
$"Sourcepoint CMP works only for real Android/iOS devices, not the Unity Editor.");
31+
2832
public SpConsents GetSpConsents()
2933
{
3034
Debug.LogWarning("Emulating GetSpConsents call.. Sourcepoint CMP works only for real Android/iOS devices, not the Unity Editor.");

Assets/ConsentManagementProvider/Scripts/wrapper/iOS/ConsentWrapperIOS.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ internal class ConsentWrapperIOS: ISpSdk
3838
[DllImport("__Internal")]
3939
private static extern void _deleteCustomConsentGDPR();
4040
[DllImport("__Internal")]
41+
private static extern void _rejectAll(int campaignType);
42+
[DllImport("__Internal")]
4143
private static extern void _addVendor(string vendor);
4244
[DllImport("__Internal")]
4345
private static extern void _addCategory(string category);
@@ -170,6 +172,13 @@ public void DeleteCustomConsentGDPR(string[] vendors, string[] categories, strin
170172
#endif
171173
}
172174

175+
public void RejectAll(CAMPAIGN_TYPE campaignType)
176+
{
177+
#if UNITY_IOS && !UNITY_EDITOR_OSX
178+
_rejectAll((int)campaignType);
179+
#endif
180+
}
181+
173182
public SpConsents GetSpConsents() => iOSListener._spConsents;
174183

175184
public GdprConsent GetCustomConsent() => iOSListener.customGdprConsent;

Assets/ExampleApp/Scripts/PrivacySettings.cs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using UnityEngine;
33
using UnityEngine.UI;
44
using System.Collections.Generic;
5+
using System;
56

67
public class PrivacySettings : MonoBehaviour, IOnConsentReady, IOnConsentSpFinished
78
{
@@ -31,6 +32,10 @@ public class PrivacySettings : MonoBehaviour, IOnConsentReady, IOnConsentSpFinis
3132
public Button clearDataButton;
3233
public Text sdkStatus;
3334

35+
public static string statusCampaignGDPR = "custom";
36+
public static string statusCampaignCCPA = "custom";
37+
public static string statusCampaignUSNAT = "custom";
38+
3439
private MESSAGE_LANGUAGE language
3540
{
3641
get
@@ -169,6 +174,9 @@ public void OnConsentReady(SpConsents consents)
169174
if(CMP.Instance.UseUSNAT)
170175
CmpDebugUtil.Log(consents.usnat.consents.ToFullString());
171176
UpdateUI();
177+
statusCampaignGDPR = UpdateStatuses(consents, CAMPAIGN_TYPE.GDPR);
178+
statusCampaignCCPA = UpdateStatuses(consents, CAMPAIGN_TYPE.CCPA);
179+
statusCampaignUSNAT = UpdateStatuses(consents, CAMPAIGN_TYPE.USNAT);
172180
}
173181

174182
public void OnConsentSpFinished()
@@ -209,6 +217,41 @@ void UpdateSdkStatus(string status)
209217
sdkStatus.text = "SDK:"+status;
210218
}
211219

220+
string UpdateStatuses(SpConsents consents, CAMPAIGN_TYPE campaign)
221+
{
222+
if (campaign == CAMPAIGN_TYPE.GDPR)
223+
{
224+
bool rejectedAny = (bool)consents.gdpr.consents.consentStatus.rejectedAny;
225+
bool rejectedLI = (bool)consents.gdpr.consents.consentStatus.rejectedLI;
226+
bool consentedAll = (bool)consents.gdpr.consents.consentStatus.consentedAll;
227+
bool consentedToAny = (bool)consents.gdpr.consents.consentStatus.consentedToAny;
228+
229+
if (consentedAll && consentedToAny)
230+
return "accepted";
231+
else if (rejectedAny && rejectedLI)
232+
return "rejected";
233+
}
234+
if (campaign == CAMPAIGN_TYPE.CCPA)
235+
{
236+
if (consents.ccpa.consents.status == "consentedAll")
237+
return "accepted";
238+
else if (consents.ccpa.consents.status == "rejectedAll")
239+
return "rejected";
240+
}
241+
if (campaign == CAMPAIGN_TYPE.USNAT)
242+
{
243+
bool rejectedAny = (bool)consents.usnat.consents.statuses.rejectedAny;
244+
bool consentedToAll = (bool)consents.usnat.consents.statuses.consentedToAll;
245+
bool consentedToAny = (bool)consents.usnat.consents.statuses.consentedToAny;
246+
247+
if (consentedToAll && consentedToAny)
248+
return "accepted";
249+
else if (rejectedAny)
250+
return "rejected";
251+
}
252+
return "custom";
253+
}
254+
212255
private void OnDestroy()
213256
{
214257
ConsentMessenger.RemoveListener<IOnConsentSpFinished>(gameObject);

0 commit comments

Comments
 (0)