Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(164)

Side by Side Diff: third_party/WebKit/Source/core/fetch/ResourceFetcherTest.cpp

Issue 2408443003: Make ResourceFetcher return Resources with LoadError instead of nullptrs. (Closed)
Patch Set: Add comment. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2013, Google Inc. All rights reserved. 2 * Copyright (c) 2013, Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 CachePolicy m_policy; 109 CachePolicy m_policy;
110 std::unique_ptr<scheduler::FakeWebTaskRunner> m_runner; 110 std::unique_ptr<scheduler::FakeWebTaskRunner> m_runner;
111 bool m_complete; 111 bool m_complete;
112 long long m_transferSize; 112 long long m_transferSize;
113 }; 113 };
114 114
115 class ResourceFetcherTest : public ::testing::Test {}; 115 class ResourceFetcherTest : public ::testing::Test {};
116 116
117 TEST_F(ResourceFetcherTest, StartLoadAfterFrameDetach) { 117 TEST_F(ResourceFetcherTest, StartLoadAfterFrameDetach) {
118 KURL secureURL(ParsedURLString, "https://secureorigin.test/image.png"); 118 KURL secureURL(ParsedURLString, "https://secureorigin.test/image.png");
119 // Try to request a url. The request should fail, no resource should be 119 // Try to request a url. The request should fail, and a resource in an error
120 // returned, and no resource should be present in the cache. 120 // state should be returned, and no resource should be present in the cache.
121 ResourceFetcher* fetcher = ResourceFetcher::create(nullptr); 121 ResourceFetcher* fetcher = ResourceFetcher::create(nullptr);
122 ResourceRequest resourceRequest(secureURL); 122 ResourceRequest resourceRequest(secureURL);
123 resourceRequest.setRequestContext(WebURLRequest::RequestContextInternal); 123 resourceRequest.setRequestContext(WebURLRequest::RequestContextInternal);
124 FetchRequest fetchRequest = 124 FetchRequest fetchRequest =
125 FetchRequest(resourceRequest, FetchInitiatorInfo()); 125 FetchRequest(resourceRequest, FetchInitiatorInfo());
126 Resource* resource = RawResource::fetch(fetchRequest, fetcher); 126 Resource* resource = RawResource::fetch(fetchRequest, fetcher);
127 EXPECT_FALSE(resource); 127 ASSERT_TRUE(resource);
128 EXPECT_TRUE(resource->errorOccurred());
129 EXPECT_TRUE(resource->resourceError().isAccessCheck());
128 EXPECT_FALSE(memoryCache()->resourceForURL(secureURL)); 130 EXPECT_FALSE(memoryCache()->resourceForURL(secureURL));
129 131
130 // Start by calling startLoad() directly, rather than via requestResource(). 132 // Start by calling startLoad() directly, rather than via requestResource().
131 // This shouldn't crash. 133 // This shouldn't crash.
132 fetcher->startLoad(RawResource::create(secureURL, Resource::Raw)); 134 fetcher->startLoad(RawResource::create(secureURL, Resource::Raw));
133 } 135 }
134 136
135 TEST_F(ResourceFetcherTest, UseExistingResource) { 137 TEST_F(ResourceFetcherTest, UseExistingResource) {
136 ResourceFetcher* fetcher = 138 ResourceFetcher* fetcher =
137 ResourceFetcher::create(ResourceFetcherTestMockFetchContext::create()); 139 ResourceFetcher::create(ResourceFetcherTestMockFetchContext::create());
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after
708 Platform::current()->getURLLoaderMockFactory()->registerURL( 710 Platform::current()->getURLLoaderMockFactory()->registerURL(
709 url, WebURLResponse(), ""); 711 url, WebURLResponse(), "");
710 Resource* newResource = RawResource::fetch(fetchRequest, fetcher); 712 Resource* newResource = RawResource::fetch(fetchRequest, fetcher);
711 fetcher->stopFetching(); 713 fetcher->stopFetching();
712 Platform::current()->getURLLoaderMockFactory()->unregisterURL(url); 714 Platform::current()->getURLLoaderMockFactory()->unregisterURL(url);
713 715
714 EXPECT_NE(resource, newResource); 716 EXPECT_NE(resource, newResource);
715 } 717 }
716 718
717 } // namespace blink 719 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/fetch/ResourceFetcher.cpp ('k') | third_party/WebKit/Source/core/loader/DocumentLoader.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698