Bug 1425458 - Resource timing entries Workers - part 7 - mochitests, r=smaug
authorAndrea Marchesini <amarchesini@mozilla.com>
Wed, 24 Jan 2018 17:17:32 +0100
changeset 400758 e08739c23a5e7ad129e1c20f15e8d800b6318832
parent 400757 dfd991faa7cb6e3bcc1f9e48dbe5b547f96aba28
child 400759 4f292fa4e4a30c8ba0745cf9884dc08c098752c0
push id99218
push useramarchesini@mozilla.com
push dateThu, 25 Jan 2018 11:12:22 +0000
treeherdermozilla-inbound@4f292fa4e4a3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1425458
milestone60.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 1425458 - Resource timing entries Workers - part 7 - mochitests, r=smaug
dom/performance/tests/empty.js
dom/performance/tests/mochitest.ini
dom/performance/tests/test_worker_performance_entries.html
dom/performance/tests/test_worker_performance_entries.js
dom/performance/tests/test_worker_performance_entries.sjs
new file mode 100644
--- /dev/null
+++ b/dom/performance/tests/empty.js
@@ -0,0 +1,1 @@
+/* Nothing here */
--- a/dom/performance/tests/mochitest.ini
+++ b/dom/performance/tests/mochitest.ini
@@ -1,16 +1,20 @@
 [DEFAULT]
 support-files =
   test_performance_observer.js
   test_performance_user_timing.js
   test_worker_performance_now.js
   worker_performance_user_timing.js
   worker_performance_observer.js
   sharedworker_performance_user_timing.js
+  test_worker_performance_entries.js
+  test_worker_performance_entries.sjs
+  empty.js
 
 [test_performance_observer.html]
 [test_performance_user_timing.html]
 [test_worker_user_timing.html]
 [test_worker_observer.html]
 [test_sharedWorker_performance_user_timing.html]
 [test_worker_performance_now.html]
 [test_timeOrigin.html]
+[test_worker_performance_entries.html]
new file mode 100644
--- /dev/null
+++ b/dom/performance/tests/test_worker_performance_entries.html
@@ -0,0 +1,31 @@
+<!-- Any copyright is dedicated to the Public Domain.
+   - http://creativecommons.org/publicdomain/zero/1.0/ -->
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>PerformanceResouceTiming in workers</title>
+  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<script class="testbody" type="text/javascript">
+
+SimpleTest.waitForExplicitFinish();
+var worker = new Worker('test_worker_performance_entries.js');
+worker.onmessage = function(event) {
+  if (event.data.type == "check") {
+    ok(event.data.status, event.data.msg);
+    return;
+  }
+
+  if (event.data.type == "finish") {
+    SimpleTest.finish();
+    return;
+  }
+
+  ok(false, "?!?");
+}
+
+</script>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/dom/performance/tests/test_worker_performance_entries.js
@@ -0,0 +1,102 @@
+function ok(a, msg) {
+  postMessage({type: "check", status: !!a, msg });
+}
+
+function is(a, b, msg) {
+  ok(a === b, msg);
+}
+
+function finish(a, msg) {
+  postMessage({type: "finish" });
+}
+
+function check(resource, initiatorType, protocol) {
+  let entries = performance.getEntries();
+  ok(entries.length == 1, "We have an entry");
+
+  ok(entries[0] instanceof PerformanceEntry,
+     "The entry is a PerformanceEntry");
+  ok(entries[0].name.endsWith(resource), "The entry has been found!");
+
+  is(entries[0].entryType, "resource", "Correct EntryType");
+  ok(entries[0].startTime > 0, "We have a startTime");
+  ok(entries[0].duration > 0, "We have a duration");
+
+  ok(entries[0] instanceof PerformanceResourceTiming,
+     "The entry is a PerformanceResourceTiming");
+
+  is(entries[0].initiatorType, initiatorType, "Correct initiatorType");
+  is(entries[0].nextHopProtocol, protocol, "Correct protocol");
+
+  performance.clearResourceTimings();
+}
+
+function simple_checks() {
+  ok("performance" in self, "We have self.performance");
+  performance.clearResourceTimings();
+  next();
+}
+
+function fetch_request() {
+  fetch("test_worker_performance_entries.sjs")
+  .then(r => r.blob())
+  .then(blob => {
+    check("test_worker_performance_entries.sjs", "fetch", "http/1.1");
+  })
+  .then(next);
+}
+
+function xhr_request() {
+  let xhr = new XMLHttpRequest();
+  xhr.open("GET", "test_worker_performance_entries.sjs");
+  xhr.send();
+  xhr.onload = () => {
+    check("test_worker_performance_entries.sjs", "xmlhttprequest", "http/1.1");
+    next();
+  }
+}
+
+function sync_xhr_request() {
+  let xhr = new XMLHttpRequest();
+  xhr.open("GET", "test_worker_performance_entries.sjs", false);
+  xhr.send();
+  check("test_worker_performance_entries.sjs", "xmlhttprequest", "http/1.1");
+  next();
+}
+
+function import_script() {
+  importScripts(["empty.js"]);
+  check("empty.js", "other", "http/1.1");
+  next();
+}
+
+function redirect() {
+  fetch("test_worker_performance_entries.sjs?redirect")
+  .then(r => r.text())
+  .then(text => {
+    is(text, "Hello world \\o/", "The redirect worked correctly");
+    check("test_worker_performance_entries.sjs?redirect", "fetch", "http/1.1");
+  })
+  .then(next);
+}
+
+let tests = [
+  simple_checks,
+  fetch_request,
+  xhr_request,
+  sync_xhr_request,
+  import_script,
+  redirect,
+];
+
+function next() {
+  if (!tests.length) {
+    finish();
+    return;
+  }
+
+  let test = tests.shift();
+  test();
+}
+
+next();
new file mode 100644
--- /dev/null
+++ b/dom/performance/tests/test_worker_performance_entries.sjs
@@ -0,0 +1,12 @@
+function handleRequest(request, response)
+{
+  response.setHeader("Content-Type", "text/html");
+
+  if (request.queryString == "redirect") {
+    response.setStatusLine(request.httpVersion, 302, "See Other");
+    response.setHeader("Location", "test_worker_performance_entries.sjs?ok");
+  } else {
+    response.setStatusLine(request.httpVersion, 200, "OK");
+    response.write("Hello world \\o/");
+  }
+}