Skip to content

Commit

Permalink
Enable named budgets by default in header validator (#1461)
Browse files Browse the repository at this point in the history
  • Loading branch information
apasel422 authored Nov 11, 2024
1 parent 0548995 commit 9f7c822
Show file tree
Hide file tree
Showing 9 changed files with 7 additions and 43 deletions.
1 change: 0 additions & 1 deletion ts/src/header-validator/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ <h1>Attribution Reporting Header Validation</h1>
<p><label><input type=radio name=header value=info><code>Attribution-Reporting-Info</code></label>
<p><label><input type=checkbox checked disabled>Use Chromium's vendor-specific values</label> <a href="https://github.com/WICG/attribution-reporting-api/blob/main/params/chromium-params.md" target=_blank>(details)</a>
<p><label><input type=checkbox name=flex>Enable experimental Flexible Event fields</label> <a href="https://github.com/WICG/attribution-reporting-api/blob/main/flexible_event_config.md" target=_blank>(details)</a>
<p><label><input type=checkbox name=namedBudgets>Enable experimental Named Budgets fields</label> <a href="https://github.com/WICG/attribution-reporting-api/issues/1396" target=_blank>(details)</a>
</fieldset>
<fieldset id=output>
<legend>Validation Result</legend>
Expand Down
10 changes: 0 additions & 10 deletions ts/src/header-validator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ const sourceTypeFieldset =
const effective = document.querySelector('#effective')!

const flexCheckbox = form.elements.namedItem('flex') as HTMLInputElement
const namedBudgetsCheckbox = form.elements.namedItem(
'namedBudgets'
) as HTMLInputElement

function sourceType(): SourceType {
return parseSourceType(sourceTypeRadios.value)
Expand All @@ -34,30 +31,25 @@ function sourceType(): SourceType {
function validate(): void {
sourceTypeFieldset.disabled = true
flexCheckbox.disabled = true
namedBudgetsCheckbox.disabled = true

let v: validator.Validator<unknown>

switch (headerRadios.value) {
case 'source':
sourceTypeFieldset.disabled = false
flexCheckbox.disabled = false
namedBudgetsCheckbox.disabled = false
v = source.validator({
vsv: vsv.Chromium,
sourceType: sourceType(),
fullFlex: flexCheckbox.checked,
namedBudgets: namedBudgetsCheckbox.checked,
noteInfoGain: true,
})
break
case 'trigger':
flexCheckbox.disabled = false
namedBudgetsCheckbox.disabled = false
v = trigger.validator({
vsv: vsv.Chromium,
fullFlex: flexCheckbox.checked,
namedBudgets: namedBudgetsCheckbox.checked,
})
break
case 'os-source':
Expand Down Expand Up @@ -108,7 +100,6 @@ document.querySelector('#linkify')!.addEventListener('click', () => {
}

url.searchParams.set('flex', flexCheckbox.checked.toString())
url.searchParams.set('namedBudgets', namedBudgetsCheckbox.checked.toString())

void navigator.clipboard.writeText(url.toString())
})
Expand Down Expand Up @@ -146,6 +137,5 @@ if (st !== null && st in SourceType) {
sourceTypeRadios.value = st

flexCheckbox.checked = params.get('flex') === 'true'
namedBudgetsCheckbox.checked = params.get('namedBudgets') === 'true'

validate()
8 changes: 0 additions & 8 deletions ts/src/header-validator/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ interface Arguments {
file?: string

fullFlex: boolean
namedBudgets: boolean
sourceType?: SourceType

silent: boolean
Expand Down Expand Up @@ -49,11 +48,6 @@ const options = parse<Arguments>(
description: 'If true, parse experimental Full Flexible Event fields.',
},

namedBudgets: {
type: Boolean,
description: 'If true, parse experimental Named Budgets fields.',
},

silent: {
type: Boolean,
description: 'If true, suppress output.',
Expand Down Expand Up @@ -101,12 +95,10 @@ const out = validate<unknown>(
? trigger.validator({
vsv: vsv.Chromium,
fullFlex: options.fullFlex,
namedBudgets: options.namedBudgets,
})
: source.validator({
vsv: vsv.Chromium,
fullFlex: options.fullFlex,
namedBudgets: options.namedBudgets,
sourceType: options.sourceType,
})
)
Expand Down
9 changes: 0 additions & 9 deletions ts/src/header-validator/source.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ const testCases: TestCase[] = [
}
}`,
sourceType: SourceType.navigation,
parseNamedBudgets: true,
expected: Maybe.some({
aggregatableReportWindow: 3601,
aggregationKeys: new Map([['a', 15n]]),
Expand Down Expand Up @@ -3083,7 +3082,6 @@ const testCases: TestCase[] = [
"named_budgets": ["1"]
}`,
sourceType: SourceType.navigation,
parseNamedBudgets: true,
expectedErrors: [
{
msg: 'must be an object',
Expand All @@ -3100,7 +3098,6 @@ const testCases: TestCase[] = [
}
}`,
sourceType: SourceType.navigation,
parseNamedBudgets: true,
expectedErrors: [
{
msg: 'name exceeds max length per budget name (26 > 25)',
Expand All @@ -3117,7 +3114,6 @@ const testCases: TestCase[] = [
}
}`,
sourceType: SourceType.navigation,
parseNamedBudgets: true,
},
{
name: 'named-budgets-too-many',
Expand Down Expand Up @@ -3153,7 +3149,6 @@ const testCases: TestCase[] = [
}
}`,
sourceType: SourceType.navigation,
parseNamedBudgets: true,
expectedErrors: [
{
msg: 'exceeds the maximum number of keys (25)',
Expand All @@ -3172,7 +3167,6 @@ const testCases: TestCase[] = [
}
}`,
sourceType: SourceType.navigation,
parseNamedBudgets: true,
expectedErrors: [
{
msg: 'must be in the range [0, 65536]',
Expand All @@ -3189,7 +3183,6 @@ const testCases: TestCase[] = [
}
}`,
sourceType: SourceType.navigation,
parseNamedBudgets: true,
expectedErrors: [
{
msg: 'must be in the range [0, 65536]',
Expand All @@ -3206,7 +3199,6 @@ const testCases: TestCase[] = [
}
}`,
sourceType: SourceType.navigation,
parseNamedBudgets: true,
expectedErrors: [
{
msg: 'must be a number',
Expand All @@ -3224,7 +3216,6 @@ testCases.forEach((tc) =>
sourceType: tc.sourceType ?? SourceType.navigation,
fullFlex: tc.parseFullFlex,
noteInfoGain: tc.noteInfoGain,
namedBudgets: tc.parseNamedBudgets,
})
)
)
9 changes: 2 additions & 7 deletions ts/src/header-validator/to-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ type Source = CommonDebug &

export interface Options {
fullFlex?: boolean | undefined
namedBudgets?: boolean | undefined
}

export function serializeSource(
Expand Down Expand Up @@ -248,9 +247,7 @@ export function serializeSource(
...ifNotNull('attribution_scopes', s.attributionScopes, (v) =>
serializeAttributionScopes(v)
),
...(opts.namedBudgets && {
named_budgets: Object.fromEntries(s.namedBudgets),
}),
named_budgets: Object.fromEntries(s.namedBudgets),
}

return stringify(source)
Expand Down Expand Up @@ -410,9 +407,7 @@ export function serializeTrigger(
serializeAggregatableDedupKey
),

...(opts.namedBudgets && {
named_budgets: Array.from(t.namedBudgets, serializeNamedBudget),
}),
named_budgets: Array.from(t.namedBudgets, serializeNamedBudget),

aggregatable_source_registration_time: t.aggregatableSourceRegistrationTime,

Expand Down
1 change: 0 additions & 1 deletion ts/src/header-validator/trigger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1769,7 +1769,6 @@ testCases.forEach((tc) =>
trigger.validator({
vsv: { ...vsv.Chromium, ...tc.vsv },
fullFlex: tc.parseFullFlex,
namedBudgets: tc.parseNamedBudgets,
})
)
)
1 change: 0 additions & 1 deletion ts/src/header-validator/validate-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export const UINT32_MAX: number = 2 ** 32 - 1
export interface RegistrationOptions {
vsv: VendorSpecificValues
fullFlex?: boolean | undefined
namedBudgets?: boolean | undefined
}

export class RegistrationContext<
Expand Down
7 changes: 4 additions & 3 deletions ts/src/header-validator/validate-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -749,9 +749,10 @@ function source(j: Json, ctx: Context): Maybe<Source> {
'attribution_scopes',
withDefault(attributionScopes, null)
),
namedBudgets: ctx.opts.namedBudgets
? field('named_budgets', withDefault(namedBudgets, new Map()))
: () => Maybe.some(new Map()),
namedBudgets: field(
'named_budgets',
withDefault(namedBudgets, new Map())
),

...commonDebugFields,
...priorityField,
Expand Down
4 changes: 1 addition & 3 deletions ts/src/header-validator/validate-trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,9 +392,7 @@ function trigger(j: Json, ctx: Context): Maybe<Trigger> {
'aggregatable_deduplication_keys',
withDefault(aggregatableDedupKeys, [])
),
namedBudgets: ctx.opts.namedBudgets
? field('named_budgets', withDefault(namedBudgets, []))
: () => Maybe.some([]),
namedBudgets: field('named_budgets', withDefault(namedBudgets, [])),
aggregatableSourceRegistrationTime: () => aggregatableSourceRegTimeVal,
eventTriggerData: field(
'event_trigger_data',
Expand Down

0 comments on commit 9f7c822

Please sign in to comment.