summaryrefslogtreecommitdiffstats
path: root/toolkit/components/glean/tests/browser
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /toolkit/components/glean/tests/browser
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/glean/tests/browser')
-rw-r--r--toolkit/components/glean/tests/browser/browser.ini19
-rw-r--r--toolkit/components/glean/tests/browser/browser_event_leak.js26
-rw-r--r--toolkit/components/glean/tests/browser/browser_fog_gmp.js84
-rw-r--r--toolkit/components/glean/tests/browser/browser_fog_gpu.js34
-rw-r--r--toolkit/components/glean/tests/browser/browser_fog_rdd.js63
-rw-r--r--toolkit/components/glean/tests/browser/browser_fog_socket.js33
-rw-r--r--toolkit/components/glean/tests/browser/browser_fog_utility.js37
-rw-r--r--toolkit/components/glean/tests/browser/browser_labeled_gifft.js50
-rw-r--r--toolkit/components/glean/tests/browser/empty_file.html9
-rw-r--r--toolkit/components/glean/tests/browser/small-shot.oggbin0 -> 6416 bytes
10 files changed, 355 insertions, 0 deletions
diff --git a/toolkit/components/glean/tests/browser/browser.ini b/toolkit/components/glean/tests/browser/browser.ini
new file mode 100644
index 0000000000..eae3f38730
--- /dev/null
+++ b/toolkit/components/glean/tests/browser/browser.ini
@@ -0,0 +1,19 @@
+# Please keep test files lexicographically sorted, with whitespace between.
+[DEFAULT]
+support-files =
+
+[browser_event_leak.js]
+
+[browser_fog_gmp.js]
+support-files = empty_file.html
+
+[browser_fog_gpu.js]
+
+[browser_fog_rdd.js]
+support-files = small-shot.ogg
+
+[browser_fog_socket.js]
+
+[browser_fog_utility.js]
+
+[browser_labeled_gifft.js]
diff --git a/toolkit/components/glean/tests/browser/browser_event_leak.js b/toolkit/components/glean/tests/browser/browser_event_leak.js
new file mode 100644
index 0000000000..1e69f17064
--- /dev/null
+++ b/toolkit/components/glean/tests/browser/browser_event_leak.js
@@ -0,0 +1,26 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+add_task(async () => {
+ Services.fog.testResetFOG(); // Needed for TV which reuses profiles on repeat
+ Assert.equal(
+ undefined,
+ Glean.testOnlyIpc.eventWithExtra.testGetValue(),
+ "Nothing to begin with"
+ );
+ Glean.testOnlyIpc.eventWithExtra.record({
+ extra1: "Some extra string",
+ extra2: 42,
+ extra3_longer_name: false,
+ });
+ Assert.equal(
+ 1,
+ Glean.testOnlyIpc.eventWithExtra.testGetValue().length,
+ "One event? One event."
+ );
+
+ // AND NOW, FOR THE TRUE TEST:
+ // Will this leak memory all over the place?
+});
diff --git a/toolkit/components/glean/tests/browser/browser_fog_gmp.js b/toolkit/components/glean/tests/browser/browser_fog_gmp.js
new file mode 100644
index 0000000000..4219605eea
--- /dev/null
+++ b/toolkit/components/glean/tests/browser/browser_fog_gmp.js
@@ -0,0 +1,84 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/**
+ * Return a web-based URL for a given file based on the testing directory.
+ * @param {String} fileName
+ * file that caller wants its web-based url
+ */
+function GetTestWebBasedURL(fileName) {
+ return (
+ getRootDirectory(gTestPath).replace(
+ "chrome://mochitests/content",
+ "https://example.org"
+ ) + fileName
+ );
+}
+
+add_task(async () => {
+ await SpecialPowers.pushPrefEnv({
+ set: [["media.eme.enabled", true]],
+ });
+
+ await BrowserTestUtils.withNewTab(
+ GetTestWebBasedURL("empty_file.html"),
+ async function(browser) {
+ await SpecialPowers.spawn(browser, [], async function() {
+ try {
+ let config = [
+ {
+ initDataTypes: ["webm"],
+ videoCapabilities: [{ contentType: 'video/webm; codecs="vp9"' }],
+ },
+ ];
+ let access = await content.navigator.requestMediaKeySystemAccess(
+ "org.w3.clearkey",
+ config
+ );
+
+ content.mediaKeys = await access.createMediaKeys();
+ info("got media keys, which should ensure a GMP process exists");
+ } catch (ex) {
+ ok(false, ex.toString());
+ }
+ });
+
+ ok(
+ (await ChromeUtils.requestProcInfo()).children.some(
+ p => p.type == "gmpPlugin"
+ ),
+ "Found the GMP process."
+ );
+
+ Services.fog.testResetFOG();
+
+ is(
+ undefined,
+ Glean.testOnlyIpc.aCounter.testGetValue(),
+ "Ensure we begin without value."
+ );
+
+ await TestUtils.waitForCondition(async () => {
+ try {
+ await Services.fog.testTriggerMetrics(
+ Ci.nsIXULRuntime.PROCESS_TYPE_GMPLUGIN
+ );
+ return true;
+ } catch (e) {
+ info(e);
+ return false;
+ }
+ }, "waiting until we can successfully send the TestTriggerMetrics IPC.");
+
+ await Services.fog.testFlushAllChildren();
+
+ is(
+ Glean.testOnlyIpc.aCounter.testGetValue(),
+ Ci.nsIXULRuntime.PROCESS_TYPE_GMPLUGIN,
+ "Ensure the GMP-process-set value shows up in the parent process."
+ );
+ }
+ );
+});
diff --git a/toolkit/components/glean/tests/browser/browser_fog_gpu.js b/toolkit/components/glean/tests/browser/browser_fog_gpu.js
new file mode 100644
index 0000000000..da0e699c20
--- /dev/null
+++ b/toolkit/components/glean/tests/browser/browser_fog_gpu.js
@@ -0,0 +1,34 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+add_task(async () => {
+ if (
+ !(await ChromeUtils.requestProcInfo()).children.some(p => p.type == "gpu")
+ ) {
+ ok(
+ true,
+ 'No GPU process? No test. Try again with --setpref "layers.gpu-process.force-enabled=true".'
+ );
+ return;
+ }
+ ok(true, "GPU Process found: Let's test.");
+
+ Services.fog.testResetFOG();
+
+ is(
+ undefined,
+ Glean.testOnlyIpc.aCounter.testGetValue(),
+ "Ensure we begin without value."
+ );
+
+ await Services.fog.testTriggerMetrics(Ci.nsIXULRuntime.PROCESS_TYPE_GPU);
+ await Services.fog.testFlushAllChildren();
+
+ is(
+ Glean.testOnlyIpc.aCounter.testGetValue(),
+ Ci.nsIXULRuntime.PROCESS_TYPE_GPU,
+ "Ensure the GPU-process-set value shows up in the parent process."
+ );
+});
diff --git a/toolkit/components/glean/tests/browser/browser_fog_rdd.js b/toolkit/components/glean/tests/browser/browser_fog_rdd.js
new file mode 100644
index 0000000000..caf9a6db1f
--- /dev/null
+++ b/toolkit/components/glean/tests/browser/browser_fog_rdd.js
@@ -0,0 +1,63 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/**
+ * Return a web-based URL for a given file based on the testing directory.
+ * @param {String} fileName
+ * file that caller wants its web-based url
+ */
+function GetTestWebBasedURL(fileName) {
+ return (
+ getRootDirectory(gTestPath).replace(
+ "chrome://mochitests/content",
+ "http://example.org"
+ ) + fileName
+ );
+}
+
+add_task(async () => {
+ await SpecialPowers.pushPrefEnv({
+ set: [["media.rdd-process.enabled", true]],
+ });
+
+ let url = GetTestWebBasedURL("small-shot.ogg");
+ info(
+ `Opening ${url} in a new tab to trigger the creation of the RDD process`
+ );
+ let tab = BrowserTestUtils.addTab(gBrowser, url);
+
+ await TestUtils.waitForCondition(
+ async () =>
+ (await ChromeUtils.requestProcInfo()).children.some(p => p.type == "rdd"),
+ "waiting to find RDD process."
+ );
+
+ Services.fog.testResetFOG();
+
+ is(
+ undefined,
+ Glean.testOnlyIpc.aCounter.testGetValue(),
+ "Ensure we begin without value."
+ );
+
+ await TestUtils.waitForCondition(async () => {
+ try {
+ await Services.fog.testTriggerMetrics(Ci.nsIXULRuntime.PROCESS_TYPE_RDD);
+ return true;
+ } catch (e) {
+ return false;
+ }
+ }, "waiting until we can successfully send the TestTriggerMetrics IPC.");
+
+ await Services.fog.testFlushAllChildren();
+
+ is(
+ Glean.testOnlyIpc.aCounter.testGetValue(),
+ Ci.nsIXULRuntime.PROCESS_TYPE_RDD,
+ "Ensure the RDD-process-set value shows up in the parent process."
+ );
+
+ BrowserTestUtils.removeTab(tab);
+});
diff --git a/toolkit/components/glean/tests/browser/browser_fog_socket.js b/toolkit/components/glean/tests/browser/browser_fog_socket.js
new file mode 100644
index 0000000000..4ca4f085a1
--- /dev/null
+++ b/toolkit/components/glean/tests/browser/browser_fog_socket.js
@@ -0,0 +1,33 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+add_task(async () => {
+ if (
+ !(await ChromeUtils.requestProcInfo()).children.some(
+ p => p.type == "socket"
+ )
+ ) {
+ ok(true, "No Socket process? No test.");
+ return;
+ }
+ ok(true, "Socket process found: Let's test.");
+
+ Services.fog.testResetFOG();
+
+ is(
+ undefined,
+ Glean.testOnlyIpc.aCounter.testGetValue(),
+ "Ensure we begin without value."
+ );
+
+ await Services.fog.testTriggerMetrics(Ci.nsIXULRuntime.PROCESS_TYPE_SOCKET);
+ await Services.fog.testFlushAllChildren();
+
+ is(
+ Glean.testOnlyIpc.aCounter.testGetValue(),
+ Ci.nsIXULRuntime.PROCESS_TYPE_SOCKET,
+ "Ensure the Socket-process-set value shows up in the parent process."
+ );
+});
diff --git a/toolkit/components/glean/tests/browser/browser_fog_utility.js b/toolkit/components/glean/tests/browser/browser_fog_utility.js
new file mode 100644
index 0000000000..aaea9cfb42
--- /dev/null
+++ b/toolkit/components/glean/tests/browser/browser_fog_utility.js
@@ -0,0 +1,37 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+add_task(async () => {
+ const utilityProcessTest = Cc[
+ "@mozilla.org/utility-process-test;1"
+ ].createInstance(Ci.nsIUtilityProcessTest);
+ await utilityProcessTest
+ .startProcess()
+ .then(async () => {
+ Services.fog.testResetFOG();
+
+ is(
+ undefined,
+ Glean.testOnlyIpc.aCounter.testGetValue(),
+ "Ensure we begin without value."
+ );
+
+ await Services.fog.testTriggerMetrics(
+ Ci.nsIXULRuntime.PROCESS_TYPE_UTILITY
+ );
+ await Services.fog.testFlushAllChildren();
+
+ is(
+ Glean.testOnlyIpc.aCounter.testGetValue(),
+ Ci.nsIXULRuntime.PROCESS_TYPE_UTILITY,
+ "Ensure the utility-process-set value shows up in the parent process."
+ );
+ })
+ .catch(async () => {
+ ok(false, "Cannot start Utility process?");
+ });
+
+ await utilityProcessTest.stopProcess();
+});
diff --git a/toolkit/components/glean/tests/browser/browser_labeled_gifft.js b/toolkit/components/glean/tests/browser/browser_labeled_gifft.js
new file mode 100644
index 0000000000..2203424e82
--- /dev/null
+++ b/toolkit/components/glean/tests/browser/browser_labeled_gifft.js
@@ -0,0 +1,50 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+function keyedScalarValue(aScalarName) {
+ let snapshot = Services.telemetry.getSnapshotForKeyedScalars();
+ return "parent" in snapshot ? snapshot.parent[aScalarName] : undefined;
+}
+
+add_task(async () => {
+ Assert.equal(
+ undefined,
+ Glean.testOnlyIpc.aLabeledCounter.a_label.testGetValue(),
+ "New labels with no values should return undefined"
+ );
+ Glean.testOnlyIpc.aLabeledCounter.a_label.add(1);
+ Glean.testOnlyIpc.aLabeledCounter.another_label.add(2);
+ Assert.equal(1, Glean.testOnlyIpc.aLabeledCounter.a_label.testGetValue());
+ Assert.equal(
+ 2,
+ Glean.testOnlyIpc.aLabeledCounter.another_label.testGetValue()
+ );
+ // What about invalid/__other__?
+ Assert.equal(
+ undefined,
+ Glean.testOnlyIpc.aLabeledCounter.__other__.testGetValue()
+ );
+ Glean.testOnlyIpc.aLabeledCounter.InvalidLabel.add(3);
+ Assert.throws(
+ () => Glean.testOnlyIpc.aLabeledCounter.__other__.testGetValue(),
+ /NS_ERROR_LOSS_OF_SIGNIFICANT_DATA/,
+ "Can't get the value when you're error'd"
+ );
+
+ let value = keyedScalarValue(
+ "telemetry.test.another_mirror_for_labeled_counter"
+ );
+ Assert.deepEqual(
+ {
+ a_label: 1,
+ another_label: 2,
+ InvalidLabel: 3,
+ },
+ value
+ );
+
+ // AND NOW, FOR THE TRUE TEST:
+ // Will this leak memory all over the place?
+});
diff --git a/toolkit/components/glean/tests/browser/empty_file.html b/toolkit/components/glean/tests/browser/empty_file.html
new file mode 100644
index 0000000000..af8440ac16
--- /dev/null
+++ b/toolkit/components/glean/tests/browser/empty_file.html
@@ -0,0 +1,9 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="UTF-8">
+ </head>
+ <body>
+ This page is intentionally left blank.
+ </body>
+</html>
diff --git a/toolkit/components/glean/tests/browser/small-shot.ogg b/toolkit/components/glean/tests/browser/small-shot.ogg
new file mode 100644
index 0000000000..1a41623f81
--- /dev/null
+++ b/toolkit/components/glean/tests/browser/small-shot.ogg
Binary files differ