|
1 | 1 | package org.eclipse.swt.browser; |
2 | 2 |
|
| 3 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
3 | 4 | import static org.junit.jupiter.api.Assertions.assertTrue; |
4 | 5 |
|
5 | 6 | import java.nio.file.*; |
| 7 | +import java.util.*; |
6 | 8 |
|
7 | 9 | import org.eclipse.swt.internal.*; |
8 | | -import org.junit.jupiter.api.*; |
| 10 | +import org.junit.*; |
| 11 | +import org.junit.jupiter.api.Test; |
9 | 12 | import org.junit.jupiter.api.extension.*; |
10 | 13 |
|
11 | 14 | @ExtendWith(PlatformSpecificExecutionExtension.class) |
12 | 15 | class EdgeTests { |
13 | 16 |
|
| 17 | + private String originalTempDir; |
| 18 | + |
| 19 | + @Before |
| 20 | + public void setup() throws Exception { |
| 21 | + originalTempDir = System.getProperty("java.io.tmpdir"); |
| 22 | + } |
| 23 | + |
| 24 | + @After |
| 25 | + public void tearDown() throws Exception { |
| 26 | + setTempDirAndInitializeEdgeLocationForCustomTextPage(originalTempDir); |
| 27 | + } |
| 28 | + |
| 29 | + private static void setTempDirAndInitializeEdgeLocationForCustomTextPage(String dir) { |
| 30 | + System.setProperty("java.io.tmpdir", dir); |
| 31 | + Edge.setupLocationForCustomTextPage(); |
| 32 | + } |
| 33 | + |
14 | 34 | /** |
15 | 35 | * https://github.com/eclipse-platform/eclipse.platform.swt/issues/1912 |
16 | 36 | */ |
17 | 37 | @Test |
18 | 38 | public void handlingOfTempDirWithSpacesAndUnicodeCharacters() throws Exception { |
19 | | - String originalTempDir = System.getProperty("java.io.tmpdir"); |
20 | | - String temporaryTempDirWithSpacesAndUnicode = Files.createTempDirectory("spaces and únîcòde").toString(); |
21 | | - System.setProperty("java.io.tmpdir", temporaryTempDirWithSpacesAndUnicode); |
22 | | - try { |
23 | | - Edge.setupLocationForCustomTextPage(); |
24 | | - |
25 | | - // URI_FOR_CUSTOM_TEXT_PAGE must already be encoded internally |
26 | | - assertTrue(Edge.URI_FOR_CUSTOM_TEXT_PAGE.toString().contains("spaces%20and%20%C3%BAn%C3%AEc%C3%B2de")); |
27 | | - assertTrue(Edge.isLocationForCustomText(Edge.URI_FOR_CUSTOM_TEXT_PAGE.toASCIIString())); |
28 | | - |
29 | | - } finally { |
30 | | - System.setProperty("java.io.tmpdir", originalTempDir); |
31 | | - Edge.setupLocationForCustomTextPage(); // restore the original value |
32 | | - } |
| 39 | + setTempDirAndInitializeEdgeLocationForCustomTextPage( |
| 40 | + Files.createTempDirectory("spaces and únîcòde").toString()); |
| 41 | + |
| 42 | + // URI_FOR_CUSTOM_TEXT_PAGE must already be encoded internally |
| 43 | + // for correct handling of spaces and unicode characters |
| 44 | + assertTrue(Edge.URI_FOR_CUSTOM_TEXT_PAGE.toString().contains("spaces%20and%20%C3%BAn%C3%AEc%C3%B2de")); |
| 45 | + assertTrue(Edge.isLocationForCustomText(Edge.URI_FOR_CUSTOM_TEXT_PAGE.toASCIIString())); |
| 46 | + } |
| 47 | + |
| 48 | + /** |
| 49 | + * https://github.com/eclipse-platform/eclipse.platform.swt/issues/2061 |
| 50 | + */ |
| 51 | + @Test |
| 52 | + public void handlingOfUpperLowerCase() throws Exception { |
| 53 | + setTempDirAndInitializeEdgeLocationForCustomTextPage(Files.createTempDirectory("FoObAr").toString()); |
| 54 | + |
| 55 | + String lowerCaseUri = Edge.URI_FOR_CUSTOM_TEXT_PAGE.toASCIIString().toLowerCase(Locale.ROOT); |
| 56 | + String upperCaseUri = "file" |
| 57 | + + Edge.URI_FOR_CUSTOM_TEXT_PAGE.toASCIIString().toUpperCase(Locale.ROOT).substring(4); |
| 58 | + |
| 59 | + assertTrue(Edge.isLocationForCustomText(lowerCaseUri)); |
| 60 | + assertTrue(Edge.isLocationForCustomText(upperCaseUri)); |
| 61 | + } |
| 62 | + |
| 63 | + @Test |
| 64 | + public void handlingOfNonFileURIs() throws Exception { |
| 65 | + setTempDirAndInitializeEdgeLocationForCustomTextPage(Files.createTempDirectory("any").toString()); |
| 66 | + |
| 67 | + String httpsUri = "https://eclipse.org"; |
| 68 | + |
| 69 | + assertFalse(Edge.isLocationForCustomText(httpsUri)); |
33 | 70 | } |
| 71 | + |
| 72 | + @Test |
| 73 | + public void handlingOfInvalidFileURIs() throws Exception { |
| 74 | + setTempDirAndInitializeEdgeLocationForCustomTextPage(Files.createTempDirectory("any").toString()); |
| 75 | + |
| 76 | + String brokenFileUri = "file://--"; |
| 77 | + |
| 78 | + assertFalse(Edge.isLocationForCustomText(brokenFileUri)); |
| 79 | + } |
| 80 | + |
34 | 81 | } |
0 commit comments