You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UnsupportedBrowserHandlerUserAgents.java 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package com.vaadin.tests.requesthandlers;
  2. import static org.junit.Assert.assertFalse;
  3. import static org.junit.Assert.assertTrue;
  4. import java.net.HttpURLConnection;
  5. import java.net.URL;
  6. import org.apache.commons.io.IOUtils;
  7. import org.junit.Test;
  8. import com.vaadin.tests.tb3.PrivateTB3Configuration;
  9. public class UnsupportedBrowserHandlerUserAgents {
  10. /*
  11. * This test doesn't use testbench, but it's still in the uitest source
  12. * folder since it should be run with the testing server deployed.
  13. */
  14. @Test
  15. public void ie7NotSupported() {
  16. String response = requestWithUserAgent(
  17. "Mozilla/5.0 (compatible; MSIE 7.0; Windows NT 5.2; WOW64; .NET CLR 2.0.50727)");
  18. assertTrue("IE7 should not be supported",
  19. response.contains("your browser is not supported"));
  20. }
  21. @Test
  22. public void ie9NotSupported() {
  23. String response = requestWithUserAgent(
  24. "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 7.1; Trident/5.0)");
  25. assertTrue("IE9 should not be supported",
  26. response.contains("your browser is not supported"));
  27. }
  28. @Test
  29. public void unknownSupported() {
  30. String response = requestWithUserAgent(
  31. "Very strange user agent, like wat");
  32. assertFalse("Unknown user agent should be supported",
  33. response.contains("your browser is not supported"));
  34. }
  35. private String requestWithUserAgent(String userAgent) {
  36. try {
  37. String url = "http://"
  38. + PrivateTB3Configuration.getConfiguredDeploymentHostname()
  39. + ":"
  40. + PrivateTB3Configuration.getConfiguredDeploymentPort()
  41. + "/run/"
  42. + com.vaadin.tests.components.ui.UIInitTest.class.getName()
  43. + "/";
  44. HttpURLConnection connection = (HttpURLConnection) new URL(url)
  45. .openConnection();
  46. connection.setRequestProperty("User-Agent", userAgent);
  47. String response = IOUtils.toString(connection.getInputStream());
  48. connection.disconnect();
  49. return response;
  50. } catch (Exception e) {
  51. throw new RuntimeException(e);
  52. }
  53. }
  54. }