summaryrefslogtreecommitdiffstats
path: root/modules/libjar/test/unit/test_empty_jar_telemetry.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /modules/libjar/test/unit/test_empty_jar_telemetry.js
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'modules/libjar/test/unit/test_empty_jar_telemetry.js')
-rw-r--r--modules/libjar/test/unit/test_empty_jar_telemetry.js109
1 files changed, 109 insertions, 0 deletions
diff --git a/modules/libjar/test/unit/test_empty_jar_telemetry.js b/modules/libjar/test/unit/test_empty_jar_telemetry.js
new file mode 100644
index 0000000000..4645edf60c
--- /dev/null
+++ b/modules/libjar/test/unit/test_empty_jar_telemetry.js
@@ -0,0 +1,109 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+"use strict";
+
+const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
+const { NetUtil } = ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
+
+const { TelemetryTestUtils } = ChromeUtils.import(
+ "resource://testing-common/TelemetryTestUtils.jsm"
+);
+
+const { TelemetryController } = ChromeUtils.import(
+ "resource://gre/modules/TelemetryController.jsm"
+);
+
+const nsIBinaryInputStream = Components.Constructor(
+ "@mozilla.org/binaryinputstream;1",
+ "nsIBinaryInputStream",
+ "setInputStream"
+);
+
+// Enable the collection (during test) for all products so even products
+// that don't collect the data will be able to run the test without failure.
+Services.prefs.setBoolPref(
+ "toolkit.telemetry.testing.overrideProductsCheck",
+ true
+);
+
+const fileBase = "test_empty_file.zip";
+const file = do_get_file("data/" + fileBase);
+const jarBase = "jar:" + Services.io.newFileURI(file).spec + "!";
+const tmpDir = Services.dirsvc.get("TmpD", Ci.nsIFile);
+
+function Listener(callback) {
+ this._callback = callback;
+}
+Listener.prototype = {
+ gotStartRequest: false,
+ available: -1,
+ gotStopRequest: false,
+ QueryInterface: ChromeUtils.generateQI(["nsIRequestObserver"]),
+ onDataAvailable(request, stream, offset, count) {
+ try {
+ this.available = stream.available();
+ Assert.equal(this.available, count);
+ // Need to consume stream to avoid assertion
+ new nsIBinaryInputStream(stream).readBytes(count);
+ } catch (ex) {
+ do_throw(ex);
+ }
+ },
+ onStartRequest(request) {
+ this.gotStartRequest = true;
+ },
+ onStopRequest(request, status) {
+ this.gotStopRequest = true;
+ Assert.equal(status, 0);
+ if (this._callback) {
+ this._callback.call(null, this);
+ }
+ },
+};
+
+const TELEMETRY_EVENTS_FILTERS = {
+ category: "network.jar.channel",
+ method: "noData",
+};
+
+add_task(async function test_empty_jar_file() {
+ var copy = tmpDir.clone();
+ copy.append("zzdxphd909dbc6r2bxtqss2m000017");
+ copy.append("zzdxphd909dbc6r2bxtqss2m000017");
+ copy.append(fileBase);
+ file.copyTo(copy.parent, copy.leafName);
+
+ var uri = "jar:" + Services.io.newFileURI(copy).spec + "!/test.txt";
+ var chan = NetUtil.newChannel({ uri, loadUsingSystemPrincipal: true });
+
+ Services.telemetry.setEventRecordingEnabled("network.jar.channel", true);
+ Services.telemetry.clearEvents();
+
+ await new Promise(resolve => {
+ chan.asyncOpen(
+ new Listener(function(l) {
+ Assert.ok(chan.contentLength == 0);
+
+ resolve();
+ })
+ );
+ });
+
+ try {
+ copy.remove(false);
+ } catch (e) {}
+
+ TelemetryTestUtils.assertEvents(
+ [
+ {
+ category: "network.jar.channel",
+ method: "noData",
+ object: "onStop",
+ value: `${fileBase}!/test.txt`,
+ },
+ ],
+ TELEMETRY_EVENTS_FILTERS
+ );
+});