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 public static final AdTechIdentifier SELLER = AdTechIdentifier.fromString("test.com"); 33 public static final AdTechIdentifier SELLER_1 = AdTechIdentifier.fromString("test2.com"); 34 35 // Uri Constants 36 public static final String DECISION_LOGIC_FRAGMENT = "/decisionFragment"; 37 public static final String TRUSTED_SCORING_SIGNAL_FRAGMENT = "/trustedScoringSignalsFragment"; 38 39 public static final Uri DECISION_LOGIC_URI = 40 CommonFixture.getUri(SELLER, DECISION_LOGIC_FRAGMENT); 41 42 public static final AdTechIdentifier BUYER = AdTechIdentifier.fromString("buyer.example.com"); 43 public static final AdTechIdentifier BUYER_1 = CommonFixture.VALID_BUYER_1; 44 public static final AdTechIdentifier BUYER_2 = CommonFixture.VALID_BUYER_2; 45 public static final AdTechIdentifier BUYER_3 = AdTechIdentifier.fromString("test3.com"); 46 public static final List<AdTechIdentifier> CUSTOM_AUDIENCE_BUYERS = 47 Arrays.asList(BUYER_1, BUYER_2, BUYER_3); 48 49 public static final AdSelectionSignals EMPTY_SIGNALS = AdSelectionSignals.EMPTY; 50 51 public static final AdSelectionSignals AD_SELECTION_SIGNALS = 52 AdSelectionSignals.fromString("{\"ad_selection_signals\":1}"); 53 54 public static final AdSelectionSignals SELLER_SIGNALS = 55 AdSelectionSignals.fromString("{\"test_seller_signals\":1}"); 56 57 public static final Map<AdTechIdentifier, AdSelectionSignals> PER_BUYER_SIGNALS = 58 Map.of( 59 BUYER_1, 60 AdSelectionSignals.fromString("{\"buyer_signals\":1}"), 61 BUYER_2, 62 AdSelectionSignals.fromString("{\"buyer_signals\":2}"), 63 BUYER_3, 64 AdSelectionSignals.fromString("{\"buyer_signals\":3}"), 65 BUYER, 66 AdSelectionSignals.fromString("{\"buyer_signals\":0}")); 67 68 public static final Uri TRUSTED_SCORING_SIGNALS_URI = 69 CommonFixture.getUri(SELLER, TRUSTED_SCORING_SIGNAL_FRAGMENT); 70 71 /** Creates an AdSelectionConfig object to be used in unit and integration tests */ anAdSelectionConfig()72 public static AdSelectionConfig anAdSelectionConfig() { 73 return anAdSelectionConfigBuilder().build(); 74 } 75 76 /** 77 * @return returns a pre-loaded builder, where the internal members of the object can be changed 78 * for the unit tests 79 */ anAdSelectionConfigBuilder()80 public static AdSelectionConfig.Builder anAdSelectionConfigBuilder() { 81 return new AdSelectionConfig.Builder() 82 .setSeller(SELLER) 83 .setDecisionLogicUri(DECISION_LOGIC_URI) 84 .setCustomAudienceBuyers(CUSTOM_AUDIENCE_BUYERS) 85 .setAdSelectionSignals(AD_SELECTION_SIGNALS) 86 .setSellerSignals(SELLER_SIGNALS) 87 .setPerBuyerSignals(PER_BUYER_SIGNALS) 88 .setTrustedScoringSignalsUri(TRUSTED_SCORING_SIGNALS_URI); 89 } 90 91 /** 92 * Creates an AdSelectionConfig object to be used in unit and integration tests Accepts a Uri 93 * decisionLogicUri to be used instead of the default 94 */ anAdSelectionConfig(@onNull Uri decisionLogicUri)95 public static AdSelectionConfig anAdSelectionConfig(@NonNull Uri decisionLogicUri) { 96 return new AdSelectionConfig.Builder() 97 .setSeller(SELLER) 98 .setDecisionLogicUri(decisionLogicUri) 99 .setCustomAudienceBuyers(CUSTOM_AUDIENCE_BUYERS) 100 .setAdSelectionSignals(AD_SELECTION_SIGNALS) 101 .setSellerSignals(SELLER_SIGNALS) 102 .setPerBuyerSignals(PER_BUYER_SIGNALS) 103 .setTrustedScoringSignalsUri(TRUSTED_SCORING_SIGNALS_URI) 104 .build(); 105 } 106 107 /** 108 * Creates an AdSelectionConfig object to be used in unit and integration tests Accepts a Uri 109 * decisionLogicUri to be used instead of the default 110 */ anAdSelectionConfig(@onNull AdTechIdentifier seller)111 public static AdSelectionConfig anAdSelectionConfig(@NonNull AdTechIdentifier seller) { 112 return new AdSelectionConfig.Builder() 113 .setSeller(seller) 114 .setDecisionLogicUri(DECISION_LOGIC_URI) 115 .setCustomAudienceBuyers(CUSTOM_AUDIENCE_BUYERS) 116 .setAdSelectionSignals(AD_SELECTION_SIGNALS) 117 .setSellerSignals(SELLER_SIGNALS) 118 .setPerBuyerSignals(PER_BUYER_SIGNALS) 119 .setTrustedScoringSignalsUri(TRUSTED_SCORING_SIGNALS_URI) 120 .build(); 121 } 122 123 /** 124 * @return returns a pre-loaded builder, where the internal members of the object can be changed 125 * for the unit tests, this version of Ad Selection builder includes contextual Ads as well 126 * @hide 127 */ anAdSelectionConfigWithSignedContextualAdsBuilder()128 public static AdSelectionConfig.Builder anAdSelectionConfigWithSignedContextualAdsBuilder() { 129 return anAdSelectionConfigBuilder() 130 .setPerBuyerSignedContextualAds( 131 SignedContextualAdsFixture.getBuyerSignedContextualAdsMap()); 132 } 133 } 134