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