WebCore:
[WebKit-https.git] / LayoutTests / fast / innerHTML / javascript-url.html
1 <head>
2 <script>
3 if (window.layoutTestController)
4     layoutTestController.dumpAsText();
5     
6 function print(message, color) 
7 {
8     var paragraph = document.createElement("div");
9     paragraph.appendChild(document.createTextNode(message));
10     paragraph.style.fontFamily = "monospace";
11     if (color)
12         paragraph.style.color = color;
13     document.getElementById("console").appendChild(paragraph);
14 }
15
16 function run(a)
17 {
18     print(a);
19     try {
20         eval(a);
21     } catch(e) {
22         print(e);
23     }
24 }
25
26 function shouldBe(a, b)
27 {
28     var evalA;
29     try {
30         evalA = eval(a);
31     } catch(e) {
32         evalA = e;
33     }
34     
35     if (evalA == b)
36         print("PASS: " + a + " should be " + b + " and is.", "green");
37     else
38         print("FAIL: " + a + " should be " + b + " but instead is " + evalA + ".", "red");
39 }
40 </script>
41 </head>
42 <body>
43 Test that innerHTML does not mangle javascript: urls.
44 <div id=console></div>
45 <div id=jsurltest><a href='
46  javascript:test(&37;3C!--D--&37;3E)'>link</a></div>
47 <script>
48 var r = document.getElementById('jsurltest');
49 run("r.innerHTML = r.innerHTML.replace(/&37;3C!--D--&37;3E/g, 123)");
50 shouldBe("r.innerHTML.indexOf('javascript:test(123)') > -1", true);
51 run("r.firstChild.setAttribute('href', 'javascript:test(\"text<\")')");
52 shouldBe("r.innerHTML.indexOf('javascript:test(\"text<\")') > -1", true);
53 run('r.firstChild.setAttribute("href", "javascript:test(\'text>\')")');
54 shouldBe('r.innerHTML.indexOf("javascript:test(\'text>\')") > -1', true);
55 testString = 'javascript:test(\'text&\',"test2&")';
56 print("testString = " + testString);
57 run('r.firstChild.setAttribute("href", testString)');
58 shouldBe('r.innerHTML.indexOf("javascript:test(\'text&\',&quot;test2&&quot;)") > 1', true);
59
60 run("r.firstChild.setAttribute('href', 'http://www.google.fi/search?q=scarlett johansson&meta=&btnG=Google-haku')");
61 print(r.innerHTML);
62 </script>