1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit;
16
17 import java.util.ArrayList;
18 import java.util.List;
19
20 import org.junit.jupiter.api.Test;
21
22
23
24
25
26
27
28 public final class IncorrectnessListenerTest extends SimpleWebTestCase {
29
30
31
32
33 @Test
34 public void notification() throws Exception {
35 final String html = DOCTYPE_HTML
36 + "<html><head>\n"
37 + " <script src='script.js'></script>\n"
38 + "</head>\n"
39 + "<body>\n"
40 + "</body>\n"
41 + "</html>";
42
43 final WebClient webClient = getWebClient();
44
45 final List<String> collectedIncorrectness = new ArrayList<>();
46 final IncorrectnessListener listener = new IncorrectnessListener() {
47 @Override
48 public void notify(final String message, final Object origin) {
49 collectedIncorrectness.add(message);
50 }
51 };
52 webClient.setIncorrectnessListener(listener);
53
54 final MockWebConnection webConnection = new MockWebConnection();
55 webClient.setWebConnection(webConnection);
56 webConnection.setResponse(URL_FIRST, html);
57 webConnection.setDefaultResponse("alert('Hello');", "application/x-javascript");
58 webClient.getPage(URL_FIRST);
59
60 final String[] expectedIncorrectness = {
61 "Obsolete content type encountered: 'application/x-javascript' for "
62 + "remotely loaded JavaScript element at 'http://localhost:22222/script.js'."
63 };
64 assertEquals(expectedIncorrectness, collectedIncorrectness);
65 }
66 }