Source Code Cross Referenced for TestJSSystemVariables.java in  » Portal » Open-Portal » com » sun » portal » rewriter » engines » js » test » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Portal » Open Portal » com.sun.portal.rewriter.engines.js.test 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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 junit.framework.TestSuite;
015:
016:        public class TestJSSystemVariables extends BasicTestCase {
017:            public TestJSSystemVariables(String aName) {
018:                super (aName);
019:            }//constuctor
020:
021:            public void testStandardSystemVariables() throws Exception {
022:                String lInput = "alert( \"pathname: \" + window.location.pathname)";
023:                String lExpectation = "alert( \"pathname: \" + "
024:                        + JSWrapperHelper.CONVERT_SYSTEM_FUNCTION_WRAP_START
025:                        + "window.location, 'window.location.pathname', window.location.pathname))"
026:                        + JSWrapperHelper.CONVERT_SYSTEM_FUNCTION_JS;
027:
028:                String lRule = "<Variable name=\"win*.*n.p*\"  source=\"*sun.com*\" type=\"SYSTEM\"/>"; //jsvar rule
029:
030:                RuleSet lRuleSet = CreateRuleSet.withJSVariableRules(lRule);
031:                Rewriter lRewriter = RewriterPool.create(lRuleSet,
032:                        LanguageConstants.JS_MIME);
033:                String lResult = lRewriter.rewrite(lInput,
034:                        getDefaultJSTranslator());
035:
036:                assertEquals(lExpectation, lResult);
037:            }//testStandardSystemVariable()
038:
039:            public void testStandardSystemVariablesInvalidRuleSource()
040:                    throws Exception {
041:                String lInput = "alert( \"pathname: \" + window.location.pathname)";
042:                String lRule = "<Variable name=\"win*.*n.p*\"  source=\"*asun.com*\" type=\"SYSTEM\"/>"; //jsvar rule
043:
044:                RuleSet lRuleSet = CreateRuleSet.withJSVariableRules(lRule);
045:                Rewriter lRewriter = RewriterPool.create(lRuleSet,
046:                        LanguageConstants.JS_MIME);
047:                String lResult = lRewriter.rewrite(lInput,
048:                        getDefaultJSTranslator());
049:
050:                assertEquals(lInput, lResult);
051:            }//testStandardSystemVariablesInvalidRuleSource()
052:
053:            public void testArraySystemVariables() throws Exception {
054:                String lInput = "alert( \"pathname: \" + window.location[10].pathname)";
055:                String lExpectation = "alert( \"pathname: \" + "
056:                        + JSWrapperHelper.CONVERT_SYSTEM_FUNCTION_WRAP_START
057:                        + "window.location[10], 'window.location[10].pathname', window.location[10].pathname))"
058:                        + JSWrapperHelper.CONVERT_SYSTEM_FUNCTION_JS;
059:                String lRule = "<Variable name=\"win*.*n*p*\" type=\"SYSTEM\"/>"; //jsvar rule
060:
061:                RuleSet lRuleSet = CreateRuleSet.withJSVariableRules(lRule);
062:                Rewriter lRewriter = RewriterPool.create(lRuleSet,
063:                        LanguageConstants.JS_MIME);
064:                String lResult = lRewriter.rewrite(lInput,
065:                        getDefaultTranslator());
066:
067:                assertEquals(lExpectation, lResult);
068:            }//testArraySystemVariables()
069:
070:            public void testArraySystemVariablesDifferentLine()
071:                    throws Exception {
072:                String lInput = "alert( \"pathname: \" + window.location[10].\n"
073:                        + "pathname)";
074:
075:                String lExpectation = "alert( \"pathname: \" + "
076:                        + JSWrapperHelper.CONVERT_SYSTEM_FUNCTION_WRAP_START
077:                        + "window.location[10], 'window.location[10].\npathname', window.location[10].\n"
078:                        + "pathname))"
079:                        + JSWrapperHelper.CONVERT_SYSTEM_FUNCTION_JS;
080:
081:                String lRule = "<Variable name=\"win*.*n*p*\" type=\"SYSTEM\"/>"; //jsvar rule
082:
083:                RuleSet lRuleSet = CreateRuleSet.withJSVariableRules(lRule);
084:                Rewriter lRewriter = RewriterPool.create(lRuleSet,
085:                        LanguageConstants.JS_MIME);
086:                String lResult = lRewriter.rewrite(lInput,
087:                        getDefaultTranslator());
088:                assertEquals(lExpectation, lResult);
089:            }//testArraySystemVariablesDifferentLine()
090:
091:            public void testSystemVariableInAlert() throws Exception {
092:                String lInput = "<HTML>"
093:                        + "<HEAD>"
094:                        + "<TITLE>JavaScript Test</TITLE>"
095:                        + "<SCRIPT LANGUAGE=\"JAVASCRIPT\">"
096:                        + "alert( \"pathname: \" + window.location.pathname)"
097:                        + "</SCRIPT>"
098:                        + "</HEAD>"
099:                        + "<BODY>"
100:                        + "<P>This page tests the windows.location.pathname function.</P>"
101:                        + "</BODY>" + "</HTML>";
102:
103:                String lExpectation = "<HTML>"
104:                        + "<HEAD>"
105:                        + "<TITLE>JavaScript Test</TITLE>"
106:                        + JSWrapperHelper.CONVERT_SYSTEM_FUNCTION_HTML
107:                        + "<SCRIPT LANGUAGE=\"JAVASCRIPT\">"
108:                        + "alert( \"pathname: \" + "
109:                        + JSWrapperHelper.CONVERT_SYSTEM_FUNCTION_WRAP_START
110:                        + "window.location, 'window.location.pathname', window.location.pathname))"
111:                        + "</SCRIPT>"
112:                        + "</HEAD>"
113:                        + "<BODY>"
114:                        + "<P>This page tests the windows.location.pathname function.</P>"
115:                        + "</BODY>" + "</HTML>";
116:
117:                String lRule = "<Variable name=\"window.location.pathname\" type=\"SYSTEM\"/>"; //jsvar rule
118:
119:                RuleSet lRuleSet = CreateRuleSet.withJSVariableRules(lRule);
120:                Rewriter lRewriter = RewriterPool.create(lRuleSet,
121:                        LanguageConstants.HTML_MIME);
122:                String lResult = lRewriter.rewrite(lInput,
123:                        getDefaultTranslator());
124:                assertEquals("Failed: ", lExpectation, lResult);
125:            }//testSystemVariableInAlert()
126:
127:            public void testSystemVariableInBody() throws Exception {
128:                String lInput = "<HTML>"
129:                        + "<HEAD>"
130:                        + "<TITLE>Second window.open.pathname rewriter Test</TITLE>"
131:                        + "</HEAD>"
132:                        + "<BODY onLoad=\"alert( 'window.location.pathname : ' + window.location.pathname )\";>"
133:                        + "</BODY>" + "<HTML>";
134:
135:                String lExpectation = "<HTML>"
136:                        + "<HEAD>"
137:                        + "<TITLE>Second window.open.pathname rewriter Test</TITLE>"
138:                        + "</HEAD>"
139:                        + JSWrapperHelper.CONVERT_SYSTEM_FUNCTION_HTML
140:                        + "<BODY onLoad=\"alert( 'window.location.pathname : ' + "
141:                        + JSWrapperHelper.CONVERT_SYSTEM_FUNCTION_WRAP_START
142:                        + "window.location, 'window.location.pathname', window.location.pathname) )\";>"
143:                        + "</BODY>" + "<HTML>";
144:
145:                String lHTMLJSTokenRules = "<Attribute name=\"onLoad\" type=\"DJS\"/>";
146:                String lJSVariableRules = "<Variable name=\"window*lo*cation.pathn*ame\" type=\"SYSTEM\"/>";
147:
148:                RuleSet lRuleSet = CreateRuleSet
149:                        .withHTMLJSTokenJSVarJSFunRules(lHTMLJSTokenRules,
150:                                lJSVariableRules, "");
151:                Rewriter lRewriter = RewriterPool.create(lRuleSet,
152:                        LanguageConstants.HTML_MIME);
153:                String lResult = lRewriter.rewrite(lInput,
154:                        getDefaultTranslator());
155:                assertEquals("Failed: ", lExpectation, lResult);
156:            }//testSystemVariableInBody()
157:
158:            public void testSystemVariableInBodyTwo() throws Exception {
159:                String lInput = "<HTML>"
160:                        + "<HEAD>"
161:                        + "<TITLE>Second window.open.pathname rewriter Test</TITLE>"
162:                        + "</HEAD>"
163:                        + "<img onLoad=\"alert( 'window.location.pathname : ' + window.location.pathname )\";>"
164:                        + "<BODY onLoad=\"alert( 'window.location.pathname : ' + window.location.pathname )\";>"
165:                        + "</BODY>" + "<HTML>";
166:
167:                String lExpectation = "<HTML>"
168:                        + "<HEAD>"
169:                        + "<TITLE>Second window.open.pathname rewriter Test</TITLE>"
170:                        + "</HEAD>"
171:                        + JSWrapperHelper.CONVERT_SYSTEM_FUNCTION_HTML
172:                        + "<img onLoad=\"alert( 'window.location.pathname : ' + "
173:                        + JSWrapperHelper.CONVERT_SYSTEM_FUNCTION_WRAP_START
174:                        + "window.location, 'window.location.pathname', window.location.pathname) )\";>"
175:                        + "<BODY onLoad=\"alert( 'window.location.pathname : ' + "
176:                        + JSWrapperHelper.CONVERT_SYSTEM_FUNCTION_WRAP_START
177:                        + "window.location, 'window.location.pathname', window.location.pathname) )\";>"
178:                        + "</BODY>" + "<HTML>";
179:
180:                String lHTMLJSTokenRules = "<Attribute name=\"onLoad\" type=\"DJS\"/>";
181:                String lJSVariableRules = "<Variable name=\"window*lo*cation.pathn*ame\" type=\"SYSTEM\"/>";
182:
183:                RuleSet lRuleSet = CreateRuleSet
184:                        .withHTMLJSTokenJSVarJSFunRules(lHTMLJSTokenRules,
185:                                lJSVariableRules, "");
186:                Rewriter lRewriter = RewriterPool.create(lRuleSet,
187:                        LanguageConstants.HTML_MIME);
188:                String lResult = lRewriter.rewrite(lInput,
189:                        getDefaultTranslator());
190:                assertEquals("Failed: ", lExpectation, lResult);
191:            }//testSystemVariableInBodyTwo()
192:
193:            public void testSystemAndExpressionVariables() throws Exception {
194:                String lInput = "<HTML>"
195:                        + "<HEAD>"
196:                        + "<TITLE>Second window.open.pathname rewriter Test</TITLE>"
197:                        + "</HEAD>"
198:                        + "<BODY onLoad=\"alert( 'window.location.pathname : ' + window.location.pathname )\";>"
199:                        + "<img src=\"\" onSubmit = 'var ab = top.location + \"./abc.html\";' />"
200:                        + "<img src=\"\" onSubmit = 'var ab = top.location + \"./abc.html\";' />"
201:                        + "</BODY>" + "<HTML>";
202:
203:                String lExpectation = "<HTML>"
204:                        + "<HEAD>"
205:                        + "<TITLE>Second window.open.pathname rewriter Test</TITLE>"
206:                        + "</HEAD>"
207:                        + JSWrapperHelper.CONVERT_ALL_FUNCTIONS_HTML
208:                        + "<BODY onLoad=\"alert( 'window.location.pathname : ' + "
209:                        + JSWrapperHelper.CONVERT_SYSTEM_FUNCTION_WRAP_START
210:                        + "window.location, 'window.location.pathname', window.location.pathname) )\";>"
211:                        + "<img src=\"\" onSubmit = 'var ab ="
212:                        + JSWrapperHelper.CONVERT_EXPRESSION_FUNCTION_WRAP_START
213:                        + " top.location + \"./abc.html\");' />"
214:                        + "<img src=\"\" onSubmit = 'var ab ="
215:                        + JSWrapperHelper.CONVERT_EXPRESSION_FUNCTION_WRAP_START
216:                        + " top.location + \"./abc.html\");' />" + "</BODY>"
217:                        + "<HTML>";
218:
219:                String lHTMLJSTokenRules = "<Attribute name=\"onLoad\" type=\"DJS\"/>"
220:                        + "<Attribute name=\"onSu*\" type=\"DJS\"/>";
221:                String lJSVariableRules = "<Variable name=\"*a*\" type=\"EXPRESSION\"/>"
222:                        + "<Variable name=\"window*lo*cation.pathn*ame\" type=\"SYSTEM\"/>";
223:
224:                RuleSet lRuleSet = CreateRuleSet
225:                        .withHTMLJSTokenJSVarJSFunRules(lHTMLJSTokenRules,
226:                                lJSVariableRules, "");
227:                Rewriter lRewriter = RewriterPool.create(lRuleSet,
228:                        LanguageConstants.HTML_MIME);
229:                String lResult = lRewriter.rewrite(lInput,
230:                        getDefaultTranslator());
231:                assertEquals("Failed: ", lExpectation, lResult);
232:            }//testSystemAndExpressionVariables()
233:
234:            public void testSystemAndExpressionVariablesPureJS()
235:                    throws Exception {
236:                String lInput = "alert( 'window.location.pathname : ' + window.location.pathname );"
237:                        + "var ab = top.location + \"./abc.html\";"
238:                        + "var ab = top.location + \"./abc.html\";";
239:
240:                String lExpectation = "alert( 'window.location.pathname : ' + "
241:                        + JSWrapperHelper.CONVERT_SYSTEM_FUNCTION_WRAP_START
242:                        + "window.location, 'window.location.pathname', window.location.pathname) );"
243:                        + "var ab ="
244:                        + JSWrapperHelper.CONVERT_EXPRESSION_FUNCTION_WRAP_START
245:                        + " top.location + \"./abc.html\");"
246:                        + "var ab ="
247:                        + JSWrapperHelper.CONVERT_EXPRESSION_FUNCTION_WRAP_START
248:                        + " top.location + \"./abc.html\");"
249:                        + JSWrapperHelper.CONVERT_ALL_FUNCTIONS_JS;
250:
251:                String lHTMLJSTokenRules = "<Attribute name=\"onLoad\" type=\"DJS\"/>"
252:                        + "<Attribute name=\"onSu*\" type=\"DJS\"/>";
253:                String lJSVariableRules = "<Variable name=\"*a*\" type=\"EXPRESSION\"/>"
254:                        + "<Variable name=\"window*lo*cation.pathn*ame\" type=\"SYSTEM\"/>";
255:
256:                RuleSet lRuleSet = CreateRuleSet
257:                        .withHTMLJSTokenJSVarJSFunRules(lHTMLJSTokenRules,
258:                                lJSVariableRules, "");
259:                Rewriter lRewriter = RewriterPool.create(lRuleSet,
260:                        LanguageConstants.JS_MIME);
261:                String lResult = lRewriter.rewrite(lInput,
262:                        getDefaultTranslator());
263:                assertEquals("Failed: ", lExpectation, lResult);
264:            }//testSystemAndExpressionVariablesPureJS()
265:
266:            public void testRHSLHSOnSystemVar() throws Exception {
267:                String lInput = "<SCRIPT LANGUAGE=\"Javascript\"> " + "<!--\n"
268:                        + "    if (top.location != document.location) "
269:                        + "    {\n" + "	top1.location=document.location;"
270:                        + "	top2.location+=document.location;"
271:                        + "	top3.location	-=document.location;"
272:                        + "	top4.location\n	-=document.location;"
273:                        + "       top.location.replace(document.location);\n"
274:                        + "    }\n" + "//-->" + "</SCRIPT>\n";
275:
276:                String lExpectation = JSWrapperHelper.CONVERT_ALL_FUNCTIONS_HTML
277:                        + "<SCRIPT LANGUAGE=\"Javascript\"> "
278:                        + "<!--\n"
279:                        + "    if ("
280:                        + JSWrapperHelper.CONVERT_SYSTEM_FUNCTION_WRAP_START
281:                        + "top, 'top.location', top.location) != "
282:                        + JSWrapperHelper.CONVERT_SYSTEM_FUNCTION_WRAP_START
283:                        + "document, 'document.location', document.location)) "
284:                        + "    {\n"
285:                        + "	top1.location="
286:                        + JSWrapperHelper.CONVERT_EXPRESSION_FUNCTION_WRAP_START
287:                        + JSWrapperHelper.CONVERT_SYSTEM_FUNCTION_WRAP_START
288:                        + "document, 'document.location', document.location));"
289:                        + "	top2.location+="
290:                        + JSWrapperHelper.CONVERT_SYSTEM_FUNCTION_WRAP_START
291:                        + "document, 'document.location', document.location);"
292:                        + "	top3.location	-="
293:                        + JSWrapperHelper.CONVERT_SYSTEM_FUNCTION_WRAP_START
294:                        + "document, 'document.location', document.location);"
295:                        + "	top4.location\n	-="
296:                        + JSWrapperHelper.CONVERT_SYSTEM_FUNCTION_WRAP_START
297:                        + "document, 'document.location', document.location);"
298:                        + "       top.location.replace("
299:                        + JSWrapperHelper.CONVERT_SYSTEM_FUNCTION_WRAP_START
300:                        + "document, 'document.location', document.location));\n"
301:                        + "    }\n" + "//-->" + "</SCRIPT>\n";
302:
303:                String lJSVariableRules = "<Variable name=\"*location\" type=\"EXPRESSION\"/>"
304:                        + "<Variable name=\"*location\" type=\"SYSTEM\"/>";
305:
306:                RuleSet lRuleSet = CreateRuleSet
307:                        .withJSVariableRules(lJSVariableRules);
308:                Rewriter lRewriter = RewriterPool.create(lRuleSet,
309:                        LanguageConstants.HTML_MIME);
310:                String lResult = lRewriter.rewrite(lInput,
311:                        getDefaultTranslator());
312:                assertEquals("Failed: ", lExpectation, lResult);
313:            }//testRHSLHSOnSystemVar()
314:
315:            public void testIgnoreFunctionCallsMatchSystemRules()
316:                    throws Exception {
317:                String lInput = "var found = url.search();\n"
318:                        + "var found = url[1].search;\n"
319:                        + "var found = url.search(re).search;\n"
320:                        + "var found = search().search;\n"
321:                        + "var found = url.search(re);\n"
322:                        + "var found = url.search(ab + ab.search());\n"
323:                        + "var found = url.search(ab + ab.search);\n"
324:                        + "var found = url.search;\n";
325:
326:                String lExpectation = "var found = url.search();\n"
327:                        + "var found = "
328:                        + JSWrapperHelper.CONVERT_SYSTEM_FUNCTION_WRAP_START
329:                        + "url[1], 'url[1].search', url[1].search);\n"
330:                        + "var found = url.search(re).search;\n"
331:                        + "var found = "
332:                        + JSWrapperHelper.CONVERT_SYSTEM_FUNCTION_WRAP_START
333:                        + "search(), 'search().search', search().search);\n"
334:                        + "var found = url.search(re);\n"
335:                        + "var found = url.search(ab + ab.search());\n"
336:                        + "var found = url.search(ab + "
337:                        + JSWrapperHelper.CONVERT_SYSTEM_FUNCTION_WRAP_START
338:                        + "ab, 'ab.search', ab.search));\n" + "var found = "
339:                        + JSWrapperHelper.CONVERT_SYSTEM_FUNCTION_WRAP_START
340:                        + "url, 'url.search', url.search);\n"
341:                        + JSWrapperHelper.CONVERT_SYSTEM_FUNCTION_JS;
342:
343:                String lJSVariableRules = "<Variable name=\"*.search\" type=\"SYSTEM\"/>";
344:
345:                RuleSet lRuleSet = CreateRuleSet
346:                        .withJSVariableRules(lJSVariableRules);
347:                Rewriter lRewriter = RewriterPool.create(lRuleSet,
348:                        LanguageConstants.JS_MIME);
349:                String lResult = lRewriter.rewrite(lInput,
350:                        getDefaultTranslator());
351:                assertEquals(lExpectation, lResult);
352:            }//testIgnoreFunctionCallsMatchSystemRules()
353:
354:            public void testSYSTEMVarAssignment() throws Exception {
355:                String lInput = "function setLocation()\n"
356:                        + "{\n"
357:                        + "	window.location.pathname = \"xsession.html\";\n"
358:                        + "	var a = window.location.pathname + \"xsession.html\";\n"
359:                        + "}\n";
360:
361:                String lExpectation = "function setLocation()\n"
362:                        + "{\n"
363:                        + "	window.location.pathname = \"xsession.html\";\n"
364:                        + "	var a = "
365:                        + JSWrapperHelper.CONVERT_SYSTEM_FUNCTION_WRAP_START
366:                        + "window.location, 'window.location.pathname', window.location.pathname) + \"xsession.html\";\n"
367:                        + "}\n" + JSWrapperHelper.CONVERT_SYSTEM_FUNCTION_JS;
368:
369:                String lJSVariableRules = "<Variable name=\"*.location.pathname\" type=\"SYSTEM\"/>";
370:
371:                RuleSet lRuleSet = CreateRuleSet
372:                        .withJSVariableRules(lJSVariableRules);
373:                Rewriter lRewriter = RewriterPool.create(lRuleSet,
374:                        LanguageConstants.JS_MIME);
375:                String lResult = lRewriter.rewrite(lInput,
376:                        getDefaultTranslator());
377:                assertEquals(lExpectation, lResult);
378:            }//testSYSTEMVarAssignment()
379:
380:            public void testSYSTEMVarWithSystemAndExpressionRules()
381:                    throws Exception {
382:                String lInput = "function setLocation()\n"
383:                        + "{\n"
384:                        + "	var a = location + \"xsession.html\";\n"
385:                        + "	window.location.pathname = ab + \"xsession.html\";\n"
386:                        + "	window.location.pathname = \"xsession.html\";\n"
387:                        + "	var a = window.location.pathname + \"xsession.html\";\n"
388:                        + "	var a = location + \"xsession.html\";\n" + "}\n";
389:
390:                String lExpectation = "function setLocation()\n"
391:                        + "{\n"
392:                        + "	var a = "
393:                        + JSWrapperHelper.CONVERT_SYSTEM_FUNCTION_WRAP_START
394:                        + "null, 'location', location) + \"xsession.html\";\n"
395:                        + "	window.location.pathname ="
396:                        + JSWrapperHelper.CONVERT_EXPRESSION_FUNCTION_WRAP_START
397:                        + " ab + \"xsession.html\");\n"
398:                        + "	window.location.pathname = \"http://rajanagendra.sun.com/Base/Raja/xsession.html\";\n"
399:                        + "	var a = "
400:                        + JSWrapperHelper.CONVERT_SYSTEM_FUNCTION_WRAP_START
401:                        + "window.location, 'window.location.pathname', window.location.pathname) + \"xsession.html\";\n"
402:                        + "	var a = "
403:                        + JSWrapperHelper.CONVERT_SYSTEM_FUNCTION_WRAP_START
404:                        + "null, 'location', location) + \"xsession.html\";\n"
405:                        + "}\n" + JSWrapperHelper.CONVERT_ALL_FUNCTIONS_JS;
406:
407:                String[] lJSVariableRules = {
408:                        "<Variable name=\"*location\" type=\"SYSTEM\"/>"
409:                                + "<Variable name=\"*location.pathname\"/>"
410:                                + "<Variable name=\"*location.pathname\" type=\"SYSTEM\"/>",
411:
412:                        "<Variable name=\"location\" type=\"SYSTEM\"/>"
413:                                + "<Variable name=\"*.location.pathname\"/>"
414:                                + "<Variable name=\"*.location.pathname\" type=\"SYSTEM\"/>",
415:
416:                        "<Variable name=\"loc*tion\" type=\"SYSTEM\"/>"
417:                                + "<Variable name=\"*.pathname\"/>"
418:                                + "<Variable name=\"*.pathname\" type=\"SYSTEM\"/>",
419:
420:                        "<Variable name=\"location\" type=\"SYSTEM\"/>"
421:                                + "<Variable name=\"*pathname\"/>"
422:                                + "<Variable name=\"*pathname\" type=\"SYSTEM\"/>", };
423:
424:                for (int i = 0; i < lJSVariableRules.length; i++) {
425:                    RuleSet lRuleSet = CreateRuleSet
426:                            .withJSVariableRules(lJSVariableRules[i]);
427:                    Rewriter lRewriter = RewriterPool.create(lRuleSet,
428:                            LanguageConstants.JS_MIME);
429:                    String lResult = lRewriter.rewrite(lInput,
430:                            getDefaultTranslator());
431:                    assertEquals("Failed: ", lExpectation, lResult);
432:                }
433:            }//testSYSTEMVarWithSystemAndExpressionRules()
434:
435:            public void testSYSTEMVarAssinmentCaseFromPortal() throws Exception {
436:                String lInput = "<!-- @(#)xsession_start.html 2.1     98/08/17 Copyright (c) 1998 i-Planet, Inc., All rights reserved.  -->\n"
437:                        + "<HTML><HEAD>\n"
438:                        + "<title>X Session</title>\n"
439:                        + "</HEAD>\n"
440:                        + "\n"
441:                        + "<script archive=\"rp_xsession.jar\" id=1>\n"
442:                        + "</script>\n"
443:                        + "\n"
444:                        + "<BODY id=2 onload=\"setSize();setLocation()\">\n"
445:                        + "\n"
446:                        + "<script LANGUAGE=JavaScript1.2 id=3>\n"
447:                        + "function setSize()\n"
448:                        + "{\n"
449:                        + "\n"
450:                        + "	var myWidth=100;\n"
451:                        + "	var myHeight=100;\n"
452:                        + "\n"
453:                        + "	if (navigator.appName == \"Netscape\")\n"
454:                        + "	{\n"
455:                        + "		wFac = 0.80;\n"
456:                        + "		hFac = 0.80;\n"
457:                        + "	}\n"
458:                        + "	else\n"
459:                        + "	{\n"
460:                        + "		// because Windows seems to size the browser so differently!\n"
461:                        + "		wFac = 0.80;\n"
462:                        + "		hFac = 0.85;\n"
463:                        + "	}\n"
464:                        + "	myWidth = Math.ceil(screen.availWidth * wFac);\n"
465:                        + "	myHeight = Math.ceil(screen.availHeight * hFac);\n"
466:                        + "	self.resizeTo(myWidth,myHeight);\n"
467:                        + "}\n"
468:                        + "function setLocation()\n"
469:                        + "{\n"
470:                        + "	window.location.pathname = \"xsession.html\";\n"
471:                        + "}\n"
472:                        + "\n"
473:                        + "</script>\n"
474:                        + "\n"
475:                        + "</body>\n"
476:                        + "</html>\n";
477:
478:                String lJSVariableRules = "<Variable name=\"*.location.pathname\" type=\"SYSTEM\"/>";
479:
480:                RuleSet lRuleSet = CreateRuleSet
481:                        .withJSVariableRules(lJSVariableRules);
482:                Rewriter lRewriter = RewriterPool.create(lRuleSet,
483:                        LanguageConstants.JS_MIME);
484:                String lResult = lRewriter.rewrite(lInput,
485:                        getDefaultTranslator());
486:                assertEquals("Failed: ", lInput, lResult);
487:            }//testSYSTEMVarAssinmentCaseFromPortal()
488:
489:            public static void main(String[] args) {
490:                BasicTestCase.run(TestJSSystemVariables.class);
491:
492:                TestSuite testSuite = new TestSuite();
493:                testSuite.addTest(new TestJSSystemVariables(
494:                        "testSYSTEMVarAssinmentCaseFromPortal"));
495:                //BasicTestCase.run( testSuite );
496:            }//main()
497:
498:        }//class TestJSSystemVariables
ww__w_.ja__v__a__2s___.__c___om_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.