• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.adservices.adselection;
18 
19 import android.adservices.common.AdSelectionSignals;
20 import android.adservices.common.AdTechIdentifier;
21 import android.adservices.common.CommonFixture;
22 import android.net.Uri;
23 
24 import androidx.annotation.NonNull;
25 
26 import java.util.Arrays;
27 import java.util.List;
28 import java.util.Map;
29 
30 /** This is a static class meant to help with tests that involve creating an AdSelectionConfig. */
31 public class AdSelectionConfigFixture {
32 
33     public static final AdTechIdentifier SELLER = AdTechIdentifier.fromString("test.com");
34     public static final AdTechIdentifier SELLER_1 = AdTechIdentifier.fromString("test2.com");
35 
36     // Uri Constants
37     public static final String DECISION_LOGIC_FRAGMENT = "/decisionFragment";
38     public static final String TRUSTED_SCORING_SIGNAL_FRAGMENT = "/trustedScoringSignalsFragment";
39 
40     public static final Uri DECISION_LOGIC_URI =
41             CommonFixture.getUri(SELLER, DECISION_LOGIC_FRAGMENT);
42 
43     public static final AdTechIdentifier BUYER = AdTechIdentifier.fromString("buyer.example.com");
44     public static final AdTechIdentifier BUYER_1 = CommonFixture.VALID_BUYER_1;
45     public static final AdTechIdentifier BUYER_2 = CommonFixture.VALID_BUYER_2;
46     public static final AdTechIdentifier BUYER_3 = AdTechIdentifier.fromString("test3.com");
47     public static final List<AdTechIdentifier> CUSTOM_AUDIENCE_BUYERS =
48             Arrays.asList(BUYER_1, BUYER_2, BUYER_3);
49 
50     public static final AdSelectionSignals EMPTY_SIGNALS = AdSelectionSignals.EMPTY;
51 
52     public static final AdSelectionSignals AD_SELECTION_SIGNALS =
53             AdSelectionSignals.fromString("{\"ad_selection_signals\":1}");
54 
55     public static final AdSelectionSignals SELLER_SIGNALS =
56             AdSelectionSignals.fromString("{\"test_seller_signals\":1}");
57 
58     public static final Map<AdTechIdentifier, AdSelectionSignals> PER_BUYER_SIGNALS =
59             Map.of(
60                     BUYER_1,
61                     AdSelectionSignals.fromString("{\"buyer_signals\":1}"),
62                     BUYER_2,
63                     AdSelectionSignals.fromString("{\"buyer_signals\":2}"),
64                     BUYER_3,
65                     AdSelectionSignals.fromString("{\"buyer_signals\":3}"),
66                     BUYER,
67                     AdSelectionSignals.fromString("{\"buyer_signals\":0}"));
68 
69     public static final Uri TRUSTED_SCORING_SIGNALS_URI =
70             CommonFixture.getUri(SELLER, TRUSTED_SCORING_SIGNAL_FRAGMENT);
71 
72     /** Creates an AdSelectionConfig object to be used in unit and integration tests */
anAdSelectionConfig()73     public static AdSelectionConfig anAdSelectionConfig() {
74         return anAdSelectionConfigBuilder().build();
75     }
76 
77     /**
78      * @return returns a pre-loaded builder, where the internal members of the object can be changed
79      *     for the unit tests
80      */
anAdSelectionConfigBuilder()81     public static AdSelectionConfig.Builder anAdSelectionConfigBuilder() {
82         return new AdSelectionConfig.Builder()
83                 .setSeller(SELLER)
84                 .setDecisionLogicUri(DECISION_LOGIC_URI)
85                 .setCustomAudienceBuyers(CUSTOM_AUDIENCE_BUYERS)
86                 .setAdSelectionSignals(AD_SELECTION_SIGNALS)
87                 .setSellerSignals(SELLER_SIGNALS)
88                 .setPerBuyerSignals(PER_BUYER_SIGNALS)
89                 .setTrustedScoringSignalsUri(TRUSTED_SCORING_SIGNALS_URI);
90     }
91 
92     /**
93      * Creates an AdSelectionConfig object to be used in unit and integration tests Accepts a Uri
94      * decisionLogicUri to be used instead of the default
95      */
anAdSelectionConfig(@onNull Uri decisionLogicUri)96     public static AdSelectionConfig anAdSelectionConfig(@NonNull Uri decisionLogicUri) {
97         return new AdSelectionConfig.Builder()
98                 .setSeller(SELLER)
99                 .setDecisionLogicUri(decisionLogicUri)
100                 .setCustomAudienceBuyers(CUSTOM_AUDIENCE_BUYERS)
101                 .setAdSelectionSignals(AD_SELECTION_SIGNALS)
102                 .setSellerSignals(SELLER_SIGNALS)
103                 .setPerBuyerSignals(PER_BUYER_SIGNALS)
104                 .setTrustedScoringSignalsUri(TRUSTED_SCORING_SIGNALS_URI)
105                 .build();
106     }
107 
108     /**
109      * Creates an AdSelectionConfig object to be used in unit and integration tests Accepts a Uri
110      * decisionLogicUri to be used instead of the default
111      */
anAdSelectionConfig(@onNull AdTechIdentifier seller)112     public static AdSelectionConfig anAdSelectionConfig(@NonNull AdTechIdentifier seller) {
113         return new AdSelectionConfig.Builder()
114                 .setSeller(seller)
115                 .setDecisionLogicUri(DECISION_LOGIC_URI)
116                 .setCustomAudienceBuyers(CUSTOM_AUDIENCE_BUYERS)
117                 .setAdSelectionSignals(AD_SELECTION_SIGNALS)
118                 .setSellerSignals(SELLER_SIGNALS)
119                 .setPerBuyerSignals(PER_BUYER_SIGNALS)
120                 .setTrustedScoringSignalsUri(TRUSTED_SCORING_SIGNALS_URI)
121                 .build();
122     }
123 
124     /**
125      * @return returns a pre-loaded builder, where the internal members of the object can be changed
126      *     for the unit tests, this version of Ad Selection builder includes contextual Ads as well
127      * @hide
128      */
anAdSelectionConfigWithContextualAdsBuilder()129     public static AdSelectionConfig.Builder anAdSelectionConfigWithContextualAdsBuilder() {
130         return anAdSelectionConfigBuilder()
131                 .setBuyerContextualAds(ContextualAdsFixture.getBuyerContextualAdsMap());
132     }
133 }
134