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

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

Issue 2588403002: TestingPlatformSupport: register Platform instance correctly (Closed)
Patch Set: new plan Created 3 years, 12 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 1107 matching lines...) Expand 10 before | Expand all | Expand 10 after
1118 EXPECT_EQ(Resource::Pending, image->getStatus()); 1118 EXPECT_EQ(Resource::Pending, image->getStatus());
1119 EXPECT_FALSE(image->isPlaceholder()); 1119 EXPECT_FALSE(image->isPlaceholder());
1120 EXPECT_EQ(nullAtom, image->resourceRequest().httpHeaderField("range")); 1120 EXPECT_EQ(nullAtom, image->resourceRequest().httpHeaderField("range"));
1121 EXPECT_EQ(static_cast<int>(WebCachePolicy::UseProtocolCachePolicy), 1121 EXPECT_EQ(static_cast<int>(WebCachePolicy::UseProtocolCachePolicy),
1122 static_cast<int>(image->resourceRequest().getCachePolicy())); 1122 static_cast<int>(image->resourceRequest().getCachePolicy()));
1123 1123
1124 image->loader()->cancel(); 1124 image->loader()->cancel();
1125 } 1125 }
1126 1126
1127 TEST(ImageResourceTest, PeriodicFlushTest) { 1127 TEST(ImageResourceTest, PeriodicFlushTest) {
1128 TestingPlatformSupportWithMockScheduler platform; 1128 ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler>
1129 platform(new TestingPlatformSupportWithMockScheduler);
1129 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); 1130 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html");
1130 URLTestHelpers::registerMockedURLLoad(testURL, "cancelTest.html", 1131 URLTestHelpers::registerMockedURLLoad(testURL, "cancelTest.html",
1131 "text/html"); 1132 "text/html");
1132 ResourceRequest request = ResourceRequest(testURL); 1133 ResourceRequest request = ResourceRequest(testURL);
1133 ImageResource* cachedImage = ImageResource::create(request); 1134 ImageResource* cachedImage = ImageResource::create(request);
1134 cachedImage->setStatus(Resource::Pending); 1135 cachedImage->setStatus(Resource::Pending);
1135 1136
1136 Persistent<MockImageResourceClient> client = 1137 Persistent<MockImageResourceClient> client =
1137 new MockImageResourceClient(cachedImage); 1138 new MockImageResourceClient(cachedImage);
1138 1139
1139 // Send the image response. 1140 // Send the image response.
1140 ResourceResponse resourceResponse(KURL(), "image/jpeg", sizeof(kJpegImage2), 1141 ResourceResponse resourceResponse(KURL(), "image/jpeg", sizeof(kJpegImage2),
1141 nullAtom, String()); 1142 nullAtom, String());
1142 resourceResponse.addHTTPHeaderField("chrome-proxy", "q=low"); 1143 resourceResponse.addHTTPHeaderField("chrome-proxy", "q=low");
1143 1144
1144 cachedImage->responseReceived(resourceResponse, nullptr); 1145 cachedImage->responseReceived(resourceResponse, nullptr);
1145 1146
1146 // This is number is sufficiently large amount of bytes necessary for the 1147 // This is number is sufficiently large amount of bytes necessary for the
1147 // image to be created (since the size is known). This was determined by 1148 // image to be created (since the size is known). This was determined by
1148 // appending one byte at a time (with flushes) until the image was decoded. 1149 // appending one byte at a time (with flushes) until the image was decoded.
1149 size_t meaningfulImageSize = 280; 1150 size_t meaningfulImageSize = 280;
1150 cachedImage->appendData(reinterpret_cast<const char*>(kJpegImage2), 1151 cachedImage->appendData(reinterpret_cast<const char*>(kJpegImage2),
1151 meaningfulImageSize); 1152 meaningfulImageSize);
1152 size_t bytesSent = meaningfulImageSize; 1153 size_t bytesSent = meaningfulImageSize;
1153 1154
1154 EXPECT_FALSE(cachedImage->errorOccurred()); 1155 EXPECT_FALSE(cachedImage->errorOccurred());
1155 EXPECT_TRUE(cachedImage->getContent()->hasImage()); 1156 EXPECT_TRUE(cachedImage->getContent()->hasImage());
1156 EXPECT_EQ(1, client->imageChangedCount()); 1157 EXPECT_EQ(1, client->imageChangedCount());
1157 1158
1158 platform.runForPeriodSeconds(1.); 1159 platform->runForPeriodSeconds(1.);
1159 platform.advanceClockSeconds(1.); 1160 platform->advanceClockSeconds(1.);
1160 1161
1161 // Sanity check that we created an image after appending |meaningfulImageSize| 1162 // Sanity check that we created an image after appending |meaningfulImageSize|
1162 // bytes just once. 1163 // bytes just once.
1163 EXPECT_FALSE(cachedImage->errorOccurred()); 1164 EXPECT_FALSE(cachedImage->errorOccurred());
1164 ASSERT_TRUE(cachedImage->getContent()->hasImage()); 1165 ASSERT_TRUE(cachedImage->getContent()->hasImage());
1165 EXPECT_EQ(1, client->imageChangedCount()); 1166 EXPECT_EQ(1, client->imageChangedCount());
1166 1167
1167 for (int flushCount = 1; flushCount <= 3; ++flushCount) { 1168 for (int flushCount = 1; flushCount <= 3; ++flushCount) {
1168 // For each of the iteration that appends data, we don't expect 1169 // For each of the iteration that appends data, we don't expect
1169 // |imageChangeCount()| to change, since the time is adjusted by 0.2001 1170 // |imageChangeCount()| to change, since the time is adjusted by 0.2001
1170 // seconds (it's greater than 0.2 to avoid double precision problems). 1171 // seconds (it's greater than 0.2 to avoid double precision problems).
1171 // After 5 appends, we breach the flush interval and the flush count 1172 // After 5 appends, we breach the flush interval and the flush count
1172 // increases. 1173 // increases.
1173 for (int i = 0; i < 5; ++i) { 1174 for (int i = 0; i < 5; ++i) {
1174 SCOPED_TRACE(i); 1175 SCOPED_TRACE(i);
1175 cachedImage->appendData( 1176 cachedImage->appendData(
1176 reinterpret_cast<const char*>(kJpegImage2) + bytesSent, 1); 1177 reinterpret_cast<const char*>(kJpegImage2) + bytesSent, 1);
1177 1178
1178 EXPECT_FALSE(cachedImage->errorOccurred()); 1179 EXPECT_FALSE(cachedImage->errorOccurred());
1179 ASSERT_TRUE(cachedImage->getContent()->hasImage()); 1180 ASSERT_TRUE(cachedImage->getContent()->hasImage());
1180 EXPECT_EQ(flushCount, client->imageChangedCount()); 1181 EXPECT_EQ(flushCount, client->imageChangedCount());
1181 1182
1182 ++bytesSent; 1183 ++bytesSent;
1183 platform.runForPeriodSeconds(0.2001); 1184 platform->runForPeriodSeconds(0.2001);
1184 } 1185 }
1185 } 1186 }
1186 1187
1187 // Increasing time by a large number only causes one extra flush. 1188 // Increasing time by a large number only causes one extra flush.
1188 platform.runForPeriodSeconds(10.); 1189 platform->runForPeriodSeconds(10.);
1189 platform.advanceClockSeconds(10.); 1190 platform->advanceClockSeconds(10.);
1190 EXPECT_FALSE(cachedImage->errorOccurred()); 1191 EXPECT_FALSE(cachedImage->errorOccurred());
1191 ASSERT_TRUE(cachedImage->getContent()->hasImage()); 1192 ASSERT_TRUE(cachedImage->getContent()->hasImage());
1192 EXPECT_FALSE(cachedImage->getContent()->getImage()->isNull()); 1193 EXPECT_FALSE(cachedImage->getContent()->getImage()->isNull());
1193 EXPECT_EQ(4, client->imageChangedCount()); 1194 EXPECT_EQ(4, client->imageChangedCount());
1194 1195
1195 // Append the rest of the data and finish (which causes another flush). 1196 // Append the rest of the data and finish (which causes another flush).
1196 cachedImage->appendData( 1197 cachedImage->appendData(
1197 reinterpret_cast<const char*>(kJpegImage2) + bytesSent, 1198 reinterpret_cast<const char*>(kJpegImage2) + bytesSent,
1198 sizeof(kJpegImage2) - bytesSent); 1199 sizeof(kJpegImage2) - bytesSent);
1199 cachedImage->finish(); 1200 cachedImage->finish();
1200 1201
1201 EXPECT_FALSE(cachedImage->errorOccurred()); 1202 EXPECT_FALSE(cachedImage->errorOccurred());
1202 ASSERT_TRUE(cachedImage->getContent()->hasImage()); 1203 ASSERT_TRUE(cachedImage->getContent()->hasImage());
1203 EXPECT_FALSE(cachedImage->getContent()->getImage()->isNull()); 1204 EXPECT_FALSE(cachedImage->getContent()->getImage()->isNull());
1204 EXPECT_EQ(5, client->imageChangedCount()); 1205 EXPECT_EQ(5, client->imageChangedCount());
1205 EXPECT_TRUE(client->notifyFinishedCalled()); 1206 EXPECT_TRUE(client->notifyFinishedCalled());
1206 EXPECT_TRUE(cachedImage->getContent()->getImage()->isBitmapImage()); 1207 EXPECT_TRUE(cachedImage->getContent()->getImage()->isBitmapImage());
1207 EXPECT_EQ(50, cachedImage->getContent()->getImage()->width()); 1208 EXPECT_EQ(50, cachedImage->getContent()->getImage()->width());
1208 EXPECT_EQ(50, cachedImage->getContent()->getImage()->height()); 1209 EXPECT_EQ(50, cachedImage->getContent()->getImage()->height());
1209 1210
1210 WTF::setTimeFunctionsForTesting(nullptr); 1211 WTF::setTimeFunctionsForTesting(nullptr);
1211 } 1212 }
1212 1213
1213 } // namespace 1214 } // namespace
1214 } // namespace blink 1215 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698