Chromium Code Reviews| 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 class ScopedRegisteredURL { | 205 class ScopedRegisteredURL { |
|
kinuko
2017/01/26 09:32:40
A generalized form of this class could be probably
Takashi Toyoshima
2017/01/26 10:57:57
Acknowledged.
| |
| 206 public: | 206 public: |
| 207 ScopedRegisteredURL(const KURL& url, | 207 ScopedRegisteredURL(const KURL& url, |
| 208 const String& fileName = "cancelTest.html", | 208 const String& fileName = "cancelTest.html", |
| 209 const String& mimeType = "text/html") | 209 const String& mimeType = "text/html") |
| 210 : m_url(url) { | 210 : m_url(url) { |
| 211 URLTestHelpers::registerMockedURLLoad(m_url, fileName, mimeType); | 211 URLTestHelpers::registerMockedURLLoad( |
| 212 m_url, testing::webTestDataPath(fileName.utf8().data()), mimeType); | |
| 212 } | 213 } |
| 213 | 214 |
| 214 ~ScopedRegisteredURL() { | 215 ~ScopedRegisteredURL() { |
| 215 Platform::current()->getURLLoaderMockFactory()->unregisterURL(m_url); | 216 Platform::current()->getURLLoaderMockFactory()->unregisterURL(m_url); |
| 216 } | 217 } |
| 217 | 218 |
| 218 private: | 219 private: |
| 219 KURL m_url; | 220 KURL m_url; |
| 220 }; | 221 }; |
| 221 | 222 |
| (...skipping 962 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1184 static_cast<int>(WebCachePolicy::UseProtocolCachePolicy), | 1185 static_cast<int>(WebCachePolicy::UseProtocolCachePolicy), |
| 1185 static_cast<int>(imageResource->resourceRequest().getCachePolicy())); | 1186 static_cast<int>(imageResource->resourceRequest().getCachePolicy())); |
| 1186 | 1187 |
| 1187 imageResource->loader()->cancel(); | 1188 imageResource->loader()->cancel(); |
| 1188 } | 1189 } |
| 1189 | 1190 |
| 1190 TEST(ImageResourceTest, PeriodicFlushTest) { | 1191 TEST(ImageResourceTest, PeriodicFlushTest) { |
| 1191 ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler> | 1192 ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler> |
| 1192 platform; | 1193 platform; |
| 1193 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); | 1194 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); |
| 1194 URLTestHelpers::registerMockedURLLoad(testURL, "cancelTest.html", | 1195 ScopedRegisteredURL scopedRegisteredURL(testURL); |
| 1195 "text/html"); | |
| 1196 ResourceRequest request = ResourceRequest(testURL); | 1196 ResourceRequest request = ResourceRequest(testURL); |
| 1197 ImageResource* imageResource = ImageResource::create(request); | 1197 ImageResource* imageResource = ImageResource::create(request); |
| 1198 imageResource->setStatus(ResourceStatus::Pending); | 1198 imageResource->setStatus(ResourceStatus::Pending); |
| 1199 | 1199 |
| 1200 std::unique_ptr<MockImageResourceObserver> observer = | 1200 std::unique_ptr<MockImageResourceObserver> observer = |
| 1201 MockImageResourceObserver::create(imageResource->getContent()); | 1201 MockImageResourceObserver::create(imageResource->getContent()); |
| 1202 | 1202 |
| 1203 // Send the image response. | 1203 // Send the image response. |
| 1204 ResourceResponse resourceResponse(KURL(), "image/jpeg", sizeof(kJpegImage2), | 1204 ResourceResponse resourceResponse(KURL(), "image/jpeg", sizeof(kJpegImage2), |
| 1205 nullAtom, String()); | 1205 nullAtom, String()); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1269 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); | 1269 EXPECT_TRUE(observer->imageNotifyFinishedCalled()); |
| 1270 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage()); | 1270 EXPECT_TRUE(imageResource->getContent()->getImage()->isBitmapImage()); |
| 1271 EXPECT_EQ(50, imageResource->getContent()->getImage()->width()); | 1271 EXPECT_EQ(50, imageResource->getContent()->getImage()->width()); |
| 1272 EXPECT_EQ(50, imageResource->getContent()->getImage()->height()); | 1272 EXPECT_EQ(50, imageResource->getContent()->getImage()->height()); |
| 1273 | 1273 |
| 1274 WTF::setTimeFunctionsForTesting(nullptr); | 1274 WTF::setTimeFunctionsForTesting(nullptr); |
| 1275 } | 1275 } |
| 1276 | 1276 |
| 1277 } // namespace | 1277 } // namespace |
| 1278 } // namespace blink | 1278 } // namespace blink |
| OLD | NEW |