mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-13 12:31:51 +00:00
LibWeb: Add SVGImageElement load and error events
This resolves all WPT timeouts in html/canvas/element/manual/imagebitmap We can now run an additional 6 tests and 126 subtests :) This also adds regression tests for this behavior.
This commit is contained in:
parent
c097f53875
commit
0c04bd6676
Notes:
github-actions[bot]
2024-10-16 22:00:25 +00:00
Author: https://github.com/beuss-git
Commit: 0c04bd6676
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1830
Reviewed-by: https://github.com/AtkinsSJ ✅
3 changed files with 49 additions and 0 deletions
|
@ -0,0 +1,3 @@
|
||||||
|
SUCCESS: "data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=="
|
||||||
|
FAIL: "file:///i-do-not-exist"
|
||||||
|
FAIL: "https://something.invalid"
|
|
@ -0,0 +1,41 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<script src="../include.js"></script>
|
||||||
|
<script type="text/javascript">
|
||||||
|
const SOURCES = [
|
||||||
|
"data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==", // Valid
|
||||||
|
"file:///i-do-not-exist", // invalid
|
||||||
|
"https://something.invalid", // invalid
|
||||||
|
];
|
||||||
|
|
||||||
|
const runTest = (source) => {
|
||||||
|
const svgNamespace = "http://www.w3.org/2000/svg";
|
||||||
|
const image = document.createElementNS(svgNamespace, "image");
|
||||||
|
const svg = document.createElementNS(svgNamespace, "svg");
|
||||||
|
svg.appendChild(image);
|
||||||
|
document.body.appendChild(svg);
|
||||||
|
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
image.addEventListener("load", () => {
|
||||||
|
resolve(`SUCCESS: "${source}"`);
|
||||||
|
document.body.removeChild(svg);
|
||||||
|
});
|
||||||
|
|
||||||
|
image.addEventListener("error", () => {
|
||||||
|
resolve(`FAIL: "${source}"`);
|
||||||
|
document.body.removeChild(svg);
|
||||||
|
});
|
||||||
|
|
||||||
|
image.setAttributeNS("http://www.w3.org/1999/xlink", "href", source);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
asyncTest(done => {
|
||||||
|
const promises = SOURCES.map(source => runTest(source));
|
||||||
|
|
||||||
|
Promise.allSettled(promises)
|
||||||
|
.then(results => {
|
||||||
|
results.forEach(result => println(result.value));
|
||||||
|
})
|
||||||
|
.finally(done);
|
||||||
|
});
|
||||||
|
</script>
|
|
@ -9,6 +9,7 @@
|
||||||
#include <LibJS/Heap/Heap.h>
|
#include <LibJS/Heap/Heap.h>
|
||||||
#include <LibWeb/Bindings/SVGImageElementPrototype.h>
|
#include <LibWeb/Bindings/SVGImageElementPrototype.h>
|
||||||
#include <LibWeb/DOM/DocumentObserver.h>
|
#include <LibWeb/DOM/DocumentObserver.h>
|
||||||
|
#include <LibWeb/DOM/Event.h>
|
||||||
#include <LibWeb/HTML/PotentialCORSRequest.h>
|
#include <LibWeb/HTML/PotentialCORSRequest.h>
|
||||||
#include <LibWeb/HTML/SharedResourceRequest.h>
|
#include <LibWeb/HTML/SharedResourceRequest.h>
|
||||||
#include <LibWeb/Layout/SVGImageBox.h>
|
#include <LibWeb/Layout/SVGImageBox.h>
|
||||||
|
@ -161,9 +162,13 @@ void SVGImageElement::fetch_the_document(URL::URL const& url)
|
||||||
}
|
}
|
||||||
set_needs_style_update(true);
|
set_needs_style_update(true);
|
||||||
document().set_needs_layout();
|
document().set_needs_layout();
|
||||||
|
|
||||||
|
dispatch_event(DOM::Event::create(realm(), HTML::EventNames::load));
|
||||||
},
|
},
|
||||||
[this] {
|
[this] {
|
||||||
m_load_event_delayer.clear();
|
m_load_event_delayer.clear();
|
||||||
|
|
||||||
|
dispatch_event(DOM::Event::create(realm(), HTML::EventNames::error));
|
||||||
});
|
});
|
||||||
|
|
||||||
if (m_resource_request->needs_fetching()) {
|
if (m_resource_request->needs_fetching()) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue