test_input_url.html 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <title>Tests for &lt;input type='url'&gt; validity</title>
  5. <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  6. <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
  7. </head>
  8. <body>
  9. <p id="display"></p>
  10. <div id="content" style="display: none">
  11. <input type='url' id='i' oninvalid='invalidEventHandler(event);'>
  12. </div>
  13. <pre id="test">
  14. <script type="application/javascript">
  15. /** Tests for <input type='url'> validity **/
  16. // More checks are done in test_bug551670.html.
  17. var gInvalid = false;
  18. function invalidEventHandler(e)
  19. {
  20. is(e.type, "invalid", "Invalid event type should be invalid");
  21. gInvalid = true;
  22. }
  23. function checkValidURL(element)
  24. {
  25. gInvalid = false;
  26. ok(!element.validity.typeMismatch,
  27. "Element should not suffer from type mismatch");
  28. ok(element.validity.valid, "Element should be valid");
  29. ok(element.checkValidity(), "Element should be valid");
  30. ok(!gInvalid, "The invalid event should not have been thrown");
  31. is(element.validationMessage, '',
  32. "Validation message should be the empty string");
  33. ok(element.matches(":valid"), ":valid pseudo-class should apply");
  34. }
  35. function checkInvalidURL(element)
  36. {
  37. gInvalid = false;
  38. ok(element.validity.typeMismatch,
  39. "Element should suffer from type mismatch");
  40. ok(!element.validity.valid, "Element should not be valid");
  41. ok(!element.checkValidity(), "Element should not be valid");
  42. ok(gInvalid, "The invalid event should have been thrown");
  43. is(element.validationMessage, "Please enter a URL.",
  44. "Validation message should be related to invalid URL");
  45. ok(element.matches(":invalid"),
  46. ":invalid pseudo-class should apply");
  47. }
  48. var url = document.getElementById('i');
  49. var values = [
  50. // [ value, validity ]
  51. // The empty string should be considered as valid.
  52. [ "", true ],
  53. [ "foo", false ],
  54. [ "http://mozilla.com/", true ],
  55. [ "http://mozilla.com", true ],
  56. [ "http://mozil\nla\r.com/", true ],
  57. [ " http://mozilla.com/ ", true ],
  58. [ "\r http://mozilla.com/ \n", true ],
  59. [ "file:///usr/bin/tulip", true ],
  60. [ "../../bar.html", false ],
  61. [ "http://mozillá.org", true ],
  62. [ "https://mózillä.org", true ],
  63. [ "http://mózillä.órg", true ],
  64. [ "ht://mózillä.órg", true ],
  65. [ "httŭ://mózillä.órg", false ],
  66. ];
  67. values.forEach(function([value, valid]) {
  68. url.value = value;
  69. if (valid) {
  70. checkValidURL(url);
  71. } else {
  72. checkInvalidURL(url);
  73. }
  74. });
  75. </script>
  76. </pre>
  77. </body>
  78. </html>