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.

CurrentTimeMillisTest.java 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package com.vaadin.tests;
  2. import static org.junit.Assert.assertFalse;
  3. import static org.junit.Assert.assertNotNull;
  4. import static org.junit.Assert.assertTrue;
  5. import java.util.List;
  6. import org.junit.Test;
  7. import org.openqa.selenium.By;
  8. import org.openqa.selenium.Keys;
  9. import org.openqa.selenium.WebElement;
  10. import org.openqa.selenium.interactions.Actions;
  11. import com.vaadin.testbench.parallel.BrowserUtil;
  12. import com.vaadin.tests.tb3.MultiBrowserTest;
  13. /**
  14. * Test to check high resolution time availability in browser (depending on
  15. * browser).
  16. *
  17. * @author Vaadin Ltd
  18. */
  19. public class CurrentTimeMillisTest extends MultiBrowserTest {
  20. @Test
  21. public void testJsonParsing() {
  22. setDebug(true);
  23. openTestURL();
  24. boolean phantomJs1 = BrowserUtil.isPhantomJS(getDesiredCapabilities())
  25. && "1".equals(getDesiredCapabilities().getVersion());
  26. boolean highResTimeSupported = !phantomJs1
  27. && !BrowserUtil.isSafari(getDesiredCapabilities());
  28. String time = getJsonParsingTime();
  29. assertNotNull("JSON parsing time is not found", time);
  30. time = time.trim();
  31. if (time.endsWith("ms")) {
  32. time = time.substring(0, time.length() - 2);
  33. }
  34. if (highResTimeSupported) {
  35. if (BrowserUtil.isChrome(getDesiredCapabilities())
  36. || BrowserUtil.isFirefox(getDesiredCapabilities())) {
  37. // Chrome (version 33 at least) sometimes doesn't use high res
  38. // time for very short times
  39. assertTrue(
  40. "High resolution time is not used in "
  41. + "JSON parsing mesurement. Time=" + time,
  42. time.equals("0") || time.equals("1")
  43. || time.indexOf('.') > 0);
  44. } else {
  45. assertTrue(
  46. "High resolution time is not used in "
  47. + "JSON parsing mesurement. Time=" + time,
  48. time.indexOf('.') > 0);
  49. }
  50. } else {
  51. assertFalse("Unexpected dot is detected in browser "
  52. + "that doesn't support high resolution time and "
  53. + "should report time as integer number. Time=" + time,
  54. time.indexOf('.') > 0);
  55. }
  56. }
  57. private String getJsonParsingTime() {
  58. Actions actions = new Actions(getDriver());
  59. actions.sendKeys(Keys.TAB);
  60. actions.sendKeys(Keys.SPACE).perform();
  61. findElement(By.className("v-debugwindow-tab")).click();
  62. List<WebElement> messages = findElements(
  63. By.className("v-debugwindow-message"));
  64. for (WebElement message : messages) {
  65. if (message.getAttribute("innerHTML").startsWith("JSON parsing")) {
  66. String text = message.getAttribute("innerHTML");
  67. int index = text.lastIndexOf(' ');
  68. return text.substring(index);
  69. }
  70. }
  71. return null;
  72. }
  73. }