Mon, 23 Jan 2017 17:03:12 -0800
Merge
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 */
24 /*
25 * @test
26 * @bug 4665566 4855876 7025314 8012375 8015997 8016328 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 */
35 public class TestJavascript extends JavadocTester {
37 //Test information.
38 private static final String BUG_ID = "4665566-4855876-8012375";
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 };
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 " try {" + NL +
61 " url = decodeURIComponent(url);" + NL +
62 " }" + NL +
63 " catch (error) {" + NL +
64 " return false;" + NL +
65 " }" + NL +
66 " var pos = url.indexOf(\".html\");" + NL +
67 " if (pos == -1 || pos != url.length - 5)" + NL +
68 " return false;" + NL +
69 " var allowNumber = false;" + NL +
70 " var allowSep = false;" + NL +
71 " var seenDot = false;" + NL +
72 " for (var i = 0; i < url.length - 5; i++) {" + NL +
73 " var ch = url.charAt(i);" + NL +
74 " if ('a' <= ch && ch <= 'z' ||" + NL +
75 " 'A' <= ch && ch <= 'Z' ||" + NL +
76 " ch == '$' ||" + NL +
77 " ch == '_' ||" + NL +
78 " ch.charCodeAt(0) > 127) {" + NL +
79 " allowNumber = true;" + NL +
80 " allowSep = true;" + NL +
81 " } else if ('0' <= ch && ch <= '9'" + NL +
82 " || ch == '-') {" + NL +
83 " if (!allowNumber)" + NL +
84 " return false;" + NL +
85 " } else if (ch == '/' || ch == '.') {" + NL +
86 " if (!allowSep)" + NL +
87 " return false;" + NL +
88 " allowNumber = false;" + NL +
89 " allowSep = false;" + NL +
90 " if (ch == '.')" + NL +
91 " seenDot = true;" + NL +
92 " if (ch == '/' && seenDot)" + NL +
93 " return false;" + NL +
94 " } else {" + NL +
95 " return false;" + NL +
96 " }" + NL +
97 " }" + NL +
98 " return true;" + NL +
99 " }" + NL +
100 " function loadFrames() {" + NL +
101 " if (targetPage != \"\" && targetPage != \"undefined\")" + NL +
102 " top.classFrame.location = top.targetPage;" + NL +
103 " }" + NL +
104 "</script>"},
106 //Make sure title javascript only runs if is-external is not true
107 {BUG_ID + FS + "pkg" + FS + "C.html",
108 " try {" + NL +
109 " if (location.href.indexOf('is-external=true') == -1) {" + NL +
110 " parent.document.title=\"C\";" + NL +
111 " }" + NL +
112 " }" + NL +
113 " catch(err) {" + NL +
114 " }"},
115 };
117 private static final String[][] NEGATED_TEST = NO_TEST;
119 /**
120 * The entry point of the test.
121 * @param args the array of command line arguments.
122 */
123 public static void main(String[] args) {
124 TestJavascript tester = new TestJavascript();
125 run(tester, ARGS, TEST, NEGATED_TEST);
126 tester.printSummary();
127 }
129 /**
130 * {@inheritDoc}
131 */
132 public String getBugId() {
133 return BUG_ID;
134 }
136 /**
137 * {@inheritDoc}
138 */
139 public String getBugName() {
140 return getClass().getName();
141 }
142 }