040cd4f8a5f6b2249adc72d70f3ba8c3228ded6a
[WebKit-https.git] / LayoutTests / fast / forms / script-tests / ValidityState-typeMismatch-url.js
1 description("Input type=url validation test");
2
3 function check(value, mismatchExpected) {
4     i.value = value;
5     var actual = i.validity.typeMismatch;
6     var didPass = actual == mismatchExpected;
7     var resultText = value + ' is ' + (didPass ? 'a correct ' : 'an incorrect ') + (actual ? 'invalid' : 'valid') + ' url.';
8     if (didPass)
9         testPassed(resultText);
10     else
11         testFailed(resultText);
12 }
13
14 function expectValid(value) {
15     check(value, false);
16 }
17
18 function expectInvalid(value) {
19     check(value, true);
20 }
21
22 var i = document.createElement('input');
23 i.type = 'url';
24
25 // Valid values
26 expectValid('http://www.google.com');
27 expectValid('http://foo:bar@www.google.com:80');
28 expectValid('http://localhost');
29 expectValid('http://127.0.0.1');
30 expectValid('http://[0000:0000:0000:0000:0000:0000:7f00:0001]/');
31 expectValid('http://[0000:0000:0000:0000:0000:0000:127.0.0.1]/');
32 expectValid('http://[::7f00:0001]/');
33 expectValid('http://[1::2:3]/');
34 expectValid('http://[0000:0::ffff:10.0.0.1]/');
35 expectValid('http://a');
36 expectValid('http://www.google.com/search?rls=en&q=WebKit&ie=UTF-8&oe=UTF-8');
37 expectValid('ftp://ftp.myhost.com');
38 expectValid('ssh://ssh.myhost.com');
39 expectValid('mailto:tkent@chromium.org');
40 expectValid('mailto:tkent@chromium.org?body=hello');
41 expectValid('file:///Users/tkent/.zshrc');
42 expectValid('file:///C:/human.sys');
43 expectValid('tel:+1-800-12345;ext=9999');
44 expectValid('tel:03(1234)5678');
45 expectValid('somescheme://ssh.myhost.com');
46 expectValid('http://a/\\\/\'\'*<>/');
47 expectValid('http://a/dfs/\kds@sds');
48 expectValid('http://a.a:1/search?a&b');
49 expectValid('http://www.google.com/#top');
50 expectValid('http://\u30C6\u30B9\u30C8\u3002jp/\u30D1\u30B9?\u540D\u524D=\u5024');
51
52 // Invalid values
53 expectInvalid('www.google.com');
54 expectInvalid('127.0.0.1');
55 expectInvalid('.com');
56 expectInvalid('http://www.google.com:aaaa');
57 expectInvalid('://');
58 expectInvalid('/http://www.google.com');
59 expectInvalid('----ftp://a');
60 expectInvalid('scheme//a');
61 expectInvalid('http://[v8.:::]/');
62
63 // KURL's host name restriction is stricter than RFC 3986. KURLGoogle is not.
64 i.value = 'http://www.g**gle.com'
65 var strictHost = i.validity.typeMismatch;
66 if (strictHost) {
67     expectInvalid('http:// www.google.com');
68     expectInvalid('http://www .google.com');
69     expectInvalid('http://www.&#10;google.&#13;com');
70     expectInvalid('http://host+');
71     expectInvalid('http://myurl!');
72 } else {
73     expectValid('http:// www.google.com');
74     expectValid('http://www .google.com');
75     expectValid('http://www.&#10;google.&#13;com');
76     expectValid('http://host+');
77     expectValid('http://myurl!');
78 }
79
80 var successfullyParsed = true;