// Regression test for crbug.com/645331, where a resource client gets callbacks // after the document is shutdown and we have no frame. TEST_F(CSSPreloadScannerTest, DoNotExpectValidDocument) { std::unique_ptr<DummyPageHolder> dummyPageHolder = DummyPageHolder::create(IntSize(500, 500)); dummyPageHolder->document().settings()->setCSSExternalScannerNoPreload(true); HTMLResourcePreloader* preloader = HTMLResourcePreloader::create(dummyPageHolder->document()); KURL url(ParsedURLString, "http://127.0.0.1/foo.css"); CSSStyleSheetResource* resource = CSSStyleSheetResource::createForTest(ResourceRequest(url), "utf-8"); resource->setStatus(Resource::Pending); PreloadSuppressingCSSPreloaderResourceClient* resourceClient = new PreloadSuppressingCSSPreloaderResourceClient(resource, preloader); dummyPageHolder->document().shutdown(); const char* data = "@import url('http://127.0.0.1/preload.css');"; resource->appendData(data, strlen(data)); EXPECT_EQ(1u, resourceClient->m_preloads.size()); EXPECT_EQ("http://127.0.0.1/preload.css", resourceClient->m_preloads.first()->resourceURL()); }
// Regression test for crbug.com/645331, where a resource client gets callbacks // after the document is shutdown and we have no frame. TEST_F(CSSPreloadScannerTest, DoNotExpectValidDocument) { std::unique_ptr<DummyPageHolder> dummyPageHolder = DummyPageHolder::create(IntSize(500, 500)); dummyPageHolder->document().settings()->setCSSExternalScannerNoPreload(true); MockHTMLResourcePreloader* preloader = new MockHTMLResourcePreloader(dummyPageHolder->document()); KURL url(ParsedURLString, "http://127.0.0.1/foo.css"); CSSStyleSheetResource* resource = CSSStyleSheetResource::createForTest(ResourceRequest(url), "utf-8"); resource->setStatus(Resource::Pending); PreloadRecordingCSSPreloaderResourceClient* resourceClient = new PreloadRecordingCSSPreloaderResourceClient(resource, preloader); dummyPageHolder->document().shutdown(); const char* data = "@import url('http://127.0.0.1/preload.css');"; resource->appendData(data, strlen(data)); // Do not expect to gather any preloads, as the document loader is invalid, // which means we can't notify WebLoadingBehaviorData of the preloads. EXPECT_EQ(0u, resourceClient->m_preloadUrls.size()); }
TEST_F(CSSPreloadScannerTest, ScanFromResourceClient) { std::unique_ptr<DummyPageHolder> dummyPageHolder = DummyPageHolder::create(IntSize(500, 500)); dummyPageHolder->document().settings()->setCSSExternalScannerNoPreload(true); MockHTMLResourcePreloader* preloader = new MockHTMLResourcePreloader(dummyPageHolder->document()); KURL url(ParsedURLString, "http://127.0.0.1/foo.css"); CSSStyleSheetResource* resource = CSSStyleSheetResource::createForTest(ResourceRequest(url), "utf-8"); resource->setStatus(Resource::Pending); PreloadRecordingCSSPreloaderResourceClient* resourceClient = new PreloadRecordingCSSPreloaderResourceClient(resource, preloader); const char* data = "@import url('http://127.0.0.1/preload.css');"; resource->appendData(data, strlen(data)); EXPECT_EQ(Resource::PreloadNotReferenced, resource->getPreloadResult()); EXPECT_EQ(1u, resourceClient->m_preloadUrls.size()); EXPECT_EQ("http://127.0.0.1/preload.css", resourceClient->m_preloadUrls.front()); }