Bug 1181038 - Add performance timing worker. r=jgraham
authorNikhil Marathe <nsm.nikhil@gmail.com>
Thu, 10 Sep 2015 15:33:44 -0700
changeset 295920 7a41937bf6a2b1cfdf984999894e9d2f51c2dbc8
parent 295919 3c837b3a38fa15b655c4115cb95eda741b55a819
child 295921 d0b7e599e6aa1b5693437848682bbbdbd94d7579
push id5245
push userraliiev@mozilla.com
push dateThu, 29 Oct 2015 11:30:51 +0000
treeherdermozilla-beta@dac831dc1bd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjgraham
bugs1181038, 1203749
milestone43.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1181038 - Add performance timing worker. r=jgraham This adds the file and fixes the path to make the test run. We do not support performance timing on workers yet. I filed Bug 1203749 for that. Update web-platform-tests expected data
testing/web-platform/mozilla/meta/service-workers/service-worker/performance-timeline.https.html.ini
testing/web-platform/mozilla/tests/service-workers/service-worker/performance-timeline.https.html
testing/web-platform/mozilla/tests/service-workers/service-worker/resources/dummy.txt
testing/web-platform/mozilla/tests/service-workers/service-worker/resources/performance-timeline-worker.js
--- a/testing/web-platform/mozilla/meta/service-workers/service-worker/performance-timeline.https.html.ini
+++ b/testing/web-platform/mozilla/meta/service-workers/service-worker/performance-timeline.https.html.ini
@@ -1,5 +1,5 @@
 [performance-timeline.https.html]
   type: testharness
-  [Test Performance Timeline API in Service Worker]
+  [Resource Timing]
     expected: FAIL
 
--- a/testing/web-platform/mozilla/tests/service-workers/service-worker/performance-timeline.https.html
+++ b/testing/web-platform/mozilla/tests/service-workers/service-worker/performance-timeline.https.html
@@ -1,11 +1,11 @@
 <!DOCTYPE html>
 <script src="/resources/testharness.js"></script>
 <script src="/resources/testharnessreport.js"></script>
 <script src="resources/test-helpers.sub.js"></script>
 <script>
 
 service_worker_test(
-    '../workers/resources/performance-timeline-worker.js',
+    'resources/performance-timeline-worker.js',
     'Test Performance Timeline API in Service Worker');
 
 </script>
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/mozilla/tests/service-workers/service-worker/resources/dummy.txt
@@ -0,0 +1,1 @@
+Hello world
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/mozilla/tests/service-workers/service-worker/resources/performance-timeline-worker.js
@@ -0,0 +1,56 @@
+importScripts('/resources/testharness.js');
+
+promise_test(function(test) {
+    var durationMsec = 100;
+    return new Promise(function(resolve) {
+        performance.mark('startMark');
+        setTimeout(resolve, durationMsec);
+      }).then(function() {
+          performance.mark('endMark');
+          performance.measure('measure', 'startMark', 'endMark');
+          var startMark = performance.getEntriesByName('startMark')[0];
+          var endMark = performance.getEntriesByName('endMark')[0];
+          var measure = performance.getEntriesByType('measure')[0];
+          assert_equals(measure.startTime, startMark.startTime);
+          assert_approx_equals(endMark.startTime - startMark.startTime,
+                               measure.duration, 0.001);
+          //XXXnsm: Timers aren't always precise. on treeherder sometimes the
+          //measured duration is like 99.5 something. Let's just measure the
+          //ballpark.
+          assert_greater_than(measure.duration, durationMsec - 1);
+          assert_equals(performance.getEntriesByType('mark').length, 2);
+          assert_equals(performance.getEntriesByType('measure').length, 1);
+          performance.clearMarks('startMark');
+          performance.clearMeasures('measure');
+          assert_equals(performance.getEntriesByType('mark').length, 1);
+          assert_equals(performance.getEntriesByType('measure').length, 0);
+      });
+  }, 'User Timing');
+
+promise_test(function(test) {
+    return fetch('dummy.txt')
+      .then(function(resp) {
+          return resp.text();
+        })
+      .then(function(text) {
+          var expectedResources = ['testharness.js', 'dummy.txt'];
+          assert_equals(performance.getEntriesByType('resource').length, expectedResources.length);
+          for (var i = 0; i < expectedResources.length; i++) {
+              var entry = performance.getEntriesByType('resource')[i];
+              assert_true(entry.name.endsWith(expectedResources[i]));
+              assert_equals(entry.workerStart, 0);
+              assert_greater_than(entry.startTime, 0);
+              assert_greater_than(entry.responseEnd, entry.startTime);
+          }
+          return new Promise(function(resolve) {
+              performance.onresourcetimingbufferfull = resolve;
+              performance.setResourceTimingBufferSize(expectedResources.length);
+            });
+        })
+      .then(function() {
+          performance.clearResourceTimings();
+          assert_equals(performance.getEntriesByType('resource').length, 0);
+        })
+  }, 'Resource Timing');
+
+done();