browser_webconsole_clickable_urls.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. // When strings containing URLs are entered into the webconsole, check
  5. // its output and ensure that the output can be clicked to open those URLs.
  6. "use strict";
  7. const inputTests = [
  8. // 0: URL opens page when clicked.
  9. {
  10. input: "'http://example.com'",
  11. output: "http://example.com",
  12. expectedTab: "http://example.com/",
  13. },
  14. // 1: URL opens page using https when clicked.
  15. {
  16. input: "'https://example.com'",
  17. output: "https://example.com",
  18. expectedTab: "https://example.com/",
  19. },
  20. // 2: URL with port opens page when clicked.
  21. {
  22. input: "'https://example.com:443'",
  23. output: "https://example.com:443",
  24. expectedTab: "https://example.com/",
  25. },
  26. // 3: URL containing non-empty path opens page when clicked.
  27. {
  28. input: "'http://example.com/foo'",
  29. output: "http://example.com/foo",
  30. expectedTab: "http://example.com/foo",
  31. },
  32. // 4: URL opens page when clicked, even when surrounded by non-URL tokens.
  33. {
  34. input: "'foo http://example.com bar'",
  35. output: "foo http://example.com bar",
  36. expectedTab: "http://example.com/",
  37. },
  38. // 5: URL opens page when clicked, and whitespace is be preserved.
  39. {
  40. input: "'foo\\nhttp://example.com\\nbar'",
  41. output: "foo\nhttp://example.com\nbar",
  42. expectedTab: "http://example.com/",
  43. },
  44. // 6: URL opens page when clicked when multiple links are present.
  45. {
  46. input: "'http://example.com http://example.com'",
  47. output: "http://example.com http://example.com",
  48. expectedTab: "http://example.com/",
  49. },
  50. // 7: URL without scheme does not open page when clicked.
  51. {
  52. input: "'example.com'",
  53. output: "example.com",
  54. },
  55. // 8: URL with invalid scheme does not open page when clicked.
  56. {
  57. input: "'foo://example.com'",
  58. output: "foo://example.com",
  59. },
  60. // 9: Shortened URL in an array
  61. {
  62. input: "['http://example.com/abcdefghijabcdefghij some other text']",
  63. output: "Array [ \"http://example.com/abcdefghijabcdef\u2026\" ]",
  64. printOutput: "http://example.com/abcdefghijabcdefghij some other text",
  65. expectedTab: "http://example.com/abcdefghijabcdefghij",
  66. getClickableNode: (msg) => msg.querySelectorAll("a")[1],
  67. },
  68. // 10: Shortened URL in an object
  69. {
  70. input: "{test: 'http://example.com/abcdefghijabcdefghij some other text'}",
  71. output: "Object { test: \"http://example.com/abcdefghijabcdef\u2026\" }",
  72. printOutput: "[object Object]",
  73. evalOutput: "http://example.com/abcdefghijabcdefghij some other text",
  74. noClick: true,
  75. consoleLogClick: true,
  76. expectedTab: "http://example.com/abcdefghijabcdefghij",
  77. getClickableNode: (msg) => msg.querySelectorAll("a")[1],
  78. },
  79. ];
  80. const url = "data:text/html;charset=utf8,Bug 1005909 - Clickable URLS";
  81. add_task(function* () {
  82. yield BrowserTestUtils.openNewForegroundTab(gBrowser, url);
  83. let hud = yield openConsole();
  84. yield checkOutputForInputs(hud, inputTests);
  85. });