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.rproxy.rewriter.engines.js.test;
006:
007: import com.sun.portal.rewriter.Rewriter;
008: import com.sun.portal.log.common.PortalLogger;
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.rproxy.rewriter.SRAPRewriterModule;
015: import com.sun.portal.rproxy.rewriter.test.util.SRAPJSWrapperHelper;
016: import com.sun.portal.rproxy.rewriter.test.util.SRAPTestSystemFactory;
017: import junit.framework.TestSuite;
018:
019: public class TestSRAPJSExpressionFunctions extends BasicTestCase {
020: public TestSRAPJSExpressionFunctions(String aName) {
021: super (aName);
022: }//constuctor
023:
024: public void testSRAPJSExpressionParamWithCornerCaseQuery()
025: throws Exception {
026: String lInput = "<script language=\"JavaScript\"> <!--\n"
027: + "function redirectToConsole() {\n"
028: + " top.location.replace(\n"
029: + " '/amconsole/base/AMAdminFrame?' + getDateStamp());\n"
030: + "}\n"
031: + "\n"
032: + "function getDateStamp() {\n"
033: + " var s='';\n"
034: + " while (s.length < 80) {\n"
035: + " t = (48 + Math.round(Math.random() * 74));\n"
036: + " r = ((t<58) || ((t>64) && (t<91)) || ((t>96) && (t<123))) ?\n"
037: + " String.fromCharCode(t) : '';\n"
038: + " s += r;\n" + " }\n" + " return s;\n"
039: + "}\n" + "//-->\n" + "</script>\n";
040:
041: String lExpectation = "<script language=\"JavaScript\"> <!--\n"
042: + "function redirectToConsole() {\n"
043: + " top.location.replace(\n"
044: + " 'https://zeus.nawab.inda.com/http://raja.sun.com/amconsole/base/AMAdminFrame?' + getDateStamp());\n"
045: + "}\n"
046: + "\n"
047: + "function getDateStamp() {\n"
048: + " var s='';\n"
049: + " while (s.length < 80) {\n"
050: + " t = (48 + Math.round(Math.random() * 74));\n"
051: + " r = ((t<58) || ((t>64) && (t<91)) || ((t>96) && (t<123))) ?\n"
052: + " String.fromCharCode(t) : '';\n"
053: + " s += r;\n" + " }\n" + " return s;\n"
054: + "}\n" + "//-->\n" + "</script>\n";
055:
056: String lJSRules = "<Function type=\"EXPRESSION\" name=\"*.replace\" paramPatterns=\"y\"/>";
057:
058: RuleSet lRuleSet = CreateRuleSet.withJSFunctionRules(lJSRules);
059: Rewriter lRewriter = RewriterPool.create(lRuleSet,
060: LanguageConstants.HTML_MIME);
061: String lResult = lRewriter.rewrite(lInput,
062: SRAPTestSystemFactory.createSRAPTranslator());
063: assertEquals(lExpectation, lResult);
064: }//testSRAPJSExpressionParamWithCornerCaseQuery()
065:
066: public void testMessgerFunction() throws Exception {
067: String lInput = "function load(f, href) {\n"
068: + "\n"
069: + " if(href.indexOf('rtfPossible')==-1 && (href.indexOf('opts_fs.html') !=-1 || href.indexOf('pab_fs.html') !=-1 || href.indexOf('msg_fs.html') !=-1 || href.indexOf('fldr_fs.html') != -1 || href.indexOf('ldap_fs.html') != -1 || href.indexOf('mbox_fs.html') != -1 || href.indexOf('frame.html') != -1 || href.indexOf('comp_fs.html') != -1))\n"
070: + " href += '?rtfPossible='+main.rtfPossibleString\n"
071: + "\n" + " if (NN > 0 || (IE >= 4 && !mac))\n"
072: + " f.location.replace(href)\n" + " else\n"
073: + " f.location.href = href\n" + "}\n";
074: String lExpectation = "function load(f, href) {\n"
075: + "\n"
076: + " if(href.indexOf('rtfPossible')==-1 && (href.indexOf('opts_fs.html') !=-1 || href.indexOf('pab_fs.html') !=-1 || href.indexOf('msg_fs.html') !=-1 || href.indexOf('fldr_fs.html') != -1 || href.indexOf('ldap_fs.html') != -1 || href.indexOf('mbox_fs.html') != -1 || href.indexOf('frame.html') != -1 || href.indexOf('comp_fs.html') != -1))\n"
077: + " href += '?rtfPossible='+main.rtfPossibleString\n"
078: + "\n"
079: + " if (NN > 0 || (IE >= 4 && !mac))\n"
080: + " f.location.replace("
081: + SRAPJSWrapperHelper.CONVERT_EXPRESSION_FUNCTION_WRAP_START
082: + "href))\n"
083: + " else\n"
084: + " f.location.href = href\n"
085: + "}\n"
086: + SRAPJSWrapperHelper.SRAP_CONVERT_EXPRESSION_FUNCTION_JS;
087:
088: String[] lJSFunRules = {
089: "<Function type=\"EXPRESSION\" name=\"*.location.replace\" paramPatterns=\"y\"/>",
090: "<Function type=\"EXPRESSION\" name=\"*location.replace\" paramPatterns=\"y\"/>", };
091:
092: for (int i = 0; i < lJSFunRules.length; i++) {
093: RuleSet lRuleSet = CreateRuleSet
094: .withJSFunctionRules(lJSFunRules[i]);
095: Rewriter lRewriter = RewriterPool.create(lRuleSet,
096: LanguageConstants.JS_MIME);
097: String lResult = lRewriter.rewrite(lInput,
098: SRAPTestSystemFactory.createSRAPTranslator());
099: assertEquals(lExpectation, lResult);
100: }
101: }//testMessgerFunction()
102:
103: public static void main(String[] args) {
104: SRAPRewriterModule.initFile();
105: //BasicTestCase.run( new TestSuite( TestSRAPJSExpressionFunctions.class ) );
106:
107: TestSuite testSuite = new TestSuite();
108: testSuite.addTest(new TestSRAPJSExpressionFunctions(
109: "testMessgerFunction"));
110: BasicTestCase.run(testSuite);
111: }//main()
112: }//class TestSRAPJSExpressionFunctions
|