Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(734)

Unified Diff: third_party/WebKit/LayoutTests/http/tests/subresource_filter/picture-disallowed.html

Issue 2535383003: Collapse images disallowed by the Safe Browsing Subresource Filter. (Closed)
Patch Set: Initial draft. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/LayoutTests/http/tests/subresource_filter/picture-disallowed.html
diff --git a/third_party/WebKit/LayoutTests/http/tests/subresource_filter/picture-disallowed.html b/third_party/WebKit/LayoutTests/http/tests/subresource_filter/picture-disallowed.html
new file mode 100644
index 0000000000000000000000000000000000000000..7f3b2ac609088f33dbe2d3afd98d4fac8f3ac5b6
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/http/tests/subresource_filter/picture-disallowed.html
@@ -0,0 +1,55 @@
+<!DOCTYPE html>
+<script src="../resources/testharness.js"></script>
+<script src="../resources/testharnessreport.js"></script>
+<body>
+<script type="text/javascript">
+// Verify that the resource selection algorithm for <img> elements nested into
+// <picture> elements runs first, and only then is subresource filtering applied
+// to the selected resource.
+
+if (window.testRunner) {
+ // Inject a subresource filter to disallow 'beta.png' (but not 'alpha.png').
+ testRunner.setDisallowedSubresourcePathSuffixes(["beta.png"]);
+}
+
+function createPicture(selectedSourceUrl, notSelectedSourceUrl) {
+ let p = document.createElement("picture");
+ let s1 = document.createElement("source");
+ s1.srcset = notSelectedSourceUrl;
+ s1.type = "not-supported-type/to-disable-this-source";
+ p.appendChild(s1);
+ let s2 = document.createElement("source");
+ s2.srcset = selectedSourceUrl;
+ s2.type = "image/png";
+ p.appendChild(s2);
+ let i = document.createElement("img");
+ i.src = "totally-not-existing-image";
+ p.appendChild(i);
+ return p;
+}
+
+async_test(t => {
+ let p = createPicture("resources/alpha.png", "resources/beta.png");
+ let i = p.lastChild;
+ i.onerror = t.unreached_func();
+ i.onload = t.step_func_done(_ => {
+ assert_equals(i.clientWidth, 100, "Images that are not disallowed are displayed at their natural width.");
+ assert_equals(i.clientHeight, 100, "Images that are not disallowed are displayed at their natural height.");
+ });
+ document.body.appendChild(p);
+}, "Images whose selected source URL is not disallowed are still displayed as normal.");
+
+async_test(t => {
+ let p = createPicture("resources/beta.png", "resources/alpha.png");
+ let i = p.lastChild;
+ i.onload = t.unreached_func();
+ i.onerror = t.step_func_done(_ => {
+ assert_equals(i.clientWidth, 0, "Images that are disallowed are collapsed.");
+ assert_equals(i.clientHeight, 0, "Images that are disallowed are collapsed.");
+ assert_equals(i.naturalWidth, 0, "Images that are disallowed are not loaded.");
+ assert_equals(i.naturalHeight, 0, "Images that are disallowed are not loaded.");
+ });
+ document.body.appendChild(p);
+}, "Images whose selected source URL is disallowed are not loaded and collapsed in the layout.");
+
+</script>

Powered by Google App Engine
This is Rietveld 408576698