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.RewriterPool;
009: import com.sun.portal.rewriter.engines.LanguageConstants;
010: import com.sun.portal.rewriter.rom.RuleSet;
011: import com.sun.portal.rewriter.test.util.BasicTestCase;
012: import com.sun.portal.rewriter.test.util.CreateRuleSet;
013: import com.sun.portal.rewriter.test.util.JSWrapperHelper;
014: import com.sun.portal.rewriter.test.util.JScriptInterpreter;
015: import junit.framework.TestSuite;
016:
017: public class TestJSConvertSystemFunction extends BasicTestCase {
018: public TestJSConvertSystemFunction(String aName) {
019: super (aName);
020: }//constuctor
021:
022: public void testConvertSystemVarFunction() throws Exception {
023: String[][] lData = {
024: { "window.location.pathname", "http://raja.sun.com" },
025: { null, null }, { "", "" }, };
026:
027: String functionDef = getDefaultTranslator().getJSFunctionSpec()
028: .getSystemFunctionDefination(
029: getDefaultTranslator().getPageSpec());
030:
031: for (int i = 0; i < lData.length; i++) {
032: String result = JScriptInterpreter.exec(functionDef,
033: JSWrapperHelper.CONVERT_SYSTEM_FUNCTION_NAME,
034: new String[] { "null", lData[i][0], lData[i][1] });
035: assertEquals("Failed at i=" + i + ":", lData[i][1], result);
036: }
037: //tobedone
038: }//testConvertSystemVarFunction()
039:
040: public void testBugNo4809850StarHashRule() throws Exception {
041: String lInput = "<FORM name=login_form \n"
042: + " onsubmit=\"return hash(this,'config/login')\" \n"
043: + " action=/config/login?44c63uvgrvp2r \n"
044: + " method=post autocomplete=\"off\">\n";
045:
046: String lExpectation = "<FORM name=login_form \n"
047: + " onsubmit=\"return hash(this,'http://rajanagendra.sun.com/Base/Raja/config/login')\" \n"
048: + " action=http://rajanagendra.sun.com/config/login?44c63uvgrvp2r \n"
049: + " method=post autocomplete=\"off\">\n";
050:
051: String lAttributeRule = "<Attribute name=\"action*\"/>"
052: + "<Attribute name=\"on*\" type=\"DJS\"/>";
053:
054: String lJSVarRule = "<Variable name=\"*.hash\" type=\"SYSTEM\"/>";
055: String lJSFunRule = "<Function name=\"h*ash\" paramPatterns=\",y\"/>";
056:
057: RuleSet lRuleSet = CreateRuleSet.withHTMLAttJSVarJSFunRules(
058: lAttributeRule, lJSVarRule, lJSFunRule);
059: Rewriter lRewriter = RewriterPool.create(lRuleSet,
060: LanguageConstants.HTML_MIME);
061:
062: String lResult = lRewriter.rewrite(lInput,
063: getDefaultTranslator());
064: assertEquals(lExpectation, lResult);
065: }//testBugNo4809850StarHashRule()
066:
067: public void testBugNo4809850StarHashRuleVarient() throws Exception {
068: String lInput = "<FORM name=login_form \n"
069: + " onsubmit=\"var a = hash(this,'/config/login')\" \n"
070: + " action=/config/login?44c63uvgrvp2r \n"
071: + " method=post autocomplete=\"off\">\n";
072:
073: String lExpectation = "<FORM name=login_form \n"
074: + " onsubmit=\"var a = hash(this,'http://rajanagendra.sun.com/config/login')\" \n"
075: + " action=http://rajanagendra.sun.com/config/login?44c63uvgrvp2r \n"
076: + " method=post autocomplete=\"off\">\n";
077:
078: String lAttributeRule = "<Attribute name=\"action*\"/>"
079: + "<Attribute name=\"on*\" type=\"DJS\"/>";
080:
081: String lJSVarRule = "<Variable name=\"*.hash\" type=\"SYSTEM\"/>";
082: String lJSFunRule = "<Function name=\"hash\" paramPatterns=\",y\"/>";
083:
084: RuleSet lRuleSet = CreateRuleSet.withHTMLAttJSVarJSFunRules(
085: lAttributeRule, lJSVarRule, lJSFunRule);
086: Rewriter lRewriter = RewriterPool.create(lRuleSet,
087: LanguageConstants.HTML_MIME);
088:
089: String lResult = lRewriter.rewrite(lInput,
090: getDefaultTranslator());
091: assertEquals(lExpectation, lResult);
092: }//testBugNo4809850StarHashRuleVarient()
093:
094: public static void main(String[] args) {
095: BasicTestCase.run(TestJSConvertSystemFunction.class);
096: TestSuite testSuite = new TestSuite();
097: testSuite.addTest(new TestJSConvertSystemFunction(
098: "testStarHashRule"));
099: //BasicTestCase.run( testSuite );
100: }//main()
101:
102: }//class TestJSConvertSystemFunction
|