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.htmlunit.junit.BrowserRunner;
21 import org.junit.Test;
22 import org.junit.runner.RunWith;
23
24
25
26
27
28
29
30 @RunWith(BrowserRunner.class)
31 public final class IncorrectnessListenerTest extends SimpleWebTestCase {
32
33
34
35
36 @Test
37 public void notification() throws Exception {
38 final String html = DOCTYPE_HTML
39 + "<html><head>\n"
40 + " <script src='script.js'></script>\n"
41 + "</head>\n"
42 + "<body>\n"
43 + "</body>\n"
44 + "</html>";
45
46 final WebClient webClient = getWebClient();
47
48 final List<String> collectedIncorrectness = new ArrayList<>();
49 final IncorrectnessListener listener = new IncorrectnessListener() {
50 @Override
51 public void notify(final String message, final Object origin) {
52 collectedIncorrectness.add(message);
53 }
54 };
55 webClient.setIncorrectnessListener(listener);
56
57 final MockWebConnection webConnection = new MockWebConnection();
58 webClient.setWebConnection(webConnection);
59 webConnection.setResponse(URL_FIRST, html);
60 webConnection.setDefaultResponse("alert('Hello');", "application/x-javascript");
61 webClient.getPage(URL_FIRST);
62
63 final String[] expectedIncorrectness = {
64 "Obsolete content type encountered: 'application/x-javascript' for "
65 + "remotely loaded JavaScript element at 'http://localhost:22222/script.js'."
66 };
67 assertEquals(expectedIncorrectness, collectedIncorrectness);
68 }
69 }