4 <title>parseHtmlSubset test
</title>
9 function parseAndAssertThrows() {
11 assertThrows(function() {
12 parseHtmlSubset
.apply(null, args
);
16 function parseAndAssertNotThrows() {
18 parseHtmlSubset
.apply(null, args
);
22 parseAndAssertNotThrows('');
23 parseAndAssertNotThrows('abc');
24 parseAndAssertNotThrows(' ');
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');
36 function testInvalidTags() {
37 parseAndAssertThrows('<unknown_tag>x</unknown_tag>');
38 parseAndAssertThrows('<img>');
39 parseAndAssertThrows('<script>alert(1)<' + '/script>');
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>');
49 function testValidAnchors() {
50 parseAndAssertNotThrows('<a href="https://google.com">Google</a>');
51 parseAndAssertNotThrows('<a href="chrome://settings">Google</a>');
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>');
62 function testInvalidAnchorAttributes() {
63 parseAndAssertThrows('<a name=foo>Google</a>');
65 '<a onclick="alert(1)" href="https://google.com">Google</a>');
66 parseAndAssertThrows('<a foo="bar(1)" href="https://google.com">Google</a>');
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>');
76 function testCustomTags() {
77 parseAndAssertNotThrows('yo <I>ho</i><bR>yo <EM>ho</em>', ['i', 'EM', 'Br']);
80 function testInvalidCustomTags() {
81 parseAndAssertThrows("a pirate's<script>lifeForMe();<" + '/script>', ['br']);
84 function testCustomAttributes() {
85 function returnsTruthy(node
, value
) {
86 assertEquals('A', node
.tagName
);
87 assertEquals('fancy', value
);
90 parseAndAssertNotThrows('<a class="fancy">I\'m fancy!</a>', null,
91 {class: returnsTruthy
});
94 function testInvalidCustomAttributes() {
95 function returnsFalsey() {
98 parseAndAssertThrows('<a class="fancy">I\'m fancy!</a>', null,
99 {class: returnsFalsey
});
100 parseAndAssertThrows('<a class="fancy">I\'m fancy!</a>');
103 function testOnErrorAsync(testDoneCalback
) {
104 window
.called
= false;
106 parseAndAssertThrows('<img onerror="window.called = true" src="_.png">');
107 parseAndAssertThrows('<img src="_.png" onerror="window.called = true">');
109 window
.setTimeout(function() {
110 assertFalse(window
.called
);