diff options
author | Denis Anisimov <denis@vaadin.com> | 2014-11-04 19:31:59 +0200 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2015-09-10 11:21:30 +0000 |
commit | cd1d8ba342828fae87c8082f66e6f81b11db701c (patch) | |
tree | 3c63097e3d18d294359f374e807c485916bbd6a8 /uitest | |
parent | 154396df74ba16dd8f50ba479a3e9819da54c072 (diff) | |
download | vaadin-framework-cd1d8ba342828fae87c8082f66e6f81b11db701c.tar.gz vaadin-framework-cd1d8ba342828fae87c8082f66e6f81b11db701c.zip |
Use high resolution time for profiling if it's available #14716, #18782.
Change-Id: Id45ccd47cac3bcdb14c5d4e93e4fb8225b1b2864
Diffstat (limited to 'uitest')
-rw-r--r-- | uitest/src/com/vaadin/tests/CurrentTimeMillis.java | 42 | ||||
-rw-r--r-- | uitest/src/com/vaadin/tests/CurrentTimeMillisTest.java | 93 |
2 files changed, 135 insertions, 0 deletions
diff --git a/uitest/src/com/vaadin/tests/CurrentTimeMillis.java b/uitest/src/com/vaadin/tests/CurrentTimeMillis.java new file mode 100644 index 0000000000..0937c53864 --- /dev/null +++ b/uitest/src/com/vaadin/tests/CurrentTimeMillis.java @@ -0,0 +1,42 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; + +/** + * Test UI (empty) to check high resolution time availability in browser. + * + * @author Vaadin Ltd + */ +public class CurrentTimeMillis extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + // no need to add anything + } + + @Override + protected Integer getTicketNumber() { + return 14716; + } + + @Override + protected String getTestDescription() { + return "Use high precision time is available instead of Date.getTime()."; + } +} diff --git a/uitest/src/com/vaadin/tests/CurrentTimeMillisTest.java b/uitest/src/com/vaadin/tests/CurrentTimeMillisTest.java new file mode 100644 index 0000000000..656b269c06 --- /dev/null +++ b/uitest/src/com/vaadin/tests/CurrentTimeMillisTest.java @@ -0,0 +1,93 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests; + +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.Keys; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Actions; + +import com.vaadin.testbench.parallel.BrowserUtil; +import com.vaadin.tests.tb3.MultiBrowserTest; + +/** + * Test to check high resolution time availability in browser (depending on + * browser). + * + * @author Vaadin Ltd + */ +public class CurrentTimeMillisTest extends MultiBrowserTest { + + @Test + public void testJsonParsing() { + setDebug(true); + openTestURL(); + + boolean highResTimeSupported = !BrowserUtil + .isIE8(getDesiredCapabilities()) + && !BrowserUtil.isIE(getDesiredCapabilities(), 9) + && !BrowserUtil.isPhantomJS(getDesiredCapabilities()) + && !BrowserUtil.isSafari(getDesiredCapabilities()); + + String time = getJsonParsingTime(); + Assert.assertNotNull("JSON parsing time is not found", time); + time = time.trim(); + if (time.endsWith("ms")) { + time = time.substring(0, time.length() - 2); + } + if (highResTimeSupported) { + if (BrowserUtil.isChrome(getDesiredCapabilities())) { + // Chrome (version 33 at least) sometimes doesn't use high res + // time if number of ms is less then 1 + Assert.assertTrue("High resolution time is not used in " + + "JSON parsing mesurement. Time=" + time, + time.equals("0") || time.indexOf('.') > 0); + } else { + Assert.assertTrue("High resolution time is not used in " + + "JSON parsing mesurement. Time=" + time, + time.indexOf('.') > 0); + } + } else { + Assert.assertFalse("Unexpected dot is detected in browser " + + "that doesn't support high resolution time and " + + "should report time as integer number. Time=" + time, + time.indexOf('.') > 0); + } + } + + private String getJsonParsingTime() { + Actions actions = new Actions(getDriver()); + actions.sendKeys(Keys.TAB); + actions.sendKeys(Keys.SPACE).perform(); + findElement(By.className("v-debugwindow-tab")).click(); + + List<WebElement> messages = findElements(By + .className("v-debugwindow-message")); + for (WebElement message : messages) { + if (message.getAttribute("innerHTML").startsWith("JSON parsing")) { + String text = message.getAttribute("innerHTML"); + int index = text.lastIndexOf(' '); + return text.substring(index); + } + } + return null; + } + +} |