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 27 matching lines...) Expand all Loading... |
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/testing/URLTestHelpers.h" | 41 #include "platform/testing/URLTestHelpers.h" |
42 #include "platform/testing/UnitTestHelpers.h" | 42 #include "platform/testing/UnitTestHelpers.h" |
43 #include "public/platform/Platform.h" | 43 #include "public/platform/Platform.h" |
44 #include "public/platform/WebURL.h" | 44 #include "public/platform/WebURL.h" |
45 #include "public/platform/WebURLLoaderMockFactory.h" | 45 #include "public/platform/WebURLLoaderMockFactory.h" |
46 #include "public/platform/WebURLResponse.h" | 46 #include "public/platform/WebURLResponse.h" |
47 #include "testing/gtest/include/gtest/gtest.h" | 47 #include "testing/gtest/include/gtest/gtest.h" |
48 #include "wtf/PtrUtil.h" | |
49 #include <memory> | |
50 | 48 |
51 namespace blink { | 49 namespace blink { |
52 | 50 |
53 static Vector<unsigned char> jpegImage() | 51 static Vector<unsigned char> jpegImage() |
54 { | 52 { |
55 Vector<unsigned char> jpeg; | 53 Vector<unsigned char> jpeg; |
56 | 54 |
57 static const unsigned char data[] = { | 55 static const unsigned char data[] = { |
58 0xff, 0xd8, 0xff, 0xe0, 0x00, 0x10, 0x4a, 0x46, 0x49, 0x46, 0x00, 0x01,
0x01, 0x01, 0x00, | 56 0xff, 0xd8, 0xff, 0xe0, 0x00, 0x10, 0x4a, 0x46, 0x49, 0x46, 0x00, 0x01,
0x01, 0x01, 0x00, |
59 0x48, 0x00, 0x48, 0x00, 0x00, 0xff, 0xfe, 0x00, 0x13, 0x43, 0x72, 0x65,
0x61, 0x74, 0x65, | 57 0x48, 0x00, 0x48, 0x00, 0x00, 0xff, 0xfe, 0x00, 0x13, 0x43, 0x72, 0x65,
0x61, 0x74, 0x65, |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 | 101 |
104 virtual ~ImageResourceTestMockFetchContext() { } | 102 virtual ~ImageResourceTestMockFetchContext() { } |
105 | 103 |
106 bool allowImage(bool imagesEnabled, const KURL&) const override { return tru
e; } | 104 bool allowImage(bool imagesEnabled, const KURL&) const override { return tru
e; } |
107 bool canRequest(Resource::Type, const ResourceRequest&, const KURL&, const R
esourceLoaderOptions&, bool forPreload, FetchRequest::OriginRestriction) const o
verride { return true; } | 105 bool canRequest(Resource::Type, const ResourceRequest&, const KURL&, const R
esourceLoaderOptions&, bool forPreload, FetchRequest::OriginRestriction) const o
verride { return true; } |
108 bool shouldLoadNewResource(Resource::Type) const override { return true; } | 106 bool shouldLoadNewResource(Resource::Type) const override { return true; } |
109 WebTaskRunner* loadingTaskRunner() const override { return m_runner.get(); } | 107 WebTaskRunner* loadingTaskRunner() const override { return m_runner.get(); } |
110 | 108 |
111 private: | 109 private: |
112 ImageResourceTestMockFetchContext() | 110 ImageResourceTestMockFetchContext() |
113 : m_runner(wrapUnique(new MockTaskRunner)) | 111 : m_runner(adoptPtr(new MockTaskRunner)) |
114 { } | 112 { } |
115 | 113 |
116 std::unique_ptr<MockTaskRunner> m_runner; | 114 OwnPtr<MockTaskRunner> m_runner; |
117 }; | 115 }; |
118 | 116 |
119 TEST(ImageResourceTest, MultipartImage) | 117 TEST(ImageResourceTest, MultipartImage) |
120 { | 118 { |
121 ResourceFetcher* fetcher = ResourceFetcher::create(ImageResourceTestMockFetc
hContext::create()); | 119 ResourceFetcher* fetcher = ResourceFetcher::create(ImageResourceTestMockFetc
hContext::create()); |
122 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); | 120 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); |
123 URLTestHelpers::registerMockedURLLoad(testURL, "cancelTest.html", "text/html
"); | 121 URLTestHelpers::registerMockedURLLoad(testURL, "cancelTest.html", "text/html
"); |
124 | 122 |
125 // Emulate starting a real load, but don't expect any "real" WebURLLoaderCli
ent callbacks. | 123 // Emulate starting a real load, but don't expect any "real" WebURLLoaderCli
ent callbacks. |
126 ImageResource* cachedImage = ImageResource::create(ResourceRequest(testURL))
; | 124 ImageResource* cachedImage = ImageResource::create(ResourceRequest(testURL))
; |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 cachedImage->loader()->didReceiveData(nullptr, reinterpret_cast<const char*>
(jpeg.data()), jpeg.size(), jpeg.size()); | 295 cachedImage->loader()->didReceiveData(nullptr, reinterpret_cast<const char*>
(jpeg.data()), jpeg.size(), jpeg.size()); |
298 cachedImage->loader()->didFinishLoading(nullptr, 0.0, jpeg.size()); | 296 cachedImage->loader()->didFinishLoading(nullptr, 0.0, jpeg.size()); |
299 ASSERT_FALSE(cachedImage->errorOccurred()); | 297 ASSERT_FALSE(cachedImage->errorOccurred()); |
300 ASSERT_TRUE(cachedImage->hasImage()); | 298 ASSERT_TRUE(cachedImage->hasImage()); |
301 ASSERT_FALSE(cachedImage->getImage()->isNull()); | 299 ASSERT_FALSE(cachedImage->getImage()->isNull()); |
302 ASSERT_TRUE(client->notifyFinishedCalled()); | 300 ASSERT_TRUE(client->notifyFinishedCalled()); |
303 ASSERT_TRUE(cachedImage->getImage()->isBitmapImage()); | 301 ASSERT_TRUE(cachedImage->getImage()->isBitmapImage()); |
304 } | 302 } |
305 | 303 |
306 } // namespace blink | 304 } // namespace blink |
OLD | NEW |