diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /mobile/android/actors/tests | |
parent | Initial commit. (diff) | |
download | thunderbird-upstream.tar.xz thunderbird-upstream.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'mobile/android/actors/tests')
3 files changed, 165 insertions, 0 deletions
diff --git a/mobile/android/actors/tests/mochitests/head.js b/mobile/android/actors/tests/mochitests/head.js new file mode 100644 index 0000000000..01288ca822 --- /dev/null +++ b/mobile/android/actors/tests/mochitests/head.js @@ -0,0 +1,51 @@ +/* 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"; + +// Bug 1799977: Using workaround to test telemtry in plain mochitests +const GleanTest = new Proxy( + {}, + { + get(target, categoryName, receiver) { + return new Proxy( + {}, + { + // eslint-disable-next-line no-shadow + get(target, metricName, receiver) { + return { + // The only API we actually implement right now. + async testGetValue() { + return SpecialPowers.spawnChrome( + [categoryName, metricName], + // eslint-disable-next-line no-shadow + async (categoryName, metricName) => { + await Services.fog.testFlushAllChildren(); + const window = this.browsingContext.topChromeWindow; + return window.Glean[categoryName][ + metricName + ].testGetValue(); + } + ); + }, + async testGetValueLabel(label) { + return SpecialPowers.spawnChrome( + [categoryName, metricName, label], + // eslint-disable-next-line no-shadow + async (categoryName, metricName, label) => { + await Services.fog.testFlushAllChildren(); + const window = this.browsingContext.topChromeWindow; + return window.Glean[categoryName][metricName][ + label + ].testGetValue(); + } + ); + }, + }; + }, + } + ); + }, + } +); diff --git a/mobile/android/actors/tests/mochitests/mochitest.ini b/mobile/android/actors/tests/mochitests/mochitest.ini new file mode 100644 index 0000000000..31fe69cb03 --- /dev/null +++ b/mobile/android/actors/tests/mochitests/mochitest.ini @@ -0,0 +1,8 @@ +[DEFAULT] +support-files = + head.js +prefs = + dom.enable_window_print=true +skip-if = + os != 'android' +[test_geckoview_actor_telemetry.html]
\ No newline at end of file diff --git a/mobile/android/actors/tests/mochitests/test_geckoview_actor_telemetry.html b/mobile/android/actors/tests/mochitests/test_geckoview_actor_telemetry.html new file mode 100644 index 0000000000..fa4e27b37a --- /dev/null +++ b/mobile/android/actors/tests/mochitests/test_geckoview_actor_telemetry.html @@ -0,0 +1,106 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=1816151 +--> +<head> + <meta charset="utf-8"> + <title>Tests for Telemetry in GeckoView Actors</title> + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> + <script type="text/javascript" src="head.js" type="application/javascript"></script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> +</head> +<body> +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1816151">Mozilla Bug 1816151 for Window.Print() Telemetry</a> +<script class="testbody" type="text/javascript"> + + const printScript = SpecialPowers.loadChromeScript(_ => { + /* eslint-env mozilla/chrome-script */ + addMessageListener("print",() => { + const navigator = Services.wm.getMostRecentWindow("navigator:geckoview"); + const printActor = navigator.window.moduleManager.getActor("GeckoViewPrintDelegate"); + printActor.telemetryDotPrintRequested(); + }); + addMessageListener("completed",(message) => { + const navigator = Services.wm.getMostRecentWindow("navigator:geckoview"); + const printActor = navigator.window.moduleManager.getActor("GeckoViewPrintDelegate"); + printActor.telemetryDotPrintPdfCompleted(message); + }); + }); + + add_task(async function test_windowDotPrintTelemetry() { + const telemetryStart = await GleanTest.dotprint.requested.testGetValue() ?? 0; + + // Using the print actor directly because + // if window.print() is requested Android exits the TestRunnerActivity and starts a PrintActivity, + // which causes the test harness to stop unexpectedly + await printScript.sendAsyncMessage("print"); + + const requestPrintOnce = await GleanTest.dotprint.requested.testGetValue() ?? 0; + is(requestPrintOnce - telemetryStart, 1, "GeckoView Dot Print Telemetry Incremented Once"); + + await printScript.sendAsyncMessage("print"); + const requestPrintTwice = await GleanTest.dotprint.requested.testGetValue() ?? 0; + is(requestPrintTwice - telemetryStart, 2, "GeckoView Dot Print Telemetry Incremented Twice"); + }); + + add_task(async function test_windowDotPrintDialogOpenedTelemetry() { + const success = {isPdfSuccessful: true} + const telemetryStart = await GleanTest.dotprint.androidDialogRequested.testGetValue() ?? 0; + await printScript.sendAsyncMessage("completed", success); + const dialogSuccessOnce = await GleanTest.dotprint.androidDialogRequested.testGetValue() ?? 0; + is(dialogSuccessOnce - telemetryStart, 1, "GeckoView Dot Print Telemetry for Android Dialog Incremented Once"); + await printScript.sendAsyncMessage("completed", success); + const dialogSuccessTwice = await GleanTest.dotprint.androidDialogRequested.testGetValue() ?? 0; + is(dialogSuccessTwice - telemetryStart, 2, "GeckoView Dot Print Telemetry for Android Dialog Incremented Twice"); + }); + + add_task(async function test_windowDotPrintFailureTelemetry() { + // UNKNOWN Failure + const failureStart = await GleanTest.dotprint.failure.testGetValueLabel("unknown") ?? 0; + await printScript.sendAsyncMessage("completed", {isPdfSuccessful: false}); + const printFailure = await GleanTest.dotprint.failure.testGetValueLabel("unknown") ?? 0; + is(printFailure - failureStart, 1, "GeckoView Dot Print Telemetry Fail Without a Specified Reason"); + + await printScript.sendAsyncMessage("completed", {}); + const printFailureEmpty = await GleanTest.dotprint.failure.testGetValueLabel("unknown") ?? 0; + is(printFailureEmpty - failureStart, 2, "GeckoView Dot Print Telemetry Fail When Empty"); + + await printScript.sendAsyncMessage("completed", {isPdfSuccessful: false, errorReason: -10}); + const printFailureUnk = await GleanTest.dotprint.failure.testGetValueLabel("unknown") ?? 0; + is(printFailureUnk - failureStart, 3, "GeckoView Dot Print Telemetry Fail With An Unknown Code"); + + // ERROR_PRINT_SETTINGS_SERVICE_NOT_AVAILABLE -1 Failure + const failure1Start = await GleanTest.dotprint.failure.testGetValueLabel("no_settings_service") ?? 0; + await printScript.sendAsyncMessage("completed", {isPdfSuccessful: false, errorReason: -1}); + const failure1End = await GleanTest.dotprint.failure.testGetValueLabel("no_settings_service") ?? 0; + is(failure1End - failure1Start, 1, "GeckoView Dot Print Telemetry Fail With No Settings Service"); + + // ERROR_UNABLE_TO_CREATE_PRINT_SETTINGS -2 Failure + const failure2Start = await GleanTest.dotprint.failure.testGetValueLabel("no_settings") ?? 0; + await printScript.sendAsyncMessage("completed", {isPdfSuccessful: false, errorReason: -2}); + const failure2End = await GleanTest.dotprint.failure.testGetValueLabel("no_settings") ?? 0; + is(failure2End - failure2Start, 1, "GeckoView Dot Print Telemetry Fail With No Settings"); + + // ERROR_UNABLE_TO_RETRIEVE_CANONICAL_BROWSING_CONTEXT -3 Failure + const failure3Start = await GleanTest.dotprint.failure.testGetValueLabel("no_canonical_context") ?? 0; + await printScript.sendAsyncMessage("completed", {isPdfSuccessful: false, errorReason: -3}); + const failure3End = await GleanTest.dotprint.failure.testGetValueLabel("no_canonical_context") ?? 0; + is(failure3End - failure3Start, 1, "GeckoView Dot Print Telemetry Fail With No Canonical Context"); + + // ERROR_NO_ACTIVITY_CONTEXT_DELEGATE -4 Failure + const failure4Start = await GleanTest.dotprint.failure.testGetValueLabel("no_activity_context_delegate") ?? 0; + await printScript.sendAsyncMessage("completed", {isPdfSuccessful: false, errorReason: -4}); + const failure4End = await GleanTest.dotprint.failure.testGetValueLabel("no_activity_context_delegate") ?? 0; + is(failure4End - failure4Start, 1, "GeckoView Dot Print Telemetry Fail With No Activity Context Delegate"); + + // ERROR_NO_ACTIVITY_CONTEXT -5 Failure + const failure5Start = await GleanTest.dotprint.failure.testGetValueLabel("no_activity_context") ?? 0; + await printScript.sendAsyncMessage("completed", {isPdfSuccessful: false, errorReason: -5}); + const failure5End = await GleanTest.dotprint.failure.testGetValueLabel("no_activity_context") ?? 0; + is(failure5End - failure5Start, 1, "GeckoView Dot Print Telemetry Fail With No Activity Context"); + }); + +</script> +</body> +</html> |