test_security-info-weakness-reasons.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. "use strict";
  4. // Tests that NetworkHelper.getReasonsForWeakness returns correct reasons for
  5. // weak requests.
  6. const { require } = Components.utils.import("resource://devtools/shared/Loader.jsm", {});
  7. Object.defineProperty(this, "NetworkHelper", {
  8. get: function () {
  9. return require("devtools/shared/webconsole/network-helper");
  10. },
  11. configurable: true,
  12. writeable: false,
  13. enumerable: true
  14. });
  15. var Ci = Components.interfaces;
  16. const wpl = Ci.nsIWebProgressListener;
  17. const TEST_CASES = [
  18. {
  19. description: "weak cipher",
  20. input: wpl.STATE_IS_BROKEN | wpl.STATE_USES_WEAK_CRYPTO,
  21. expected: ["cipher"]
  22. }, {
  23. description: "only STATE_IS_BROKEN flag",
  24. input: wpl.STATE_IS_BROKEN,
  25. expected: []
  26. }, {
  27. description: "only STATE_IS_SECURE flag",
  28. input: wpl.STATE_IS_SECURE,
  29. expected: []
  30. },
  31. ];
  32. function run_test() {
  33. do_print("Testing NetworkHelper.getReasonsForWeakness.");
  34. for (let {description, input, expected} of TEST_CASES) {
  35. do_print("Testing " + description);
  36. deepEqual(NetworkHelper.getReasonsForWeakness(input), expected,
  37. "Got the expected reasons for weakness.");
  38. }
  39. }