|
16 | 16 | import static org.junit.jupiter.api.Assertions.assertEquals; |
17 | 17 | import static org.junit.jupiter.api.Assertions.assertNotNull; |
18 | 18 |
|
| 19 | +import java.io.File; |
| 20 | +import java.io.IOException; |
19 | 21 | import java.net.URL; |
| 22 | +import java.nio.file.Files; |
| 23 | +import java.nio.file.StandardCopyOption; |
20 | 24 |
|
21 | 25 | import org.eclipse.jface.resource.ImageDescriptor; |
22 | 26 | import org.eclipse.swt.graphics.ImageData; |
@@ -199,4 +203,71 @@ public void testQueryParameterWithMultipleParams() throws Exception { |
199 | 203 | assertEquals(24, imageData.height, "Height should be 24 from query parameter"); |
200 | 204 | } |
201 | 205 |
|
| 206 | + /** |
| 207 | + * Tests that file: URLs can have query parameters for size hints. |
| 208 | + * This is important because file URLs need special handling - the query |
| 209 | + * parameter should be used for size detection but stripped when accessing |
| 210 | + * the actual file. |
| 211 | + */ |
| 212 | + @Test |
| 213 | + public void testFileURLWithQueryParameter() throws IOException { |
| 214 | + // Copy test SVG to a temporary file |
| 215 | + URL resourceUrl = URLHintProviderTest.class.getResource("/icons/imagetests/test-icon.svg"); |
| 216 | + assertNotNull(resourceUrl, "Test SVG not found"); |
| 217 | + |
| 218 | + File tempSvg = File.createTempFile("test-icon", ".svg"); |
| 219 | + try { |
| 220 | + Files.copy(resourceUrl.openStream(), tempSvg.toPath(), StandardCopyOption.REPLACE_EXISTING); |
| 221 | + |
| 222 | + // Create file: URL with query parameter |
| 223 | + URL fileUrl = tempSvg.toURI().toURL(); |
| 224 | + String fileUrlWithQuery = fileUrl.toExternalForm() + "?size=16x16"; |
| 225 | + URL fileUrlQuery = new URL(fileUrlWithQuery); |
| 226 | + |
| 227 | + // Verify URL has file protocol and query parameter |
| 228 | + assertEquals("file", fileUrlQuery.getProtocol(), "Should be a file URL"); |
| 229 | + assertEquals("size=16x16", fileUrlQuery.getQuery(), "Query parameter should be preserved"); |
| 230 | + |
| 231 | + // Test that ImageDescriptor can load the image with query parameter |
| 232 | + ImageDescriptor descriptor = ImageDescriptor.createFromURL(fileUrlQuery); |
| 233 | + ImageData imageData = descriptor.getImageData(100); |
| 234 | + |
| 235 | + assertNotNull(imageData, "ImageData should not be null for file URL with query parameter"); |
| 236 | + assertEquals(16, imageData.width, "Width should be 16 based on query parameter"); |
| 237 | + assertEquals(16, imageData.height, "Height should be 16 based on query parameter"); |
| 238 | + } finally { |
| 239 | + tempSvg.delete(); |
| 240 | + } |
| 241 | + } |
| 242 | + |
| 243 | + /** |
| 244 | + * Tests that file: URLs with query parameters work at different zoom levels. |
| 245 | + */ |
| 246 | + @Test |
| 247 | + public void testFileURLWithQueryParameterZoom() throws IOException { |
| 248 | + // Copy test SVG to a temporary file |
| 249 | + URL resourceUrl = URLHintProviderTest.class.getResource("/icons/imagetests/test-icon.svg"); |
| 250 | + assertNotNull(resourceUrl, "Test SVG not found"); |
| 251 | + |
| 252 | + File tempSvg = File.createTempFile("test-icon", ".svg"); |
| 253 | + try { |
| 254 | + Files.copy(resourceUrl.openStream(), tempSvg.toPath(), StandardCopyOption.REPLACE_EXISTING); |
| 255 | + |
| 256 | + // Create file: URL with query parameter |
| 257 | + URL fileUrl = tempSvg.toURI().toURL(); |
| 258 | + String fileUrlWithQuery = fileUrl.toExternalForm() + "?size=16x16"; |
| 259 | + URL fileUrlQuery = new URL(fileUrlWithQuery); |
| 260 | + |
| 261 | + // Test at 200% zoom |
| 262 | + ImageDescriptor descriptor = ImageDescriptor.createFromURL(fileUrlQuery); |
| 263 | + ImageData imageData = descriptor.getImageData(200); |
| 264 | + |
| 265 | + assertNotNull(imageData, "ImageData should not be null"); |
| 266 | + assertEquals(32, imageData.width, "Width should be 32 (16*2) at 200% zoom"); |
| 267 | + assertEquals(32, imageData.height, "Height should be 32 (16*2) at 200% zoom"); |
| 268 | + } finally { |
| 269 | + tempSvg.delete(); |
| 270 | + } |
| 271 | + } |
| 272 | + |
202 | 273 | } |
0 commit comments