Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(93)

Side by Side Diff: chrome/browser/resources/shared/js/parse_html_subset_test.html

Issue 11962043: Move webui resources from chrome\browser\resources\shared to ui\webui\resources. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <title>parseHtmlSubset test</title>
5 <script src="http://closure-library.googlecode.com/svn/trunk/closure/goog/base.j s"></script>
6 <script src="parse_html_subset.js"></script>
7 <script>
8
9 goog.require('goog.testing.jsunit');
10
11 </script>
12
13 </head>
14 <body>
15 <script>
16
17 function parseAndAssertThrows() {
18 var args = arguments;
19 assertThrows(function() {
20 parseHtmlSubset.apply(null, args);
21 });
22 }
23
24 function parseAndAssertNotThrows() {
25 var args = arguments;
26 assertNotThrows(function() {
27 parseHtmlSubset.apply(null, args);
28 });
29 }
30
31 function testText() {
32 parseAndAssertNotThrows('');
33 parseAndAssertNotThrows('abc');
34 parseAndAssertNotThrows('&nbsp;');
35 }
36
37 function testSupportedTags() {
38 parseAndAssertNotThrows('<b>bold</b>');
39 parseAndAssertNotThrows('Some <b>bold</b> text');
40 parseAndAssertNotThrows('Some <strong>strong</strong> text');
41 parseAndAssertNotThrows('<B>bold</B>');
42 parseAndAssertNotThrows('Some <B>bold</B> text');
43 parseAndAssertNotThrows('Some <STRONG>strong</STRONG> text');
44 }
45
46 function testInvalidTags() {
47 parseAndAssertThrows('<unknown_tag>x</unknown_tag>');
48 parseAndAssertThrows('<img>');
49 parseAndAssertThrows('<script>alert(1)<' + '/script>');
50 }
51
52 function testInvalidAttributes() {
53 parseAndAssertThrows('<b onclick="alert(1)">x</b>');
54 parseAndAssertThrows('<b style="color:red">x</b>');
55 parseAndAssertThrows('<b foo>x</b>');
56 parseAndAssertThrows('<b foo=bar></b>');
57 }
58
59 function testValidAnchors() {
60 parseAndAssertNotThrows('<a href="https://google.com">Google</a>');
61 parseAndAssertNotThrows('<a href="chrome://settings">Google</a>');
62 }
63
64 function testInvalidAnchorHrefs() {
65 parseAndAssertThrows('<a href="http://google.com">Google</a>');
66 parseAndAssertThrows('<a href="ftp://google.com">Google</a>');
67 parseAndAssertThrows('<a href="http/google.com">Google</a>');
68 parseAndAssertThrows('<a href="javascript:alert(1)">Google</a>');
69 parseAndAssertThrows('<a href="chrome-extension://whurblegarble">Google</a>');
70 }
71
72 function testInvalidAnchorAttributes() {
73 parseAndAssertThrows('<a name=foo>Google</a>');
74 parseAndAssertThrows(
75 '<a onclick="alert(1)" href="https://google.com">Google</a>');
76 parseAndAssertThrows('<a foo="bar(1)" href="https://google.com">Google</a>');
77 }
78
79 function testAnchorTarget() {
80 parseAndAssertNotThrows(
81 '<a href="https://google.com" target="blank_">Google</a>');
82 parseAndAssertNotThrows(
83 '<a href="https://google.com" target="foo">Google</a>');
84 }
85
86 function testCustomTags() {
87 parseAndAssertNotThrows('yo <I>ho</i><bR>yo <EM>ho</em>', ['i', 'EM', 'Br']);
88 }
89
90 function testInvalidCustomTags() {
91 parseAndAssertThrows("a pirate's<script>lifeForMe();<" + '/script>', ['br']);
92 }
93
94 function testCustomAttributes() {
95 function returnsTruthy(node, value) {
96 assertEquals('A', node.tagName);
97 assertEquals('fancy', value);
98 return true;
99 }
100 parseAndAssertNotThrows('<a class="fancy">I\'m fancy!</a>', null,
101 {class: returnsTruthy});
102 }
103
104 function testInvalidCustomAttributes() {
105 function returnsFalsey() {
106 return false;
107 }
108 parseAndAssertThrows('<a class="fancy">I\'m fancy!</a>', null,
109 {class: returnsFalsey});
110 parseAndAssertThrows('<a class="fancy">I\'m fancy!</a>');
111 }
112
113 </script>
114
115 </body>
116 </html>
OLDNEW
« no previous file with comments | « chrome/browser/resources/shared/js/parse_html_subset.js ('k') | chrome/browser/resources/shared/js/util.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698