TEST(LinkLoaderTest, Preload)
{
    struct TestCase {
        const char* href;
        const char* as;
        const ResourceLoadPriority priority;
        const bool shouldLoad;
    } cases[] = {
        {"data://example.com/cat.jpg", "image", ResourceLoadPriorityVeryLow, true},
        {"data://example.com/cat.jpg", "script", ResourceLoadPriorityMedium, true},
        {"data://example.com/cat.jpg", "stylesheet", ResourceLoadPriorityHigh, true},
        {"data://example.com/cat.jpg", "blabla", ResourceLoadPriorityUnresolved, true},
        {"data://example.com/cat.jpg", "image", ResourceLoadPriorityUnresolved, false},
    };

    // Test the cases with a single header
    for (const auto& testCase : cases) {
        OwnPtr<DummyPageHolder> dummyPageHolder = DummyPageHolder::create(IntSize(500, 500));
        MockLinkLoaderClient loaderClient(testCase.shouldLoad);
        LinkLoader loader(&loaderClient);
        KURL hrefURL = KURL(KURL(), testCase.href);
        loader.loadLink(LinkRelAttribute("preload"),
            AtomicString(),
            String(),
            testCase.as,
            hrefURL,
            dummyPageHolder->document());
        if (testCase.priority == ResourceLoadPriorityUnresolved) {
            ASSERT(!loader.resource());
        } else {
            ASSERT(loader.resource());
            ASSERT_EQ(testCase.priority, loader.resource()->resourceRequest().priority());
        }
    }
}
Esempio n. 2
0
void LocalFrame::detach()
{
    // A lot of the following steps can result in the current frame being
    // detached, so protect a reference to it.
    RefPtr<LocalFrame> protect(this);
    m_deprecatedLoader.stopAllLoaders();
    m_deprecatedLoader.closeURL();
    detachChildren();
    // stopAllLoaders() needs to be called after detachChildren(), because detachChildren()
    // will trigger the unload event handlers of any child frames, and those event
    // handlers might start a new subresource load in this frame.
    m_deprecatedLoader.stopAllLoaders();

    setView(nullptr);
    willDetachFrameHost();

    // After this, we must no longer talk to the client since this clears
    // its owning reference back to our owning LocalFrame.
    loaderClient()->detachedFromParent();
    clearClient();
    detachFromFrameHost();
}