From 60ac9773d29a0d761d8be42878b471c755a59779 Mon Sep 17 00:00:00 2001 From: Holger Dürer Date: Wed, 7 Jun 2017 18:29:10 +0100 Subject: Catch any errors thrown during url-retrieve. On Emacs24 I've been able to reliably fail url fetching which exposed issues in loading a timeline (it aborts the loading). This catches any errors, marking the image load as failed so that we won't retry (retries are a TODO item I guess) and then succeeds the function so the rest of the timeline loading can proceed. --- test/mastodon-media-tests.el | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'test/mastodon-media-tests.el') diff --git a/test/mastodon-media-tests.el b/test/mastodon-media-tests.el index 4bb89c7..7031e90 100644 --- a/test/mastodon-media-tests.el +++ b/test/mastodon-media-tests.el @@ -111,6 +111,24 @@ (let ((mastodon-media--preview-max-height 321)) (should (eq :called-as-expected (mastodon-media--load-image-from-url url 'media-link 7 5)))))))) +(ert-deftest mastodon-media:load-image-from-url:url-fetching-fails () + "Should cope with failures in url-retrieve." + (let ((url "http://example.org/image.png") + (mastodon-media--avatar-height 123)) + (with-mock + (mock (image-type-available-p 'imagemagick) => t) + (mock (create-image * 'imagemagick t :height 123) => '(image foo)) + (stub url-retrieve => (error "url-retrieve failed")) + + (with-temp-buffer + (insert (concat "Start:" + (mastodon-media--get-avatar-rendering "http://example.org/img.png") + ":rest")) + + (should (eq :loading-failed (mastodon-media--load-image-from-url url 'avatar 7 1))) + ;; the media state was updated so we won't load this again: + (should (eq 'loading-failed (get-text-property 7 'media-state))))))) + (ert-deftest mastodon-media:process-image-response () "Should process the HTTP response and adjust the source buffer." (with-temp-buffer -- cgit v1.2.3