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 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()); |
|
hiroshige
2016/07/27 08:13:40
Could you confirm that |client2| is also notified,
hajimehoshi
2016/07/27 08:26:30
Done.
| |
| 249 } | 255 } |
| 250 | 256 |
| 251 TEST(ImageResourceTest, CancelOnDetach) | 257 TEST(ImageResourceTest, CancelOnDetach) |
| 252 { | 258 { |
| 253 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); | 259 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); |
| 254 URLTestHelpers::registerMockedURLLoad(testURL, "cancelTest.html", "text/html "); | 260 URLTestHelpers::registerMockedURLLoad(testURL, "cancelTest.html", "text/html "); |
| 255 | 261 |
| 256 ResourceFetcher* fetcher = ResourceFetcher::create(ImageResourceTestMockFetc hContext::create()); | 262 ResourceFetcher* fetcher = ResourceFetcher::create(ImageResourceTestMockFetc hContext::create()); |
| 257 | 263 |
| 258 // Emulate starting a real load. | 264 // 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); | 621 Persistent<MockResourceClient> client2 = new MockResourceClient(imageResourc e); |
| 616 | 622 |
| 617 ASSERT_TRUE(imageResource->hasImage()); | 623 ASSERT_TRUE(imageResource->hasImage()); |
| 618 EXPECT_FALSE(imageResource->getImage()->isNull()); | 624 EXPECT_FALSE(imageResource->getImage()->isNull()); |
| 619 EXPECT_EQ(1, imageResource->getImage()->width()); | 625 EXPECT_EQ(1, imageResource->getImage()->width()); |
| 620 EXPECT_EQ(1, imageResource->getImage()->height()); | 626 EXPECT_EQ(1, imageResource->getImage()->height()); |
| 621 EXPECT_TRUE(client2->notifyFinishedCalled()); | 627 EXPECT_TRUE(client2->notifyFinishedCalled()); |
| 622 } | 628 } |
| 623 | 629 |
| 624 } // namespace blink | 630 } // namespace blink |
| OLD | NEW |