Bug 1252215 - [webext] Add xpcshell test for LegacyExtensionContext params validation. r=kmag,aswan
MozReview-Commit-ID: 3heZceJK85w
new file mode 100644
--- /dev/null
+++ b/toolkit/components/extensions/test/xpcshell/test_legacy_extension_utils.js
@@ -0,0 +1,34 @@
+/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* vim: set sts=2 sw=2 et tw=80: */
+"use strict";
+
+const {
+ LegacyExtensionsUtils: {
+ LegacyExtensionContext,
+ },
+} = Cu.import("resource://gre/modules/LegacyExtensionsUtils.jsm", {});
+
+/**
+ * This test ensures that the LegacyExtensionContext raises the
+ * expected exception on params validation errors.
+ */
+add_task(function* test_legacy_extension_context_params_validation() {
+ // Missing mandatory targetAddonId
+ Assert.throws(
+ () => {
+ new LegacyExtensionContext();
+ },
+ /targetExtension parameter is mandatory/,
+ "Got the expected exception on missing mandatory parameter"
+ );
+
+ // targetExtension is not an Extension class instance
+ Assert.throws(
+ () => {
+ let targetExtension = {id: "fake@target-extension"};
+ new LegacyExtensionContext(targetExtension);
+ },
+ /targetExtension is not an Extension class instance/,
+ "Got the expected exception on invalid target extension parameter"
+ );
+});
--- a/toolkit/components/extensions/test/xpcshell/xpcshell.ini
+++ b/toolkit/components/extensions/test/xpcshell/xpcshell.ini
@@ -9,10 +9,11 @@ skip-if = toolkit == 'gonk' || appname =
[test_locale_data.js]
[test_locale_converter.js]
[test_ext_contexts.js]
[test_ext_json_parser.js]
[test_ext_manifest_content_security_policy.js]
[test_ext_manifest_incognito.js]
[test_ext_schemas.js]
[test_getAPILevelForWindow.js]
+[test_legacy_extension_utils.js]
[test_native_messaging.js]
skip-if = os == "android"