Skip to content

Commit

Permalink
[Save Data Client Hint] (3) Add/Update WPTs
Browse files Browse the repository at this point in the history
These WPTs have to be internal as there is no external way to enable
data saver mode. For launch, this is sufficient as it verifies the
behavior of the ch-save-data permissions policy.
https://groups.google.com/a/chromium.org/g/blink-dev/c/HR7tWmewbSA/m/8lAP0lZVEwAJ

This CL is part of a series:
(1) Remove legacy feature
(2) Implement as Client Hint
(3) Add/Update WPTs

Bug: 1293443
Change-Id: I18516ef01236fc109ca726c946ad7c8e66aaea60
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3582420
Reviewed-by: Ali Beyad <abeyad@chromium.org>
Auto-Submit: Ari Chivukula <arichiv@chromium.org>
Commit-Queue: Ari Chivukula <arichiv@chromium.org>
Cr-Commit-Position: refs/heads/main@{#992343}
  • Loading branch information
arichiv authored and Chromium LUCI CQ committed Apr 14, 2022
1 parent 5fc8082 commit da36459
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 41 deletions.
@@ -0,0 +1,28 @@
<html>
<title>Tests for 'Save-Data' header when Data Saver is disabled and the policy is *.</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
internals.setSaveDataEnabled(false);
</script>
<iframe allow="ch-save-data *;" srcdoc="
<!DOCTYPE html>
<script src='/resources/testharness.js'></script>
<script src='/resources/testharnessreport.js'></script>
<script>
var CHECK_PATH = './resources/check-save-data-header.php';
var METHODS = ['GET', 'POST', 'PUT'];
var REQUESTS =
METHODS.map(method => new Request(CHECK_PATH, {method: method}));
window.top.promise_test(t => {
return Promise.all(REQUESTS.map(request => fetch(request.clone())))
.then(responses => Promise.all(responses.map(response => response.text())))
.then(texts => {
for (var i = 0; i < METHODS.length; ++i) {
assert_equals(texts[i], 'No Save-Data');
}
});
}, 'Save-Data should not be sent when disabled if policy is *.');
</script>
"></iframe>
</html>
@@ -0,0 +1,28 @@
<html>
<title>Tests for 'Save-Data' header when Data Saver is disabled and the policy is 'none'.</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
internals.setSaveDataEnabled(false);
</script>
<iframe allow="ch-save-data 'none';" srcdoc="
<!DOCTYPE html>
<script src='/resources/testharness.js'></script>
<script src='/resources/testharnessreport.js'></script>
<script>
var CHECK_PATH = './resources/check-save-data-header.php';
var METHODS = ['GET', 'POST', 'PUT'];
var REQUESTS =
METHODS.map(method => new Request(CHECK_PATH, {method: method}));
window.top.promise_test(t => {
return Promise.all(REQUESTS.map(request => fetch(request.clone())))
.then(responses => Promise.all(responses.map(response => response.text())))
.then(texts => {
for (var i = 0; i < METHODS.length; ++i) {
assert_equals(texts[i], 'No Save-Data');
}
});
}, 'Save-Data should not be sent when disabled if policy is none.');
</script>
"></iframe>
</html>
@@ -1,42 +1,28 @@
<html>
<title>Tests for 'Save-Data' header.</title>
<title>Tests for 'Save-Data' header when Data Saver is disabled.</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<script> internals.setSaveDataEnabled(false); </script>

<script>
internals.setSaveDataEnabled(false);
</script>
<iframe srcdoc="
<!DOCTYPE html>
<script src='/resources/testharness.js'></script>
<script src='/resources/testharnessreport.js'></script>
<script>
var CHECK_PATH = './resources/check-save-data-header.php';
var METHODS = ['GET', 'POST', 'PUT'];
var REQUESTS =
METHODS.map(method => new Request(CHECK_PATH, {method: method}));
internals.setSaveDataEnabled(false);
window.top.promise_test(t => {
internals.setSaveDataEnabled(false);
return Promise.all(REQUESTS.map(request => fetch(request.clone())))
.then(responses => Promise.all(responses.map(response => response.text())))
.then(texts => {
for (var i = 0; i < METHODS.length; ++i) {
assert_equals(
texts[i], 'No Save-Data',
'Save-Data header should not be sent when disabled. method: ' +
METHODS[i]);
assert_equals(texts[i], 'No Save-Data');
}
});
}, 'fetch() from document with Data-Saver disabled.');
// Tests for dedicated workers and shared workers are implemented as browser
// tests because they are requested from the browser process, and
// internals.setSaveDataEnable() doesn't work in those cases.
}, 'Save-Data should not be sent when disabled.');
</script>
"></iframe>

</html>
@@ -0,0 +1,28 @@
<html>
<title>Tests for 'Save-Data' header when Data Saver is enabled and the policy is *.</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
internals.setSaveDataEnabled(true);
</script>
<iframe allow="ch-save-data *;" srcdoc="
<!DOCTYPE html>
<script src='/resources/testharness.js'></script>
<script src='/resources/testharnessreport.js'></script>
<script>
var CHECK_PATH = './resources/check-save-data-header.php';
var METHODS = ['GET', 'POST', 'PUT'];
var REQUESTS =
METHODS.map(method => new Request(CHECK_PATH, {method: method}));
window.top.promise_test(t => {
return Promise.all(REQUESTS.map(request => fetch(request.clone())))
.then(responses => Promise.all(responses.map(response => response.text())))
.then(texts => {
for (var i = 0; i < METHODS.length; ++i) {
assert_equals(texts[i], 'Save-Data: on');
}
});
}, 'Save-Data should be sent when enabled if policy is *.');
</script>
"></iframe>
</html>
@@ -0,0 +1,28 @@
<html>
<title>Tests for 'Save-Data' header when Data Saver is enabled and the policy is 'none'.</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
internals.setSaveDataEnabled(true);
</script>
<iframe allow="ch-save-data 'none';" srcdoc="
<!DOCTYPE html>
<script src='/resources/testharness.js'></script>
<script src='/resources/testharnessreport.js'></script>
<script>
var CHECK_PATH = './resources/check-save-data-header.php';
var METHODS = ['GET', 'POST', 'PUT'];
var REQUESTS =
METHODS.map(method => new Request(CHECK_PATH, {method: method}));
window.top.promise_test(t => {
return Promise.all(REQUESTS.map(request => fetch(request.clone())))
.then(responses => Promise.all(responses.map(response => response.text())))
.then(texts => {
for (var i = 0; i < METHODS.length; ++i) {
assert_equals(texts[i], 'No Save-Data');
}
});
}, 'Save-Data should not be sent when enabled if policy is none.');
</script>
"></iframe>
</html>
@@ -1,43 +1,28 @@
<html>
<title>Tests for 'Save-Data' header.</title>
<title>Tests for 'Save-Data' header when Data Saver is enabled.</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<!-- Enable save data header and the JavaScript attribute -->
<script> internals.setSaveDataEnabled(true); </script>

<script>
internals.setSaveDataEnabled(true);
</script>
<iframe srcdoc="
<!DOCTYPE html>
<script src='/resources/testharness.js'></script>
<script src='/resources/testharnessreport.js'></script>
<script>
internals.setSaveDataEnabled(true);
var CHECK_PATH = './resources/check-save-data-header.php';
var METHODS = ['GET', 'POST', 'PUT'];
var REQUESTS =
METHODS.map(method => new Request(CHECK_PATH, {method: method}));
window.top.promise_test(t => {
internals.setSaveDataEnabled(true);
return Promise.all(REQUESTS.map(request => fetch(request.clone())))
.then(responses => Promise.all(responses.map(response => response.text())))
.then(texts => {
for (var i = 0; i < METHODS.length; ++i) {
assert_equals(
texts[i], 'Save-Data: on',
'Save-Data header should be sent when disabled. method: ' +
METHODS[i]);
assert_equals(texts[i], 'Save-Data: on');
}
});
}, 'fetch() from document with Data-Saver enabled.');
// Tests for dedicated workers and shared workers are implemented as browser
// tests because they are requested from the browser process, and
// internals.setSaveDataEnable() doesn't work in those cases.
}, 'Save-Data should be sent when enabled.');
</script>
"></iframe>

</html>

0 comments on commit da36459

Please sign in to comment.