summaryrefslogtreecommitdiffstats
path: root/dom/tests/browser/perfmetrics
diff options
context:
space:
mode:
Diffstat (limited to 'dom/tests/browser/perfmetrics')
-rw-r--r--dom/tests/browser/perfmetrics/browser.ini21
-rw-r--r--dom/tests/browser/perfmetrics/browser_test_performance_metrics.js201
-rw-r--r--dom/tests/browser/perfmetrics/browser_test_unresponsive.js31
-rw-r--r--dom/tests/browser/perfmetrics/dummy.html13
-rw-r--r--dom/tests/browser/perfmetrics/hello.oggbin0 -> 11328 bytes
-rw-r--r--dom/tests/browser/perfmetrics/ping_worker.html26
-rw-r--r--dom/tests/browser/perfmetrics/ping_worker.js11
-rw-r--r--dom/tests/browser/perfmetrics/ping_worker2.html20
-rw-r--r--dom/tests/browser/perfmetrics/setinterval.html19
-rw-r--r--dom/tests/browser/perfmetrics/settimeout.html17
-rw-r--r--dom/tests/browser/perfmetrics/shared_worker.js7
-rw-r--r--dom/tests/browser/perfmetrics/sound.html14
-rw-r--r--dom/tests/browser/perfmetrics/unresponsive.html21
13 files changed, 401 insertions, 0 deletions
diff --git a/dom/tests/browser/perfmetrics/browser.ini b/dom/tests/browser/perfmetrics/browser.ini
new file mode 100644
index 0000000000..b4b1d4b63a
--- /dev/null
+++ b/dom/tests/browser/perfmetrics/browser.ini
@@ -0,0 +1,21 @@
+[DEFAULT]
+prefs =
+ dom.performance.children_results_ipc_timeout=2000
+
+support-files =
+ dummy.html
+ ping_worker.html
+ ping_worker2.html
+ ping_worker.js
+ setinterval.html
+ settimeout.html
+ shared_worker.js
+ unresponsive.html
+ hello.ogg
+ sound.html
+
+[browser_test_performance_metrics.js]
+skip-if = verify
+
+[browser_test_unresponsive.js]
+skip-if = true # Bug 1498426
diff --git a/dom/tests/browser/perfmetrics/browser_test_performance_metrics.js b/dom/tests/browser/perfmetrics/browser_test_performance_metrics.js
new file mode 100644
index 0000000000..65a7aaaee2
--- /dev/null
+++ b/dom/tests/browser/perfmetrics/browser_test_performance_metrics.js
@@ -0,0 +1,201 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* vim: set ts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+const ROOT_URL = "http://example.com/browser/dom/tests/browser/perfmetrics";
+const DUMMY_URL = ROOT_URL + "/dummy.html";
+const WORKER_URL = ROOT_URL + "/ping_worker.html";
+const WORKER_URL2 = ROOT_URL + "/ping_worker2.html";
+const INTERVAL_URL = ROOT_URL + "/setinterval.html";
+const TIMEOUT_URL = ROOT_URL + "/settimeout.html";
+const SOUND_URL = ROOT_URL + "/sound.html";
+const CATEGORY_TIMER = 2;
+
+add_task(async function test() {
+ waitForExplicitFinish();
+
+ // Load 3 pages and wait. The 3rd one has a worker
+ let page1 = await BrowserTestUtils.openNewForegroundTab({
+ gBrowser,
+ opening: "about:about",
+ forceNewProcess: false,
+ });
+
+ let page2 = await BrowserTestUtils.openNewForegroundTab({
+ gBrowser,
+ opening: "about:memory",
+ forceNewProcess: false,
+ });
+
+ let page3 = await BrowserTestUtils.openNewForegroundTab({
+ gBrowser,
+ opening: WORKER_URL,
+ });
+ // load a 4th tab with a worker
+ await BrowserTestUtils.withNewTab(
+ { gBrowser, url: WORKER_URL2 },
+ async function (browser) {
+ // grab events..
+ let workerDuration = 0;
+ let workerTotal = 0;
+ let duration = 0;
+ let total = 0;
+ let isTopLevel = false;
+ let aboutMemoryFound = false;
+ let parentProcessEvent = false;
+ let subFrameIds = [];
+ let topLevelIds = [];
+ let sharedWorker = false;
+ let counterIds = [];
+ let timerCalls = 0;
+ let heapUsage = 0;
+ let mediaMemory = 0;
+
+ function exploreResults(data, filterByWindowId) {
+ for (let entry of data) {
+ if (filterByWindowId && entry.windowId != filterByWindowId) {
+ continue;
+ }
+ if (!counterIds.includes(entry.pid + ":" + entry.counterId)) {
+ counterIds.push(entry.pid + ":" + entry.counterId);
+ }
+ sharedWorker =
+ entry.host.endsWith("shared_worker.js") || sharedWorker;
+ heapUsage += entry.memoryInfo.jsMemUsage;
+ mediaMemory +=
+ entry.memoryInfo.media.audioSize +
+ entry.memoryInfo.media.resourcesSize;
+ Assert.ok(
+ entry.host != "" || entry.windowId != 0,
+ "An entry should have a host or a windowId"
+ );
+ if (
+ entry.windowId != 0 &&
+ !entry.isToplevel &&
+ !entry.isWorker &&
+ !subFrameIds.includes(entry.windowId)
+ ) {
+ subFrameIds.push(entry.windowId);
+ }
+ if (entry.isTopLevel && !topLevelIds.includes(entry.windowId)) {
+ topLevelIds.push(entry.windowId);
+ }
+ if (entry.host == "example.com" && entry.isTopLevel) {
+ isTopLevel = true;
+ }
+ if (entry.host == "about:memory") {
+ aboutMemoryFound = true;
+ }
+ if (entry.pid == Services.appinfo.processID) {
+ parentProcessEvent = true;
+ }
+ if (entry.isWorker) {
+ workerDuration += entry.duration;
+ } else {
+ duration += entry.duration;
+ }
+ // let's look at the data we got back
+ for (let item of entry.items) {
+ Assert.ok(
+ item.count > 0,
+ "Categories with an empty count are dropped"
+ );
+ if (entry.isWorker) {
+ workerTotal += item.count;
+ } else {
+ total += item.count;
+ }
+ if (item.category == CATEGORY_TIMER) {
+ timerCalls += item.count;
+ }
+ }
+ }
+ }
+
+ // get all metrics via the promise
+ let results = await ChromeUtils.requestPerformanceMetrics();
+ exploreResults(results);
+
+ Assert.greater(workerDuration, 0, "Worker duration should be positive");
+ Assert.greater(workerTotal, 0, "Worker count should be positive");
+ Assert.greater(duration, 0, "Duration should be positive");
+ Assert.greater(total, 0, "Should get a positive count");
+ Assert.ok(parentProcessEvent, "parent process sent back some events");
+ Assert.ok(isTopLevel, "example.com as a top level window");
+ Assert.ok(aboutMemoryFound, "about:memory");
+ Assert.greater(heapUsage, 0, "got some memory value reported");
+ Assert.ok(sharedWorker, "We got some info from a shared worker");
+ let numCounters = counterIds.length;
+ Assert.ok(
+ numCounters > 5,
+ "This test generated at least " + numCounters + " unique counters"
+ );
+
+ // checking that subframes are not orphans
+ for (let frameId of subFrameIds) {
+ Assert.ok(topLevelIds.includes(frameId), "subframe is not orphan ");
+ }
+
+ // Doing a second call, we shoud get bigger values
+ let previousWorkerDuration = workerDuration;
+ let previousWorkerTotal = workerTotal;
+ let previousDuration = duration;
+ let previousTotal = total;
+
+ results = await ChromeUtils.requestPerformanceMetrics();
+ exploreResults(results);
+
+ Assert.ok(
+ workerDuration > previousWorkerDuration,
+ "Worker duration should be positive"
+ );
+ Assert.ok(
+ workerTotal > previousWorkerTotal,
+ "Worker count should be positive"
+ );
+ Assert.greater(duration, previousDuration, "Duration should be positive");
+ Assert.greater(total, previousTotal, "Should get a positive count");
+
+ // load a tab with a setInterval, we should get counters on TaskCategory::Timer
+ await BrowserTestUtils.withNewTab(
+ { gBrowser, url: INTERVAL_URL },
+ async function (browser) {
+ let tabId = gBrowser.selectedBrowser.outerWindowID;
+ let previousTimerCalls = timerCalls;
+ results = await ChromeUtils.requestPerformanceMetrics();
+ exploreResults(results, tabId);
+ Assert.greater(timerCalls, previousTimerCalls, "Got timer calls");
+ }
+ );
+
+ // load a tab with a setTimeout, we should get counters on TaskCategory::Timer
+ await BrowserTestUtils.withNewTab(
+ { gBrowser, url: TIMEOUT_URL },
+ async function (browser) {
+ let tabId = gBrowser.selectedBrowser.outerWindowID;
+ let previousTimerCalls = timerCalls;
+ results = await ChromeUtils.requestPerformanceMetrics();
+ exploreResults(results, tabId);
+ Assert.greater(timerCalls, previousTimerCalls, "Got timer calls");
+ }
+ );
+
+ // load a tab with a sound
+ await BrowserTestUtils.withNewTab(
+ { gBrowser, url: SOUND_URL },
+ async function (browser) {
+ let tabId = gBrowser.selectedBrowser.outerWindowID;
+ results = await ChromeUtils.requestPerformanceMetrics();
+ exploreResults(results, tabId);
+ Assert.greater(mediaMemory, 0, "Got some memory used for media");
+ }
+ );
+ }
+ );
+
+ BrowserTestUtils.removeTab(page1);
+ BrowserTestUtils.removeTab(page2);
+ BrowserTestUtils.removeTab(page3);
+});
diff --git a/dom/tests/browser/perfmetrics/browser_test_unresponsive.js b/dom/tests/browser/perfmetrics/browser_test_unresponsive.js
new file mode 100644
index 0000000000..770c387e7a
--- /dev/null
+++ b/dom/tests/browser/perfmetrics/browser_test_unresponsive.js
@@ -0,0 +1,31 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* vim: set ts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+const ROOT_URL = "http://example.com/browser/dom/tests/browser/perfmetrics";
+const PAGE_URL = ROOT_URL + "/unresponsive.html";
+
+add_task(async function test() {
+ waitForExplicitFinish();
+
+ await BrowserTestUtils.withNewTab(
+ { gBrowser, url: PAGE_URL },
+ async function (browser) {
+ let dataBack = 0;
+ let tabId = gBrowser.selectedBrowser.outerWindowID;
+
+ function exploreResults(data, filterByWindowId) {
+ for (let entry of data) {
+ if (entry.windowId == tabId && entry.host != "about:blank") {
+ dataBack += 1;
+ }
+ }
+ }
+ let results = await ChromeUtils.requestPerformanceMetrics();
+ exploreResults(results);
+ Assert.ok(dataBack == 0);
+ }
+ );
+});
diff --git a/dom/tests/browser/perfmetrics/dummy.html b/dom/tests/browser/perfmetrics/dummy.html
new file mode 100644
index 0000000000..6ec72c2160
--- /dev/null
+++ b/dom/tests/browser/perfmetrics/dummy.html
@@ -0,0 +1,13 @@
+<!doctype html>
+<html>
+<head>
+<title>Dummy test page</title>
+<meta http-equiv="Content-Type" content="text/html;charset=utf-8"></meta>
+</head>
+<body>
+<p>Dummy test page</p>
+<script>
+ localStorage.setItem("foo", "bar");
+</script>
+</body>
+</html>
diff --git a/dom/tests/browser/perfmetrics/hello.ogg b/dom/tests/browser/perfmetrics/hello.ogg
new file mode 100644
index 0000000000..7a80926065
--- /dev/null
+++ b/dom/tests/browser/perfmetrics/hello.ogg
Binary files differ
diff --git a/dom/tests/browser/perfmetrics/ping_worker.html b/dom/tests/browser/perfmetrics/ping_worker.html
new file mode 100644
index 0000000000..c576dbcb22
--- /dev/null
+++ b/dom/tests/browser/perfmetrics/ping_worker.html
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html lang="en" dir="ltr">
+<head>
+ <meta charset="utf-8">
+ <script type="text/javascript">
+
+ var myWorker;
+ var shared;
+
+ function init() {
+ myWorker = new Worker("ping_worker.js");
+ for (let i = 0; i++; i < 10) myWorker.postMessage("ping");
+
+ shared = new SharedWorker("shared_worker.js");
+ shared.port.start();
+ shared.port.onmessage = function(e) {
+ console.log(e);
+ };
+ }
+
+ </script>
+</head>
+<body onload="init()">
+ <h1>A page with a worker and a shared worker</h1>
+</body>
+</html>
diff --git a/dom/tests/browser/perfmetrics/ping_worker.js b/dom/tests/browser/perfmetrics/ping_worker.js
new file mode 100644
index 0000000000..0ed6bb8ba4
--- /dev/null
+++ b/dom/tests/browser/perfmetrics/ping_worker.js
@@ -0,0 +1,11 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+function messageListener(event) {
+ postMessage("pong");
+}
+
+addEventListener("message", { handleEvent: messageListener });
diff --git a/dom/tests/browser/perfmetrics/ping_worker2.html b/dom/tests/browser/perfmetrics/ping_worker2.html
new file mode 100644
index 0000000000..48f6658218
--- /dev/null
+++ b/dom/tests/browser/perfmetrics/ping_worker2.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<html lang="en" dir="ltr">
+<head>
+ <meta charset="utf-8">
+ <script type="text/javascript">
+
+ var shared;
+
+ function init() {
+ shared = new SharedWorker("shared_worker.js");
+ shared.port.start();
+ for (let i = 0; i < 10; i++) shared.port.postMessage(["ok"]);
+ }
+
+ </script>
+</head>
+<body onload="init()">
+ <h1>A page with a shared worker</h1>
+</body>
+</html>
diff --git a/dom/tests/browser/perfmetrics/setinterval.html b/dom/tests/browser/perfmetrics/setinterval.html
new file mode 100644
index 0000000000..4c3e7264ca
--- /dev/null
+++ b/dom/tests/browser/perfmetrics/setinterval.html
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<html lang="en" dir="ltr">
+<head>
+ <meta charset="utf-8">
+ <script type="text/javascript">
+ var interval;
+
+ function doSomething() {
+ console.log("We are doing something here");
+ clearInterval(interval);
+ }
+
+ interval = setInterval(doSomething, 1);
+ </script>
+</head>
+<body>
+ <h1>A page with a setInterval() call</h1>
+</body>
+</html>
diff --git a/dom/tests/browser/perfmetrics/settimeout.html b/dom/tests/browser/perfmetrics/settimeout.html
new file mode 100644
index 0000000000..01f632caf5
--- /dev/null
+++ b/dom/tests/browser/perfmetrics/settimeout.html
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html lang="en" dir="ltr">
+<head>
+ <meta charset="utf-8">
+ <script type="text/javascript">
+
+ function doSomething() {
+ console.log("We are doing something here");
+ }
+
+ setTimeout(doSomething, 1);
+ </script>
+</head>
+<body>
+ <h1>A page with a setTimeout() call</h1>
+</body>
+</html>
diff --git a/dom/tests/browser/perfmetrics/shared_worker.js b/dom/tests/browser/perfmetrics/shared_worker.js
new file mode 100644
index 0000000000..cb00bfb3eb
--- /dev/null
+++ b/dom/tests/browser/perfmetrics/shared_worker.js
@@ -0,0 +1,7 @@
+let onconnect = function (e) {
+ var port = e.ports[0];
+
+ port.onmessage = function (e) {
+ port.postMessage(e.data[0]);
+ };
+};
diff --git a/dom/tests/browser/perfmetrics/sound.html b/dom/tests/browser/perfmetrics/sound.html
new file mode 100644
index 0000000000..e365396f31
--- /dev/null
+++ b/dom/tests/browser/perfmetrics/sound.html
@@ -0,0 +1,14 @@
+<!doctype html>
+<html>
+<head>
+<title>Dummy test page</title>
+<meta http-equiv="Content-Type" content="text/html;charset=utf-8"></meta>
+</head>
+<body>
+<p>Page with a sound</p>
+<audio controls autoplay>
+ <source src="hello.ogg" type="audio/ogg">
+</audio>
+</script>
+</body>
+</html>
diff --git a/dom/tests/browser/perfmetrics/unresponsive.html b/dom/tests/browser/perfmetrics/unresponsive.html
new file mode 100644
index 0000000000..e139eb7f9d
--- /dev/null
+++ b/dom/tests/browser/perfmetrics/unresponsive.html
@@ -0,0 +1,21 @@
+<!DOCTYPE html>
+<html lang="en" dir="ltr">
+<head>
+ <meta charset="utf-8">
+ <script type="text/javascript">
+
+ function fn() {
+ let start = Date.now();
+ while (Date.now() - start < 5000)
+ ; // do nothing
+ setTimeout(fn, 0);
+ }
+
+ setTimeout(fn, 10);
+
+ </script>
+</head>
+<body>
+ <h1>An unresponsive page</h1>
+</body>
+</html>