1 /* 2 * Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @bug 4665566 4855876 8012375 8015998 8024756 8151921 27 * @summary Verify that the output has the right javascript. 28 * @author jamieh 29 * @library ../lib/ 30 * @build JavadocTester 31 * @build TestJavascript 32 * @run main TestJavascript 33 */ 34 35 public class TestJavascript extends JavadocTester { 36 37 //Test information. 38 private static final String BUG_ID = "4665566-4855876-8012375"; 39 40 //Javadoc arguments. 41 private static final String[] ARGS = new String[] { 42 "-d", BUG_ID, "-sourcepath", SRC_DIR, "pkg", SRC_DIR + FS + "TestJavascript.java" 43 }; 44 45 //Input for string search tests. 46 private static final String[][] TEST = { 47 {BUG_ID + FS + "pkg" + FS + "C.html", 48 "<a href=\"../index.html?pkg/C.html\" target=\"_top\">FRAMES</a>"}, 49 {BUG_ID + FS + "TestJavascript.html", 50 "<a href=\"index.html?TestJavascript.html\" target=\"_top\">FRAMES</a>"}, 51 {BUG_ID + FS + "index.html", 52 "<script type=\"text/javascript\">" + NL + 53 " tmpTargetPage = \"\" + window.location.search;" + NL + 54 " if (tmpTargetPage != \"\" && tmpTargetPage != \"undefined\")" + NL + 55 " tmpTargetPage = tmpTargetPage.substring(1);" + NL + 56 " if (tmpTargetPage.indexOf(\":\") != -1 || (tmpTargetPage != \"\" && !validURL(tmpTargetPage)))" + NL + 57 " tmpTargetPage = \"undefined\";" + NL + 58 " targetPage = tmpTargetPage;" + NL + 59 " function validURL(url) {" + NL + 60 " var pos = url.indexOf(\".html\");" + NL + 61 " if (pos == -1 || pos != url.length - 5)" + NL + 62 " return false;" + NL + 63 " var allowNumber = false;" + NL + 64 " var allowSep = false;" + NL + 65 " var seenDot = false;" + NL + 66 " for (var i = 0; i < url.length - 5; i++) {" + NL + 67 " var ch = url.charAt(i);" + NL + 68 " if ('a' <= ch && ch <= 'z' ||" + NL + 69 " 'A' <= ch && ch <= 'Z' ||" + NL + 70 " ch == '$' ||" + NL + 71 " ch == '_') {" + NL + 72 " allowNumber = true;" + NL + 73 " allowSep = true;" + NL + 74 " } else if ('0' <= ch && ch <= '9'" + NL + 75 " || ch == '-') {" + NL + 76 " if (!allowNumber)" + NL + 77 " return false;" + NL + 78 " } else if (ch == '/' || ch == '.') {" + NL + 79 " if (!allowSep)" + NL + 80 " return false;" + NL + 81 " allowNumber = false;" + NL + 82 " allowSep = false;" + NL + 83 " if (ch == '.')" + NL + 84 " seenDot = true;" + NL + 85 " if (ch == '/' && seenDot)" + NL + 86 " return false;" + NL + 87 " } else {" + NL + 88 " return false;" + NL + 89 " }" + NL + 90 " }" + NL + 91 " return true;" + NL + 92 " }" + NL + 93 " function loadFrames() {" + NL + 94 " if (targetPage != \"\" && targetPage != \"undefined\")" + NL + 95 " top.classFrame.location = top.targetPage;" + NL + 96 " }" + NL + 97 "</script>"}, 98 99 //Make sure title javascript only runs if is-external is not true 100 {BUG_ID + FS + "pkg" + FS + "C.html", 101 " try {" + NL + 102 " if (location.href.indexOf('is-external=true') == -1) {" + NL + 103 " parent.document.title=\"C\";" + NL + 104 " }" + NL + 105 " }" + NL + 106 " catch(err) {" + NL + 107 " }"}, 108 }; 109 110 private static final String[][] NEGATED_TEST = NO_TEST; 111 112 /** 113 * The entry point of the test. 114 * @param args the array of command line arguments. 115 */ 116 public static void main(String[] args) { 117 TestJavascript tester = new TestJavascript(); 118 run(tester, ARGS, TEST, NEGATED_TEST); 119 tester.printSummary(); 120 } 121 122 /** 123 * {@inheritDoc} 124 */ 125 public String getBugId() { 126 return BUG_ID; 127 } 128 129 /** 130 * {@inheritDoc} 131 */ 132 public String getBugName() { 133 return getClass().getName(); 134 } 135 }