Bug 1323941 - navigationStart should not be exposed to workers as timing attribute, r=bz
authorAndrea Marchesini <amarchesini@mozilla.com>
Sat, 17 Dec 2016 07:51:22 +0100
changeset 326290 6be7eb833b119bd37ffc641f9356617cfeeb22f2
parent 326289 dcc7b0c683ce81ed762d1fe4ff396ea9caeb0bea
child 326291 06429d283d5b465e5c484dc6a7447ad03b2589c0
push id31093
push userphilringnalda@gmail.com
push dateSat, 17 Dec 2016 22:01:00 +0000
treeherdermozilla-central@5745bab28ff5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs1323941
milestone53.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 1323941 - navigationStart should not be exposed to workers as timing attribute, r=bz
dom/performance/Performance.h
dom/performance/PerformanceWorker.cpp
dom/performance/PerformanceWorker.h
dom/performance/tests/test_performance_user_timing.js
testing/web-platform/meta/MANIFEST.json
testing/web-platform/tests/user-timing/resources/webperftestharness.js
testing/web-platform/tests/user-timing/test_user_timing_mark_and_measure_exception_when_invoke_with_timing_attributes.html
testing/web-platform/tests/user-timing/test_user_timing_mark_and_measure_exception_when_invoke_with_timing_attributes.js
--- a/dom/performance/Performance.h
+++ b/dom/performance/Performance.h
@@ -121,20 +121,26 @@ protected:
   virtual nsISupports* GetAsISupports() = 0;
 
   virtual void DispatchBufferFullEvent() = 0;
 
   virtual TimeStamp CreationTimeStamp() const = 0;
 
   virtual DOMHighResTimeStamp CreationTime() const = 0;
 
-  virtual bool IsPerformanceTimingAttribute(const nsAString& aName) = 0;
+  virtual bool IsPerformanceTimingAttribute(const nsAString& aName)
+  {
+    return false;
+  }
 
   virtual DOMHighResTimeStamp
-  GetPerformanceTimingFromString(const nsAString& aTimingName) = 0;
+  GetPerformanceTimingFromString(const nsAString& aTimingName)
+  {
+    return 0;
+  }
 
   bool IsResourceEntryLimitReached() const
   {
     return mResourceEntries.Length() >= mResourceTimingBufferSize;
   }
 
   void LogEntry(PerformanceEntry* aEntry, const nsACString& aOwner) const;
   void TimingNotification(PerformanceEntry* aEntry, const nsACString& aOwner,
--- a/dom/performance/PerformanceWorker.cpp
+++ b/dom/performance/PerformanceWorker.cpp
@@ -18,39 +18,16 @@ PerformanceWorker::PerformanceWorker(Wor
   mWorkerPrivate->AssertIsOnWorkerThread();
 }
 
 PerformanceWorker::~PerformanceWorker()
 {
   mWorkerPrivate->AssertIsOnWorkerThread();
 }
 
-// To be removed once bug 1124165 lands
-bool
-PerformanceWorker::IsPerformanceTimingAttribute(const nsAString& aName)
-{
-  // In workers we just support navigationStart.
-  return aName.EqualsASCII("navigationStart");
-}
-
-DOMHighResTimeStamp
-PerformanceWorker::GetPerformanceTimingFromString(const nsAString& aProperty)
-{
-  if (!IsPerformanceTimingAttribute(aProperty)) {
-    return 0;
-  }
-
-  if (aProperty.EqualsLiteral("navigationStart")) {
-    return mWorkerPrivate->CreationTime();
-  }
-
-  MOZ_CRASH("IsPerformanceTimingAttribute and GetPerformanceTimingFromString are out of sync");
-  return 0;
-}
-
 void
 PerformanceWorker::InsertUserEntry(PerformanceEntry* aEntry)
 {
   if (mWorkerPrivate->PerformanceLoggingEnabled()) {
     nsAutoCString uri;
     nsCOMPtr<nsIURI> scriptURI = mWorkerPrivate->GetResolvedScriptURI();
     if (!scriptURI || NS_FAILED(scriptURI->GetHost(uri))) {
       // If we have no URI, just put in "none".
--- a/dom/performance/PerformanceWorker.h
+++ b/dom/performance/PerformanceWorker.h
@@ -66,21 +66,16 @@ protected:
 
   nsISupports* GetAsISupports() override
   {
     return nullptr;
   }
 
   void InsertUserEntry(PerformanceEntry* aEntry) override;
 
-  bool IsPerformanceTimingAttribute(const nsAString& aName) override;
-
-  DOMHighResTimeStamp
-  GetPerformanceTimingFromString(const nsAString& aTimingName) override;
-
   void DispatchBufferFullEvent() override
   {
     MOZ_CRASH("This should not be called on workers.");
   }
 
 private:
   workers::WorkerPrivate* mWorkerPrivate;
 };
--- a/dom/performance/tests/test_performance_user_timing.js
+++ b/dom/performance/tests/test_performance_user_timing.js
@@ -175,25 +175,28 @@ var steps = [
         is(measures_type.length, 1, "Number of measures by type should be 1");
         var measure = measures_type[0];
         is(measure.startTime, last_mark.startTime, "Measure start time should be the start time of the latest 'test' mark");
         // Tolerance testing to avoid oranges, since we're doing double math across two different languages.
         ok(measure.duration - (test_mark.startTime - last_mark.startTime) < .00001,
            "Measure duration ( " + measure.duration + ") should be difference between two marks");
     },
     function() {
-        ok(true, "Running measure addition with no start/end time test");
-        performance.measure("test", "navigationStart");
-        var measures = performance.getEntriesByType("measure");
-        is(measures.length, 1, "number of measures should be 1");
-        var measure = measures[0];
-        is(measure.name, "test", "measure name should be 'test'");
-        is(measure.entryType, "measure", "measure type should be 'measure'");
-        is(measure.startTime, 0, "measure start time should be zero");
-        ok(measure.duration >= 0, "measure duration should not be negative");
+        // We don't have navigationStart in workers.
+        if ("window" in self) {
+          ok(true, "Running measure addition with no start/end time test");
+          performance.measure("test", "navigationStart");
+          var measures = performance.getEntriesByType("measure");
+          is(measures.length, 1, "number of measures should be 1");
+          var measure = measures[0];
+          is(measure.name, "test", "measure name should be 'test'");
+          is(measure.entryType, "measure", "measure type should be 'measure'");
+          is(measure.startTime, 0, "measure start time should be zero");
+          ok(measure.duration >= 0, "measure duration should not be negative");
+        }
     },
     // Test all measure removal
     function () {
         ok(true, "Running all measure removal test");
         performance.measure("test");
         performance.measure("test2");
         var measures = performance.getEntriesByType("measure");
         is(measures.length, 2, "measure entries should be length 2");
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -31921,16 +31921,20 @@
         "path": "user-timing/test_user_timing_exists.html",
         "url": "/user-timing/test_user_timing_exists.html"
       },
       {
         "path": "user-timing/test_user_timing_mark.html",
         "url": "/user-timing/test_user_timing_mark.html"
       },
       {
+        "path": "user-timing/test_user_timing_mark_and_measure_exception_when_invoke_with_timing_attributes.html",
+        "url": "/user-timing/test_user_timing_mark_and_measure_exception_when_invoke_with_timing_attributes.html"
+      },
+      {
         "path": "user-timing/test_user_timing_mark_and_measure_exception_when_invoke_without_parameter.html",
         "url": "/user-timing/test_user_timing_mark_and_measure_exception_when_invoke_without_parameter.html"
       },
       {
         "path": "user-timing/test_user_timing_mark_exceptions.html",
         "url": "/user-timing/test_user_timing_mark_exceptions.html"
       },
       {
--- a/testing/web-platform/tests/user-timing/resources/webperftestharness.js
+++ b/testing/web-platform/tests/user-timing/resources/webperftestharness.js
@@ -7,17 +7,17 @@ policies and contribution forms [3].
 [2] http://www.w3.org/Consortium/Legal/2008/03-bsd-license
 [3] http://www.w3.org/2004/10/27-testcases
  */
 
 //
 // Helper Functions for NavigationTiming W3C tests
 //
 
-var performanceNamespace = window.performance;
+var performanceNamespace = self.performance;
 var timingAttributes = [
     'connectEnd',
     'connectStart',
     'domComplete',
     'domContentLoadedEventEnd',
     'domContentLoadedEventStart',
     'domInteractive',
     'domLoading',
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/user-timing/test_user_timing_mark_and_measure_exception_when_invoke_with_timing_attributes.html
@@ -0,0 +1,32 @@
+<!DOCTYPE html>
+<html>
+  <head>
+    <meta charset="utf-8" />
+    <title>exception test of performance.mark and performance.measure</title>
+    <meta rel="help" href="http://www.w3.org/TR/user-timing/#extensions-performance-interface"/>
+    <script src="/resources/testharness.js"></script>
+    <script src="/resources/testharnessreport.js"></script>
+    <script src="resources/webperftestharness.js"></script>
+  </head>
+  <body>
+    <script>
+    setup({explicit_done: true});
+    test_namespace();
+
+    test(function() {
+      for (var i in timingAttributes) {
+        assert_throws("SyntaxError", function() { window.performance.mark(timingAttributes[i]); });
+        assert_throws("SyntaxError", function() { window.performance.measure(timingAttributes[i]); });
+      }
+    }, "performance.mark and performance.measure should throw if used with timing attribute values");
+
+    fetch_tests_from_worker(new Worker("test_user_timing_mark_and_measure_exception_when_invoke_with_timing_attributes.js"));
+
+    done();
+
+    </script>
+    <h1>Description</h1>
+    <p>This test validates exception scenarios of invoking mark() and measure() with timing attributes as value.</p>
+    <div id="log"></div>
+  </body>
+</html>
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/user-timing/test_user_timing_mark_and_measure_exception_when_invoke_with_timing_attributes.js
@@ -0,0 +1,14 @@
+importScripts("/resources/testharness.js");
+importScripts("resources/webperftestharness.js");
+
+test(function() {
+  for (var i in timingAttributes) {
+    performance.mark(timingAttributes[i]);
+    performance.clearMarks(timingAttributes[i]);
+
+    performance.measure(timingAttributes[i]);
+    performance.clearMeasures(timingAttributes[i]);
+  }
+}, "performance.mark and performance.measure should not throw if used with timing attribute values in workers");
+
+done();