102772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch/* 202772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * Copyright (c) 2013, Google Inc. All rights reserved. 302772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * 402772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * Redistribution and use in source and binary forms, with or without 502772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * modification, are permitted provided that the following conditions are 602772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * met: 702772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * 802772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * * Redistributions of source code must retain the above copyright 902772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * notice, this list of conditions and the following disclaimer. 1002772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * * Redistributions in binary form must reproduce the above 1102772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * copyright notice, this list of conditions and the following disclaimer 1202772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * in the documentation and/or other materials provided with the 1302772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * distribution. 1402772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * * Neither the name of Google Inc. nor the names of its 1502772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * contributors may be used to endorse or promote products derived from 1602772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * this software without specific prior written permission. 1702772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * 1802772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1902772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 2002772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 2102772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2202772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2302772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2402772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2502772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2602772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2702772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2802772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2902772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch */ 3002772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch 3102772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch#include "config.h" 3202772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch#include "core/loader/cache/ResourceFetcher.h" 3302772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch 3402772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch#include "core/html/HTMLDocument.h" 3502772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch#include "core/loader/DocumentLoader.h" 36fff8884795cb540f87cf6e6d67b629519b00eb8bBen Murdoch#include "core/loader/cache/FetchInitiatorInfo.h" 3702772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch#include "core/loader/cache/FetchRequest.h" 3802772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch#include "core/loader/cache/MemoryCache.h" 39fff8884795cb540f87cf6e6d67b629519b00eb8bBen Murdoch#include "core/loader/cache/ResourcePtr.h" 4002772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch#include "core/platform/network/ResourceRequest.h" 4102772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch#include <gtest/gtest.h> 4202772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch 4302772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdochusing namespace WebCore; 4402772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch 4502772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdochnamespace { 4602772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch 4702772c6a72f1ee0b226341a4f4439970c29fc861Ben MurdochTEST(ResourceFetcherTest, StartLoadAfterFrameDetach) 4802772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch{ 4902772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.jpg"); 5002772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch 5102772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch // Create a ResourceFetcher that has a real DocumentLoader and Document, but is not attached to a Frame. 5202772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch // Technically, we're concerned about what happens after a Frame is detached (rather than before 5302772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch // any attach occurs), but ResourceFetcher can't tell the difference. 5402772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch RefPtr<DocumentLoader> documentLoader = DocumentLoader::create(ResourceRequest(testURL), SubstituteData()); 5502772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch RefPtr<HTMLDocument> document = HTMLDocument::create(); 5602772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch RefPtr<ResourceFetcher> fetcher(documentLoader->fetcher()); 5702772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch fetcher->setDocument(document.get()); 5802772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch EXPECT_EQ(fetcher->frame(), static_cast<Frame*>(0)); 5902772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch 6002772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch // Try to request a url. The request should fail, no resource should be returned, 6102772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch // and no resource should be present in the cache. 62fff8884795cb540f87cf6e6d67b629519b00eb8bBen Murdoch FetchRequest fetchRequest = FetchRequest(ResourceRequest(testURL), FetchInitiatorInfo()); 63e6d4491e48613634a83c1957c72759da80987961Ben Murdoch ResourcePtr<ImageResource> image = fetcher->requestImage(fetchRequest); 64e6d4491e48613634a83c1957c72759da80987961Ben Murdoch EXPECT_EQ(image.get(), static_cast<ImageResource*>(0)); 65fff8884795cb540f87cf6e6d67b629519b00eb8bBen Murdoch EXPECT_EQ(memoryCache()->resourceForURL(testURL), static_cast<Resource*>(0)); 6602772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch} 6702772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch 6802772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch} // namespace 69