test_input_url.html (2553B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <title>Tests for <input type='url'> validity</title> 5 <script 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 16 /** Tests for <input type='url'> validity */ 17 18 // More checks are done in test_bug551670.html. 19 20 var gInvalid = false; 21 22 function invalidEventHandler(e) 23 { 24 is(e.type, "invalid", "Invalid event type should be invalid"); 25 gInvalid = true; 26 } 27 28 function checkValidURL(element) 29 { 30 info(`Checking ${element.value}\n`); 31 gInvalid = false; 32 ok(!element.validity.typeMismatch, 33 "Element should not suffer from type mismatch"); 34 ok(element.validity.valid, "Element should be valid"); 35 ok(element.checkValidity(), "Element should be valid"); 36 ok(!gInvalid, "The invalid event should not have been thrown"); 37 is(element.validationMessage, '', 38 "Validation message should be the empty string"); 39 ok(element.matches(":valid"), ":valid pseudo-class should apply"); 40 } 41 42 function checkInvalidURL(element) 43 { 44 gInvalid = false; 45 ok(element.validity.typeMismatch, 46 "Element should suffer from type mismatch"); 47 ok(!element.validity.valid, "Element should not be valid"); 48 ok(!element.checkValidity(), "Element should not be valid"); 49 ok(gInvalid, "The invalid event should have been thrown"); 50 is(element.validationMessage, "Please enter a URL.", 51 "Validation message should be related to invalid URL"); 52 ok(element.matches(":invalid"), 53 ":invalid pseudo-class should apply"); 54 } 55 56 var url = document.getElementById('i'); 57 58 var values = [ 59 // [ value, validity ] 60 // The empty string should be considered as valid. 61 [ "", true ], 62 [ "foo", false ], 63 [ "http://mozilla.com/", true ], 64 [ "http://mozilla.com", true ], 65 [ "http://mozil\nla\r.com/", true ], 66 [ " http://mozilla.com/ ", true ], 67 [ "\r http://mozilla.com/ \n", true ], 68 [ "file:///usr/bin/tulip", true ], 69 [ "../../bar.html", false ], 70 [ "http://mozillá.org", true ], 71 [ "https://mózillä.org", true ], 72 [ "http://mózillä.órg", true ], 73 [ "ht://mózillä.órg", true ], 74 [ "httŭ://mózillä.órg", false ], 75 [ "chrome://bookmarks", true ], 76 ]; 77 78 values.forEach(function([value, valid]) { 79 url.value = value; 80 81 if (valid) { 82 checkValidURL(url); 83 } else { 84 checkInvalidURL(url); 85 } 86 }); 87 88 </script> 89 </pre> 90 </body> 91 </html>