From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- .../components/glean/tests/browser/browser.toml | 17 +++++ .../glean/tests/browser/browser_event_leak.js | 26 +++++++ .../glean/tests/browser/browser_fog_gmp.js | 84 +++++++++++++++++++++ .../glean/tests/browser/browser_fog_gpu.js | 34 +++++++++ .../glean/tests/browser/browser_fog_rdd.js | 63 ++++++++++++++++ .../glean/tests/browser/browser_fog_socket.js | 33 ++++++++ .../glean/tests/browser/browser_fog_utility.js | 37 +++++++++ .../glean/tests/browser/browser_labeled_gifft.js | 54 +++++++++++++ .../components/glean/tests/browser/empty_file.html | 9 +++ .../components/glean/tests/browser/small-shot.ogg | Bin 0 -> 6416 bytes 10 files changed, 357 insertions(+) create mode 100644 toolkit/components/glean/tests/browser/browser.toml create mode 100644 toolkit/components/glean/tests/browser/browser_event_leak.js create mode 100644 toolkit/components/glean/tests/browser/browser_fog_gmp.js create mode 100644 toolkit/components/glean/tests/browser/browser_fog_gpu.js create mode 100644 toolkit/components/glean/tests/browser/browser_fog_rdd.js create mode 100644 toolkit/components/glean/tests/browser/browser_fog_socket.js create mode 100644 toolkit/components/glean/tests/browser/browser_fog_utility.js create mode 100644 toolkit/components/glean/tests/browser/browser_labeled_gifft.js create mode 100644 toolkit/components/glean/tests/browser/empty_file.html create mode 100644 toolkit/components/glean/tests/browser/small-shot.ogg (limited to 'toolkit/components/glean/tests/browser') diff --git a/toolkit/components/glean/tests/browser/browser.toml b/toolkit/components/glean/tests/browser/browser.toml new file mode 100644 index 0000000000..70c4afc8b1 --- /dev/null +++ b/toolkit/components/glean/tests/browser/browser.toml @@ -0,0 +1,17 @@ +[DEFAULT] + +["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..f61c3806f1 --- /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( + null, + 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..6911ae8026 --- /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( + null, + 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..51c10bbf31 --- /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( + null, + 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..5ccf59dabb --- /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( + null, + 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..2f6913eefc --- /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( + null, + 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..a6b5761c98 --- /dev/null +++ b/toolkit/components/glean/tests/browser/browser_labeled_gifft.js @@ -0,0 +1,54 @@ +/* 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 () => { + // Ensure we're starting with a clean slate. test-verify can be tricky. + Services.fog.testResetFOG(); + Services.telemetry.clearScalars(); + + 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["1".repeat(72)].add(3); + Assert.throws( + () => Glean.testOnlyIpc.aLabeledCounter.__other__.testGetValue(), + /DataError/, + "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, + ["1".repeat(72)]: 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 @@ + + + + + + + This page is intentionally left blank. + + 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 Binary files /dev/null and b/toolkit/components/glean/tests/browser/small-shot.ogg differ -- cgit v1.2.3