Skip to content

Commit

Permalink
Import wpt@eb25c93dec4bd85f69baae714bc10dc56897f7f3
Browse files Browse the repository at this point in the history
Using wpt-import in Chromium 3fb9aa7.
With Chromium commits locally applied on WPT:
4dc1449 "Upstream fragmentation/table-with-border-spacing.html"


Note to sheriffs: This CL imports external tests and adds
expectations for those tests; if this CL is large and causes
a few new failures, please fix the failures by adding new
lines to TestExpectations rather than reverting. See:
https://chromium.googlesource.com/chromium/src/+/main/docs/testing/web_platform_tests.md

Directory owners for changes in this CL:
npm@chromium.org:
  external/wpt/largest-contentful-paint

NOAUTOREVERT=true
R=rubber-stamper@appspot.gserviceaccount.com

No-Export: true
Cq-Include-Trybots: luci.chromium.try:linux-wpt-identity-fyi-rel,linux-wpt-input-fyi-rel,linux-blink-rel
Change-Id: I9c35b73c15d519a344c5868ccfb6ebdf44e27b7f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3645430
Auto-Submit: WPT Autoroller <wpt-autoroller@chops-service-accounts.iam.gserviceaccount.com>
Commit-Queue: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Cr-Commit-Position: refs/heads/main@{#1002858}
  • Loading branch information
Chromium WPT Sync authored and Chromium LUCI CQ committed May 12, 2022
1 parent fe276a6 commit e9b2da4
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 1 deletion.
2 changes: 1 addition & 1 deletion third_party/blink/web_tests/external/Version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Version: f33556247265212bc9d4569ea4ac9e24a678691b
Version: eb25c93dec4bd85f69baae714bc10dc56897f7f3
23 changes: 23 additions & 0 deletions third_party/blink/web_tests/external/WPT_BASE_MANIFEST_8.json
Original file line number Diff line number Diff line change
Expand Up @@ -368881,6 +368881,15 @@
{}
]
],
"table": {
"border-spacing.html": [
"fc5e87e35dde4b4cb2ed5c457f5cd22ec73d96b0",
[
null,
{}
]
]
},
"transform-010.html": [
"8418551cdc8172862d57d8359a732968b3467aba",
[
Expand Down Expand Up @@ -465029,6 +465038,13 @@
{}
]
],
"sandbox-inherit-to-blank-document-unsandboxed-frame.html": [
"7040d07860eb4762976b102287a7b1453695c115",
[
null,
{}
]
],
"sandbox-inherit-to-blank-document-unsandboxed.html": [
"f60ab0da30ad82ff9a87d41af60fe68c96d29939",
[
Expand Down Expand Up @@ -480753,6 +480769,13 @@
{}
]
],
"image-upscaling.html": [
"a4f7d8079d3b9a75f79b896743cbc018cc81c9ce",
[
null,
{}
]
],
"initially-invisible-images.html": [
"d0bede67614ac3b0ca413dbc380457f32ab0d1f0",
[
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<!DOCTYPE HTML>
<meta charset=utf-8>
<title>Largest Contentful Paint: largest image is reported.</title>
<body>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/largest-contentful-paint-helpers.js"></script>
<script src="/common/utils.js"></script>
<script>
setup(() =>
assert_implements(window.LargestContentfulPaint, "LargestContentfulPaint is not implemented"));

const imageURL = `${window.location.origin}/images/blue.png`;
async function load_image_and_get_lcp_size(t, imageStyle = {}, containerStyle = {}) {
const popup = window.open('about:blank');
t.add_cleanup(() => popup.close());
const image = popup.document.createElement('img');
image.src = imageURL;

// We decode the image to get the natural size (though it's a constant)
await image.decode();
const naturalSize = image.width * image.height;

const container = popup.document.createElement('div');
container.appendChild(image);
const applyStyle = (el, style = {}) =>
Object.entries(style).forEach(([k, v]) => el.style.setProperty(k, v));

applyStyle(image, imageStyle);
applyStyle(container, containerStyle);
image.id = token();
const entryReported = new Promise(resolve => new popup.PerformanceObserver(entryList => {
entryList.getEntries().forEach(entry => {
if (entry.id === image.id)
resolve(entry.size);
});
}).observe({type: 'largest-contentful-paint'}));
popup.document.body.appendChild(container);
const timeout = new Promise(resolve => t.step_timeout(() => resolve('not reported'), 1000));
return {lcpSize: (await Promise.any([entryReported, timeout])), naturalSize};
}

// We set the image to display: none when testing background, so that only the background is reported
// and not the image itself
const load_background_image_and_get_lcp_size = (t, style) =>
load_image_and_get_lcp_size(t, {display: 'none'},
{
position: 'absolute',
'background-image': `url(${imageURL})`,
...style,
});

promise_test(async t => {
const {naturalSize, lcpSize} = await load_image_and_get_lcp_size(t);
assert_equals(lcpSize, naturalSize);
}, 'Non-scaled image should report the natural size');

promise_test(async t => {
const {naturalSize, lcpSize} = await load_image_and_get_lcp_size(t, {width: '50px', height: '50px'});
assert_equals(lcpSize, 50 * 50);
}, 'A downscaled image (width/height) should report the displayed size');

promise_test(async t => {
const {naturalSize, lcpSize} = await load_image_and_get_lcp_size(t, {transform: 'scale(0.5)'});
assert_equals(Math.floor(lcpSize), Math.floor(naturalSize / 4));
}, 'A downscaled image (using scale) should report the displayed size');

promise_test(async t => {
const {naturalSize, lcpSize} = await load_image_and_get_lcp_size(t, {width: '500px', height: '500px'});
assert_equals(lcpSize, naturalSize);
}, 'An upscaled image (width/height) should report the natural size');

promise_test(async t => {
const {naturalSize, lcpSize} = await load_image_and_get_lcp_size(t, {transform: 'scale(2)'});
assert_equals(Math.floor(lcpSize), Math.floor(naturalSize));
}, 'An upscaled image (using scale) should report the natural size');

promise_test(async t => {
const {naturalSize, lcpSize} = await load_image_and_get_lcp_size(t, {'object-size': '300px 300px'});
assert_equals(Math.floor(lcpSize), Math.floor(naturalSize));
}, 'An upscaled image (using object-size) should report the natural size');

promise_test(async t => {
const {naturalSize, lcpSize} = await load_image_and_get_lcp_size(t, {'object-position': '-100px 0'});
assert_equals(lcpSize, 3498);
}, 'An intersecting element with a partial-intersecting image (object-position) should report the image intersection');

promise_test(async t => {
const {naturalSize, lcpSize} = await load_background_image_and_get_lcp_size(t, {width: '50px', height: '50px'});
assert_equals(lcpSize, 50 * 50);
}, 'A background image larger than the container should report the container size');

promise_test(async t => {
const {naturalSize, lcpSize} = await load_background_image_and_get_lcp_size(t, {width: '300px', height: '300px'});
assert_equals(lcpSize, naturalSize);
}, 'A background image smaller than the container should report the natural size');

promise_test(async t => {
const {naturalSize, lcpSize} = await load_background_image_and_get_lcp_size(t, {width: '300px', height: '300px', 'background-size': '10px 10x'});
assert_equals(lcpSize, 100);
}, 'A scaled-down background image should report the background size');
</script>
</body>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
This is a testharness.js-based test.
PASS Non-scaled image should report the natural size
PASS A downscaled image (width/height) should report the displayed size
PASS A downscaled image (using scale) should report the displayed size
PASS An upscaled image (width/height) should report the natural size
FAIL An upscaled image (using scale) should report the natural size assert_equals: expected 14098 but got 34652
PASS An upscaled image (using object-size) should report the natural size
PASS An intersecting element with a partial-intersecting image (object-position) should report the image intersection
FAIL A background image larger than the container should report the container size assert_equals: expected (number) 2500 but got (string) "not reported"
FAIL A background image smaller than the container should report the natural size assert_equals: expected (number) 14098 but got (string) "not reported"
FAIL A scaled-down background image should report the background size assert_equals: expected (number) 100 but got (string) "not reported"
Harness: the test ran to completion.

0 comments on commit e9b2da4

Please sign in to comment.