diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /mobile/android/actors/tests | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'mobile/android/actors/tests')
3 files changed, 118 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..66735cddb6 --- /dev/null +++ b/mobile/android/actors/tests/mochitests/head.js @@ -0,0 +1,5 @@ +/* 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"; diff --git a/mobile/android/actors/tests/mochitests/mochitest.toml b/mobile/android/actors/tests/mochitests/mochitest.toml new file mode 100644 index 0000000000..10fb8342b4 --- /dev/null +++ b/mobile/android/actors/tests/mochitests/mochitest.toml @@ -0,0 +1,5 @@ +[DEFAULT] +support-files = ["head.js"] +run-if = ["os == 'android'"] + +["test_geckoview_experiment_delegate.html"] diff --git a/mobile/android/actors/tests/mochitests/test_geckoview_experiment_delegate.html b/mobile/android/actors/tests/mochitests/test_geckoview_experiment_delegate.html new file mode 100644 index 0000000000..c6425e2983 --- /dev/null +++ b/mobile/android/actors/tests/mochitests/test_geckoview_experiment_delegate.html @@ -0,0 +1,108 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=1845824 +--> +<head> + <meta charset="utf-8"> + <title>Test Experiment Delegate</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> +<script class="testbody" type="text/javascript"> + + // Note: TestRunnerActivity provides a pseudo Experiment Delegate for this test. + async function requestExperiment(message) { + const chromeScript = SpecialPowers.loadChromeScript(_ => { + /* eslint-env mozilla/chrome-script */ + addMessageListener("experiment", (msg) => { + var result; + const navigator = Services.wm.getMostRecentWindow("navigator:geckoview"); + const experimentActor = navigator.window.moduleManager.getActor("GeckoViewExperimentDelegate"); + switch (msg.endpoint) { + case 'getExperimentFeature': + result = experimentActor.getExperimentFeature(msg.feature); + break; + case 'recordExposure': + result = experimentActor.recordExposure(msg.feature); + break + case 'recordExperimentExposure': + result = experimentActor.recordExperimentExposure(msg.feature, msg.slug); + break; + case 'recordExperimentMalformedConfig': + result = experimentActor.recordExperimentMalformedConfig(msg.feature, msg.part); + break; + default: + result = null; + break; + } + return result; + }); + + }); + + const result = await chromeScript.sendQuery("experiment", message); + chromeScript.destroy(); + return result; + } + + add_task(async function test_getExperimentFeature() { + const success = await requestExperiment({endpoint: "getExperimentFeature", feature: "test"}); + is(success["item-one"], true, "Retrieved TestRunnerActivity experiment feature 'test' for 'item-one'."); + is(success["item-two"], 5, "Retrieved TestRunnerActivity experiment feature 'test' for 'item-two'."); + var didErrorOccur = false; + try { + await requestExperiment({endpoint: "getExperimentFeature", feature: "no-feature"}); + } catch (error) { + is(error, "An error occurred while retrieving feature data.", "Correctly failed when the feature did not exist."); + didErrorOccur = true; + } + is(didErrorOccur, true, "Error was caught when no feature existed."); + }); + + add_task(async function test_recordExposure() { + const success = await requestExperiment({endpoint: "recordExposure", feature: "test"}); + is(success, true, "Recorded exposure for the feature."); + var didErrorOccur = false; + try { + await requestExperiment({endpoint: "recordExposure", feature: "no-feature"}); + } catch (error) { + is(error, "An error occurred while recording feature.", "Correctly failed when the feature did not exist."); + didErrorOccur = true; + } + is(didErrorOccur, true, "Error was caught when no feature existed."); + }); + + + add_task(async function test_recordExperimentExposure() { + const success = await requestExperiment({endpoint: "recordExperimentExposure", feature: "test", slug: "test"}); + is(success, true, "Recorded experiment exposure for the feature."); + var didErrorOccur = false; + try { + await requestExperiment({endpoint: "recordExperimentExposure", feature: "no-feature", slug: "no-slug"}); + } catch (error) { + is(error, "An error occurred while recording experiment feature.", "Correctly failed when the feature did not exist."); + didErrorOccur = true; + } + is(didErrorOccur, true, "Error was caught when no feature existed."); + }); + + + add_task(async function test_recordExperimentMalformedConfig() { + const success = await requestExperiment({endpoint: "recordExperimentMalformedConfig", feature: "test", part: "test"}); + is(success, true, "Recorded exposure for the feature."); + var didErrorOccur = false; + try { + await requestExperiment({endpoint: "recordExperimentMalformedConfig", feature: "no-feature", part:"no-part"}); + } catch (error) { + is(error, "An error occurred while recording malformed feature config.", "Correctly failed when the feature did not exist."); + didErrorOccur = true; + } + is(didErrorOccur, true, "Error was caught when no feature existed."); + }); + +</script> +</body> +</html> |