Bug 1252215 - [webext] Add xpcshell test for LegacyExtensionContext params validation. r=kmag,aswan draft
authorLuca Greco <lgreco@mozilla.com>
Wed, 25 May 2016 20:11:07 +0200
changeset 388652 5f6fa87939c821e1f11ff658d89d39f227cf4ef4
parent 388651 620728ef68b25d75b9c23e2849796c8e129f2827
child 388653 1200af00b11d82d7f5f474b13f149a265b72b070
push id23215
push userluca.greco@alcacoop.it
push dateSat, 16 Jul 2016 20:37:12 +0000
reviewerskmag, aswan
bugs1252215
milestone50.0a1
Bug 1252215 - [webext] Add xpcshell test for LegacyExtensionContext params validation. r=kmag,aswan MozReview-Commit-ID: 3heZceJK85w
toolkit/components/extensions/test/xpcshell/test_legacy_extension_utils.js
toolkit/components/extensions/test/xpcshell/xpcshell.ini
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"