layout/style/test/test_parse_url.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <!--
michael@0 4 https://bugzilla.mozilla.org/show_bug.cgi?id=473914
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <title>Test for Bug 473914</title>
michael@0 8 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
michael@0 10 </head>
michael@0 11 <body>
michael@0 12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=473914">Mozilla Bug 473914</a>
michael@0 13 <p id="display"></p>
michael@0 14 <div id="content" style="display: none">
michael@0 15
michael@0 16 </div>
michael@0 17 <pre id="test">
michael@0 18 <script type="application/javascript">
michael@0 19
michael@0 20 /** Test for Bug 473914 **/
michael@0 21
michael@0 22 var div = document.getElementById("content");
michael@0 23
michael@0 24 // This test relies on normalization (insertion of quote marks) that
michael@0 25 // we're not really guaranteed to continue doing in the future.
michael@0 26 div.style.listStyleImage = 'url(http://example.org/**/)';
michael@0 27 is(div.style.listStyleImage, 'url("http://example.org/**/")',
michael@0 28 "not treated as comment");
michael@0 29 div.style.listStyleImage = 'url("http://example.org/**/")';
michael@0 30 is(div.style.listStyleImage, 'url("http://example.org/**/")',
michael@0 31 "not treated as comment");
michael@0 32 div.style.listStyleImage = 'url(/**/foo)';
michael@0 33 is(div.style.listStyleImage, 'url("/**/foo")',
michael@0 34 "not treated as comment");
michael@0 35 div.style.listStyleImage = 'url("/**/foo")';
michael@0 36 is(div.style.listStyleImage, 'url("/**/foo")',
michael@0 37 "not treated as comment");
michael@0 38 div.style.listStyleImage = 'url(/**/)';
michael@0 39 is(div.style.listStyleImage, 'url("/**/")',
michael@0 40 "not treated as comment");
michael@0 41 div.style.listStyleImage = 'url("/**/")';
michael@0 42 is(div.style.listStyleImage, 'url("/**/")',
michael@0 43 "not treated as comment");
michael@0 44
michael@0 45 // Tests from Alfred Keyser's patch in bug 337287 (modified by dbaron)
michael@0 46 div.style.listStyleImage = 'url("bad")';
michael@0 47 div.style.listStyleImage = 'url(good /*bad comment*/)';
michael@0 48 is(div.style.listStyleImage, 'url("bad")',
michael@0 49 "comment not allowed inside token");
michael@0 50
michael@0 51 div.style.listStyleImage = 'url(good /*bad comments*/ /*Hello*/)';
michael@0 52 is(div.style.listStyleImage, 'url("bad")',
michael@0 53 "comment not allowed inside token");
michael@0 54
michael@0 55 div.style.listStyleImage = 'url(good/*commentaspartofurl*/)';
michael@0 56 is(div.style.listStyleImage, 'url("good/*commentaspartofurl*/")',
michael@0 57 "comment-like syntax not comment inside of url");
michael@0 58
michael@0 59 div.style.listStyleImage = 'url("bad")';
michael@0 60 div.style.listStyleImage = 'url(good/**/ /*secondcommentcanbeskipped*/ )';
michael@0 61 is(div.style.listStyleImage, 'url("bad")',
michael@0 62 "comment not allowed inside token");
michael@0 63
michael@0 64 div.style.listStyleImage = 'url(/*partofurl*/good)';
michael@0 65 is(div.style.listStyleImage, 'url("/*partofurl*/good")',
michael@0 66 "comment not parsed as part of url");
michael@0 67
michael@0 68 div.style.listStyleImage = 'url(good';
michael@0 69 is(div.style.listStyleImage, 'url("good")',
michael@0 70 "URL ending with eof not correctly handled");
michael@0 71
michael@0 72 div.style.listStyleImage = 'url("bad")';
michael@0 73 div.style.listStyleImage = 'url(good /*)*/';
michael@0 74 is(div.style.listStyleImage, 'url("bad")',
michael@0 75 "comment not allowed inside token");
michael@0 76
michael@0 77 div.style.listStyleImage = 'url("bad")';
michael@0 78 div.style.listStyleImage = 'url(good /*)*/ tokenaftercommentevenwithclosebracketisinvalid';
michael@0 79 is(div.style.listStyleImage, 'url("bad")',
michael@0 80 "comment not allowed inside token");
michael@0 81
michael@0 82 div.style.listStyleImage = 'url(bad)';
michael@0 83 div.style.listStyleImage = 'url("good"';
michael@0 84 is(div.style.listStyleImage, 'url("good")',
michael@0 85 "URL as string without close bracket");
michael@0 86
michael@0 87 div.style.listStyleImage = 'url(bad)';
michael@0 88 div.style.listStyleImage = 'url("good';
michael@0 89 is(div.style.listStyleImage, 'url("good")',
michael@0 90 "URL as string without closing quote");
michael@0 91
michael@0 92 div.style.listStyleImage = 'url("bad")';
michael@0 93 div.style.listStyleImage = 'url(good notgood';
michael@0 94 is(div.style.listStyleImage, 'url("bad")',
michael@0 95 "second token should make url invalid");
michael@0 96
michael@0 97 div.style.listStyleImage = 'url("bad")';
michael@0 98 div.style.listStyleImage = 'url(good(notgood';
michael@0 99 is(div.style.listStyleImage, 'url("bad")',
michael@0 100 "open bracket in url not recognized as invalid");
michael@0 101
michael@0 102 var longurl = '';
michael@0 103 for (i=0;i<1000;i++) {
michael@0 104 longurl = longurl + 'verylongurlindeed_thequickbrownfoxjumpsoverthelazydoq';
michael@0 105 }
michael@0 106 div.style.listStyleImage = 'url(' + longurl;
michael@0 107 is(div.style.listStyleImage, 'url("' + longurl + '")',
michael@0 108 "very long url not correctly parsed");
michael@0 109
michael@0 110
michael@0 111 // Additional tests from
michael@0 112 // https://bugzilla.mozilla.org/show_bug.cgi?id=337287#c21
michael@0 113
michael@0 114 div.style.listStyleImage = 'url(good/*)';
michael@0 115 is(div.style.listStyleImage, 'url("good/*")',
michael@0 116 "URL containing comment start is valid");
michael@0 117
michael@0 118 div.style.listStyleImage = 'url("bad")';
michael@0 119 div.style.listStyleImage = 'url(good bad)';
michael@0 120 is(div.style.listStyleImage, 'url("bad")',
michael@0 121 "unquoted URL with spaces not allowed");
michael@0 122
michael@0 123 div.style.listStyleImage = 'url(\\g b)';
michael@0 124 is(div.style.listStyleImage, 'url("bad")',
michael@0 125 "unquoted URL with spaces not allowed");
michael@0 126
michael@0 127 div.style.listStyleImage = 'url( \\g b)';
michael@0 128 is(div.style.listStyleImage, 'url("bad")',
michael@0 129 "unquoted URL with spaces not allowed");
michael@0 130
michael@0 131 div.style.listStyleImage = 'url(c\\g b)';
michael@0 132 is(div.style.listStyleImage, 'url("bad")',
michael@0 133 "unquoted URL with spaces not allowed");
michael@0 134
michael@0 135 div.style.listStyleImage = 'url(cc\\g b)';
michael@0 136 is(div.style.listStyleImage, 'url("bad")',
michael@0 137 "unquoted URL with spaces not allowed");
michael@0 138
michael@0 139 div.style.listStyleImage = 'url(\\f b)';
michael@0 140 is(div.style.listStyleImage, 'url("bad")',
michael@0 141 "unquoted URL with spaces not allowed");
michael@0 142
michael@0 143 div.style.listStyleImage = 'url( \\f b)';
michael@0 144 is(div.style.listStyleImage, 'url("bad")',
michael@0 145 "unquoted URL with spaces not allowed");
michael@0 146
michael@0 147 div.style.listStyleImage = 'url(c\\f b)';
michael@0 148 is(div.style.listStyleImage, 'url("bad")',
michael@0 149 "unquoted URL with spaces not allowed");
michael@0 150
michael@0 151 div.style.listStyleImage = 'url(cc\\f b)';
michael@0 152 is(div.style.listStyleImage, 'url("bad")',
michael@0 153 "unquoted URL with spaces not allowed");
michael@0 154
michael@0 155 var chars = [ 1, 2, 3, 4, 5, 6, 7, 8, 11, 14, 15, 16, 17, 18, 19, 20,
michael@0 156 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 127];
michael@0 157
michael@0 158 for (var i in chars) {
michael@0 159 var charcode = chars[i];
michael@0 160 div.style.listStyleImage = 'url(' + String.fromCharCode(charcode) + ')';
michael@0 161 is(div.style.listStyleImage, 'url("bad")',
michael@0 162 "unquoted URL with control character " + charcode + " not allowed");
michael@0 163 }
michael@0 164
michael@0 165 div.style.listStyleImage = 'url(\u00ff)';
michael@0 166 is(div.style.listStyleImage, 'url("\u00ff")', "U+A0-U+FF allowed in unquoted URL");
michael@0 167
michael@0 168 div.style.listStyleImage = 'url(\\f good)';
michael@0 169 is(div.style.listStyleImage, 'url("\\F good")', "URL allowed");
michael@0 170 div.style.listStyleImage = 'url( \\f good)';
michael@0 171 is(div.style.listStyleImage, 'url("\\F good")', "URL allowed");
michael@0 172 div.style.listStyleImage = 'url(f\\f good)';
michael@0 173 is(div.style.listStyleImage, 'url("f\\F good")', "URL allowed");
michael@0 174 div.style.listStyleImage = 'url(go\\od)';
michael@0 175 is(div.style.listStyleImage, 'url("good")', "URL allowed");
michael@0 176 div.style.listStyleImage = 'url(goo\\d)';
michael@0 177 is(div.style.listStyleImage, 'url("goo\\D ")', "URL allowed");
michael@0 178 div.style.listStyleImage = 'url(go\\o)';
michael@0 179 is(div.style.listStyleImage, 'url("goo")', "URL allowed");
michael@0 180
michael@0 181 div.setAttribute("style", "color: url(/*); color: green");
michael@0 182 is(div.style.color, 'green',
michael@0 183 "URL tokenized correctly outside properties taking URLs");
michael@0 184
michael@0 185 div.style.listStyleImage = 'url("foo\\\nbar1")';
michael@0 186 is(div.style.listStyleImage, 'url("foobar1")',
michael@0 187 "escaped newline allowed in string form of URL");
michael@0 188 div.style.listStyleImage = 'url(foo\\\nbar2)';
michael@0 189 is(div.style.listStyleImage, 'url("foobar1")',
michael@0 190 "escaped newline NOT allowed in NON-string form of URL");
michael@0 191
michael@0 192 </script>
michael@0 193 </pre>
michael@0 194 </body>
michael@0 195 </html>

mercurial