| 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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 : m_runner(adoptRef(new scheduler::FakeWebTaskRunner)) {} | 195 : m_runner(adoptRef(new scheduler::FakeWebTaskRunner)) {} |
| 196 | 196 |
| 197 RefPtr<scheduler::FakeWebTaskRunner> m_runner; | 197 RefPtr<scheduler::FakeWebTaskRunner> m_runner; |
| 198 }; | 198 }; |
| 199 | 199 |
| 200 // Convenience class that registers a mocked URL load on construction, and | 200 // Convenience class that registers a mocked URL load on construction, and |
| 201 // unregisters it on destruction. This allows for a test to use constructs like | 201 // unregisters it on destruction. This allows for a test to use constructs like |
| 202 // ASSERT_TRUE() without needing to worry about unregistering the mocked URL | 202 // ASSERT_TRUE() without needing to worry about unregistering the mocked URL |
| 203 // load to avoid putting other tests into inconsistent states in case the | 203 // load to avoid putting other tests into inconsistent states in case the |
| 204 // assertion fails. | 204 // assertion fails. |
| 205 // TODO(toyoshim): Generalize and move to platform/testing/URLTestHelpers. |
| 205 class ScopedRegisteredURL { | 206 class ScopedRegisteredURL { |
| 206 public: | 207 public: |
| 207 ScopedRegisteredURL(const KURL& url, | 208 ScopedRegisteredURL(const KURL& url, |
| 208 const String& fileName = "cancelTest.html", | 209 const String& fileName = "cancelTest.html", |
| 209 const String& mimeType = "text/html") | 210 const String& mimeType = "text/html") |
| 210 : m_url(url) { | 211 : m_url(url) { |
| 211 URLTestHelpers::registerMockedURLLoad(m_url, fileName, mimeType); | 212 URLTestHelpers::registerMockedURLLoad( |
| 213 m_url, testing::webTestDataPath(fileName.utf8().data()), mimeType); |
| 212 } | 214 } |
| 213 | 215 |
| 214 ~ScopedRegisteredURL() { | 216 ~ScopedRegisteredURL() { |
| 215 Platform::current()->getURLLoaderMockFactory()->unregisterURL(m_url); | 217 Platform::current()->getURLLoaderMockFactory()->unregisterURL(m_url); |
| 216 } | 218 } |
| 217 | 219 |
| 218 private: | 220 private: |
| 219 KURL m_url; | 221 KURL m_url; |
| 220 }; | 222 }; |
| 221 | 223 |
| (...skipping 962 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1184 static_cast<int>(WebCachePolicy::UseProtocolCachePolicy), | 1186 static_cast<int>(WebCachePolicy::UseProtocolCachePolicy), |
| 1185 static_cast<int>(imageResource->resourceRequest().getCachePolicy())); | 1187 static_cast<int>(imageResource->resourceRequest().getCachePolicy())); |
| 1186 | 1188 |
| 1187 imageResource->loader()->cancel(); | 1189 imageResource->loader()->cancel(); |
| 1188 } | 1190 } |
| 1189 | 1191 |
| 1190 TEST(ImageResourceTest, PeriodicFlushTest) { | 1192 TEST(ImageResourceTest, PeriodicFlushTest) { |
| 1191 ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler> | 1193 ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler> |
| 1192 platform; | 1194 platform; |
| 1193 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); | 1195 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); |
| 1194 URLTestHelpers::registerMockedURLLoad(testURL, "cancelTest.html", | 1196 ScopedRegisteredURL scopedRegisteredURL(testURL); |
| 1195 "text/html"); | |
| 1196 ResourceRequest request = ResourceRequest(testURL); | 1197 ResourceRequest request = ResourceRequest(testURL); |
| 1197 ImageResource* imageResource = ImageResource::create(request); | 1198 ImageResource* imageResource = ImageResource::create(request); |
| 1198 imageResource->setStatus(ResourceStatus::Pending); | 1199 imageResource->setStatus(ResourceStatus::Pending); |
| 1199 | 1200 |
| 1200 std::unique_ptr<MockImageResourceObserver> observer = | 1201 std::unique_ptr<MockImageResourceObserver> observer = |
| 1201 MockImageResourceObserver::create(imageResource->getContent()); | 1202 MockImageResourceObserver::create(imageResource->getContent()); |
| 1202 | 1203 |
| 1203 // Send the image response. | 1204 // Send the image response. |
| 1204 ResourceResponse resourceResponse(KURL(), "image/jpeg", sizeof(kJpegImage2), | 1205 ResourceResponse resourceResponse(KURL(), "image/jpeg", sizeof(kJpegImage2), |
| 1205 nullAtom, String()); | 1206 nullAtom, String()); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1269 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); | 1270 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); |
| 1270 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage()); | 1271 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage()); |
| 1271 EXPECT_EQ(50, imageResource->getContent()->getImage()->width()); | 1272 EXPECT_EQ(50, imageResource->getContent()->getImage()->width()); |
| 1272 EXPECT_EQ(50, imageResource->getContent()->getImage()->height()); | 1273 EXPECT_EQ(50, imageResource->getContent()->getImage()->height()); |
| 1273 | 1274 |
| 1274 WTF::setTimeFunctionsForTesting(nullptr); | 1275 WTF::setTimeFunctionsForTesting(nullptr); |
| 1275 } | 1276 } |
| 1276 | 1277 |
| 1277 } // namespace | 1278 } // namespace |
| 1278 } // namespace blink | 1279 } // namespace blink |
| OLD | NEW |