layout/style/test/test_parse_url.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/style/test/test_parse_url.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,195 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=473914
     1.8 +-->
     1.9 +<head>
    1.10 +  <title>Test for Bug 473914</title>
    1.11 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.12 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.13 +</head>
    1.14 +<body>
    1.15 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=473914">Mozilla Bug 473914</a>
    1.16 +<p id="display"></p>
    1.17 +<div id="content" style="display: none">
    1.18 +  
    1.19 +</div>
    1.20 +<pre id="test">
    1.21 +<script type="application/javascript">
    1.22 +
    1.23 +/** Test for Bug 473914 **/
    1.24 +
    1.25 +var div = document.getElementById("content");
    1.26 +
    1.27 +// This test relies on normalization (insertion of quote marks) that
    1.28 +// we're not really guaranteed to continue doing in the future.
    1.29 +div.style.listStyleImage = 'url(http://example.org/**/)';
    1.30 +is(div.style.listStyleImage, 'url("http://example.org/**/")',
    1.31 +   "not treated as comment");
    1.32 +div.style.listStyleImage = 'url("http://example.org/**/")';
    1.33 +is(div.style.listStyleImage, 'url("http://example.org/**/")',
    1.34 +   "not treated as comment");
    1.35 +div.style.listStyleImage = 'url(/**/foo)';
    1.36 +is(div.style.listStyleImage, 'url("/**/foo")',
    1.37 +   "not treated as comment");
    1.38 +div.style.listStyleImage = 'url("/**/foo")';
    1.39 +is(div.style.listStyleImage, 'url("/**/foo")',
    1.40 +   "not treated as comment");
    1.41 +div.style.listStyleImage = 'url(/**/)';
    1.42 +is(div.style.listStyleImage, 'url("/**/")',
    1.43 +   "not treated as comment");
    1.44 +div.style.listStyleImage = 'url("/**/")';
    1.45 +is(div.style.listStyleImage, 'url("/**/")',
    1.46 +   "not treated as comment");
    1.47 +
    1.48 +// Tests from Alfred Keyser's patch in bug 337287 (modified by dbaron)
    1.49 +div.style.listStyleImage = 'url("bad")';
    1.50 +div.style.listStyleImage = 'url(good /*bad comment*/)';
    1.51 +is(div.style.listStyleImage, 'url("bad")',
    1.52 +   "comment not allowed inside token");
    1.53 +
    1.54 +div.style.listStyleImage = 'url(good /*bad comments*/ /*Hello*/)';
    1.55 +is(div.style.listStyleImage, 'url("bad")',
    1.56 +   "comment not allowed inside token");
    1.57 +
    1.58 +div.style.listStyleImage = 'url(good/*commentaspartofurl*/)';
    1.59 +is(div.style.listStyleImage, 'url("good/*commentaspartofurl*/")',
    1.60 +   "comment-like syntax not comment inside of url");
    1.61 +
    1.62 +div.style.listStyleImage = 'url("bad")';
    1.63 +div.style.listStyleImage = 'url(good/**/ /*secondcommentcanbeskipped*/ )';
    1.64 +is(div.style.listStyleImage, 'url("bad")',
    1.65 +   "comment not allowed inside token");
    1.66 +
    1.67 +div.style.listStyleImage = 'url(/*partofurl*/good)';
    1.68 +is(div.style.listStyleImage, 'url("/*partofurl*/good")',
    1.69 +   "comment not parsed as part of url");
    1.70 +
    1.71 +div.style.listStyleImage = 'url(good';
    1.72 +is(div.style.listStyleImage, 'url("good")',
    1.73 +   "URL ending with eof not correctly handled");
    1.74 +
    1.75 +div.style.listStyleImage = 'url("bad")';
    1.76 +div.style.listStyleImage = 'url(good /*)*/';
    1.77 +is(div.style.listStyleImage, 'url("bad")',
    1.78 +   "comment not allowed inside token");
    1.79 +
    1.80 +div.style.listStyleImage = 'url("bad")';
    1.81 +div.style.listStyleImage = 'url(good /*)*/ tokenaftercommentevenwithclosebracketisinvalid';
    1.82 +is(div.style.listStyleImage, 'url("bad")',
    1.83 +   "comment not allowed inside token");
    1.84 +
    1.85 +div.style.listStyleImage = 'url(bad)';
    1.86 +div.style.listStyleImage = 'url("good"';
    1.87 +is(div.style.listStyleImage, 'url("good")',
    1.88 +   "URL as string without close bracket");
    1.89 +
    1.90 +div.style.listStyleImage = 'url(bad)';
    1.91 +div.style.listStyleImage = 'url("good';
    1.92 +is(div.style.listStyleImage, 'url("good")',
    1.93 +   "URL as string without closing quote");
    1.94 +
    1.95 +div.style.listStyleImage = 'url("bad")';
    1.96 +div.style.listStyleImage = 'url(good notgood';
    1.97 +is(div.style.listStyleImage, 'url("bad")',
    1.98 +   "second token should make url invalid");
    1.99 +
   1.100 +div.style.listStyleImage = 'url("bad")';
   1.101 +div.style.listStyleImage = 'url(good(notgood';
   1.102 +is(div.style.listStyleImage, 'url("bad")',
   1.103 +   "open bracket in url not recognized as invalid");
   1.104 +
   1.105 +var longurl = '';
   1.106 +for (i=0;i<1000;i++) {
   1.107 +    longurl = longurl + 'verylongurlindeed_thequickbrownfoxjumpsoverthelazydoq';
   1.108 +}
   1.109 +div.style.listStyleImage = 'url(' + longurl;
   1.110 +is(div.style.listStyleImage, 'url("' + longurl + '")',
   1.111 +   "very long url not correctly parsed");
   1.112 +
   1.113 +
   1.114 +// Additional tests from
   1.115 +// https://bugzilla.mozilla.org/show_bug.cgi?id=337287#c21
   1.116 +
   1.117 +div.style.listStyleImage = 'url(good/*)';
   1.118 +is(div.style.listStyleImage, 'url("good/*")',
   1.119 +   "URL containing comment start is valid");
   1.120 +
   1.121 +div.style.listStyleImage = 'url("bad")';
   1.122 +div.style.listStyleImage = 'url(good bad)';
   1.123 +is(div.style.listStyleImage, 'url("bad")',
   1.124 +   "unquoted URL with spaces not allowed");
   1.125 +
   1.126 +div.style.listStyleImage = 'url(\\g b)';
   1.127 +is(div.style.listStyleImage, 'url("bad")',
   1.128 +   "unquoted URL with spaces not allowed");
   1.129 +
   1.130 +div.style.listStyleImage = 'url( \\g b)';
   1.131 +is(div.style.listStyleImage, 'url("bad")',
   1.132 +   "unquoted URL with spaces not allowed");
   1.133 +
   1.134 +div.style.listStyleImage = 'url(c\\g b)';
   1.135 +is(div.style.listStyleImage, 'url("bad")',
   1.136 +   "unquoted URL with spaces not allowed");
   1.137 +
   1.138 +div.style.listStyleImage = 'url(cc\\g b)';
   1.139 +is(div.style.listStyleImage, 'url("bad")',
   1.140 +   "unquoted URL with spaces not allowed");
   1.141 +
   1.142 +div.style.listStyleImage = 'url(\\f  b)';
   1.143 +is(div.style.listStyleImage, 'url("bad")',
   1.144 +   "unquoted URL with spaces not allowed");
   1.145 +
   1.146 +div.style.listStyleImage = 'url( \\f  b)';
   1.147 +is(div.style.listStyleImage, 'url("bad")',
   1.148 +   "unquoted URL with spaces not allowed");
   1.149 +
   1.150 +div.style.listStyleImage = 'url(c\\f  b)';
   1.151 +is(div.style.listStyleImage, 'url("bad")',
   1.152 +   "unquoted URL with spaces not allowed");
   1.153 +
   1.154 +div.style.listStyleImage = 'url(cc\\f  b)';
   1.155 +is(div.style.listStyleImage, 'url("bad")',
   1.156 +   "unquoted URL with spaces not allowed");
   1.157 +
   1.158 +var chars = [ 1, 2, 3, 4, 5, 6, 7, 8, 11, 14, 15, 16, 17, 18, 19, 20,
   1.159 +              21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 127];
   1.160 +
   1.161 +for (var i in chars) {
   1.162 +  var charcode = chars[i];
   1.163 +  div.style.listStyleImage = 'url(' + String.fromCharCode(charcode) + ')';
   1.164 +  is(div.style.listStyleImage, 'url("bad")',
   1.165 +     "unquoted URL with control character " + charcode + " not allowed");
   1.166 +}
   1.167 +
   1.168 +div.style.listStyleImage = 'url(\u00ff)';
   1.169 +is(div.style.listStyleImage, 'url("\u00ff")', "U+A0-U+FF allowed in unquoted URL");
   1.170 +
   1.171 +div.style.listStyleImage = 'url(\\f good)';
   1.172 +is(div.style.listStyleImage, 'url("\\F good")', "URL allowed");
   1.173 +div.style.listStyleImage = 'url( \\f good)';
   1.174 +is(div.style.listStyleImage, 'url("\\F good")', "URL allowed");
   1.175 +div.style.listStyleImage = 'url(f\\f good)';
   1.176 +is(div.style.listStyleImage, 'url("f\\F good")', "URL allowed");
   1.177 +div.style.listStyleImage = 'url(go\\od)';
   1.178 +is(div.style.listStyleImage, 'url("good")', "URL allowed");
   1.179 +div.style.listStyleImage = 'url(goo\\d)';
   1.180 +is(div.style.listStyleImage, 'url("goo\\D ")', "URL allowed");
   1.181 +div.style.listStyleImage = 'url(go\\o)';
   1.182 +is(div.style.listStyleImage, 'url("goo")', "URL allowed");
   1.183 +
   1.184 +div.setAttribute("style", "color: url(/*); color: green");
   1.185 +is(div.style.color, 'green',
   1.186 +   "URL tokenized correctly outside properties taking URLs");
   1.187 +
   1.188 +div.style.listStyleImage = 'url("foo\\\nbar1")';
   1.189 +is(div.style.listStyleImage, 'url("foobar1")',
   1.190 +   "escaped newline allowed in string form of URL");
   1.191 +div.style.listStyleImage = 'url(foo\\\nbar2)';
   1.192 +is(div.style.listStyleImage, 'url("foobar1")',
   1.193 +   "escaped newline NOT allowed in NON-string form of URL");
   1.194 +
   1.195 +</script>
   1.196 +</pre>
   1.197 +</body>
   1.198 +</html>

mercurial