summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/hr-time
diff options
context:
space:
mode:
Diffstat (limited to 'testing/web-platform/tests/hr-time')
-rw-r--r--testing/web-platform/tests/hr-time/OWNERS3
-rw-r--r--testing/web-platform/tests/hr-time/basic.html47
-rw-r--r--testing/web-platform/tests/hr-time/basic.worker.js18
-rw-r--r--testing/web-platform/tests/hr-time/idlharness.html53
-rw-r--r--testing/web-platform/tests/hr-time/monotonic-clock.html35
-rw-r--r--testing/web-platform/tests/hr-time/resources/now_frame.html9
-rw-r--r--testing/web-platform/tests/hr-time/test_cross_frame_start.html59
7 files changed, 224 insertions, 0 deletions
diff --git a/testing/web-platform/tests/hr-time/OWNERS b/testing/web-platform/tests/hr-time/OWNERS
new file mode 100644
index 000000000..56997198b
--- /dev/null
+++ b/testing/web-platform/tests/hr-time/OWNERS
@@ -0,0 +1,3 @@
+@plehegar
+@igrigorik
+@toddreifsteck
diff --git a/testing/web-platform/tests/hr-time/basic.html b/testing/web-platform/tests/hr-time/basic.html
new file mode 100644
index 000000000..cc26d242f
--- /dev/null
+++ b/testing/web-platform/tests/hr-time/basic.html
@@ -0,0 +1,47 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8" />
+<title>window.performance.now exists</title>
+<link rel="author" title="W3C" href="http://www.w3.org/" />
+<link rel="help" href="http://www.w3.org/TR/hr-time/#sec-extenstions-performance-interface"/>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+test(function() {
+ assert_equals(typeof window.performance, "object");
+}, "window.performance is defined", {assert: "The window.performance attribute provides a hosting area for performance related attributes."});
+
+test(function() {
+ assert_not_equals(window.performance.now, undefined, 'window.performance.now is defined');
+}, "High Resolution Time extension to the Performance interface", {assert: "window.performance.now exists"});
+
+test(function() {
+ assert_equals(typeof window.performance.now, "function", "window.performance.now is a function");
+}, "window.performance.now() function", {assert: "window.performance.now is a function"});
+
+test(function() {
+ assert_equals(typeof window.performance.now(), "number", "window.performance.now() returns a number");
+}, "window.performance.now() returns a number", {assert: "The now method MUST return a DOMHighResTimeStamp"});
+
+async_test(function() {
+ // Check whether the performance.now() method is close to Date() within 30ms (due to inaccuracies)
+ var initial_hrt = performance.now();
+ var initial_date = Date.now();
+ this.step_timeout(function() {
+ var final_hrt = performance.now();
+ var final_date = Date.now();
+ assert_approx_equals(final_hrt - initial_hrt, final_date - initial_date, 30, 'High resolution time value increased by approximately the same amount as time from date object');
+ this.done();
+ }, 2000);
+}, 'High resolution time has approximately the right relative magnitude');
+</script>
+</head>
+<body>
+<h1>Description</h1>
+<p>This test validates that window.performance.now() exist and is a function.</p>
+
+<div id="log"></div>
+
+</body>
+</html>
diff --git a/testing/web-platform/tests/hr-time/basic.worker.js b/testing/web-platform/tests/hr-time/basic.worker.js
new file mode 100644
index 000000000..6a9f7a393
--- /dev/null
+++ b/testing/web-platform/tests/hr-time/basic.worker.js
@@ -0,0 +1,18 @@
+importScripts("/resources/testharness.js");
+
+test(function() {
+ assert_true((performance !== undefined), "WorkerGlobalScope.performance exists");
+ assert_equals((typeof performance.now), "function");
+}, "WorkerGlobalScope.performance.now() is a function");
+
+test(function() {
+ assert_true(performance.now() > 0);
+}, "WorkerGlobalScope.performance.now() returns a positive number");
+
+test(function() {
+ var now1 = performance.now();
+ var now2 = performance.now();
+ assert_true((now2-now1) >= 0);
+ }, "WorkerGlobalScope.performance.now() difference is not negative");
+
+done();
diff --git a/testing/web-platform/tests/hr-time/idlharness.html b/testing/web-platform/tests/hr-time/idlharness.html
new file mode 100644
index 000000000..0b1fd7d32
--- /dev/null
+++ b/testing/web-platform/tests/hr-time/idlharness.html
@@ -0,0 +1,53 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<title>High Resolution Time IDL tests</title>
+<link rel="author" title="W3C" href="http://www.w3.org/" />
+<link rel="help" href="http://www.w3.org/TR/hr-time/#sec-extenstions-performance-interface"/>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/resources/WebIDLParser.js"></script>
+<script src="/resources/idlharness.js"></script>
+</head>
+<body>
+<h1>High Resolution Time IDL tests</h1>
+<div id="log"></div>
+
+<pre id='untested_idl' style='display:none'>
+
+interface Window {
+};
+
+interface Performance {
+};
+
+partial interface Window {
+ [Replaceable] readonly attribute Performance performance;
+};
+</pre>
+
+<pre id='idl'>
+typedef double DOMHighResTimeStamp;
+
+partial interface Performance {
+ DOMHighResTimeStamp now();
+};
+</pre>
+
+<script>
+
+(function() {
+ var idl_array = new IdlArray();
+
+ idl_array.add_untested_idls(document.getElementById("untested_idl").textContent);
+ idl_array.add_idls(document.getElementById("idl").textContent);
+
+ idl_array.add_objects({Performance: ["window.performance"]});
+
+ idl_array.test();
+})();
+
+</script>
+</body>
+</html>
diff --git a/testing/web-platform/tests/hr-time/monotonic-clock.html b/testing/web-platform/tests/hr-time/monotonic-clock.html
new file mode 100644
index 000000000..af3b230f8
--- /dev/null
+++ b/testing/web-platform/tests/hr-time/monotonic-clock.html
@@ -0,0 +1,35 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8" />
+<title>window.performance.now() chronology</title>
+<link rel="author" title="W3C" href="http://www.w3.org/" />
+<link rel="help" href="http://www.w3.org/TR/hr-time/#sec-monotonic-clock"/>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+test(function() {
+ assert_true(window.performance.now() > 0, "window.performance.now() returns positive numbers");
+}, "window.performance.now() returns a positive number", {assert: "The time values returned when calling the now method MUST be monotonically increasing and not subject to system clock adjustments or system clock skew."});
+
+test(function() {
+ var now1 = window.performance.now();
+ var now2 = window.performance.now();
+ assert_true((now2-now1) >= 0, "window.performance.now() difference is not negative");
+ },
+ "window.performance.now() difference is not negative",
+ {
+ assert: "The difference between any two chronologically recorded time values returned from the now method MUST never be negative."
+ }
+);
+
+</script>
+</head>
+<body>
+<h1>Description</h1>
+<p>This test validates that window.performance.now() follows the monotonic clock requirements.</p>
+
+<div id="log"></div>
+
+</body>
+</html>
diff --git a/testing/web-platform/tests/hr-time/resources/now_frame.html b/testing/web-platform/tests/hr-time/resources/now_frame.html
new file mode 100644
index 000000000..5bec688af
--- /dev/null
+++ b/testing/web-platform/tests/hr-time/resources/now_frame.html
@@ -0,0 +1,9 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
+ <title>window.performance.now frame</title>
+ <link rel="author" title="Google" href="http://www.google.com/" />
+ </head>
+ <body></body>
+</html>
diff --git a/testing/web-platform/tests/hr-time/test_cross_frame_start.html b/testing/web-platform/tests/hr-time/test_cross_frame_start.html
new file mode 100644
index 000000000..30e804bd7
--- /dev/null
+++ b/testing/web-platform/tests/hr-time/test_cross_frame_start.html
@@ -0,0 +1,59 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8" >
+ <title>window.performance.now across frames</title>
+ <link rel="author" title="Google" href="http://www.google.com/">
+ <link rel="help" href="http://www.w3.org/TR/hr-time/#sec-extenstions-performance-interface">
+
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+
+ <script type="text/javascript">
+ setup({explicit_done: true});
+
+ var setup_frame = async_test("Setup the frame");
+
+ function start_test() {
+ setup_frame.step_timeout(function () {
+ var iframe = document.createElement('iframe');
+ iframe.id = 'frameContext';
+ iframe.onload = finish_test;
+ iframe.src = "resources/now_frame.html";
+ document.body.appendChild(iframe);
+ setup_frame.done();
+ }, 1000);
+ }
+
+ function finish_test() {
+ var childWindow = document.getElementById('frameContext').contentWindow;
+
+ // Verify a positive number is returned for both the frame and parent.
+ test(function() { assert_true(window.performance.now() > 0); }, 'parent performance.now() > 0');
+ test(function() { assert_true(childWindow.performance.now() > 0); }, 'child performance.now() > 0');
+
+ // Verify that the test properly created the child at least a second after the parent.
+ test(function () { assert_true(childWindow.performance.timing.navigationStart > (window.performance.timing.navigationStart + 1000)); },
+ 'Child created at least 1 second after parent');
+
+ test(function () {
+ var parentNow = window.performance.now();
+ var childNow = childWindow.performance.now();
+ var childParentSkew = Math.abs(childNow - parentNow);
+ assert_true(childParentSkew > 1000, 'Child and parent\'s now()s have different bases (skewed more than 1 second)');
+
+ var childLoadTime = childWindow.performance.timing.loadEventStart - childWindow.performance.timing.navigationStart;
+ assert_true(1000 > (childNow - childLoadTime), 'Child\'s now() is based on its document\'s navigationStart');
+ }, 'Child and parent time bases are correct');
+
+ done();
+ }
+ </script>
+
+ </head>
+ <body onload="start_test()">
+ <h1>Description</h1>
+ <p>This test validates the values of the window.performance.now() are based on the current document's navigationStart.</p>
+ <div id="log"></div>
+ </body>
+</html>