bool ImageLoader::shouldLoadImmediately(const KURL& url) const { // We force any image loads which might require alt content through the asynchronous path so that we can add the shadow DOM // for the alt-text content when style recalc is over and DOM mutation is allowed again. if (!url.isNull()) { Resource* resource = memoryCache()->resourceForURL(url, m_element->document().fetcher()->getCacheIdentifier()); if (resource && !resource->errorOccurred()) return true; } return (m_loadingImageDocument || isHTMLObjectElement(m_element) || isHTMLEmbedElement(m_element) || url.protocolIsData()); }
TEST_F(ResourceFetcherTest, StartLoadAfterFrameDetach) { KURL secureURL(ParsedURLString, "https://secureorigin.test/image.png"); // Try to request a url. The request should fail, and a resource in an error // state should be returned, and no resource should be present in the cache. ResourceFetcher* fetcher = ResourceFetcher::create(nullptr); ResourceRequest resourceRequest(secureURL); resourceRequest.setRequestContext(WebURLRequest::RequestContextInternal); FetchRequest fetchRequest = FetchRequest(resourceRequest, FetchInitiatorInfo()); Resource* resource = RawResource::fetch(fetchRequest, fetcher); ASSERT_TRUE(resource); EXPECT_TRUE(resource->errorOccurred()); EXPECT_TRUE(resource->resourceError().isAccessCheck()); EXPECT_FALSE(memoryCache()->resourceForURL(secureURL)); // Start by calling startLoad() directly, rather than via requestResource(). // This shouldn't crash. fetcher->startLoad(RawResource::create(secureURL, Resource::Raw)); }