001: /*
002: * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */
005: package com.sun.portal.rewriter.engines.js.test;
006:
007: import com.sun.portal.rewriter.Rewriter;
008: import com.sun.portal.rewriter.RewriterModule;
009: import com.sun.portal.rewriter.RewriterPool;
010: import com.sun.portal.rewriter.engines.LanguageConstants;
011: import com.sun.portal.rewriter.rom.RuleSet;
012: import com.sun.portal.rewriter.test.util.BasicTestCase;
013: import com.sun.portal.rewriter.test.util.CreateRuleSet;
014: import com.sun.portal.rewriter.test.util.JSWrapperHelper;
015: import junit.framework.TestSuite;
016:
017: public class TestJSDJSFunctions extends BasicTestCase {
018: public TestJSDJSFunctions(String aName) {
019: super (aName);
020: }//constuctor
021:
022: public void testSimpleDJSFunctions() throws Exception {
023: String lInput = "abc.write(\"var imgsrc = '/tmp/tmp.jpt';\")";
024: String lExpectation = "abc.write(\"var imgsrc = 'http://rajanagendra.sun.com/tmp/tmp.jpt';\")";
025:
026: String lVariablesRules = "<Variable name=\"imgsrc\" type=\"URL\"/>";
027: String lFunctionRules = "<Function type=\"DJS\" name=\"abc.write\" paramPatterns=\"y\"/>";
028:
029: RuleSet lRuleSet = CreateRuleSet.withHTMLAttJSVarJSFunRules("",
030: lVariablesRules, lFunctionRules);
031: Rewriter lRewriter = RewriterPool.create(lRuleSet,
032: LanguageConstants.JS_MIME);
033: String lResult = lRewriter.rewrite(lInput,
034: getDefaultTranslator());
035: assertEquals(lExpectation, lResult);
036: }//testSimpleDJSFunctions()
037:
038: public void testSimpleDJSFunctions1() throws Exception {
039: String lInput = "eval('location');" + "eval('http://abc.com');"
040: + "eval('index.html');" + "eval('./index.html');"
041: + "eval('/index.html');";
042:
043: String lExpectation = "eval('location');"
044: + "eval('http://abc.com');"
045: + "eval('index.html');"
046: + //Need to Fix
047: //"eval('http://rajanagendra.sun.com/Base/Raja/index.html');" +
048: "eval('http://rajanagendra.sun.com/Base/Raja/index.html');"
049: + "eval('http://rajanagendra.sun.com/index.html');";
050:
051: String lFunctionRules = "<Function type=\"DJS\" name=\"eval\" paramPatterns=\"y\"/>";
052:
053: RuleSet lRuleSet = CreateRuleSet
054: .withJSFunctionRules(lFunctionRules);
055: Rewriter lRewriter = RewriterPool.create(lRuleSet,
056: LanguageConstants.JS_MIME);
057: String lResult = lRewriter.rewrite(lInput,
058: getDefaultTranslator());
059: assertEquals(lExpectation, lResult);
060: }//testSimpleDJSFunctions1()
061:
062: public void testRecusiveDJSFunctions1() throws Exception {
063: String lInput = "abc.write(abc.write(\"var imgsrc = '/tmp/tmp.jpt';\"))";
064: String lExpectation = "abc.write(abc.write(\"var imgsrc = 'http://rajanagendra.sun.com/tmp/tmp.jpt';\"))";
065:
066: String lVariablesRules = "<Variable name=\"imgsrc\" type=\"URL\"/>";
067: String lFunctionRules = "<Function type=\"DJS\" name=\"abc.write\" paramPatterns=\"y\"/>";
068:
069: RuleSet lRuleSet = CreateRuleSet.withHTMLAttJSVarJSFunRules("",
070: lVariablesRules, lFunctionRules);
071: Rewriter lRewriter = RewriterPool.create(lRuleSet,
072: LanguageConstants.JS_MIME);
073: String lResult = lRewriter.rewrite(lInput,
074: getDefaultTranslator());
075: assertEquals(lExpectation, lResult);
076: }//testRecusiveDJSFunctions1()
077:
078: public void testDJSParamExpressionRules() throws Exception {
079: String lInput = "abc.write(\"djsVar = 'var imgsrc = '/tmp/tmp.jpt';'\")";
080: String lExpectation = "abc.write(\"http://rajanagendra.sun.com/Base/Raja/djsVar = 'var imgsrc = '/tmp/tmp.jpt';'\")";
081: //lInput;
082: //"abc.write(" + LanguageConstants.CONVERT_EXPRESSION_FUNCTION_WRAP_START + "\"djsVar = 'var imgsrc = '/tmp/tmp.jpt';'\"))" + TestHTMLJSTokens.CONVERT_EXPRESSION_FUNCTION_JS;
083:
084: String lVariablesRules = "<Variable name=\"imgsrc\" type=\"URL\"/>";
085: String lFunctionRules = "<Function type=\"EXPRESSION\" name=\"abc.write\" paramPatterns=\"y\"/>";
086: RuleSet lRuleSet = CreateRuleSet.withHTMLAttJSVarJSFunRules("",
087: lVariablesRules, lFunctionRules);
088: Rewriter lRewriter = RewriterPool.create(lRuleSet,
089: LanguageConstants.JS_MIME);
090: String lResult = lRewriter.rewrite(lInput,
091: getDefaultJSTranslator());
092: assertEquals(lExpectation, lResult);
093: }//testDJSParamExpressionRules()
094:
095: public void testWrongJSFunctions2() throws Exception {
096: String lInput = "abc.write(\"djsVar = 'var imgsrc = \"/tmp/tmp.jpt\";'\")";
097: String lExpectation = lInput;
098:
099: String lVariablesRules = "<Variable name=\"djsVar\" type=\"DJS\"/>"
100: + " <Variable name=\"imgsrc\" type=\"URL\"/>";
101: String lFunctionRules = "<Function type=\"DJS\" name=\"abc.write\" paramPatterns=\"y\"/>";
102:
103: RuleSet lRuleSet = CreateRuleSet.withHTMLAttJSVarJSFunRules("",
104: lVariablesRules, lFunctionRules);
105: Rewriter lRewriter = RewriterPool.create(lRuleSet,
106: LanguageConstants.JS_MIME);
107: String lResult = lRewriter.rewrite(lInput,
108: getDefaultTranslator());
109: assertEquals(lExpectation, lResult);
110: }//testWrongDJSFunctions2()
111:
112: public void testBug4641833() throws Exception {
113: String lInput = "menu.addItem(new NavBarMenuItem(\"All Available Information\",\"JavaScript:top.location='/DisplayMarketPortalServlet?portalid=1'\"));"
114: + "menu.addItem(new NavBarMenuItem(\"All Available Information\",\"/DisplayMarketPortalServlet?portalid=4\"));";
115:
116: String lExpectation = "menu.addItem(new NavBarMenuItem(\"All Available Information\",\"JavaScript:top.location='http://rajanagendra.sun.com/DisplayMarketPortalServlet?portalid=1'\"));"
117: + "menu.addItem(new NavBarMenuItem(\"All Available Information\",\"http://rajanagendra.sun.com/DisplayMarketPortalServlet?portalid=4\"));";
118:
119: String lVariablesRules = "<Variable name=\"top.location\" type=\"URL\"/>";
120: String lFunctionRules = "<Function type=\"DJS\" name=\"NavBarMenuItem\" paramPatterns=\",y\"/>";
121:
122: RuleSet lRuleSet = CreateRuleSet.withHTMLAttJSVarJSFunRules("",
123: lVariablesRules, lFunctionRules);
124: Rewriter lRewriter = RewriterPool.create(lRuleSet,
125: LanguageConstants.JS_MIME);
126: String lResult = lRewriter.rewrite(lInput,
127: getDefaultTranslator());
128: assertEquals(lExpectation, lResult);
129: }//testBug4641833()
130:
131: public void testBug4641833Varient1() throws Exception {
132: String lInput = "menu.addItem(new NavBarMenuItem(\"All Available Information\",\"JavaScript:top.location='/DisplayMarketPortalServlet?portalid=1'\"));"
133: + "menu.addItem(new NavBarMenuItem(\"All Available Information\",\"/DisplayMarketPortalServlet\"));";
134:
135: String lExpectation = "menu.addItem(new NavBarMenuItem(\"All Available Information\",\"JavaScript:top.location='http://rajanagendra.sun.com/DisplayMarketPortalServlet?portalid=1'\"));"
136: + "menu.addItem(new NavBarMenuItem(\"All Available Information\",\"http://rajanagendra.sun.com/DisplayMarketPortalServlet\"));";
137:
138: String lVariablesRules = "<Variable name=\"top.location\" source=\"*rajanagendra.sun.com*\" type=\"URL\"/>";
139: String lFunctionRules = "<Function source=\"http://rajanagendra.sun.com/Base/Raja/raja.html\" type=\"DJS\" name=\"NavBarMenuItem\" paramPatterns=\",y\"/>";
140:
141: RuleSet lRuleSet = CreateRuleSet.withHTMLAttJSVarJSFunRules("",
142: lVariablesRules, lFunctionRules);
143: Rewriter lRewriter = RewriterPool.create(lRuleSet,
144: LanguageConstants.JS_MIME);
145: String lResult = lRewriter.rewrite(lInput,
146: getDefaultTranslator());
147: assertEquals(lExpectation, lResult);
148: }//testBug4641833Varient1()
149:
150: public void testBug4641833Varient2() throws Exception {
151: String lInput = "menu.addItem(new NavBarMenuItem(\"All Available Information\",\"JavaScript:top.location='/DisplayMarketPortalServlet?portalid=1'\"));"
152: + "menu.addItem(new NavBarMenuItem(\"All Available Information\",\"http://sun.com/DisplayMarketPortalServlet\"));";
153:
154: String lExpectation = "menu.addItem(new NavBarMenuItem(\"All Available Information\",\"JavaScript:top.location='http://rajanagendra.sun.com/DisplayMarketPortalServlet?portalid=1'\"));"
155: + "menu.addItem(new NavBarMenuItem(\"All Available Information\",\"http://sun.com/DisplayMarketPortalServlet\"));";
156:
157: String lVariablesRules = "<Variable name=\"top.location\" type=\"URL\"/>";
158: String lFunctionRules = "<Function type=\"DJS\" name=\"NavBarMenuItem\" paramPatterns=\",y\"/>";
159:
160: RuleSet lRuleSet = CreateRuleSet.withHTMLAttJSVarJSFunRules("",
161: lVariablesRules, lFunctionRules);
162: Rewriter lRewriter = RewriterPool.create(lRuleSet,
163: LanguageConstants.JS_MIME);
164: String lResult = lRewriter.rewrite(lInput,
165: getDefaultTranslator());
166: assertEquals(lExpectation, lResult);
167: }//testBug4641833Varient2()
168:
169: public void testBug4641833Varient3() throws Exception {
170: String lInput = "menu.addItem(new NavBarMenuItem(\"All Available Information\",\"JavaScript:top.location='/DisplayMarketPortalServlet?portalid=1'\"));"
171: + "menu.addItem(new NavBarMenuItem(\"All Available Information\",\"httpS://sun.com/DisplayMarketPortalServlet\"));";
172:
173: String lExpectation = "menu.addItem(new NavBarMenuItem(\"All Available Information\",\"JavaScript:top.location='http://rajanagendra.sun.com/DisplayMarketPortalServlet?portalid=1'\"));"
174: + "menu.addItem(new NavBarMenuItem(\"All Available Information\",\"httpS://sun.com/DisplayMarketPortalServlet\"));";
175:
176: String lVariablesRules = "<Variable name=\"top.location\" type=\"URL\"/>";
177: String lFunctionRules = "<Function type=\"DJS\" name=\"NavBarMenuItem\" paramPatterns=\",y\"/>";
178:
179: RuleSet lRuleSet = CreateRuleSet.withHTMLAttJSVarJSFunRules("",
180: lVariablesRules, lFunctionRules);
181: Rewriter lRewriter = RewriterPool.create(lRuleSet,
182: LanguageConstants.JS_MIME);
183: String lResult = lRewriter.rewrite(lInput,
184: getDefaultTranslator());
185: assertEquals(lExpectation, lResult);
186: }//testBug4641833Varient3()
187:
188: public void testBug4641833Varient4() throws Exception {
189: String lInput = "menu.addItem(new NavBarMenuItem(\"All Available Information\",\"JavaScript:top.location='/DisplayMarketPortalServlet?portalid=1'\"));"
190: + "menu.addItem(new NavBarMenuItem(\"All Available Information\",\"top.location='/DisplayMarketPortalServlet?portalid=1'\"));";
191:
192: String lExpectation = "menu.addItem(new NavBarMenuItem(\"All Available Information\",\"JavaScript:top.location='http://rajanagendra.sun.com/DisplayMarketPortalServlet?portalid=1'\"));"
193: + "menu.addItem(new NavBarMenuItem(\"All Available Information\",\"top.location='http://rajanagendra.sun.com/DisplayMarketPortalServlet?portalid=1'\"));";
194:
195: String lVariablesRules = "<Variable name=\"top.location\" type=\"URL\"/>";
196: String lFunctionRules = "<Function type=\"DJS\" name=\"NavBarMenuItem\" paramPatterns=\",y\"/>";
197:
198: RuleSet lRuleSet = CreateRuleSet.withHTMLAttJSVarJSFunRules("",
199: lVariablesRules, lFunctionRules);
200: Rewriter lRewriter = RewriterPool.create(lRuleSet,
201: LanguageConstants.JS_MIME);
202: String lResult = lRewriter.rewrite(lInput,
203: getDefaultTranslator());
204: assertEquals(lExpectation, lResult);
205: }//testBug4641833Varient4()
206:
207: public void testBug4641833Varient5() throws Exception {
208: String lInput = "menu.addItem(new NavBarMenuItem(\"All Available Information\",\"JavaScript:top.location='/DisplayMarketPortalServlet?portalid=1'\"));"
209: + "menu.addItem(new NavBarMenuItem(\"All Available Information\",\"abc(top.location='/DisplayMarketPortalServlet?portalid=1')\"));"
210: + "menu.addItem(new NavBarMenuItem(\"All Available Information\",\"JavaScript:top.location='/DisplayMarketPortalServlet?portalid=1'\"));";
211:
212: String lExpectation = "menu.addItem(new NavBarMenuItem(\"All Available Information\",\"JavaScript:top.location='http://rajanagendra.sun.com/DisplayMarketPortalServlet?portalid=1'\"));"
213: + "menu.addItem(new NavBarMenuItem(\"All Available Information\",\"abc(top.location='http://rajanagendra.sun.com/DisplayMarketPortalServlet?portalid=1')\"));"
214: + "menu.addItem(new NavBarMenuItem(\"All Available Information\",\"JavaScript:top.location='http://rajanagendra.sun.com/DisplayMarketPortalServlet?portalid=1'\"));";
215:
216: String lVariablesRules = "<Variable name=\"top.location\" type=\"URL\"/>";
217: String lFunctionRules = "<Function type=\"DJS\" name=\"NavBarMenuItem\" paramPatterns=\",y\"/>";
218:
219: RuleSet lRuleSet = CreateRuleSet.withHTMLAttJSVarJSFunRules("",
220: lVariablesRules, lFunctionRules);
221: Rewriter lRewriter = RewriterPool.create(lRuleSet,
222: LanguageConstants.JS_MIME);
223: String lResult = lRewriter.rewrite(lInput,
224: getDefaultTranslator());
225: assertEquals(lExpectation, lResult);
226: }//testBug4641833Varient5()
227:
228: public void testBug4641833Varient6() throws Exception {
229: String lInput = "menu.addItem(new NavBarMenuItem(\"All Available Information\",\"JavaScript:top.location='/DisplayMarketPortalServlet?portalid=1'\"));"
230: + "menu.addItem(new NavBarMenuItem(\"All Available Information\",\"abc(top.location='/DisplayMarketPortalServlet')\"));"
231: + "menu.addItem(new NavBarMenuItem(\"All Available Information\",\"JavaScript:top.location='/DisplayMarketPortalServlet?portalid=1'\"));";
232:
233: String lExpectation = "menu.addItem(new NavBarMenuItem(\"All Available Information\",\"JavaScript:top.location='http://rajanagendra.sun.com/DisplayMarketPortalServlet?portalid=1'\"));"
234: + "menu.addItem(new NavBarMenuItem(\"All Available Information\",\"abc(top.location='http://rajanagendra.sun.com/DisplayMarketPortalServlet')\"));"
235: + "menu.addItem(new NavBarMenuItem(\"All Available Information\",\"JavaScript:top.location='http://rajanagendra.sun.com/DisplayMarketPortalServlet?portalid=1'\"));";
236:
237: String lVariablesRules = "<Variable name=\"top.location\" type=\"URL\"/>";
238: String lFunctionRules = "<Function type=\"DJS\" name=\"NavBarMenuItem\" paramPatterns=\",y\"/>";
239:
240: RuleSet lRuleSet = CreateRuleSet.withHTMLAttJSVarJSFunRules("",
241: lVariablesRules, lFunctionRules);
242: Rewriter lRewriter = RewriterPool.create(lRuleSet,
243: LanguageConstants.JS_MIME);
244: String lResult = lRewriter.rewrite(lInput,
245: getDefaultTranslator());
246: assertEquals(lExpectation, lResult);
247: }//testBug4641833Varient6()
248:
249: public void testBug4641833Varient() throws Exception {
250: String lInput = "menu.addItem(new NavBarMenuItem(\"All Available Information\",\"JavaScript:top.location='/DisplayMarketPortalServlet?portalid=1'\"));";
251: String lExpectation = "menu.addItem(new NavBarMenuItem(\"All Available Information\",\"JavaScript:top.location='http://rajanagendra.sun.com/DisplayMarketPortalServlet?portalid=1'\"));";
252:
253: String lVariablesRules = "<Variable name=\"top.location\" source=\"*rajanagendra.sun.com*\" type=\"URL\"/>";
254: String lFunctionRules = "<Function type=\"DJS\" name=\"NavBarMenuItem\" paramPatterns=\",y\"/>";
255:
256: RuleSet lRuleSet = CreateRuleSet.withHTMLAttJSVarJSFunRules("",
257: lVariablesRules, lFunctionRules);
258: Rewriter lRewriter = RewriterPool.create(lRuleSet,
259: LanguageConstants.JS_MIME);
260: String lResult = lRewriter.rewrite(lInput,
261: getDefaultTranslator());
262: assertEquals(lExpectation, lResult);
263: }//testBug4641833Varient()
264:
265: public void testBug4512672() throws Exception {
266: String lInput = "menu.addItem(new NavBarMenuItem(\"All Available Information\",\"javaScript:top.location='/DisplayMarketPortalServlet?portalid=1'\"));";
267: String lExpectation = "menu.addItem(new NavBarMenuItem(\"All Available Information\",\"javaScript:top.location='http://rajanagendra.sun.com/DisplayMarketPortalServlet?portalid=1'\"));";
268:
269: String lVariablesRules = "<Variable name=\"top.location\" type=\"URL\"/>";
270: String lFunctionRules = "<Function type=\"DJS\" name=\"NavBarMenuItem\" paramPatterns=\",y\"/>";
271:
272: RuleSet lRuleSet = CreateRuleSet.withHTMLAttJSVarJSFunRules("",
273: lVariablesRules, lFunctionRules);
274: Rewriter lRewriter = RewriterPool.create(lRuleSet,
275: LanguageConstants.JS_MIME);
276: String lResult = lRewriter.rewrite(lInput,
277: getDefaultTranslator());
278: assertEquals(lExpectation, lResult);
279: }//testBug4512672()
280:
281: public void testBug4512672Varient() throws Exception {
282: String lInput = "menu.addItem(new NavBarMenuItem(\"All Available Information\",\"JAVASCRIPT:top.location='/DisplayMarketPortalServlet?portalid=1'\"));";
283: String lExpectation = "menu.addItem(new NavBarMenuItem(\"All Available Information\",\"JAVASCRIPT:top.location='http://rajanagendra.sun.com/DisplayMarketPortalServlet?portalid=1'\"));";
284:
285: String lVariablesRules = "<Variable name=\"top.location\" type=\"URL\"/>";
286: String lFunctionRules = "<Function source=\"*rajanagendra.sun.com*\" type=\"DJS\" name=\"NavBarMenuItem\" paramPatterns=\",y\"/>";
287:
288: RuleSet lRuleSet = CreateRuleSet.withHTMLAttJSVarJSFunRules("",
289: lVariablesRules, lFunctionRules);
290: Rewriter lRewriter = RewriterPool.create(lRuleSet,
291: LanguageConstants.JS_MIME);
292: String lResult = lRewriter.rewrite(lInput,
293: getDefaultTranslator());
294: assertEquals(lExpectation, lResult);
295: }//testBug4512672Varient()
296:
297: public void testBug4512672Varient1() throws Exception {
298: String lInput = "menu.addItem(new NavBarMenuItem(\"All Available Information\",\"top.location='/DisplayMarketPortalServlet?portalid=1'\"));";
299: String lExpectation = "menu.addItem(new NavBarMenuItem(\"All Available Information\",\"top.location='http://rajanagendra.sun.com/DisplayMarketPortalServlet?portalid=1'\"));";
300:
301: String lVariablesRules = "<Variable name=\"top.location\" type=\"URL\"/>";
302: String lFunctionRules = "<Function type=\"DJS\" name=\"NavBarMenuItem\" paramPatterns=\",y\"/>";
303:
304: RuleSet lRuleSet = CreateRuleSet.withHTMLAttJSVarJSFunRules("",
305: lVariablesRules, lFunctionRules);
306: Rewriter lRewriter = RewriterPool.create(lRuleSet,
307: LanguageConstants.JS_MIME);
308: String lResult = lRewriter.rewrite(lInput,
309: getDefaultTranslator());
310: assertEquals(lExpectation, lResult);
311: }//testBug4512672Varient1()
312:
313: public void testEvalDJS() throws Exception {
314: //RFE:TODO: in 6.1
315: String lInput = "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n"
316: + "<html>\n"
317: + "<head>\n"
318: + "<title>Please Wait While Redirecting to console</title>\n"
319: + "<script language=\"JavaScript\">\n"
320: + "<!--\n"
321: + "function Console_goToURL() { //v3.0\n"
322: + " var i, args=Console_goToURL.arguments; document.Console_returnValue= false;\n"
323: + " for (i=0; i<(args.length-1); i+=2)\n"
324: + "eval(args[i]+\".location='\"+args[i+1]+\"'\");\n"
325: + "}\n"
326: + "//-->\n"
327: + "</script>\n"
328: + "</head>\n"
329: + "\n"
330: + "<body bgcolor=\"#FFFFFF\"\n"
331: + "onLoad=\"Console_goToURL('parent','/amconsole/base/AMAdminFrame');return \n"
332: + "document.Console_returnValue\">\n"
333: + "</body>\n"
334: + "</html>\n";
335:
336: String lExpectation = "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n"
337: + "<html>\n"
338: + "<head>\n"
339: + "<title>Please Wait While Redirecting to console</title>\n"
340: + "<script language=\"JavaScript\">\n"
341: + "<!--\n"
342: + "function Console_goToURL() { //v3.0\n"
343: + " var i, args=Console_goToURL.arguments; document.Console_returnValue= false;\n"
344: + " for (i=0; i<(args.length-1); i+=2)\n"
345: + "eval(args[i]+\".location='\"+args[i+1]+\"'\");\n"
346: + "}\n"
347: + "//-->\n"
348: + "</script>\n"
349: + "</head>\n"
350: + "\n"
351: + "<body bgcolor=\"#FFFFFF\"\n"
352: + "onLoad=\"Console_goToURL('parent','/amconsole/base/AMAdminFrame');return \n"
353: + "document.Console_returnValue\">\n"
354: + "</body>\n"
355: + "</html>\n";
356:
357: String lVariablesRules = "<Variable name=\"*location\" source=\"*rajanagendra.sun.com*\" type=\"EXPRESSION\"/>";
358: String lFunctionRules = "<Function source=\"*rajanagendra.sun.com*\" type=\"DJS\" name=\"eval\" paramPatterns=\"y\"/>"
359: + "<Function type=\"DJS\" name=\"eval\" paramPatterns=\"y\"/>";
360:
361: RuleSet lRuleSet = CreateRuleSet.withHTMLAttJSVarJSFunRules("",
362: lVariablesRules, lFunctionRules);
363: Rewriter lRewriter = RewriterPool.create(lRuleSet,
364: LanguageConstants.JS_MIME);
365: String lResult = lRewriter.rewrite(lInput,
366: getDefaultTranslator());
367: assertEquals(lExpectation, lResult);
368: }//testEvalDJS()
369:
370: //Bug:FixMe:
371: public void atestEvalDJSVarient() throws Exception {
372: String lInput = " function imageon(imgName) {\n"
373: + " if (document.images) {\n"
374: + " document[imgName].src = eval(\"eeoen.ede\" + imgName );\n"
375: + " document[imgName].src = eval(\"eeoen.ede\" );\n"
376: + " document[imgName].src = eval(imgName );\n"
377: + " document[imgName].src = eval(imgName + \"eeoen.ede\");\n"
378: + " document[imgName].src = eval(imgName + \"on.ede\");\n"
379: + " document[imgName].src = eval(imgName + \"on.src\");\n"
380: + " }\n" + " }\n";
381:
382: String lExpectation = " function imageon(imgName) {\n"
383: + " if (document.images) {\n"
384: + " document[imgName].src ="
385: + JSWrapperHelper.CONVERT_EXPRESSION_FUNCTION_WRAP_START
386: + " eval(\"eeoen.ede\" + imgName ));\n"
387: + " document[imgName].src ="
388: + JSWrapperHelper.CONVERT_EXPRESSION_FUNCTION_WRAP_START
389: + " eval(\"eeoen.ede\" ));\n"
390: + " document[imgName].src ="
391: + JSWrapperHelper.CONVERT_EXPRESSION_FUNCTION_WRAP_START
392: + " eval(imgName ));\n"
393: + " document[imgName].src ="
394: + JSWrapperHelper.CONVERT_EXPRESSION_FUNCTION_WRAP_START
395: + " eval(imgName + \"eeoen.ede\"));\n"
396: + " document[imgName].src ="
397: + JSWrapperHelper.CONVERT_EXPRESSION_FUNCTION_WRAP_START
398: + " eval(imgName + \"on.ede\"));\n"
399: + " document[imgName].src ="
400: + JSWrapperHelper.CONVERT_EXPRESSION_FUNCTION_WRAP_START
401: + " eval(imgName + \"on.src\"));\n" + " }\n"
402: + " }\n"
403: + JSWrapperHelper.CONVERT_EXPRESSION_FUNCTION_JS;
404:
405: String lVariablesRules = "<Variable name=\"document*.src\"/>";
406: String lFunctionRules = "<Function name=\"eval\" paramPatterns=\"y\" type=\"DJS\"/>";
407:
408: RuleSet lRuleSet = CreateRuleSet.withHTMLAttJSVarJSFunRules("",
409: lVariablesRules, lFunctionRules);
410: Rewriter lRewriter = RewriterPool.create(lRuleSet,
411: LanguageConstants.JS_MIME);
412: String lResult = lRewriter.rewrite(lInput,
413: getDefaultTranslator());
414: assertEquals(lExpectation, lResult);
415: }//testEvalDJSVarient()
416:
417: public void testBugNo4345630() throws Exception {
418: String lInput = "<head>\n"
419: + "<meta name=\"SERVER\" content=\"NatWeb (R) Server 3.0\">\n"
420: + "<meta name=\"GENERATOR\" content=\"HTML Editor - NatWeb 1.0\">\n"
421: + "<title></title><base HREF=\"/scripts/cgifcgi.exe\"></head>\n"
422: + "<body>\n"
423: + "<form method=\"post\" action=\"scripts/cgifcgi.exe/nwdvisip/nwdvisip=7be/L_PAGINE.TCVI90WI.7.103.17\" name=\"DATI\" target=\"pippo\">\n"
424: + "<center>\n"
425: + "<b>CONSERVATORIA DI<font color=\"blue\" SIZE=\"+2\">\n"
426: + "GROSSETO</font></b><br>\n"
427: + "<B><font size=\"+1\"> Ricerca ristretta - con omocodici</FONT><br>\n"
428: + "<FONT size=\"+1\"><b> </b></font></center><br>\n"
429: + "<CENTER><FONT SIZE=\"+2\">IL DOCUMENTO E' PRONTO :</FONT><br> \n"
430: + "<font size=\"+2\" color=\"blue\"> <a href=\"isptemp/10212001.pdf\" TARGET=\"Pippo\">CLICCA QUI</a></FONT>\n"
431: + "<font size=\"+2\"> PER VISUALIZZARLO.</FONT></CENTER><p></p>\n"
432: + "\n"
433: + "<script language=\"JavaScript\" type=\"text/javascript\"> var tempo = setTimeout(\"window.open('isptemp/10212001.pdf','Pippo', 'resizable=1,toolbar=0,location=0,directories=0,status=0,menubar=0,width=500,height=500');\",500); </script>\n"
434: + "</body>\n" + "</form>\n";
435:
436: String lExpectation = "<head>\n"
437: + "<meta name=\"SERVER\" content=\"NatWeb (R) Server 3.0\">\n"
438: + "<meta name=\"GENERATOR\" content=\"HTML Editor - NatWeb 1.0\">\n"
439: + "<title></title><!-- base HREF=\"http://rajanagendra.sun.com/scripts/cgifcgi.exe\" --></head>\n"
440: + "<body>\n"
441: + "<form method=\"post\" action=\"http://rajanagendra.sun.com/scripts/scripts/cgifcgi.exe/nwdvisip/nwdvisip=7be/L_PAGINE.TCVI90WI.7.103.17\" name=\"DATI\" target=\"pippo\">\n"
442: + "<center>\n"
443: + "<b>CONSERVATORIA DI<font color=\"blue\" SIZE=\"+2\">\n"
444: + "GROSSETO</font></b><br>\n"
445: + "<B><font size=\"+1\"> Ricerca ristretta - con omocodici</FONT><br>\n"
446: + "<FONT size=\"+1\"><b> </b></font></center><br>\n"
447: + "<CENTER><FONT SIZE=\"+2\">IL DOCUMENTO E' PRONTO :</FONT><br> \n"
448: + "<font size=\"+2\" color=\"blue\"> <a href=\"http://rajanagendra.sun.com/scripts/isptemp/10212001.pdf\" TARGET=\"Pippo\">CLICCA QUI</a></FONT>\n"
449: + "<font size=\"+2\"> PER VISUALIZZARLO.</FONT></CENTER><p></p>\n"
450: + "\n"
451: + "<script language=\"JavaScript\" type=\"text/javascript\"> var tempo = setTimeout(\"window.open('http://rajanagendra.sun.com/scripts/isptemp/10212001.pdf','Pippo', 'resizable=1,toolbar=0,location=0,directories=0,status=0,menubar=0,width=500,height=500');\",500); </script>\n"
452: + "</body>\n" + "</form>\n";
453:
454: String lHTMLAttRules = "<Attribute name=\"href\" />"
455: + "<Attribute name=\"action\" />";
456:
457: String lJSFunRules = "<Function type=\"DJS\" name=\"setTimeout\" paramPatterns=\"y\"/>"
458: + "<Function type=\"EXPRESSION\" name=\"*open\" paramPatterns=\"y\"/>";
459:
460: RuleSet lRuleSet = CreateRuleSet.withHTMLAttJSFunRules(
461: lHTMLAttRules, lJSFunRules);
462: Rewriter lRewriter = RewriterPool.create(lRuleSet,
463: LanguageConstants.HTML_MIME);
464: String lResult = lRewriter.rewrite(lInput,
465: getDefaultTranslator());
466: assertEquals(lExpectation, lResult);
467: }//testBugNo4345630()
468:
469: public void testRobCase() throws Exception {
470: String lInput = "window.setTimeout(\"statusMsg('/http://www.iplanet.com')\", 1000);\n";
471: String lExpectation = "window.setTimeout(\"statusMsg('http://rajanagendra.sun.com/http://www.iplanet.com')\", 1000);\n";
472:
473: String[] lJSFunRules = {
474: "<Function name=\"window.setTimeout\" paramPatterns =\"y,\" type=\"DJS\"/>\n"
475: + "<Function name=\"statusMsg\" paramPatterns =\"y\" type=\"EXPRESSION\"/>\n",
476: "<Function name=\"window.setTimeout\" paramPatterns =\"y,\" type=\"DJS\"/>\n"
477: + "<Function name=\"statusMsg\" paramPatterns =\"y\" type=\"URL\"/>\n", };
478:
479: for (int i = 0; i < lJSFunRules.length; i++) {
480: RuleSet lRuleSet = CreateRuleSet
481: .withJSFunctionRules(lJSFunRules[i]);
482: Rewriter lRewriter = RewriterPool.create(lRuleSet,
483: LanguageConstants.JS_MIME);
484: String lResult = lRewriter.rewrite(lInput,
485: getDefaultTranslator());
486: assertEquals(lExpectation, lResult);
487: }
488: }//testRobCase()
489:
490: public void testSAPCase() throws Exception {
491: String lInput = "<meta HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=utf-8\">\n"
492: + "<script>\n"
493: + "if (String(window.navigator.appVersion).indexOf(\"MSIE 5.0\")>-1) {\n"
494: + "eval(\"document.write('<script language=\\\"Jscript\\\" src=\\\"../utf8UriComponentEncoder_ie5.js\\\"></script\" + \">');\");\n"
495: + "}\n" + "</script>\n";
496:
497: String lExpectation = "<meta HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=utf-8\">\n"
498: + "<script>\n"
499: + "if (String(window.navigator.appVersion).indexOf(\"MSIE 5.0\")>-1) {\n"
500: + "eval(\"document.write('<script language=\\\"Jscript\\\" src=\\\"http://rajanagendra.sun.com/Base/utf8UriComponentEncoder_ie5.js?psScriptReferrer=http://rajanagendra.sun.com/Base/Raja/"
501: + ""
502: + ".END.\\\"></script\" + \">');\");\n"
503: + "}\n"
504: + "</script>\n";
505:
506: String lHTMLAttRules = "<Attribute name=\"src\" />";
507:
508: String lJSFunRules = "<Function name=\"document.write*\" paramPatterns =\"y\" type=\"DHTML\"/>\n"
509: + "<Function name=\"eval\" paramPatterns =\"y\" type=\"DJS\"/>\n";
510:
511: RuleSet lRuleSet = CreateRuleSet.withHTMLAttJSFunRules(
512: lHTMLAttRules, lJSFunRules);
513: Rewriter lRewriter = RewriterPool.create(lRuleSet,
514: LanguageConstants.HTML_MIME);
515: String lResult = lRewriter.rewrite(lInput,
516: getDefaultTranslator());
517: assertEquals(lExpectation, lResult);
518: }//testSAPCase()
519:
520: public void testSAPCaseShorterOne() throws Exception {
521: String lInput = "eval(\"document.write('<script language=\\\"Jscript\\\" src=\\\"../utf8UriComponentEncoder_ie5.js\\\"></script\" + \">');\");\n";
522:
523: String lExpectation = "eval(\"document.write('<script language=\\\"Jscript\\\" src=\\\"http://rajanagendra.sun.com/Base/utf8UriComponentEncoder_ie5.js?psScriptReferrer=http://rajanagendra.sun.com/Base/Raja/.END.\\\"></script\" + \">');\");\n";
524:
525: String lHTMLAttRules = "<Attribute name=\"src\" />";
526:
527: String lJSFunRules = "<Function name=\"document.write*\" paramPatterns =\"y\" type=\"DHTML\"/>\n"
528: + "<Function name=\"eval\" paramPatterns =\"y\" type=\"DJS\"/>\n";
529:
530: RuleSet lRuleSet = CreateRuleSet.withHTMLAttJSFunRules(
531: lHTMLAttRules, lJSFunRules);
532: Rewriter lRewriter = RewriterPool.create(lRuleSet,
533: LanguageConstants.JS_MIME);
534: String lResult = lRewriter.rewrite(lInput,
535: getDefaultTranslator());
536: assertEquals(lExpectation, lResult);
537: }//testSAPCaseShorterOne()
538:
539: public void testSAPCaseSubCase() throws Exception {
540: String lInput = "document.write('<script language=\\\"Jscript\\\" src=\\\"../utf8UriComponentEncoder_ie5.js\\\"></script\" + \">');\n";
541:
542: String lExpectation = "document.write('<script language=\\\"Jscript\\\" src=\\\"http://rajanagendra.sun.com/Base/utf8UriComponentEncoder_ie5.js?psScriptReferrer=http://rajanagendra.sun.com/Base/Raja/.END.\\\"></script\" + \">');\n";
543:
544: String lHTMLAttRules = "<Attribute name=\"src\" />";
545:
546: String lJSFunRules = "<Function name=\"document.write*\" paramPatterns =\"y\" type=\"DHTML\"/>\n";
547:
548: RuleSet lRuleSet = CreateRuleSet.withHTMLAttJSFunRules(
549: lHTMLAttRules, lJSFunRules);
550: Rewriter lRewriter = RewriterPool.create(lRuleSet,
551: LanguageConstants.JS_MIME);
552: String lResult = lRewriter.rewrite(lInput,
553: getDefaultTranslator());
554: assertEquals(lExpectation, lResult);
555: }//testSAPCaseSubCase()
556:
557: public void testSAPCaseShorterOneHTML_MIME() throws Exception {
558: String lInput = "eval(\"document.write('<script language=\\\"Jscript\\\" src=\\\"../utf8UriComponentEncoder_ie5.js\\\"></script\" + \">');\");\n";
559:
560: String lExpectation = "eval(\"document.write('<script language=\\\"Jscript\\\" src=\\\"http://rajanagendra.sun.com/Base/utf8UriComponentEncoder_ie5.js?psScriptReferrer=http://rajanagendra.sun.com/Base/Raja/.END.\\\"></script\" + \">');\");\n";
561:
562: String lHTMLAttRules = "<Attribute name=\"src\" />";
563:
564: String lJSFunRules = "<Function name=\"document.writeln\" paramPatterns =\"y\" type=\"DHTML\"/>\n"
565: + "<Function name=\"eval\" paramPatterns =\"y\" type=\"DJS\"/>\n";
566:
567: RuleSet lRuleSet = CreateRuleSet.withHTMLAttJSFunRules(
568: lHTMLAttRules, lJSFunRules);
569: Rewriter lRewriter = RewriterPool.create(lRuleSet,
570: LanguageConstants.HTML_MIME);
571: String lResult = lRewriter.rewrite(lInput,
572: getDefaultTranslator());
573: assertEquals(lExpectation, lResult);
574: }//testSAPCaseShorterOnehtmlmime()
575:
576: public static void main(String[] args) {
577: RewriterModule.initFile();
578: BasicTestCase.run(TestJSDJSFunctions.class);
579: // TestSuite testSuite = new TestSuite();
580: // testSuite.addTest( new TestJSDJSFunctions( "testSimpleDJSFunctions" ) );
581: // BasicTestCase.run( testSuite );
582: }//main()
583:
584: }//class TestJSDJSFunctions
|