OLD | NEW |
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 20 matching lines...) Expand all Loading... |
31 #include "core/fetch/ImageResource.h" | 31 #include "core/fetch/ImageResource.h" |
32 | 32 |
33 #include "core/fetch/MemoryCache.h" | 33 #include "core/fetch/MemoryCache.h" |
34 #include "core/fetch/MockResourceClients.h" | 34 #include "core/fetch/MockResourceClients.h" |
35 #include "core/fetch/ResourceFetcher.h" | 35 #include "core/fetch/ResourceFetcher.h" |
36 #include "core/fetch/ResourceLoader.h" | 36 #include "core/fetch/ResourceLoader.h" |
37 #include "core/fetch/UniqueIdentifier.h" | 37 #include "core/fetch/UniqueIdentifier.h" |
38 #include "platform/SharedBuffer.h" | 38 #include "platform/SharedBuffer.h" |
39 #include "platform/exported/WrappedResourceResponse.h" | 39 #include "platform/exported/WrappedResourceResponse.h" |
40 #include "platform/graphics/Image.h" | 40 #include "platform/graphics/Image.h" |
| 41 #include "platform/scheduler/test/fake_web_task_runner.h" |
41 #include "platform/testing/URLTestHelpers.h" | 42 #include "platform/testing/URLTestHelpers.h" |
42 #include "platform/testing/UnitTestHelpers.h" | 43 #include "platform/testing/UnitTestHelpers.h" |
43 #include "public/platform/Platform.h" | 44 #include "public/platform/Platform.h" |
44 #include "public/platform/WebURL.h" | 45 #include "public/platform/WebURL.h" |
45 #include "public/platform/WebURLLoaderMockFactory.h" | 46 #include "public/platform/WebURLLoaderMockFactory.h" |
46 #include "public/platform/WebURLResponse.h" | 47 #include "public/platform/WebURLResponse.h" |
47 #include "testing/gtest/include/gtest/gtest.h" | 48 #include "testing/gtest/include/gtest/gtest.h" |
48 #include "wtf/PtrUtil.h" | 49 #include "wtf/PtrUtil.h" |
49 #include <memory> | 50 #include <memory> |
50 | 51 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 { | 146 { |
146 ResourceResponse response; | 147 ResourceResponse response; |
147 response.setURL(url); | 148 response.setURL(url); |
148 response.setHTTPStatusCode(200); | 149 response.setHTTPStatusCode(200); |
149 response.setMimeType(mimeType); | 150 response.setMimeType(mimeType); |
150 imageResource->responseReceived(response, nullptr); | 151 imageResource->responseReceived(response, nullptr); |
151 imageResource->appendData(reinterpret_cast<const char*>(data.data()), data.s
ize()); | 152 imageResource->appendData(reinterpret_cast<const char*>(data.data()), data.s
ize()); |
152 imageResource->finish(); | 153 imageResource->finish(); |
153 } | 154 } |
154 | 155 |
155 class MockTaskRunner : public blink::WebTaskRunner { | |
156 void postTask(const WebTraceLocation&, Task*) override { } | |
157 void postDelayedTask(const WebTraceLocation&, Task*, double) override { } | |
158 bool runsTasksOnCurrentThread() override { return true; } | |
159 std::unique_ptr<WebTaskRunner> clone() override { return nullptr; } | |
160 double virtualTimeSeconds() const override { return 0.0; } | |
161 double monotonicallyIncreasingVirtualTimeSeconds() const override { return 0
.0; } | |
162 SingleThreadTaskRunner* taskRunner() override { return nullptr; } | |
163 }; | |
164 | |
165 } | 156 } |
166 | 157 |
167 class ImageResourceTestMockFetchContext : public FetchContext { | 158 class ImageResourceTestMockFetchContext : public FetchContext { |
168 public: | 159 public: |
169 static ImageResourceTestMockFetchContext* create() | 160 static ImageResourceTestMockFetchContext* create() |
170 { | 161 { |
171 return new ImageResourceTestMockFetchContext; | 162 return new ImageResourceTestMockFetchContext; |
172 } | 163 } |
173 | 164 |
174 virtual ~ImageResourceTestMockFetchContext() { } | 165 virtual ~ImageResourceTestMockFetchContext() { } |
175 | 166 |
176 bool allowImage(bool imagesEnabled, const KURL&) const override { return tru
e; } | 167 bool allowImage(bool imagesEnabled, const KURL&) const override { return tru
e; } |
177 bool canRequest(Resource::Type, const ResourceRequest&, const KURL&, const R
esourceLoaderOptions&, bool forPreload, FetchRequest::OriginRestriction) const o
verride { return true; } | 168 bool canRequest(Resource::Type, const ResourceRequest&, const KURL&, const R
esourceLoaderOptions&, bool forPreload, FetchRequest::OriginRestriction) const o
verride { return true; } |
178 bool shouldLoadNewResource(Resource::Type) const override { return true; } | 169 bool shouldLoadNewResource(Resource::Type) const override { return true; } |
179 WebTaskRunner* loadingTaskRunner() const override { return m_runner.get(); } | 170 WebTaskRunner* loadingTaskRunner() const override { return m_runner.get(); } |
180 | 171 |
181 private: | 172 private: |
182 ImageResourceTestMockFetchContext() | 173 ImageResourceTestMockFetchContext() |
183 : m_runner(wrapUnique(new MockTaskRunner)) | 174 : m_runner(wrapUnique(new scheduler::FakeWebTaskRunner)) |
184 { } | 175 { } |
185 | 176 |
186 std::unique_ptr<MockTaskRunner> m_runner; | 177 std::unique_ptr<scheduler::FakeWebTaskRunner> m_runner; |
187 }; | 178 }; |
188 | 179 |
189 TEST(ImageResourceTest, MultipartImage) | 180 TEST(ImageResourceTest, MultipartImage) |
190 { | 181 { |
191 ResourceFetcher* fetcher = ResourceFetcher::create(ImageResourceTestMockFetc
hContext::create()); | 182 ResourceFetcher* fetcher = ResourceFetcher::create(ImageResourceTestMockFetc
hContext::create()); |
192 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); | 183 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); |
193 URLTestHelpers::registerMockedURLLoad(testURL, "cancelTest.html", "text/html
"); | 184 URLTestHelpers::registerMockedURLLoad(testURL, "cancelTest.html", "text/html
"); |
194 | 185 |
195 // Emulate starting a real load, but don't expect any "real" WebURLLoaderCli
ent callbacks. | 186 // Emulate starting a real load, but don't expect any "real" WebURLLoaderCli
ent callbacks. |
196 ImageResource* cachedImage = ImageResource::create(ResourceRequest(testURL))
; | 187 ImageResource* cachedImage = ImageResource::create(ResourceRequest(testURL))
; |
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 ImageResource* cachedImage = ImageResource::fetch(request, fetcher); | 631 ImageResource* cachedImage = ImageResource::fetch(request, fetcher); |
641 Platform::current()->getURLLoaderMockFactory()->unregisterURL(testURL); | 632 Platform::current()->getURLLoaderMockFactory()->unregisterURL(testURL); |
642 | 633 |
643 cachedImage->loader()->didReceiveResponse(nullptr, WrappedResourceResponse(R
esourceResponse(testURL, "image/jpeg", 18, nullAtom, String())), nullptr); | 634 cachedImage->loader()->didReceiveResponse(nullptr, WrappedResourceResponse(R
esourceResponse(testURL, "image/jpeg", 18, nullAtom, String())), nullptr); |
644 cachedImage->loader()->didReceiveData(nullptr, "notactuallyanimage", 18, 18,
18); | 635 cachedImage->loader()->didReceiveData(nullptr, "notactuallyanimage", 18, 18,
18); |
645 EXPECT_EQ(Resource::DecodeError, cachedImage->getStatus()); | 636 EXPECT_EQ(Resource::DecodeError, cachedImage->getStatus()); |
646 EXPECT_FALSE(cachedImage->isLoading()); | 637 EXPECT_FALSE(cachedImage->isLoading()); |
647 } | 638 } |
648 | 639 |
649 } // namespace blink | 640 } // namespace blink |
OLD | NEW |