This is supported by reals browsers but not with HtmlUnit. @throws Exception if the test fails
()
| 439 | * @throws Exception if the test fails |
| 440 | */ |
| 441 | @Test |
| 442 | public void localFile() throws Exception { |
| 443 | final URL url = getClass().getClassLoader().getResource("simple.html"); |
| 444 | String file = URLDecoder.decode(url.getFile(), StandardCharsets.UTF_8); |
| 445 | if (file.startsWith("/") && file.contains(":")) { |
| 446 | // we have to remove the trailing slash to test the c:\.... case. |
| 447 | file = file.substring(1); |
| 448 | } |
| 449 | |
| 450 | assertTrue("File '" + file + "' does not exist", new File(file).exists()); |
| 451 | |
| 452 | try (WebClient webClient = new WebClient(getBrowserVersion())) { |
| 453 | webClient.getPage(file); |
| 454 | fail("IOException expected"); |
| 455 | } |
| 456 | catch (final IOException e) { |
| 457 | assertTrue(e.getMessage(), |
| 458 | e.getMessage().startsWith("Unsupported protocol '") |
| 459 | || e.getMessage().startsWith("no protocol: /")); |
| 460 | } |
| 461 | } |
| 462 | |
| 463 | /** |
| 464 | * @throws Exception if the test fails |
nothing calls this directly
no test coverage detected