1 /* 2 * Copyright (c) 2003, 2019, 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 4131628 4664607 7025314 8023700 7198273 8025633 8026567 8081854 8150188 8151743 8196027 8182765 27 * 8196200 8196202 8223378 28 * @summary Make sure the Next/Prev Class links iterate through all types. 29 * Make sure the navagation is 2 columns, not 3. 30 * @library /tools/lib ../../lib 31 * @modules jdk.javadoc/jdk.javadoc.internal.tool 32 * @build toolbox.ToolBox javadoc.tester.* 33 * @run main TestNavigation 34 */ 35 36 import java.io.IOException; 37 import java.nio.file.Path; 38 import java.nio.file.Paths; 39 40 import javadoc.tester.JavadocTester; 41 import toolbox.ToolBox; 42 43 public class TestNavigation extends JavadocTester { 44 45 public final ToolBox tb; 46 public static void main(String... args) throws Exception { 47 TestNavigation tester = new TestNavigation(); 48 tester.runTests(m -> new Object[] { Paths.get(m.getName()) }); 49 } 50 51 public TestNavigation() { 52 tb = new ToolBox(); 53 } 54 55 @Test 56 public void test(Path ignore) { 57 javadoc("-d", "out", 58 "-overview", testSrc("overview.html"), 59 "-sourcepath", testSrc, 60 "pkg"); 61 checkExit(Exit.OK); 62 checkSubNav(); 63 64 checkOutput("pkg/A.html", true, 65 "<ul class=\"navList\" title=\"Navigation\">\n" + 66 "<li><a href=\"../index.html\">Overview</a></li>"); 67 68 checkOutput("pkg/C.html", true, 69 "<ul class=\"navList\" title=\"Navigation\">\n" + 70 "<li><a href=\"../index.html\">Overview</a></li>"); 71 72 checkOutput("pkg/E.html", true, 73 "<ul class=\"navList\" title=\"Navigation\">\n" + 74 "<li><a href=\"../index.html\">Overview</a></li>"); 75 76 checkOutput("pkg/I.html", true, 77 // Test for 4664607 78 "<div class=\"skipNav\"><a href=\"#skip.navbar.top\" title=\"Skip navigation links\">Skip navigation links</a></div>\n" 79 + "<a id=\"navbar.top.firstrow\">\n" 80 + "<!-- -->\n" 81 + "</a>", 82 "<li><a href=\"../index.html\">Overview</a></li>"); 83 84 // Remaining tests check for additional padding to offset the fixed navigation bar. 85 checkOutput("pkg/A.html", true, 86 "<!-- ========= END OF TOP NAVBAR ========= -->\n" 87 + "<div class=\"skipNav\"><a id=\"skip.navbar.top\">\n" 88 + "<!-- -->\n" 89 + "</a></div>\n" 90 + "</nav>\n" 91 + "</header>\n" 92 + "<div class=\"flexContent\">\n" 93 + "<main role=\"main\">\n" 94 + "<!-- ======== START OF CLASS DATA ======== -->"); 95 96 checkOutput("pkg/package-summary.html", true, 97 "<!-- ========= END OF TOP NAVBAR ========= -->\n" 98 + "<div class=\"skipNav\"><a id=\"skip.navbar.top\">\n" 99 + "<!-- -->\n" 100 + "</a></div>\n" 101 + "</nav>\n" 102 + "</header>\n" 103 + "<div class=\"flexContent\">\n" 104 + "<main role=\"main\">\n" 105 + "<div class=\"header\">"); 106 } 107 108 // Test for checking additional padding to offset the fixed navigation bar in HTML5. 109 @Test 110 public void test1(Path ignore) { 111 javadoc("-d", "out-1", 112 "-html5", 113 "-sourcepath", testSrc, 114 "pkg"); 115 checkExit(Exit.OK); 116 checkSubNav(); 117 118 checkOutput("pkg/A.html", true, 119 "<!-- ========= END OF TOP NAVBAR ========= -->\n" 120 + "<div class=\"skipNav\"><a id=\"skip.navbar.top\">\n" 121 + "<!-- -->\n" 122 + "</a></div>\n" 123 + "</nav>\n" 124 + "</header>\n" 125 + "<div class=\"flexContent\">\n" 126 + "<main role=\"main\">\n" 127 + "<!-- ======== START OF CLASS DATA ======== -->"); 128 129 checkOutput("pkg/package-summary.html", true, 130 "<!-- ========= END OF TOP NAVBAR ========= -->\n" 131 + "<div class=\"skipNav\"><a id=\"skip.navbar.top\">\n" 132 + "<!-- -->\n" 133 + "</a></div>\n" 134 + "</nav>"); 135 } 136 137 // Test to make sure that no extra padding for nav bar gets generated if -nonavbar is specified. 138 @Test 139 public void test2(Path ignore) { 140 javadoc("-d", "out-2", 141 "-nonavbar", 142 "-sourcepath", testSrc, 143 "pkg"); 144 checkExit(Exit.OK); 145 checkSubNav(); 146 147 checkOutput("pkg/A.html", false, 148 "<!-- ========= END OF TOP NAVBAR ========= -->\n" 149 + "</div>\n" 150 + "<div class=\"skipNav\"><a id=\"skip.navbar.top\">\n" 151 + "<!-- -->\n" 152 + "</a></div>\n" 153 + "</nav>\n" 154 + "</header>\n" 155 + "<!-- ======== START OF CLASS DATA ======== -->"); 156 157 checkOutput("pkg/package-summary.html", false, 158 "<!-- ========= END OF TOP NAVBAR ========= -->\n" 159 + "</div>\n" 160 + "<div class=\"skipNav\"><a id=\"skip.navbar.top\">\n" 161 + "<!-- -->\n" 162 + "</a></div>\n" 163 + "</nav>"); 164 } 165 166 @Test 167 public void test3(Path base) throws IOException { 168 Path src = base.resolve("src"); 169 tb.writeJavaFiles(src, 170 "package pkg1; public class A {\n" 171 + " /**\n" 172 + " * Class with members.\n" 173 + " */\n" 174 + " public static class X {\n" 175 + " /**\n" 176 + " * A ctor\n" 177 + " */\n" 178 + " public X() {\n" 179 + " }\n" 180 + " /**\n" 181 + " * A field\n" 182 + " */\n" 183 + " public int field;\n" 184 + " /**\n" 185 + " * A method\n" 186 + " */\n" 187 + " public void method() {\n" 188 + " }\n" 189 + " /**\n" 190 + " * An inner class\n" 191 + " */\n" 192 + " public static class IC {\n" 193 + " }\n" 194 + " }\n" 195 + " /**\n" 196 + " * Class with all inherited members.\n" 197 + " */\n" 198 + " public static class Y extends X {\n" 199 + " }\n" 200 + "}"); 201 202 tb.writeJavaFiles(src, 203 "package pkg1; public class C {\n" 204 + "}"); 205 206 tb.writeJavaFiles(src, 207 "package pkg1; public interface InterfaceWithNoMembers {\n" 208 + "}"); 209 210 javadoc("-d", "out-3", 211 "-sourcepath", src.toString(), 212 "pkg1"); 213 checkExit(Exit.OK); 214 215 checkOrder("pkg1/A.X.html", 216 "Summary", 217 "<li><a href=\"#nested.class.summary\">Nested</a> | </li>", 218 "<li><a href=\"#field.summary\">Field</a> | </li>", 219 "<li><a href=\"#constructor.summary\">Constr</a> | </li>", 220 "<li><a href=\"#method.summary\">Method</a></li>"); 221 222 checkOrder("pkg1/A.Y.html", 223 "Summary", 224 "<li><a href=\"#nested.class.summary\">Nested</a> | </li>", 225 "<li><a href=\"#field.summary\">Field</a> | </li>", 226 "<li><a href=\"#constructor.summary\">Constr</a> | </li>", 227 "<li><a href=\"#method.summary\">Method</a></li>"); 228 229 checkOrder("pkg1/A.X.IC.html", 230 "Summary", 231 "<li>Nested | </li>", 232 "<li>Field | </li>", 233 "<li><a href=\"#constructor.summary\">Constr</a> | </li>", 234 "<li><a href=\"#method.summary\">Method</a></li>"); 235 236 checkOrder("pkg1/C.html", 237 "Summary", 238 "<li>Nested | </li>", 239 "<li>Field | </li>", 240 "<li><a href=\"#constructor.summary\">Constr</a> | </li>", 241 "<li><a href=\"#method.summary\">Method</a></li>"); 242 243 checkOrder("pkg1/InterfaceWithNoMembers.html", 244 "Summary", 245 "<li>Nested | </li>", 246 "<li>Field | </li>", 247 "<li>Constr | </li>", 248 "<li>Method</li>"); 249 } 250 251 private void checkSubNav() { 252 253 checkOutput("pkg/A.html", false, 254 "All Classes", 255 "<script type=\"text/javascript\"><!--\n" 256 + " allClassesLink = document.getElementById(\"allclasses_navbar_top\");", 257 "<script type=\"text/javascript\"><!--\n" 258 + " allClassesLink = document.getElementById(\"allclasses_navbar_bottom\");"); 259 260 checkOutput("pkg/C.html", false, 261 "All Classes", 262 "<script type=\"text/javascript\"><!--\n" 263 + " allClassesLink = document.getElementById(\"allclasses_navbar_top\");", 264 "<script type=\"text/javascript\"><!--\n" 265 + " allClassesLink = document.getElementById(\"allclasses_navbar_bottom\");"); 266 267 checkOutput("pkg/E.html", false, 268 "All Classes", 269 "<script type=\"text/javascript\"><!--\n" 270 + " allClassesLink = document.getElementById(\"allclasses_navbar_top\");", 271 "<script type=\"text/javascript\"><!--\n" 272 + " allClassesLink = document.getElementById(\"allclasses_navbar_bottom\");"); 273 274 checkOutput("pkg/I.html", false, 275 "All Classes", 276 "<script type=\"text/javascript\"><!--\n" 277 + " allClassesLink = document.getElementById(\"allclasses_navbar_top\");", 278 "<script type=\"text/javascript\"><!--\n" 279 + " allClassesLink = document.getElementById(\"allclasses_navbar_bottom\");"); 280 281 checkOutput("pkg/package-summary.html", false, 282 "All Classes", 283 "<script type=\"text/javascript\"><!--\n" 284 + " allClassesLink = document.getElementById(\"allclasses_navbar_top\");", 285 "<script type=\"text/javascript\"><!--\n" 286 + " allClassesLink = document.getElementById(\"allclasses_navbar_bottom\");"); 287 } 288 }