@throws Exception if the test fails
()
| 265 | * @throws Exception if the test fails |
| 266 | */ |
| 267 | @Test |
| 268 | public void jsUrlEncoded() throws Exception { |
| 269 | final String content = DOCTYPE_HTML |
| 270 | + "<html>\n" |
| 271 | + "<head>\n" |
| 272 | + " <title>page 1</title>\n" |
| 273 | + " <script src='foo1.js'></script>\n" |
| 274 | + " <script src='foo2.js?foo[1]=bar/baz'></script>\n" |
| 275 | + "</head>\n" |
| 276 | + "<body>\n" |
| 277 | + " <a href='page2.html'>to page 2</a>\n" |
| 278 | + "</body>\n" |
| 279 | + "</html>"; |
| 280 | |
| 281 | final String content2 = DOCTYPE_HTML |
| 282 | + "<html>\n" |
| 283 | + "<head>\n" |
| 284 | + " <title>page 2</title>\n" |
| 285 | + " <script src='foo2.js?foo[1]=bar/baz'></script>\n" |
| 286 | + "</head>\n" |
| 287 | + "<body>\n" |
| 288 | + " <a href='page1.html'>to page 1</a>\n" |
| 289 | + "</body>\n" |
| 290 | + "</html>"; |
| 291 | |
| 292 | final String script1 = "alert('in foo1');"; |
| 293 | final String script2 = "alert('in foo2');"; |
| 294 | |
| 295 | final URL urlPage1 = new URL(URL_FIRST, "page1.html"); |
| 296 | getMockWebConnection().setResponse(urlPage1, content); |
| 297 | final URL urlPage2 = new URL(URL_FIRST, "page2.html"); |
| 298 | getMockWebConnection().setResponse(urlPage2, content2); |
| 299 | |
| 300 | final List<NameValuePair> headers = new ArrayList<>(); |
| 301 | headers.add(new NameValuePair(LAST_MODIFIED, "Sun, 15 Jul 2007 20:46:27 GMT")); |
| 302 | getMockWebConnection().setResponse(new URL(URL_FIRST, "foo1.js"), script1, |
| 303 | 200, "ok", MimeType.TEXT_JAVASCRIPT, headers); |
| 304 | getMockWebConnection().setDefaultResponse(script2, 200, "ok", MimeType.TEXT_JAVASCRIPT, headers); |
| 305 | |
| 306 | final WebClient webClient = getWebClientWithMockWebConnection(); |
| 307 | |
| 308 | final List<String> collectedAlerts = new ArrayList<>(); |
| 309 | webClient.setAlertHandler(new CollectingAlertHandler(collectedAlerts)); |
| 310 | |
| 311 | final HtmlPage page1 = webClient.getPage(urlPage1); |
| 312 | final String[] expectedAlerts = {"in foo1", "in foo2"}; |
| 313 | assertEquals(expectedAlerts, collectedAlerts); |
| 314 | |
| 315 | collectedAlerts.clear(); |
| 316 | page1.getAnchors().get(0).click(); |
| 317 | |
| 318 | assertEquals(new String[] {"in foo2"}, collectedAlerts); |
| 319 | assertEquals("no request for scripts should have been performed", |
| 320 | urlPage2, getMockWebConnection().getLastWebRequest().getUrl()); |
| 321 | } |
| 322 | |
| 323 | /** |
| 324 | * @throws Exception if the test fails |
nothing calls this directly
no test coverage detected