summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/fledge/tentative/deprecated-render-url-replacements.https.window.js
blob: 4f8bc1cc7f0f5cd12b78a8cb05f787841b63f120 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
// META: script=/resources/testdriver.js
// META: script=/common/utils.js
// META: script=resources/fledge-util.sub.js
// META: script=/common/subset-tests.js
// META: timeout=long
// META: variant=?1-5
// META: variant=?6-10
// META: variant=?11-15
// META: variant=?16-last


"use strict;"

// This test ensures proper handling of deprecatedRenderURLReplacements within auctionConfigOverrides.
// It validates that these replacements are correctly applied to the winning bid's renderURL by
// injecting a URL with matching macros into an interest group and ensuring that a new url with
// the replacements in it, is tracked and observed.
const makeTest = ({
    // Test name
    name,
    // Overrides to the interest group.
    interestGroupOverrides = {},
    // Overrides to the auction config.
    auctionConfigOverrides = {},
    // This is what goes into the renderURL and is expected to be replaced.
    beforeReplacements,
    // This is what's expected when 'beforeReplacements' is replaced.
    afterReplacements,
}) => {
    subsetTest(promise_test, async test => {
        const uuid = generateUuid(test);
        let urlBeforeReplacements = createTrackerURL(window.location.origin, uuid, 'track_get', beforeReplacements);
        let urlAfterReplacements = createTrackerURL(window.location.origin, uuid, 'track_get', afterReplacements);
        interestGroupOverrides.ads = [{ renderURL: urlBeforeReplacements }];
        await joinInterestGroup(test, uuid, interestGroupOverrides);

        await runBasicFledgeAuctionAndNavigate(test, uuid, auctionConfigOverrides);
        await waitForObservedRequests(
            uuid,
            [urlAfterReplacements, createSellerReportURL(uuid), createBidderReportURL(uuid)]);
    }, name);
};

makeTest({
    name: 'Replacements with brackets.',
    auctionConfigOverrides: {
        deprecatedRenderURLReplacements: { '${EXAMPLE-MACRO}': 'SSP' }
    },
    beforeReplacements: "${EXAMPLE-MACRO}",
    afterReplacements: 'SSP',

});

makeTest({
    name: 'Replacements with percents.',
    auctionConfigOverrides: {
        deprecatedRenderURLReplacements: { '%%EXAMPLE-MACRO%%': 'SSP' }
    },
    beforeReplacements: "%%EXAMPLE-MACRO%%",
    afterReplacements: 'SSP',
});

makeTest({
    name: 'Multiple replacements within a URL.',
    auctionConfigOverrides: {
        deprecatedRenderURLReplacements: { '${EXAMPLE-MACRO1}': 'SSP1', '%%EXAMPLE-MACRO2%%': 'SSP2' }
    },
    beforeReplacements: "${EXAMPLE-MACRO1}/%%EXAMPLE-MACRO2%%",
    afterReplacements: 'SSP1/SSP2',
});

makeTest({
    name: 'Recursive and reduce size with brackets.',
    auctionConfigOverrides: {
        deprecatedRenderURLReplacements: { '${1}': '1' }
    },
    beforeReplacements: "${${${1}}}",
    afterReplacements: "${${1}}"
});

makeTest({
    name: 'Recursive and increase size with brackets.',
    auctionConfigOverrides: {
        deprecatedRenderURLReplacements: { '${1}': '${${1}}' }
    },
    beforeReplacements: "${1}",
    afterReplacements: "${${1}}"
});

makeTest({
    name: 'Replacements use a single pass with brackets.',
    auctionConfigOverrides: {
        deprecatedRenderURLReplacements: { '${1}': '${2}', '${2}': '${1}' }
    },
    beforeReplacements: "${1}${2}",
    afterReplacements: "${2}${1}"
});

makeTest({
    name: 'Multiple instances of same substitution string with brackets.',
    auctionConfigOverrides: {
        deprecatedRenderURLReplacements: { '${1}': '${2}' }
    },
    beforeReplacements: "{${1}${1}}",
    afterReplacements: "{${2}${2}}"
});

makeTest({
    name: 'Mismatched replacement with brackets.',
    auctionConfigOverrides: {
        deprecatedRenderURLReplacements: { '${2}': '${1}' }
    },
    beforeReplacements: "${1}",
    afterReplacements: "${1}"
});

makeTest({
    name: 'Recursive and reduce size with percents.',
    auctionConfigOverrides: {
        deprecatedRenderURLReplacements: { '%%1%%': '1' }
    },
    beforeReplacements: "%%%%1%%%%",
    afterReplacements: "%%1%%"
});

makeTest({
    name: 'Recursive and increase size with percents.',
    auctionConfigOverrides: {
        deprecatedRenderURLReplacements: { '%%1%%': '%%%%1%%%%' }
    },
    beforeReplacements: "%%1%%",
    afterReplacements: "%%%%1%%%%"
});

makeTest({
    name: 'Replacements use a single pass with percents.',
    auctionConfigOverrides: {
        deprecatedRenderURLReplacements: { '%%1%%': '%%2%%', '%%2%%': '%%1%%' }
    },
    beforeReplacements: "%%1%%%%2%%",
    afterReplacements: "%%2%%%%1%%"
});

makeTest({
    name: 'Multiple instances of same substitution string with percents.',
    auctionConfigOverrides: {
        deprecatedRenderURLReplacements: { '%%1%%': '%%2%%' }
    },
    beforeReplacements: "%%1%%%%1%%",
    afterReplacements: "%%2%%%%2%%"
});

makeTest({
    name: 'Mismatched replacement with percents.',
    auctionConfigOverrides: {
        deprecatedRenderURLReplacements: { '%%2%%': '%%1%%' }
    },
    beforeReplacements: "%%1%%",
    afterReplacements: "%%1%%"
});

makeTest({
    name: 'Case sensativity.',
    auctionConfigOverrides: {
        deprecatedRenderURLReplacements: { '%%foo%%': '%%bar%%' }
    },
    beforeReplacements: "%%FOO%%%%foo%%",
    afterReplacements: "%%FOO%%%%bar%%"
});

makeTest({
    name: 'Super macro, a macro with a macro inside it basically, with percents.',
    auctionConfigOverrides: {
        deprecatedRenderURLReplacements: { '%%%%foo%%%%': 'foo' }
    },
    beforeReplacements: "%%%%foo%%%%",
    afterReplacements: "foo"
});

makeTest({
    name: 'Super macro, with brackets.',
    auctionConfigOverrides: {
        deprecatedRenderURLReplacements: { '${${foo}}': 'foo' }
    },
    beforeReplacements: "${${foo}}",
    afterReplacements: "foo"
});

makeTest({
    name: 'Super macro, with both.',
    auctionConfigOverrides: {
        deprecatedRenderURLReplacements: { '${%%foo%%}': 'foo', '%%${bar}%%':'bar' }
    },
    beforeReplacements: "${%%foo%%}%%${bar}%%",
    afterReplacements: "foobar"
});