Bug 1252215 - [webext] Add xpcshell test for ClassicExtensionContext params validation. r=kmag,aswan draft
authorLuca Greco <lgreco@mozilla.com>
Wed, 25 May 2016 20:11:07 +0200
changeset 371013 0baa6359ce5dff8f6ee158e8a124415c2810d835
parent 371012 4234e88ddf77e372e9c961c84861aa562a154f2d
child 371014 891b200f33958c1614b3f526941fd05aa6454188
push id19202
push userluca.greco@alcacoop.it
push dateWed, 25 May 2016 20:04:11 +0000
reviewerskmag, aswan
bugs1252215
milestone49.0a1
Bug 1252215 - [webext] Add xpcshell test for ClassicExtensionContext params validation. r=kmag,aswan MozReview-Commit-ID: 3heZceJK85w
toolkit/components/extensions/test/xpcshell/test_classic_extension_utils.js
toolkit/components/extensions/test/xpcshell/xpcshell.ini
new file mode 100644
--- /dev/null
+++ b/toolkit/components/extensions/test/xpcshell/test_classic_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 {
+  ClassicExtensionsUtils: {
+    ClassicExtensionContext,
+  },
+} = Cu.import("resource://gre/modules/ClassicExtensionsUtils.jsm", {});
+
+/**
+ * This test ensures that the ClassicExtensionContext raises the
+ * expected exception on params validation errors.
+ */
+add_task(function* test_classic_extension_context_params_validation() {
+  // Missing mandatory targetAddonId
+  Assert.throws(
+    () => {
+      new ClassicExtensionContext();
+    },
+    /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 ClassicExtensionContext(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
@@ -8,8 +8,9 @@ skip-if = toolkit == 'gonk' || appname =
 [test_csp_validator.js]
 [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_schemas.js]
 [test_getAPILevelForWindow.js]
+[test_classic_extension_utils.js]