Commit 2fa0636a authored by Charlie Hu's avatar Charlie Hu Committed by Commit Bot

[Document Policy] Use unique image URLs for image policy tests

This CL uses unique image URLs for image policy tests, so that
the policy violation console messages do not get deduplicated.

This is the prework to land violation report deduplication for
document policy violation(https://chromium-review.googlesource.com/c/chromium/src/+/2405646).

Bug: 924684, 926199
Change-Id: Ib736799fb7370b639e8102361c0b0d4627f0ccb4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2416849
Commit-Queue: Charlie Hu <chenleihu@google.com>
Reviewed-by: default avatarJason Chase <chasej@chromium.org>
Cr-Commit-Position: refs/heads/master@{#812558}
parent 5b3265e3
......@@ -20,9 +20,12 @@ header("Document-Policy: oversized-images=2.0");
</head>
<body onload=loaded()>
<img src="resources/green-256x256.jpg" width="100" height="100">
<img src="resources/green-256x256.jpg" style="width: 100px; height: 100px">
<!-- Note: give each image a unique URL so that the violation report is actually
sent, instead of being ignored as a duplicate. -->
<img src="resources/green-256x256.jpg?id=1" width="100" height="100">
<img src="resources/green-256x256.jpg?id=2" style="width: 100px; height: 100px">
<script>
document.body.offsetTop;
</script>
</body>
\ No newline at end of file
</body>
......@@ -19,15 +19,18 @@ header("Document-Policy: oversized-images=2.0");
After the resize, there should not be any violations triggered.
It is expected that non of images on page are replaced by placeholders
after resize. (content in -expected.png)
-->
-->
<img src="resources/green-256x256.jpg" width="100" height="128">
<img src="resources/green-256x256.jpg" style="height: 100px; width: 128px">
<img src="resources/green-256x256.jpg" width="100" height="100">
<img src="resources/green-256x256.jpg" style="height: 100px; width: 100px">
<!-- Note: give each image a unique URL so that the violation report is
actually sent, instead of being ignored as a duplicate. -->
<img src="resources/green-256x256.jpg?id=1" width="100" height="128">
<img src="resources/green-256x256.jpg?id=2" style="height: 100px; width: 128px">
<img src="resources/green-256x256.jpg?id=3" width="100" height="100">
<img src="resources/green-256x256.jpg?id=4" style="height: 100px; width: 100px">
<script>
runAfterLayoutAndPaint(function() {
function changeImageSize() {
var images = document.getElementsByTagName('img');
for (var i = 0; i < images.length; i++) {
var image = images[i];
......@@ -39,7 +42,19 @@ header("Document-Policy: oversized-images=2.0");
image.style.height = "150px";
}
}
}, true);
}
const imgs = document.getElementsByTagName('img');
let unloaded_image_count = imgs.length;
for (const img of imgs) {
img.onload = () => {
unloaded_image_count--;
// Change image size after all images are loaded and painted.
if (unloaded_image_count === 0) {
runAfterLayoutAndPaint(changeImageSize, true);
}
};
}
</script>
</body>
......
......@@ -12,7 +12,9 @@ header("Document-Policy: oversized-images=2.0");
</script>
<body onload=loaded()>
<img srcset="resources/green-256x256.jpg 256w" sizes="100px" width="127" height="127">
<img srcset="resources/green-256x256.jpg 256w" sizes="100px" width="128" height="128">
<img srcset="resources/green-256x256.jpg 256w" sizes="100px" width="129" height="129">
<!-- Note: give each image a unique URL so that the violation report is
actually sent, instead of being ignored as a duplicate. -->
<img srcset="resources/green-256x256.jpg?id=1 256w" sizes="100px" width="127" height="127">
<img srcset="resources/green-256x256.jpg?id=2 256w" sizes="100px" width="128" height="128">
<img srcset="resources/green-256x256.jpg?id=3 256w" sizes="100px" width="129" height="129">
</body>
......@@ -16,9 +16,11 @@ header("Document-Policy: oversized-images=2.0");
<body onload=loaded()>
<!-- Should not trigger violation message. -->
<img src="resources/green-256x256.jpg" width="128" height="128" style="border: 10px solid red;">
<img src="resources/green-256x256.jpg?id=1" width="128" height="128" style="border: 10px solid red;">
<!-- Should generate a violation message each and get replaced with placeholder image. -->
<img src="resources/green-256x256.jpg" width="120" height="120" style="border: 10px solid red;">
<img src="resources/green-256x256.jpg" width="120" height="120" style="padding: 10px;">
<img src="resources/green-256x256.jpg" width="120" height="120" style="border: 10px solid red; padding: 5px;">
<img src="resources/green-256x256.jpg?id=2" width="120" height="120" style="border: 10px solid red;">
<img src="resources/green-256x256.jpg?id=3" width="120" height="120" style="padding: 10px;">
<img src="resources/green-256x256.jpg?id=4" width="120" height="120" style="border: 10px solid red; padding: 5px;">
<!-- Note: give each image a unique URL so that the violation report is
actually sent, instead of being ignored as a duplicate. -->
</body>
......@@ -2,6 +2,7 @@
header("Document-Policy: oversized-images=2.0");
?>
<!DOCTYPE html>
<head>
<base href="resources/">
<script>
......@@ -13,15 +14,18 @@ header("Document-Policy: oversized-images=2.0");
}
</script>
</head>
<!-- Note: give each image a unique URL so that the violation report is actually
sent, instead of being ignored as a duplicate. -->
<body onload=loaded()>
<div width="600" height="500">
<img src="green-256x256.jpg">
<img src="green-256x256.jpg" width="100" height="256">
<img src="green-256x256.jpg" style="height: 100px; width: 256px">
<img src="green-256x256.jpg" width="128" height="128" >
<img src="green-256x256.jpg" width="50" height="50">
<img src="green-256x256.jpg" style="height: 50px; width: 50px">
<img src="green-256x256.jpg" style="height: 1cm; width: 1cm">
<img src="green-256x256.jpg" style="height: 1cm; width: 1cm; border-radius: 5px; border: 1px solid blue;">
<img src="green-256x256.jpg?id=1">
<img src="green-256x256.jpg?id=2" width="100" height="256">
<img src="green-256x256.jpg?id=3" style="height: 100px; width: 256px">
<img src="green-256x256.jpg?id=4" width="128" height="128">
<img src="green-256x256.jpg?id=5" width="50" height="50">
<img src="green-256x256.jpg?id=6" style="height: 50px; width: 50px">
<img src="green-256x256.jpg?id=7" style="height: 1cm; width: 1cm">
<img src="green-256x256.jpg?id=8" style="height: 1cm; width: 1cm; border-radius: 5px; border: 1px solid blue;">
</div>
</body>
</body>
\ No newline at end of file
......@@ -22,6 +22,8 @@ header("Document-Policy: oversized-images=2.0");
</head>
<body onload=loaded()>
<!-- Note: give each image a unique URL so that the violation report is
actually sent, instead of being ignored as a duplicate. -->
<div style="display: inline-block;">
<p style="width: 100%;">
Following cases are for device pixel ratio = 1.0.<br>
......@@ -36,9 +38,9 @@ header("Document-Policy: oversized-images=2.0");
</tr>
<tr>
<td></td>
<td><img src="resources/green-256x256.jpg" width="127" height="127"></td>
<td><img src="resources/green-256x256.jpg" width="128" height="128"></td>
<td><img src="resources/green-256x256.jpg" width="129" height="129"></td>
<td><img src="resources/green-256x256.jpg?id=1" width="127" height="127"></td>
<td><img src="resources/green-256x256.jpg?id=2" width="128" height="128"></td>
<td><img src="resources/green-256x256.jpg?id=3" width="129" height="129"></td>
</tr>
</table>
</div>
......@@ -56,9 +58,9 @@ header("Document-Policy: oversized-images=2.0");
</tr>
<tr>
<td></td>
<td><img src="resources/green-256x256.jpg" width="63" height="63"></td>
<td><img src="resources/green-256x256.jpg" width="64" height="64"></td>
<td><img src="resources/green-256x256.jpg" width="65" height="65"></td>
<td><img src="resources/green-256x256.jpg?id=4" width="63" height="63"></td>
<td><img src="resources/green-256x256.jpg?id=5" width="64" height="64"></td>
<td><img src="resources/green-256x256.jpg?id=6" width="65" height="65"></td>
</tr>
</table>
</div>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment