# HG changeset patch # User Andrea Marchesini # Date 1516810652 -3600 # Node ID e08739c23a5e7ad129e1c20f15e8d800b6318832 # Parent 14e0b437b9a8260db75fd5a69500d2b10762d5d7 Bug 1425458 - Resource timing entries Workers - part 7 - mochitests, r=smaug diff --git a/dom/performance/tests/empty.js b/dom/performance/tests/empty.js new file mode 100644 --- /dev/null +++ b/dom/performance/tests/empty.js @@ -0,0 +1,1 @@ +/* Nothing here */ diff --git a/dom/performance/tests/mochitest.ini b/dom/performance/tests/mochitest.ini --- 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] diff --git a/dom/performance/tests/test_worker_performance_entries.html b/dom/performance/tests/test_worker_performance_entries.html new file mode 100644 --- /dev/null +++ b/dom/performance/tests/test_worker_performance_entries.html @@ -0,0 +1,31 @@ + + + + + PerformanceResouceTiming in workers + + + + + + + diff --git a/dom/performance/tests/test_worker_performance_entries.js b/dom/performance/tests/test_worker_performance_entries.js 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(); diff --git a/dom/performance/tests/test_worker_performance_entries.sjs b/dom/performance/tests/test_worker_performance_entries.sjs 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/"); + } +}