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 junit.framework.TestSuite;
015:
016: public class TestJSGeneralThree extends BasicTestCase {
017: public TestJSGeneralThree(String aName) {
018: super (aName);
019: }//constuctor
020:
021: public void testBugNo4896278HTMLCommentsInJS() throws Exception {
022: String lInput = "<html>\n"
023: + "<head></head>\n"
024: + "<body>\n"
025: + "Welcome v1\n"
026: + "<SCRIPT language=javaScript>\n"
027: + "// Comment\n"
028: + " var messageImageURL = '/snd/hi/images/logo_sun.gif';\n"
029: + "<!-- Comment -->\n"
030: + "\n"
031: + " function getWelcomeMsg(){\n"
032: + " return \"<img src='\" + messageImageURL + \" ' align='absbottom' alt='Welcome to connect'>\";\n"
033: + " }\n" + "\n"
034: + " document.write(getWelcomeMsg());\n"
035: + "var abc = 'abc.html'\n" + "</SCRIPT>\n" + "\n"
036: + "</body>\n" + "</html> \n";
037:
038: String lExpectation = "<html>\n"
039: + "<head></head>\n"
040: + "<body>\n"
041: + "Welcome v1\n"
042: + "<SCRIPT language=javaScript>\n"
043: + "// Comment\n"
044: + " var messageImageURL = 'http://rajanagendra.sun.com/snd/hi/images/logo_sun.gif';\n"
045: + "<!-- Comment -->\n"
046: + "\n"
047: + " function getWelcomeMsg(){\n"
048: + " return \"<img src='\" + messageImageURL + \" ' align='absbottom' alt='Welcome to connect'>\";\n"
049: + " }\n"
050: + "\n"
051: + " document.write(getWelcomeMsg());\n"
052: + "var abc = 'http://rajanagendra.sun.com/Base/Raja/abc.html'\n"
053: + "</SCRIPT>\n" + "\n" + "</body>\n" + "</html> \n";
054:
055: String lHTMLAttRules = "<Attribute name=\"href\"/>"
056: + "<Attribute name=\"src\"/>";
057:
058: String lJSVarRules = "<Variable name=\"messageImageURL;abc\" type=\"URL\"/>";
059:
060: String lJSFunRules = "<Function type=\"DHTML\" name=\"document.write\" paramPatterns=\"y\"/>";
061:
062: RuleSet lRuleSet = CreateRuleSet.withHTMLAttJSVarJSFunRules(
063: lHTMLAttRules, lJSVarRules, lJSFunRules);
064: Rewriter lRewriter = RewriterPool.create(lRuleSet,
065: LanguageConstants.HTML_MIME);
066: String lResult = lRewriter.rewrite(lInput,
067: getDefaultTranslator());
068: assertEquals(lExpectation, lResult);
069: }//testBugNo4896278HTMLCommentsInJS()
070:
071: public void testBugNo4896278HTMLCommentsInJSVarient()
072: throws Exception {
073: String lInput = "<html>\n"
074: + "<head></head>\n"
075: + "<body>\n"
076: + "Welcome v1\n"
077: + "<SCRIPT language=javaScript>\n"
078: + "<!-- Comment -->\n"
079: + " var messageImageURL = '/snd/hi/images/logo_sun.gif';\n"
080: + "<!-- Comment -->\n"
081: + "\n"
082: + " function getWelcomeMsg(){\n"
083: + " return \"<img src='\" + messageImageURL + \" ' align='absbottom' alt='Welcome to connect'>\";\n"
084: + " }\n" + "\n"
085: + " document.write(getWelcomeMsg());\n"
086: + " abc =\"abc.js\"\n" + "</SCRIPT>\n" + "\n"
087: + "</body>\n" + "</html> \n";
088:
089: String lExpectation = "<html>\n"
090: + "<head></head>\n"
091: + "<body>\n"
092: + "Welcome v1\n"
093: + "<SCRIPT language=javaScript>\n"
094: + "<!-- Comment -->\n"
095: + " var messageImageURL = 'http://rajanagendra.sun.com/snd/hi/images/logo_sun.gif';\n"
096: + "<!-- Comment -->\n"
097: + "\n"
098: + " function getWelcomeMsg(){\n"
099: + " return \"<img src='\" + messageImageURL + \" ' align='absbottom' alt='Welcome to connect'>\";\n"
100: + " }\n"
101: + "\n"
102: + " document.write(getWelcomeMsg());\n"
103: + " abc =\"http://rajanagendra.sun.com/Base/Raja/abc.js\"\n"
104: + "</SCRIPT>\n" + "\n" + "</body>\n" + "</html> \n";
105:
106: String lHTMLAttRules = "<Attribute name=\"href\"/>"
107: + "<Attribute name=\"src\"/>";
108:
109: String lJSVarRules = "<Variable name=\"abc;messageImageURL;\" type=\"URL\"/>";
110:
111: String lJSFunRules = "<Function type=\"DHTML\" name=\"document.write\" paramPatterns=\"y\"/>";
112:
113: RuleSet lRuleSet = CreateRuleSet.withHTMLAttJSVarJSFunRules(
114: lHTMLAttRules, lJSVarRules, lJSFunRules);
115: Rewriter lRewriter = RewriterPool.create(lRuleSet,
116: LanguageConstants.HTML_MIME);
117: String lResult = lRewriter.rewrite(lInput,
118: getDefaultTranslator());
119: assertEquals(lExpectation, lResult);
120: }//testBugNo4896278HTMLCommentsInJSVarient()
121:
122: public void testBugNo4896278HTMLCommentsInJSVarient1()
123: throws Exception {
124: String lInput = "<html>\n"
125: + "<head></head>\n"
126: + "<body>\n"
127: + "Welcome v1\n"
128: + "<SCRIPT language=javaScript>\n"
129: + "//<!-- Comment -->\n"
130: + " var messageImageURL = '/snd/hi/images/logo_sun.gif';\n"
131: + "//<!-- Comment -->\n"
132: + "\n"
133: + " function getWelcomeMsg(){\n"
134: + " return \"<img src='\" + messageImageURL + \" ' align='absbottom' alt='Welcome to connect'>\";\n"
135: + " }\n" + "\n"
136: + " document.write(getWelcomeMsg());\n"
137: + " abc =\"abc.js\"\n" + "</SCRIPT>\n" + "\n"
138: + "</body>\n" + "</html> \n";
139:
140: String lExpectation = "<html>\n"
141: + "<head></head>\n"
142: + "<body>\n"
143: + "Welcome v1\n"
144: + "<SCRIPT language=javaScript>\n"
145: + "//<!-- Comment -->\n"
146: + " var messageImageURL = 'http://rajanagendra.sun.com/snd/hi/images/logo_sun.gif';\n"
147: + "//<!-- Comment -->\n"
148: + "\n"
149: + " function getWelcomeMsg(){\n"
150: + " return \"<img src='\" + messageImageURL + \" ' align='absbottom' alt='Welcome to connect'>\";\n"
151: + " }\n"
152: + "\n"
153: + " document.write(getWelcomeMsg());\n"
154: + " abc =\"http://rajanagendra.sun.com/Base/Raja/abc.js\"\n"
155: + "</SCRIPT>\n" + "\n" + "</body>\n" + "</html> \n";
156:
157: String lHTMLAttRules = "<Attribute name=\"href;srC\"/>";
158:
159: String lJSVarRules = "<Variable name=\"abc;messageImageURL;\" type=\"URL\"/>";
160:
161: String lJSFunRules = "<Function type=\"DHTML\" name=\"document.write\" paramPatterns=\"y\"/>";
162:
163: RuleSet lRuleSet = CreateRuleSet.withHTMLAttJSVarJSFunRules(
164: lHTMLAttRules, lJSVarRules, lJSFunRules);
165: Rewriter lRewriter = RewriterPool.create(lRuleSet,
166: LanguageConstants.HTML_MIME);
167: String lResult = lRewriter.rewrite(lInput,
168: getDefaultTranslator());
169: assertEquals(lExpectation, lResult);
170: }//testBugNo4896278HTMLCommentsInJSVarient1()
171:
172: public void testBugNo4896278HTMLCommentsInJSVarient2()
173: throws Exception {
174: String lInput = "<html>\n"
175: + "<head></head>\n"
176: + "<body>\n"
177: + "Welcome v1\n"
178: + "<SCRIPT language=javaScript>\n"
179: + "<!-- Comment -->\n"
180: + " var messageImageURL = '/snd/hi/images/logo_sun.gif';\n"
181: + "//<!-- Comment -->\n"
182: + "\n"
183: + " function getWelcomeMsg(){\n"
184: + " return \"<img src='\" + messageImageURL + \" ' align='absbottom' alt='Welcome to connect'>\";\n"
185: + " }\n" + "\n"
186: + " document.write(getWelcomeMsg());\n"
187: + " abc =\"abc.js\"\n" + "</SCRIPT>\n" + "\n"
188: + "</body>\n" + "</html> \n";
189:
190: String lExpectation = "<html>\n"
191: + "<head></head>\n"
192: + "<body>\n"
193: + "Welcome v1\n"
194: + "<SCRIPT language=javaScript>\n"
195: + "<!-- Comment -->\n"
196: + " var messageImageURL = 'http://rajanagendra.sun.com/snd/hi/images/logo_sun.gif';\n"
197: + "//<!-- Comment -->\n"
198: + "\n"
199: + " function getWelcomeMsg(){\n"
200: + " return \"<img src='\" + messageImageURL + \" ' align='absbottom' alt='Welcome to connect'>\";\n"
201: + " }\n"
202: + "\n"
203: + " document.write(getWelcomeMsg());\n"
204: + " abc =\"http://rajanagendra.sun.com/Base/Raja/abc.js\"\n"
205: + "</SCRIPT>\n" + "\n" + "</body>\n" + "</html> \n";
206:
207: String lHTMLAttRules = "<Attribute name=\"hREf;srC\"/>";
208:
209: String lJSVarRules = "<Variable name=\"abc;messageImageURL;\" type=\"URL\"/>";
210:
211: String lJSFunRules = "<Function type=\"DHTML\" name=\"document.write\" paramPatterns=\"y\"/>";
212:
213: RuleSet lRuleSet = CreateRuleSet.withHTMLAttJSVarJSFunRules(
214: lHTMLAttRules, lJSVarRules, lJSFunRules);
215: Rewriter lRewriter = RewriterPool.create(lRuleSet,
216: LanguageConstants.HTML_MIME);
217: String lResult = lRewriter.rewrite(lInput,
218: getDefaultTranslator());
219: assertEquals(lExpectation, lResult);
220: }//testHTMLCommentsInJSVarient2()
221:
222: public void testBugNo4896278HTMLCommentsInJSVarient3()
223: throws Exception {
224: String lInput = "<html>\n"
225: + "<head></head>\n"
226: + "<body>\n"
227: + "Welcome v1\n"
228: + "<SCRIPT language=javaScript>\n"
229: + "//<!-- Comment -->\n"
230: + " var messageImageURL = '/snd/hi/images/logo_sun.gif';\n"
231: + "<!-- Comment -->\n"
232: + "\n"
233: + " function getWelcomeMsg(){\n"
234: + " return \"<img src='\" + messageImageURL + \" ' align='absbottom' alt='Welcome to connect'>\";\n"
235: + " }\n" + "\n"
236: + " document.write(getWelcomeMsg());\n"
237: + " abc =\"abc.js\"\n" + "</SCRIPT>\n" + "\n"
238: + "</body>\n" + "</html> \n";
239:
240: String lExpectation = "<html>\n"
241: + "<head></head>\n"
242: + "<body>\n"
243: + "Welcome v1\n"
244: + "<SCRIPT language=javaScript>\n"
245: + "//<!-- Comment -->\n"
246: + " var messageImageURL = 'http://rajanagendra.sun.com/snd/hi/images/logo_sun.gif';\n"
247: + "<!-- Comment -->\n"
248: + "\n"
249: + " function getWelcomeMsg(){\n"
250: + " return \"<img src='\" + messageImageURL + \" ' align='absbottom' alt='Welcome to connect'>\";\n"
251: + " }\n"
252: + "\n"
253: + " document.write(getWelcomeMsg());\n"
254: + " abc =\"http://rajanagendra.sun.com/Base/Raja/abc.js\"\n"
255: + "</SCRIPT>\n" + "\n" + "</body>\n" + "</html> \n";
256:
257: String lHTMLAttRules = "<Attribute name=\"hREf;srC\"/>";
258:
259: String lJSVarRules = "<Variable name=\"abc;messageImageURL;\" type=\"URL\"/>";
260:
261: String lJSFunRules = "<Function type=\"DHTML\" name=\"document.write\" paramPatterns=\"y\"/>";
262:
263: RuleSet lRuleSet = CreateRuleSet.withHTMLAttJSVarJSFunRules(
264: lHTMLAttRules, lJSVarRules, lJSFunRules);
265: Rewriter lRewriter = RewriterPool.create(lRuleSet,
266: LanguageConstants.HTML_MIME);
267: String lResult = lRewriter.rewrite(lInput,
268: getDefaultTranslator());
269: assertEquals(lExpectation, lResult);
270: }//testBugNo4896278HTMLCommentsInJSVarient3()
271:
272: public void testBugNo4896278HTMLCommentsInJScase1()
273: throws Exception {
274: String lInput = "<html>\n"
275: + "<head></head>\n"
276: + "<body>\n"
277: + "Welcome v1\n"
278: + "<SCRIPT language=javaScript>\n"
279: + "<!-- Comment -->\n"
280: + " var messageImageURL = '/snd/hi/images/logo_sun.gif';\n"
281: + "</SCRIPT>\n" + "\n" + "</body>\n" + "</html> \n";
282:
283: String lExpectation = "<html>\n"
284: + "<head></head>\n"
285: + "<body>\n"
286: + "Welcome v1\n"
287: + "<SCRIPT language=javaScript>\n"
288: + "<!-- Comment -->\n"
289: + " var messageImageURL = 'http://rajanagendra.sun.com/snd/hi/images/logo_sun.gif';\n"
290: + "</SCRIPT>\n" + "\n" + "</body>\n" + "</html> \n";
291:
292: String lHTMLAttRules = "<Attribute name=\"hREf;srC\"/>";
293:
294: String lJSVarRules = "<Variable name=\"abc;messageImageURL;\" type=\"URL\"/>";
295:
296: String lJSFunRules = "<Function type=\"DHTML\" name=\"document.write\" paramPatterns=\"y\"/>";
297:
298: RuleSet lRuleSet = CreateRuleSet.withHTMLAttJSVarJSFunRules(
299: lHTMLAttRules, lJSVarRules, lJSFunRules);
300: Rewriter lRewriter = RewriterPool.create(lRuleSet,
301: LanguageConstants.HTML_MIME);
302: String lResult = lRewriter.rewrite(lInput,
303: getDefaultTranslator());
304: assertEquals(lExpectation, lResult);
305: }//testHTMLCommentsInJScase1()
306:
307: public void testBugNo4896278HTMLCommentsInJScase2()
308: throws Exception {
309: String lInput = "<html>\n"
310: + "<head></head>\n"
311: + "<body>\n"
312: + "Welcome v1\n"
313: + "<SCRIPT language=javaScript>\n"
314: + "<!-- Comment //-->\n"
315: + " var messageImageURL = '/snd/hi/images/logo_sun.gif';\n"
316: + "</SCRIPT>\n" + "\n" + "</body>\n" + "</html> \n";
317:
318: String lExpectation = "<html>\n"
319: + "<head></head>\n"
320: + "<body>\n"
321: + "Welcome v1\n"
322: + "<SCRIPT language=javaScript>\n"
323: + "<!-- Comment //-->\n"
324: + " var messageImageURL = 'http://rajanagendra.sun.com/snd/hi/images/logo_sun.gif';\n"
325: + "</SCRIPT>\n" + "\n" + "</body>\n" + "</html> \n";
326:
327: String lHTMLAttRules = "<Attribute name=\"hREf;srC\"/>";
328:
329: String lJSVarRules = "<Variable name=\"abc;messageImageURL;\" type=\"URL\"/>";
330:
331: String lJSFunRules = "<Function type=\"DHTML\" name=\"document.write\" paramPatterns=\"y\"/>";
332:
333: RuleSet lRuleSet = CreateRuleSet.withHTMLAttJSVarJSFunRules(
334: lHTMLAttRules, lJSVarRules, lJSFunRules);
335: Rewriter lRewriter = RewriterPool.create(lRuleSet,
336: LanguageConstants.HTML_MIME);
337: String lResult = lRewriter.rewrite(lInput,
338: getDefaultTranslator());
339: assertEquals(lExpectation, lResult);
340: }//testBugNo4896278HTMLCommentsInJScase2()
341:
342: public void testBugNo4896278HTMLCommentsInJScase3()
343: throws Exception {
344: String lInput = "<html>\n"
345: + "<head></head>\n"
346: + "<body>\n"
347: + "Welcome v1\n"
348: + "<SCRIPT language=javaScript>\n"
349: + "<!-- "
350: + "//Comment "
351: + "//-->\n"
352: + " var messageImageURL = '/snd/hi/images/logo_sun.gif';\n"
353: + "</SCRIPT>\n" + "\n" + "</body>\n" + "</html> \n";
354:
355: String lExpectation = "<html>\n"
356: + "<head></head>\n"
357: + "<body>\n"
358: + "Welcome v1\n"
359: + "<SCRIPT language=javaScript>\n"
360: + "<!-- "
361: + "//Comment "
362: + "//-->\n"
363: + " var messageImageURL = 'http://rajanagendra.sun.com/snd/hi/images/logo_sun.gif';\n"
364: + "</SCRIPT>\n" + "\n" + "</body>\n" + "</html> \n";
365:
366: String lHTMLAttRules = "<Attribute name=\"hREf;srC\"/>";
367:
368: String lJSVarRules = "<Variable name=\"abc;messageImageURL;\" type=\"URL\"/>";
369:
370: String lJSFunRules = "<Function type=\"DHTML\" name=\"document.write\" paramPatterns=\"y\"/>";
371:
372: RuleSet lRuleSet = CreateRuleSet.withHTMLAttJSVarJSFunRules(
373: lHTMLAttRules, lJSVarRules, lJSFunRules);
374: Rewriter lRewriter = RewriterPool.create(lRuleSet,
375: LanguageConstants.HTML_MIME);
376: String lResult = lRewriter.rewrite(lInput,
377: getDefaultTranslator());
378: assertEquals(lExpectation, lResult);
379: }//testBugNo4896278HTMLCommentsInJScase3()
380:
381: public void testBugNo4896278HTMLCommentsInJScase4()
382: throws Exception {
383: String lInput = "<html>\n"
384: + "<body>\n"
385: + "<SCRIPT language=javaScript>\n"
386: + "var hello;"
387: + "<!--Comment-->\n"
388: + " var messageImageURL = '/snd/hi/images/logo_sun.gif';\n"
389: + "</SCRIPT>\n" + "\n" + "</body>\n" + "</html> \n";
390:
391: String lExpectation = "<html>\n"
392: + "<body>\n"
393: + "<SCRIPT language=javaScript>\n"
394: + "var hello;"
395: + "<!--Comment-->\n"
396: + " var messageImageURL = 'http://rajanagendra.sun.com/snd/hi/images/logo_sun.gif';\n"
397: + "</SCRIPT>\n" + "\n" + "</body>\n" + "</html> \n";
398:
399: String lHTMLAttRules = "<Attribute name=\"hREf;srC\"/>";
400:
401: String lJSVarRules = "<Variable name=\"abc;messageImageURL;\" type=\"URL\"/>";
402:
403: String lJSFunRules = "<Function type=\"DHTML\" name=\"document.write\" paramPatterns=\"y\"/>";
404:
405: RuleSet lRuleSet = CreateRuleSet.withHTMLAttJSVarJSFunRules(
406: lHTMLAttRules, lJSVarRules, lJSFunRules);
407: Rewriter lRewriter = RewriterPool.create(lRuleSet,
408: LanguageConstants.HTML_MIME);
409: String lResult = lRewriter.rewrite(lInput,
410: getDefaultTranslator());
411: assertEquals(lExpectation, lResult);
412: }//testBugNo4896278HTMLCommentsInJScase4()
413:
414: public static void main(String[] args) {
415: RewriterModule.initFile();
416: BasicTestCase.run(TestJSGeneralThree.class);
417: TestSuite testSuite = new TestSuite();
418: testSuite.addTest(new TestJSGeneralThree(
419: "testHTMLCommentsInJScase1"));
420: //BasicTestCase.run( testSuite );
421: }//main()
422:
423: }//class TestJSGeneralThree
|