MCPcopy Create free account
hub / github.com/HtmlUnit/htmlunit / cssUrlEncoded

Method cssUrlEncoded

src/test/java/org/htmlunit/CacheTest.java:326–393  ·  view source on GitHub ↗

@throws Exception if the test fails

()

Source from the content-addressed store, hash-verified

324 * @throws Exception if the test fails
325 */
326 @Test
327 public void cssUrlEncoded() throws Exception {
328 final String content = DOCTYPE_HTML
329 + "<html>\n"
330 + "<head>\n"
331 + " <title>page 1</title>\n"
332 + " <link href='foo1.css' type='text/css' rel='stylesheet'>\n"
333 + " <link href='foo2.js?foo[1]=bar/baz' type='text/css' rel='stylesheet'>\n"
334 + "</head>\n"
335 + "<body>\n"
336 + " <a href='page2.html'>to page 2</a>\n"
337 + " <script>\n"
338 + " var sheets = document.styleSheets;\n"
339 + " alert(sheets.length);\n"
340 + " var rules = sheets[0].cssRules || sheets[0].rules;\n"
341 + " alert(rules.length);\n"
342 + " rules = sheets[1].cssRules || sheets[1].rules;\n"
343 + " alert(rules.length);\n"
344 + " </script>\n"
345 + "</body>\n"
346 + "</html>";
347
348 final String content2 = DOCTYPE_HTML
349 + "<html>\n"
350 + "<head>\n"
351 + " <title>page 2</title>\n"
352 + " <link href='foo2.js?foo[1]=bar/baz' type='text/css' rel='stylesheet'>\n"
353 + "</head>\n"
354 + "<body>\n"
355 + " <a href='page1.html'>to page 1</a>\n"
356 + " <script>\n"
357 + " var sheets = document.styleSheets;\n"
358 + " alert(sheets.length);\n"
359 + " var rules = sheets[0].cssRules || sheets[0].rules;\n"
360 + " alert(rules.length);\n"
361 + " </script>\n"
362 + "</body>\n"
363 + "</html>";
364
365 final URL urlPage1 = new URL(URL_FIRST, "page1.html");
366 getMockWebConnection().setResponse(urlPage1, content);
367 final URL urlPage2 = new URL(URL_FIRST, "page2.html");
368 getMockWebConnection().setResponse(urlPage2, content2);
369
370 final List<NameValuePair> headers = new ArrayList<>();
371 headers.add(new NameValuePair(LAST_MODIFIED, "Sun, 15 Jul 2007 20:46:27 GMT"));
372 getMockWebConnection().setResponse(new URL(URL_FIRST, "foo1.js"), "",
373 200, "ok", MimeType.TEXT_CSS, headers);
374 getMockWebConnection().setDefaultResponse("", 200, "ok", MimeType.TEXT_CSS, headers);
375
376 final WebClient webClient = getWebClientWithMockWebConnection();
377
378 final List<String> collectedAlerts = new ArrayList<>();
379 webClient.setAlertHandler(new CollectingAlertHandler(collectedAlerts));
380
381 final HtmlPage page1 = webClient.getPage(urlPage1);
382 final String[] expectedAlerts = {"2", "0", "0"};
383 assertEquals(expectedAlerts, collectedAlerts);

Callers

nothing calls this directly

Calls 15

setAlertHandlerMethod · 0.95
getPageMethod · 0.95
getAnchorsMethod · 0.95
setResponseMethod · 0.80
getMockWebConnectionMethod · 0.80
setDefaultResponseMethod · 0.80
getRequestCountMethod · 0.80
getLastWebRequestMethod · 0.80
getUrlMethod · 0.65
addMethod · 0.45
assertEqualsMethod · 0.45

Tested by

no test coverage detected