- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / test / data / webui / parse_html_subset_test.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <title>parseHtmlSubset test</title>
5 </head>
6 <body>
7 <script>
8
9 function parseAndAssertThrows() {
10   var args = arguments;
11   assertThrows(function() {
12     parseHtmlSubset.apply(null, args);
13   });
14 }
15
16 function parseAndAssertNotThrows() {
17   var args = arguments;
18   parseHtmlSubset.apply(null, args);
19 }
20
21 function testText() {
22   parseAndAssertNotThrows('');
23   parseAndAssertNotThrows('abc');
24   parseAndAssertNotThrows('&nbsp;');
25 }
26
27 function testSupportedTags() {
28   parseAndAssertNotThrows('<b>bold</b>');
29   parseAndAssertNotThrows('Some <b>bold</b> text');
30   parseAndAssertNotThrows('Some <strong>strong</strong> text');
31   parseAndAssertNotThrows('<B>bold</B>');
32   parseAndAssertNotThrows('Some <B>bold</B> text');
33   parseAndAssertNotThrows('Some <STRONG>strong</STRONG> text');
34 }
35
36 function testInvalidTags() {
37   parseAndAssertThrows('<unknown_tag>x</unknown_tag>');
38   parseAndAssertThrows('<img>');
39   parseAndAssertThrows('<script>alert(1)<' + '/script>');
40 }
41
42 function testInvalidAttributes() {
43   parseAndAssertThrows('<b onclick="alert(1)">x</b>');
44   parseAndAssertThrows('<b style="color:red">x</b>');
45   parseAndAssertThrows('<b foo>x</b>');
46   parseAndAssertThrows('<b foo=bar></b>');
47 }
48
49 function testValidAnchors() {
50   parseAndAssertNotThrows('<a href="https://google.com">Google</a>');
51   parseAndAssertNotThrows('<a href="chrome://settings">Google</a>');
52 }
53
54 function testInvalidAnchorHrefs() {
55   parseAndAssertThrows('<a href="http://google.com">Google</a>');
56   parseAndAssertThrows('<a href="ftp://google.com">Google</a>');
57   parseAndAssertThrows('<a href="http/google.com">Google</a>');
58   parseAndAssertThrows('<a href="javascript:alert(1)">Google</a>');
59   parseAndAssertThrows('<a href="chrome-extension://whurblegarble">Google</a>');
60 }
61
62 function testInvalidAnchorAttributes() {
63   parseAndAssertThrows('<a name=foo>Google</a>');
64   parseAndAssertThrows(
65       '<a onclick="alert(1)" href="https://google.com">Google</a>');
66   parseAndAssertThrows('<a foo="bar(1)" href="https://google.com">Google</a>');
67 }
68
69 function testAnchorTarget() {
70   parseAndAssertNotThrows(
71       '<a href="https://google.com" target="_blank">Google</a>');
72   parseAndAssertNotThrows(
73       '<a href="https://google.com" target="foo">Google</a>');
74 }
75
76 function testCustomTags() {
77   parseAndAssertNotThrows('yo <I>ho</i><bR>yo <EM>ho</em>', ['i', 'EM', 'Br']);
78 }
79
80 function testInvalidCustomTags() {
81   parseAndAssertThrows("a pirate's<script>lifeForMe();<" + '/script>', ['br']);
82 }
83
84 function testCustomAttributes() {
85   function returnsTruthy(node, value) {
86     assertEquals('A', node.tagName);
87     assertEquals('fancy', value);
88     return true;
89   }
90   parseAndAssertNotThrows('<a class="fancy">I\'m fancy!</a>', null,
91       {class: returnsTruthy});
92 }
93
94 function testInvalidCustomAttributes() {
95   function returnsFalsey() {
96     return false;
97   }
98   parseAndAssertThrows('<a class="fancy">I\'m fancy!</a>', null,
99       {class: returnsFalsey});
100   parseAndAssertThrows('<a class="fancy">I\'m fancy!</a>');
101 }
102
103 function testOnErrorAsync(testDoneCalback) {
104   window.called = false;
105
106   parseAndAssertThrows('<img onerror="window.called = true" src="_.png">');
107   parseAndAssertThrows('<img src="_.png" onerror="window.called = true">');
108
109   window.setTimeout(function() {
110     assertFalse(window.called);
111     testDoneCalback();
112   });
113 }
114
115 </script>
116
117 </body>
118 </html>