Skip to content

Commit

Permalink
Auto merge of #21399 - gterzian:error_on_placeholder_load, r=jdm
Browse files Browse the repository at this point in the history
Fire error when placeholder is loaded

<!-- Please describe your changes on the following line: -->

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [ ] `./mach build -d` does not report any errors
- [ ] `./mach test-tidy` does not report any errors
- [ ] These changes fix #21397 (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/21399)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo committed Aug 26, 2018
2 parents 6b6fc7d + 7b8d903 commit da36740
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 23 deletions.
51 changes: 28 additions & 23 deletions components/script/dom/htmlimageelement.rs
Expand Up @@ -303,38 +303,43 @@ impl HTMLImageElement {
document.loader_mut().fetch_async_background(request, action_sender);
}

/// Step 14 of https://html.spec.whatwg.org/multipage/#update-the-image-data
// Steps common to when an image has been loaded.
fn handle_loaded_image(&self, image: Arc<Image>, url: ServoUrl) {
self.current_request.borrow_mut().metadata = Some(ImageMetadata {
height: image.height,
width: image.width
});
self.current_request.borrow_mut().final_url = Some(url);
self.current_request.borrow_mut().image = Some(image);
self.current_request.borrow_mut().state = State::CompletelyAvailable;
LoadBlocker::terminate(&mut self.current_request.borrow_mut().blocker);
// Mark the node dirty
self.upcast::<Node>().dirty(NodeDamage::OtherNodeDamage);
}

/// Step 24 of https://html.spec.whatwg.org/multipage/#update-the-image-data
fn process_image_response(&self, image: ImageResponse) {
// TODO: Handle multipart/x-mixed-replace
let (trigger_image_load, trigger_image_error) = match (image, self.image_request.get()) {
(ImageResponse::Loaded(image, url), ImageRequestPhase::Current) |
(ImageResponse::Loaded(image, url), ImageRequestPhase::Current) => {
self.handle_loaded_image(image, url);
(true, false)
},
(ImageResponse::PlaceholderLoaded(image, url), ImageRequestPhase::Current) => {
self.current_request.borrow_mut().metadata = Some(ImageMetadata {
height: image.height,
width: image.width
});
self.current_request.borrow_mut().final_url = Some(url);
self.current_request.borrow_mut().image = Some(image);
self.current_request.borrow_mut().state = State::CompletelyAvailable;
LoadBlocker::terminate(&mut self.current_request.borrow_mut().blocker);
// Mark the node dirty
self.upcast::<Node>().dirty(NodeDamage::OtherNodeDamage);
self.handle_loaded_image(image, url);
(false, true)
},
(ImageResponse::Loaded(image, url), ImageRequestPhase::Pending) => {
self.abort_request(State::Unavailable, ImageRequestPhase::Pending);
self.image_request.set(ImageRequestPhase::Current);
self.handle_loaded_image(image, url);
(true, false)
},
(ImageResponse::Loaded(image, url), ImageRequestPhase::Pending) |
(ImageResponse::PlaceholderLoaded(image, url), ImageRequestPhase::Pending) => {
self.abort_request(State::Unavailable, ImageRequestPhase::Pending);
self.image_request.set(ImageRequestPhase::Current);
self.current_request.borrow_mut().metadata = Some(ImageMetadata {
height: image.height,
width: image.width
});
self.current_request.borrow_mut().final_url = Some(url);
self.current_request.borrow_mut().image = Some(image);
self.current_request.borrow_mut().state = State::CompletelyAvailable;
LoadBlocker::terminate(&mut self.current_request.borrow_mut().blocker);
self.upcast::<Node>().dirty(NodeDamage::OtherNodeDamage);
(true, false)
self.handle_loaded_image(image, url);
(false, true)
},
(ImageResponse::MetadataLoaded(meta), ImageRequestPhase::Current) => {
self.current_request.borrow_mut().state = State::PartiallyAvailable;
Expand Down
10 changes: 10 additions & 0 deletions tests/wpt/mozilla/meta/MANIFEST.json
Expand Up @@ -13976,6 +13976,12 @@
{}
]
],
"mozilla/img_placeholder_load.html": [
[
"/_mozilla/mozilla/img_placeholder_load.html",
{}
]
],
"mozilla/img_width_height.html": [
[
"/_mozilla/mozilla/img_width_height.html",
Expand Down Expand Up @@ -27043,6 +27049,10 @@
"e9f1b56ac4c49c146868123a9a73f55c85ae3771",
"testharness"
],
"mozilla/img_placeholder_load.html": [
"c90b0041a4bc4c255819839cec7265ae65454674",
"testharness"
],
"mozilla/img_width_height.html": [
"ec68ac34ee2a35aebb38eb297a33a1cd98f5893c",
"testharness"
Expand Down
21 changes: 21 additions & 0 deletions tests/wpt/mozilla/tests/mozilla/img_placeholder_load.html
@@ -0,0 +1,21 @@
<!DOCTYPE HTML>
<meta charset="utf-8">
<title>Loading a placeholder image should trigger an error on the img element</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<img>

<script>
async_test(function(t) {
var img = document.querySelector("img");
img.onload = this.step_func_done(function() {
assert_unreached("image.onload() was not supposed to be called");
});
img.onerror = this.step_func_done(function(e) {
assert_equals(e.type, "error", "image.onerror() called");
t.done();
});
img.src = "http://whatevertheheckawefawefawe.org/img.gif";
});
</script>

0 comments on commit da36740

Please sign in to comment.