browser_webconsole_certificate_messages.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
  2. /* Any copyright is dedicated to the Public Domain.
  3. * http://creativecommons.org/publicdomain/zero/1.0/ */
  4. // Tests that the Web Console shows weak crypto warnings (SHA-1 Certificate)
  5. "use strict";
  6. const TEST_URI = "data:text/html;charset=utf8,Web Console weak crypto " +
  7. "warnings test";
  8. const TEST_URI_PATH = "/browser/devtools/client/webconsole/test/" +
  9. "test-certificate-messages.html";
  10. var gWebconsoleTests = [
  11. {url: "https://sha1ee.example.com" + TEST_URI_PATH,
  12. name: "SHA1 warning displayed successfully",
  13. warning: ["SHA-1"], nowarning: ["SSL 3.0", "RC4"]},
  14. {url: "https://sha256ee.example.com" + TEST_URI_PATH,
  15. name: "SSL warnings appropriately not present",
  16. warning: [], nowarning: ["SHA-1", "SSL 3.0", "RC4"]},
  17. ];
  18. const TRIGGER_MSG = "If you haven't seen ssl warnings yet, you won't";
  19. var gHud = undefined, gContentBrowser;
  20. var gCurrentTest;
  21. function test() {
  22. registerCleanupFunction(function () {
  23. gHud = gContentBrowser = null;
  24. });
  25. loadTab(TEST_URI).then(({browser}) => {
  26. gContentBrowser = browser;
  27. openConsole().then(runTestLoop);
  28. });
  29. }
  30. function runTestLoop(theHud) {
  31. gCurrentTest = gWebconsoleTests.shift();
  32. if (!gCurrentTest) {
  33. finishTest();
  34. return;
  35. }
  36. if (!gHud) {
  37. gHud = theHud;
  38. }
  39. gHud.jsterm.clearOutput();
  40. gContentBrowser.addEventListener("load", onLoad, true);
  41. if (gCurrentTest.pref) {
  42. SpecialPowers.pushPrefEnv({"set": gCurrentTest.pref},
  43. function () {
  44. BrowserTestUtils.loadURI(gBrowser.selectedBrowser, gCurrentTest.url);
  45. });
  46. } else {
  47. BrowserTestUtils.loadURI(gBrowser.selectedBrowser, gCurrentTest.url);
  48. }
  49. }
  50. function onLoad() {
  51. gContentBrowser.removeEventListener("load", onLoad, true);
  52. waitForSuccess({
  53. name: gCurrentTest.name,
  54. validator: function () {
  55. if (gHud.outputNode.textContent.indexOf(TRIGGER_MSG) >= 0) {
  56. for (let warning of gCurrentTest.warning) {
  57. if (gHud.outputNode.textContent.indexOf(warning) < 0) {
  58. return false;
  59. }
  60. }
  61. for (let nowarning of gCurrentTest.nowarning) {
  62. if (gHud.outputNode.textContent.indexOf(nowarning) >= 0) {
  63. return false;
  64. }
  65. }
  66. return true;
  67. }
  68. }
  69. }).then(runTestLoop);
  70. }