LEFT | RIGHT |
1 // Copyright (C) 2008 Google Inc. | 1 // Copyright (C) 2008 Google Inc. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 TestHttpServletResponse resp = new TestHttpServletResponse(); | 103 TestHttpServletResponse resp = new TestHttpServletResponse(); |
104 service.doGet(req, resp); | 104 service.doGet(req, resp); |
105 return resp.getOutputObject(); | 105 return resp.getOutputObject(); |
106 } | 106 } |
107 | 107 |
108 public void testSimpleJs() throws Exception { | 108 public void testSimpleJs() throws Exception { |
109 registerUri("http://foo/bar.js", "g(1);", "text/javascript"); | 109 registerUri("http://foo/bar.js", "g(1);", "text/javascript"); |
110 assertEquals( | 110 assertEquals( |
111 valijaModule("moduleResult___ = $v.cf($v.ro('g'), [ 1 ]);"), | 111 valijaModule("moduleResult___ = $v.cf($v.ro('g'), [ 1 ]);"), |
112 request("?url=http://foo/bar.js&mime-type=text/javascript" + | 112 request("?url=http://foo/bar.js&mime-type=text/javascript" + |
113 "&transform=VALIJA")); | 113 "&transform=VALIJA")); |
114 } | 114 } |
115 | 115 |
116 public void testInnocentJs() throws Exception { | 116 public void testInnocentJs() throws Exception { |
117 registerUri("http://foo/innocent.js", "for (var k in x) { k; }", | 117 registerUri("http://foo/innocent.js", "for (var k in x) { k; }", |
118 "text/javascript"); | 118 "text/javascript"); |
119 assertEquals("{\n" + | 119 assertEquals("{\n" + |
120 " var x0___;\n" + | 120 " var x0___;\n" + |
121 " for (x0___ in x) {\n" + | 121 " for (x0___ in x) {\n" + |
122 " if (x0___.match(/___$/)) { continue; }\n" + | 122 " if (x0___.match(/___$/)) { continue; }\n" + |
123 " k = x0___;\n" + | 123 " k = x0___;\n" + |
(...skipping 29 matching lines...) Expand all Loading... |
153 (byte[]) request("?url=http://foo/bar.gif&mime-type=image/*"), | 153 (byte[]) request("?url=http://foo/bar.gif&mime-type=image/*"), |
154 byteData)); | 154 byteData)); |
155 } | 155 } |
156 | 156 |
157 public void testNotImage() throws Exception { | 157 public void testNotImage() throws Exception { |
158 registerUri("http://foo/bar.gif", "foo()", "text/javascript"); | 158 registerUri("http://foo/bar.gif", "foo()", "text/javascript"); |
159 assertEquals("ERROR", request("?url=http://foo/bar.gif&mime-type=image/*")); | 159 assertEquals("ERROR", request("?url=http://foo/bar.gif&mime-type=image/*")); |
160 } | 160 } |
161 | 161 |
162 public void testHtml() throws Exception { | 162 public void testHtml() throws Exception { |
163 String indent = " "; | |
164 String htmlEnvelope = ( | 163 String htmlEnvelope = ( |
165 "<html>" + | 164 "<html>" + |
166 " <head><title>Caja Test</title></head>" + | 165 "<head><title>Caja Test</title></head>" + |
167 " <body>" + | 166 "<body>" + |
168 " %s" + | 167 "%s" + |
169 " </body>" + | 168 "</body>" + |
170 "</html>"); | 169 "</html>"); |
171 | 170 |
172 registerUri("http://foo/bar.js", "foo()", "text/javascript"); | 171 registerUri("http://foo/bar.js", "foo()", "text/javascript"); |
173 registerUri("http://foo/bar.html", | 172 registerUri("http://foo/bar.html", |
174 String.format( | 173 String.format( |
175 htmlEnvelope, | 174 htmlEnvelope, |
176 "<p>Hello, World!</p><script src=bar.js></script>"), | 175 "<p>Hello, World!</p><script src=bar.js></script>"), |
177 "text/html"); | 176 "text/html"); |
178 assertMessagesLessSevereThan(MessageLevel.WARNING); | 177 assertMessagesLessSevereThan(MessageLevel.WARNING); |
179 assertEquals( | 178 assertEquals( |
180 "<p>Hello, World</p><script type=\"text/javascript\">{\n" | 179 "<p>Hello, World!</p><script type=\"text/javascript\">{" |
181 + " ___.loadModule({\n" | 180 + "___.loadModule({" |
182 + indent + " 'instantiate': function (___, IMPORTS___) {\n" | 181 + "'instantiate':function(___,IMPORTS___){" |
183 + indent + " var moduleResult___ = ___.NO_RESULT;\n" | 182 + "var moduleResult___=___.NO_RESULT;" |
184 + indent + " var $v = ___.readImport(IMPORTS___, '$v', {\n" | 183 + "var\n$v=___.readImport(IMPORTS___,'$v',{" |
185 + indent + " 'getOuters': {\n" | 184 + "'getOuters':{'()':{}}," |
186 + indent + " '()': { }\n" | 185 + "'initOuter':{'()':{}}," |
187 + indent + " },\n" | 186 + "'cf':{'()':{}}," |
188 + indent + " 'initOuter': {\n" | 187 + "'ro':{'()':{}}" |
189 + indent + " '()': { }\n" | 188 + "});" |
190 + indent + " }\n" | 189 + "var\n$dis=$v.getOuters();" |
191 + indent + " });\n" | 190 + "$v.initOuter('onerror');" |
192 + indent + " var $dis = $v.getOuters();\n" | 191 + "try{" |
193 + indent + " $v.initOuter('onerror');\n" | 192 + "{moduleResult___=$v.cf($v.ro('foo'),[]);}" |
194 + indent + " moduleResult___ = $v.co('foo', []);\n" | 193 + "}catch(ex___){" |
195 + indent + " return moduleResult___;\n" | 194 + "___.getNewModuleHandler().handleUncaughtException(" |
196 + indent + " },\n" | 195 + "ex___,$v.ro('onerror'),'bar.js','1');" |
197 + indent + " 'cajolerName': 'com.google.caja',\n" | 196 + "}" |
198 + indent + " 'cajolerVersion': 'testBuildVersion',\n" | 197 + "return moduleResult___;" |
199 + indent + " 'cajoledDate': 0\n" | 198 + "}," |
200 + indent + "});\n" | 199 + "'cajolerName':'com.google.caja'," |
| 200 + "'cajolerVersion':'testBuildVersion'," |
| 201 + "'cajoledDate':0" |
| 202 + "});" |
201 + "}</script>", | 203 + "}</script>", |
202 (String) request("?url=http://foo/bar.html&mime-type=*/*")); | 204 (String) request("?url=http://foo/bar.html&mime-type=*/*")); |
203 } | 205 } |
204 | 206 |
205 public void testGadget() throws Exception { | 207 public void testGadget() throws Exception { |
206 String moduleEnvelope = ( | 208 String moduleEnvelope = ( |
207 "<Module><ModulePrefs /><Content type=\"html\">" | 209 "<Module><ModulePrefs /><Content type=\"html\">" |
208 + "<![CDATA[%s]]>" | 210 + "<![CDATA[%s]]>" |
209 + "</Content></Module>"); | 211 + "</Content></Module>"); |
210 | 212 |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 return new String(bytes, enc); | 488 return new String(bytes, enc); |
487 } catch (UnsupportedEncodingException ex) { | 489 } catch (UnsupportedEncodingException ex) { |
488 throw new RuntimeException(ex); | 490 throw new RuntimeException(ex); |
489 } | 491 } |
490 } | 492 } |
491 return bytes; | 493 return bytes; |
492 } | 494 } |
493 return ((StringWriter) output).toString(); | 495 return ((StringWriter) output).toString(); |
494 } | 496 } |
495 } | 497 } |
LEFT | RIGHT |