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

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

Issue 1845323002: Remove WebUnitTestSupport (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 24 matching lines...) Expand all
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/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/WebURLResponse.h" 46 #include "public/platform/WebURLResponse.h"
46 #include "public/platform/WebUnitTestSupport.h"
47 #include "testing/gtest/include/gtest/gtest.h" 47 #include "testing/gtest/include/gtest/gtest.h"
48 48
49 namespace blink { 49 namespace blink {
50 50
51 static Vector<unsigned char> jpegImage() 51 static Vector<unsigned char> jpegImage()
52 { 52 {
53 Vector<unsigned char> jpeg; 53 Vector<unsigned char> jpeg;
54 54
55 static const unsigned char data[] = { 55 static const unsigned char data[] = {
56 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,
(...skipping 26 matching lines...) Expand all
83 TEST(ImageResourceTest, MultipartImage) 83 TEST(ImageResourceTest, MultipartImage)
84 { 84 {
85 ResourceFetcher* fetcher = ResourceFetcher::create(nullptr); 85 ResourceFetcher* fetcher = ResourceFetcher::create(nullptr);
86 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); 86 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html");
87 URLTestHelpers::registerMockedURLLoad(testURL, "cancelTest.html", "text/html "); 87 URLTestHelpers::registerMockedURLLoad(testURL, "cancelTest.html", "text/html ");
88 88
89 // Emulate starting a real load, but don't expect any "real" WebURLLoaderCli ent callbacks. 89 // Emulate starting a real load, but don't expect any "real" WebURLLoaderCli ent callbacks.
90 ImageResource* cachedImage = ImageResource::create(ResourceRequest(testURL), nullptr); 90 ImageResource* cachedImage = ImageResource::create(ResourceRequest(testURL), nullptr);
91 cachedImage->setIdentifier(createUniqueIdentifier()); 91 cachedImage->setIdentifier(createUniqueIdentifier());
92 cachedImage->load(fetcher); 92 cachedImage->load(fetcher);
93 Platform::current()->unitTestSupport()->unregisterMockedURL(testURL); 93 Platform::current()->getURLLoaderMockFactory()->unregisterURL(testURL);
94 94
95 MockImageResourceClient client(cachedImage); 95 MockImageResourceClient client(cachedImage);
96 EXPECT_EQ(Resource::Pending, cachedImage->getStatus()); 96 EXPECT_EQ(Resource::Pending, cachedImage->getStatus());
97 97
98 // Send the multipart response. No image or data buffer is created. 98 // Send the multipart response. No image or data buffer is created.
99 // Note that the response must be routed through ResourceLoader to 99 // Note that the response must be routed through ResourceLoader to
100 // ensure the load is flagged as multipart. 100 // ensure the load is flagged as multipart.
101 ResourceResponse multipartResponse(KURL(), "multipart/x-mixed-replace", 0, n ullAtom, String()); 101 ResourceResponse multipartResponse(KURL(), "multipart/x-mixed-replace", 0, n ullAtom, String());
102 multipartResponse.setMultipartBoundary("boundary", strlen("boundary")); 102 multipartResponse.setMultipartBoundary("boundary", strlen("boundary"));
103 cachedImage->loader()->didReceiveResponse(nullptr, WrappedResourceResponse(m ultipartResponse), nullptr); 103 cachedImage->loader()->didReceiveResponse(nullptr, WrappedResourceResponse(m ultipartResponse), nullptr);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 // The load should still be alive, but a timer should be started to cancel t he load inside removeClient(). 163 // The load should still be alive, but a timer should be started to cancel t he load inside removeClient().
164 client.removeAsClient(); 164 client.removeAsClient();
165 EXPECT_EQ(Resource::Pending, cachedImage->getStatus()); 165 EXPECT_EQ(Resource::Pending, cachedImage->getStatus());
166 EXPECT_NE(reinterpret_cast<Resource*>(0), memoryCache()->resourceForURL(test URL)); 166 EXPECT_NE(reinterpret_cast<Resource*>(0), memoryCache()->resourceForURL(test URL));
167 167
168 // Trigger the cancel timer, ensure the load was cancelled and the resource was evicted from the cache. 168 // Trigger the cancel timer, ensure the load was cancelled and the resource was evicted from the cache.
169 blink::testing::runPendingTasks(); 169 blink::testing::runPendingTasks();
170 EXPECT_EQ(Resource::LoadError, cachedImage->getStatus()); 170 EXPECT_EQ(Resource::LoadError, cachedImage->getStatus());
171 EXPECT_EQ(reinterpret_cast<Resource*>(0), memoryCache()->resourceForURL(test URL)); 171 EXPECT_EQ(reinterpret_cast<Resource*>(0), memoryCache()->resourceForURL(test URL));
172 172
173 Platform::current()->unitTestSupport()->unregisterMockedURL(testURL); 173 Platform::current()->getURLLoaderMockFactory()->unregisterURL(testURL);
174 } 174 }
175 175
176 TEST(ImageResourceTest, DecodedDataRemainsWhileHasClients) 176 TEST(ImageResourceTest, DecodedDataRemainsWhileHasClients)
177 { 177 {
178 ImageResource* cachedImage = ImageResource::create(ResourceRequest(), nullpt r); 178 ImageResource* cachedImage = ImageResource::create(ResourceRequest(), nullpt r);
179 cachedImage->setStatus(Resource::Pending); 179 cachedImage->setStatus(Resource::Pending);
180 180
181 MockImageResourceClient client(cachedImage); 181 MockImageResourceClient client(cachedImage);
182 182
183 // Send the image response. 183 // Send the image response.
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 cachedImage->appendData(reinterpret_cast<const char*>(jpeg.data()), jpeg.siz e()); 261 cachedImage->appendData(reinterpret_cast<const char*>(jpeg.data()), jpeg.siz e());
262 cachedImage->finish(); 262 cachedImage->finish();
263 ASSERT_FALSE(cachedImage->errorOccurred()); 263 ASSERT_FALSE(cachedImage->errorOccurred());
264 ASSERT_TRUE(cachedImage->hasImage()); 264 ASSERT_TRUE(cachedImage->hasImage());
265 ASSERT_FALSE(cachedImage->getImage()->isNull()); 265 ASSERT_FALSE(cachedImage->getImage()->isNull());
266 ASSERT_TRUE(client.notifyFinishedCalled()); 266 ASSERT_TRUE(client.notifyFinishedCalled());
267 ASSERT_TRUE(cachedImage->getImage()->isBitmapImage()); 267 ASSERT_TRUE(cachedImage->getImage()->isBitmapImage());
268 } 268 }
269 269
270 } // namespace blink 270 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698