Skip to content

Commit 789953e

Browse files
lflores-msmertcanaltin
authored andcommitted
Initial implementation for network-efficiency-guardrails
Adds Document Policy configuration point for network-efficiency-guardrails and base implementation for HTTP resource compression check. Bug: 434744664 Change-Id: I708e06e1a37f1ed8652c81460bfaa952077b5fa6 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6844536 Reviewed-by: Ari Chivukula <[email protected]> Reviewed-by: Takashi Toyoshima <[email protected]> Commit-Queue: Luis Flores <[email protected]> Cr-Commit-Position: refs/heads/main@{#1515624}
1 parent 627d506 commit 789953e

8 files changed

+112
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<!DOCTYPE html>
2+
<html>
3+
4+
<head>
5+
<script src='/resources/testharness.js'></script>
6+
<script src='/resources/testharnessreport.js'></script>
7+
8+
<link rel="stylesheet" href="./resources/compressed.css?pipe=gzip">
9+
</head>
10+
11+
<body>
12+
<script>
13+
document.addEventListener('DOMContentLoaded', () => {
14+
const check_report_format = ([reports, observer], resourceUrl) => {
15+
const report = reports[0];
16+
assert_equals(report.type, "document-policy-violation");
17+
assert_equals(report.body.featureId, "network-efficiency-guardrails");
18+
assert_equals(report.body.disposition, "enforce");
19+
assert_equals(report.body.sourceFile, resourceUrl);
20+
};
21+
22+
promise_test(async t => {
23+
const report = new Promise(resolve => {
24+
new ReportingObserver((reports, observer) => resolve([reports, observer]),
25+
{ types: ['document-policy-violation'], buffered: false }).observe();
26+
});
27+
28+
let response = await fetch('./resources/compressed.json');
29+
document.getElementById('monitor').value = await response.text();
30+
31+
check_report_format(await report, response.url);
32+
}, "NetworkEfficiencyGuardrails json compression");
33+
});
34+
</script>
35+
<h1>Network Efficiency Guardrails</h1>
36+
<textarea id="monitor" rows="5" cols="80" readonly></textarea>
37+
</body>
38+
39+
</html>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Document-Policy: network-efficiency-guardrails
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<!DOCTYPE html>
2+
<html>
3+
4+
<head>
5+
<script src='/resources/testharness.js'></script>
6+
<script src='/resources/testharnessreport.js'></script>
7+
8+
<link rel="stylesheet" href="./resources/compressed.css">
9+
</head>
10+
11+
<body>
12+
<script>
13+
const check_report_format = ([reports, observer]) => {
14+
const report = reports[0];
15+
assert_equals(report.type, "document-policy-violation");
16+
assert_equals(report.body.featureId, "network-efficiency-guardrails");
17+
assert_equals(report.body.disposition, "report");
18+
assert_equals(report.body.sourceFile, document.styleSheets[0].href);
19+
};
20+
21+
promise_test(async t => {
22+
const report = new Promise(resolve => {
23+
new ReportingObserver((reports, observer) => resolve([reports, observer]),
24+
{ types: ['document-policy-violation'], buffered: true }).observe();
25+
});
26+
check_report_format(await report);
27+
}, "NetworkEfficiencyGuardrails compression");
28+
</script>
29+
<h1>Network Efficiency Guardrails</h1>
30+
</body>
31+
32+
</html>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Document-Policy-Report-Only: network-efficiency-guardrails
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<!DOCTYPE html>
2+
<html>
3+
4+
<head>
5+
<script src='/resources/testharness.js'></script>
6+
<script src='/resources/testharnessreport.js'></script>
7+
8+
<link rel="stylesheet" href="./resources/compressed.css">
9+
</head>
10+
11+
<body>
12+
<script>
13+
const check_report_format = ([reports, observer]) => {
14+
const report = reports[0];
15+
assert_equals(report.type, "document-policy-violation");
16+
assert_equals(report.body.featureId, "network-efficiency-guardrails");
17+
assert_equals(report.body.disposition, "enforce");
18+
assert_equals(report.body.sourceFile, document.styleSheets[0].href);
19+
};
20+
21+
promise_test(async t => {
22+
const report = new Promise(resolve => {
23+
new ReportingObserver((reports, observer) => resolve([reports, observer]),
24+
{ types: ['document-policy-violation'], buffered: true }).observe();
25+
});
26+
check_report_format(await report);
27+
}, "NetworkEfficiencyGuardrails compression");
28+
</script>
29+
<h1>Network Efficiency Guardrails</h1>
30+
</body>
31+
32+
</html>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Document-Policy: network-efficiency-guardrails
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
h1 {
2+
color: red;
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"policy": "network-efficiency-guardrails"
3+
}

0 commit comments

Comments
 (0)