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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
77 0x00, 0x00, 0xff, 0xda, 0x00, 0x0c, 0x03, 0x01, 0x00, 0x02, 0x11, 0x03, 0x11, 0x00, 0x3f, | 77 0x00, 0x00, 0xff, 0xda, 0x00, 0x0c, 0x03, 0x01, 0x00, 0x02, 0x11, 0x03, 0x11, 0x00, 0x3f, |
78 0x00, 0xb2, 0xc0, 0x07, 0xff, 0xd9 | 78 0x00, 0xb2, 0xc0, 0x07, 0xff, 0xd9 |
79 }; | 79 }; |
80 | 80 |
81 jpeg.append(data, sizeof(data)); | 81 jpeg.append(data, sizeof(data)); |
82 return jpeg; | 82 return jpeg; |
83 } | 83 } |
84 | 84 |
85 TEST(ImageResourceTest, MultipartImage) | 85 TEST(ImageResourceTest, MultipartImage) |
86 { | 86 { |
87 RefPtrWillBeRawPtr<ResourceFetcher> fetcher = ResourceFetcher::create(nullpt r); | 87 ResourceFetcher* fetcher = ResourceFetcher::create(nullptr); |
88 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); | 88 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); |
89 URLTestHelpers::registerMockedURLLoad(testURL, "cancelTest.html", "text/html "); | 89 URLTestHelpers::registerMockedURLLoad(testURL, "cancelTest.html", "text/html "); |
90 | 90 |
91 // Emulate starting a real load, but don't expect any "real" WebURLLoaderCli ent callbacks. | 91 // Emulate starting a real load, but don't expect any "real" WebURLLoaderCli ent callbacks. |
92 ResourcePtr<ImageResource> cachedImage = new ImageResource(ResourceRequest(t estURL), nullptr); | 92 ResourcePtr<ImageResource> cachedImage = new ImageResource(ResourceRequest(t estURL), nullptr); |
93 cachedImage->setIdentifier(createUniqueIdentifier()); | 93 cachedImage->setIdentifier(createUniqueIdentifier()); |
94 cachedImage->load(fetcher.get(), ResourceLoaderOptions()); | 94 cachedImage->load(fetcher, ResourceLoaderOptions()); |
95 Platform::current()->unitTestSupport()->unregisterMockedURL(testURL); | 95 Platform::current()->unitTestSupport()->unregisterMockedURL(testURL); |
96 | 96 |
97 MockImageResourceClient client; | 97 MockImageResourceClient client; |
98 cachedImage->addClient(&client); | 98 cachedImage->addClient(&client); |
99 EXPECT_EQ(Resource::Pending, cachedImage->status()); | 99 EXPECT_EQ(Resource::Pending, cachedImage->status()); |
100 | 100 |
101 // Send the multipart response. No image or data buffer is created. | 101 // Send the multipart response. No image or data buffer is created. |
102 // Note that the response must be routed through ResourceLoader to | 102 // Note that the response must be routed through ResourceLoader to |
103 // ensure the load is flagged as multipart. | 103 // ensure the load is flagged as multipart. |
104 ResourceResponse multipartResponse(KURL(), "multipart/x-mixed-replace", 0, n ullAtom, String()); | 104 ResourceResponse multipartResponse(KURL(), "multipart/x-mixed-replace", 0, n ullAtom, String()); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
136 ASSERT_EQ(cachedImage->image()->height(), 1); | 136 ASSERT_EQ(cachedImage->image()->height(), 1); |
137 ASSERT_EQ(client.imageChangedCount(), 2); | 137 ASSERT_EQ(client.imageChangedCount(), 2); |
138 ASSERT_TRUE(client.notifyFinishedCalled()); | 138 ASSERT_TRUE(client.notifyFinishedCalled()); |
139 } | 139 } |
140 | 140 |
141 TEST(ImageResourceTest, CancelOnDetach) | 141 TEST(ImageResourceTest, CancelOnDetach) |
142 { | 142 { |
143 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); | 143 KURL testURL(ParsedURLString, "http://www.test.com/cancelTest.html"); |
144 URLTestHelpers::registerMockedURLLoad(testURL, "cancelTest.html", "text/html "); | 144 URLTestHelpers::registerMockedURLLoad(testURL, "cancelTest.html", "text/html "); |
145 | 145 |
146 RefPtrWillBeRawPtr<ResourceFetcher> fetcher = ResourceFetcher::create(nullpt r); | 146 ResourceFetcher* fetcher = ResourceFetcher::create(FetchContext::create()); |
sof
2015/06/29 13:29:29
Why are we passing FetchContext::create() instead
peria
2015/06/30 07:14:39
Thank you for pointing it out.
I was not aware of
| |
147 | 147 |
148 // Emulate starting a real load. | 148 // Emulate starting a real load. |
149 ResourcePtr<ImageResource> cachedImage = new ImageResource(ResourceRequest(t estURL), nullptr); | 149 ResourcePtr<ImageResource> cachedImage = new ImageResource(ResourceRequest(t estURL), nullptr); |
150 cachedImage->setIdentifier(createUniqueIdentifier()); | 150 cachedImage->setIdentifier(createUniqueIdentifier()); |
151 | 151 |
152 cachedImage->load(fetcher.get(), ResourceLoaderOptions()); | 152 cachedImage->load(fetcher, ResourceLoaderOptions()); |
153 memoryCache()->add(cachedImage.get()); | 153 memoryCache()->add(cachedImage.get()); |
154 | 154 |
155 MockImageResourceClient client; | 155 MockImageResourceClient client; |
156 cachedImage->addClient(&client); | 156 cachedImage->addClient(&client); |
157 EXPECT_EQ(Resource::Pending, cachedImage->status()); | 157 EXPECT_EQ(Resource::Pending, cachedImage->status()); |
158 | 158 |
159 // The load should still be alive, but a timer should be started to cancel t he load inside removeClient(). | 159 // The load should still be alive, but a timer should be started to cancel t he load inside removeClient(). |
160 cachedImage->removeClient(&client); | 160 cachedImage->removeClient(&client); |
161 EXPECT_EQ(Resource::Pending, cachedImage->status()); | 161 EXPECT_EQ(Resource::Pending, cachedImage->status()); |
162 EXPECT_NE(reinterpret_cast<Resource*>(0), memoryCache()->resourceForURL(test URL)); | 162 EXPECT_NE(reinterpret_cast<Resource*>(0), memoryCache()->resourceForURL(test URL)); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
221 ASSERT_FALSE(cachedImage->image()->isNull()); | 221 ASSERT_FALSE(cachedImage->image()->isNull()); |
222 ASSERT_EQ(client.imageChangedCount(), 2); | 222 ASSERT_EQ(client.imageChangedCount(), 2); |
223 ASSERT_TRUE(client.notifyFinishedCalled()); | 223 ASSERT_TRUE(client.notifyFinishedCalled()); |
224 | 224 |
225 HashSet<ImageResource*> bitmapImages; | 225 HashSet<ImageResource*> bitmapImages; |
226 ASSERT_TRUE(cachedImage->image()->isBitmapImage()); | 226 ASSERT_TRUE(cachedImage->image()->isBitmapImage()); |
227 bitmapImages.add(cachedImage.get()); | 227 bitmapImages.add(cachedImage.get()); |
228 } | 228 } |
229 | 229 |
230 } // namespace blink | 230 } // namespace blink |
OLD | NEW |