@throws Exception if the test fails
()
| 501 | * @throws Exception if the test fails |
| 502 | */ |
| 503 | @Test |
| 504 | public void cssFromCacheIsUsed() throws Exception { |
| 505 | final String html = DOCTYPE_HTML |
| 506 | + "<html><head><title>page 1</title>\n" |
| 507 | + "<link rel='stylesheet' type='text/css' href='foo.css' />\n" |
| 508 | + "<link rel='stylesheet' type='text/css' href='foo.css' />\n" |
| 509 | + "</head>\n" |
| 510 | + "<body>x</body>\n" |
| 511 | + "</html>"; |
| 512 | |
| 513 | final String css = ".x { color: red; }"; |
| 514 | |
| 515 | final WebClient client = getWebClient(); |
| 516 | |
| 517 | final MockWebConnection connection = new MockWebConnection(); |
| 518 | client.setWebConnection(connection); |
| 519 | |
| 520 | final URL pageUrl = new URL(URL_FIRST, "page1.html"); |
| 521 | connection.setResponse(pageUrl, html); |
| 522 | |
| 523 | final URL cssUrl = new URL(URL_FIRST, "foo.css"); |
| 524 | final List<NameValuePair> headers = new ArrayList<>(); |
| 525 | headers.add(new NameValuePair(LAST_MODIFIED, "Sun, 15 Jul 2007 20:46:27 GMT")); |
| 526 | connection.setResponse(cssUrl, css, 200, "OK", MimeType.TEXT_CSS, headers); |
| 527 | |
| 528 | client.getPage(pageUrl); |
| 529 | |
| 530 | assertEquals(2, connection.getRequestCount()); |
| 531 | assertEquals(1, client.getCache().getSize()); |
| 532 | } |
| 533 | |
| 534 | /** |
| 535 | * @throws Exception if the test fails |
nothing calls this directly
no test coverage detected