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 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 EXPECT_EQ("image/svg+xml", cachedImage->response().mimeType()); | 224 EXPECT_EQ("image/svg+xml", cachedImage->response().mimeType()); |
225 | 225 |
226 const char secondPart[] = "<svg xmlns='http://www.w3.org/2000/svg' width='1'
height='1'><rect width='1' height='1' fill='green'/></svg>\n"; | 226 const char secondPart[] = "<svg xmlns='http://www.w3.org/2000/svg' width='1'
height='1'><rect width='1' height='1' fill='green'/></svg>\n"; |
227 // The first bytes arrive. The data buffer is created, but no image is creat
ed. | 227 // The first bytes arrive. The data buffer is created, but no image is creat
ed. |
228 cachedImage->appendData(secondPart, strlen(secondPart)); | 228 cachedImage->appendData(secondPart, strlen(secondPart)); |
229 ASSERT_TRUE(cachedImage->resourceBuffer()); | 229 ASSERT_TRUE(cachedImage->resourceBuffer()); |
230 ASSERT_FALSE(cachedImage->hasImage()); | 230 ASSERT_FALSE(cachedImage->hasImage()); |
231 ASSERT_EQ(client->imageChangedCount(), 0); | 231 ASSERT_EQ(client->imageChangedCount(), 0); |
232 ASSERT_FALSE(client->notifyFinishedCalled()); | 232 ASSERT_FALSE(client->notifyFinishedCalled()); |
233 | 233 |
| 234 // Add a client to check an assertion error doesn't happen |
| 235 // (crbug.com/630983). |
| 236 Persistent<MockImageResourceClient> client2 = new MockImageResourceClient(ca
chedImage); |
| 237 ASSERT_EQ(client2->imageChangedCount(), 0); |
| 238 ASSERT_FALSE(client2->notifyFinishedCalled()); |
| 239 |
234 const char thirdPart[] = "--boundary"; | 240 const char thirdPart[] = "--boundary"; |
235 cachedImage->appendData(thirdPart, strlen(thirdPart)); | 241 cachedImage->appendData(thirdPart, strlen(thirdPart)); |
236 ASSERT_TRUE(cachedImage->resourceBuffer()); | 242 ASSERT_TRUE(cachedImage->resourceBuffer()); |
237 ASSERT_EQ(cachedImage->resourceBuffer()->size(), strlen(secondPart) - 1); | 243 ASSERT_EQ(cachedImage->resourceBuffer()->size(), strlen(secondPart) - 1); |
238 | 244 |
239 // This part finishes. The image is created, callbacks are sent, and the dat
a buffer is cleared. | 245 // This part finishes. The image is created, callbacks are sent, and the dat
a buffer is cleared. |
240 cachedImage->loader()->didFinishLoading(nullptr, 0.0, 0); | 246 cachedImage->loader()->didFinishLoading(nullptr, 0.0, 0); |
241 ASSERT_TRUE(cachedImage->resourceBuffer()); | 247 ASSERT_TRUE(cachedImage->resourceBuffer()); |
242 ASSERT_FALSE(cachedImage->errorOccurred()); | 248 ASSERT_FALSE(cachedImage->errorOccurred()); |
243 ASSERT_TRUE(cachedImage->hasImage()); | 249 ASSERT_TRUE(cachedImage->hasImage()); |
244 ASSERT_FALSE(cachedImage->getImage()->isNull()); | 250 ASSERT_FALSE(cachedImage->getImage()->isNull()); |
245 ASSERT_EQ(cachedImage->getImage()->width(), 1); | 251 ASSERT_EQ(cachedImage->getImage()->width(), 1); |
246 ASSERT_EQ(cachedImage->getImage()->height(), 1); | 252 ASSERT_EQ(cachedImage->getImage()->height(), 1); |
247 ASSERT_EQ(client->imageChangedCount(), 1); | 253 ASSERT_EQ(client->imageChangedCount(), 1); |
248 ASSERT_TRUE(client->notifyFinishedCalled()); | 254 ASSERT_TRUE(client->notifyFinishedCalled()); |
| 255 ASSERT_EQ(client2->imageChangedCount(), 1); |
| 256 ASSERT_TRUE(client2->notifyFinishedCalled()); |
249 } | 257 } |
250 | 258 |
251 TEST(ImageResourceTest, CancelOnDetach) | 259 TEST(ImageResourceTest, CancelOnDetach) |
252 { | 260 { |
253 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); | 261 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); |
254 URLTestHelpers::registerMockedURLLoad(testURL, "cancelTest.html", "text/html
"); | 262 URLTestHelpers::registerMockedURLLoad(testURL, "cancelTest.html", "text/html
"); |
255 | 263 |
256 ResourceFetcher* fetcher = ResourceFetcher::create(ImageResourceTestMockFetc
hContext::create()); | 264 ResourceFetcher* fetcher = ResourceFetcher::create(ImageResourceTestMockFetc
hContext::create()); |
257 | 265 |
258 // Emulate starting a real load. | 266 // Emulate starting a real load. |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
615 Persistent<MockResourceClient> client2 = new MockResourceClient(imageResourc
e); | 623 Persistent<MockResourceClient> client2 = new MockResourceClient(imageResourc
e); |
616 | 624 |
617 ASSERT_TRUE(imageResource->hasImage()); | 625 ASSERT_TRUE(imageResource->hasImage()); |
618 EXPECT_FALSE(imageResource->getImage()->isNull()); | 626 EXPECT_FALSE(imageResource->getImage()->isNull()); |
619 EXPECT_EQ(1, imageResource->getImage()->width()); | 627 EXPECT_EQ(1, imageResource->getImage()->width()); |
620 EXPECT_EQ(1, imageResource->getImage()->height()); | 628 EXPECT_EQ(1, imageResource->getImage()->height()); |
621 EXPECT_TRUE(client2->notifyFinishedCalled()); | 629 EXPECT_TRUE(client2->notifyFinishedCalled()); |
622 } | 630 } |
623 | 631 |
624 } // namespace blink | 632 } // namespace blink |
OLD | NEW |