1/* 2 * Copyright (c) 2015, 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 8141492 27 * @summary Test the search feature of javadoc. 28 * @author bpatel 29 * @library ../lib 30 * @modules jdk.javadoc 31 * @build JavadocTester 32 * @run main TestSearch 33 */ 34 35public class TestSearch extends JavadocTester { 36 37 public static void main(String... args) throws Exception { 38 TestSearch tester = new TestSearch(); 39 tester.runTests(); 40 } 41 42 @Test 43 void test1() { 44 javadoc("-d", "out-1", "-sourcepath", "-use", testSrc("UnnamedPkgClass.java")); 45 checkExit(Exit.OK); 46 checkSearchOutput("UnnamedPkgClass.html", true); 47 checkJqueryAndImageFiles(true); 48 checkFiles(false, 49 "package-search-index.zip", 50 "tag-search-index.zip"); 51 checkFiles(true, 52 "member-search-index.zip", 53 "type-search-index.zip"); 54 } 55 56 @Test 57 void test2() { 58 javadoc("-d", "out-2", "-Xdoclint:none", "-sourcepath", testSrc, 59 "-use", "pkg", "pkg1", "pkg2", "pkg3"); 60 checkExit(Exit.OK); 61 checkInvalidUsageIndexTag(); 62 checkSearchOutput(true); 63 checkSingleIndex(true); 64 checkJqueryAndImageFiles(true); 65 checkFiles(true, 66 "member-search-index.zip", 67 "package-search-index.zip", 68 "tag-search-index.zip", 69 "type-search-index.zip"); 70 } 71 72 @Test 73 void test3() { 74 javadoc("-d", "out-3", "-noindex", "-Xdoclint:none", 75 "-sourcepath", testSrc, 76 "-use", "pkg", "pkg1", "pkg2", "pkg3"); 77 checkExit(Exit.OK); 78 checkSearchOutput(false); 79 checkJqueryAndImageFiles(false); 80 checkFiles(false, 81 "member-search-index.zip", 82 "package-search-index.zip", 83 "tag-search-index.zip", 84 "type-search-index.zip", 85 "index-all.html"); 86 } 87 88 @Test 89 void test4() { 90 javadoc("-d", "out-4", "-html5", "-Xdoclint:none", 91 "-sourcepath", testSrc, 92 "-use", "pkg", "pkg1", "pkg2", "pkg3"); 93 checkExit(Exit.OK); 94 checkSearchOutput(true); 95 checkSingleIndex(true); 96 checkJqueryAndImageFiles(true); 97 checkFiles(true, 98 "member-search-index.zip", 99 "package-search-index.zip", 100 "tag-search-index.zip", 101 "type-search-index.zip"); 102 } 103 104 @Test 105 void test5() { 106 javadoc("-d", "out-5", "-noindex", "-html5", "-Xdoclint:none", 107 "-sourcepath", testSrc, 108 "-use", "pkg", "pkg1", "pkg2", "pkg3"); 109 checkExit(Exit.OK); 110 checkSearchOutput(false); 111 checkJqueryAndImageFiles(false); 112 checkFiles(false, 113 "member-search-index.zip", 114 "package-search-index.zip", 115 "tag-search-index.zip", 116 "type-search-index.zip", 117 "index-all.html"); 118 } 119 120 @Test 121 void test6() { 122 javadoc("-d", "out-6", "-nocomment", "-Xdoclint:none", 123 "-sourcepath", testSrc, 124 "-use", "pkg", "pkg1", "pkg2", "pkg3"); 125 checkExit(Exit.OK); 126 checkSearchOutput(true); 127 checkIndexNoComment(); 128 checkJqueryAndImageFiles(true); 129 checkFiles(true, 130 "member-search-index.zip", 131 "package-search-index.zip", 132 "tag-search-index.zip", 133 "type-search-index.zip"); 134 } 135 136 @Test 137 void test7() { 138 javadoc("-d", "out-7", "-nodeprecated", "-Xdoclint:none", 139 "-sourcepath", testSrc, 140 "-use", "pkg", "pkg1", "pkg2", "pkg3"); 141 checkExit(Exit.OK); 142 checkSearchOutput(true); 143 checkIndexNoDeprecated(); 144 checkJqueryAndImageFiles(true); 145 checkFiles(true, 146 "member-search-index.zip", 147 "package-search-index.zip", 148 "tag-search-index.zip", 149 "type-search-index.zip"); 150 } 151 152 @Test 153 void test8() { 154 javadoc("-d", "out-8", "-splitindex", "-Xdoclint:none", "-sourcepath", testSrc, 155 "-use", "pkg", "pkg1", "pkg2", "pkg3"); 156 checkExit(Exit.OK); 157 checkInvalidUsageIndexTag(); 158 checkSearchOutput(true); 159 checkSplitIndex(); 160 checkJqueryAndImageFiles(true); 161 checkFiles(true, 162 "member-search-index.zip", 163 "package-search-index.zip", 164 "tag-search-index.zip", 165 "type-search-index.zip"); 166 } 167 168 @Test 169 void test9() { 170 javadoc("-d", "out-9", "-sourcepath", testSrc, "-javafx", "-package", 171 "-use", "pkgfx", "pkg3"); 172 checkExit(Exit.OK); 173 checkSearchOutput(true); 174 checkJavaFXOutput(); 175 checkJqueryAndImageFiles(true); 176 checkFiles(false, 177 "tag-search-index.zip"); 178 checkFiles(true, 179 "member-search-index.zip", 180 "package-search-index.zip", 181 "type-search-index.zip"); 182 } 183 184 void checkSearchOutput(boolean expectedOutput) { 185 checkSearchOutput("overview-summary.html", expectedOutput); 186 } 187 188 void checkSearchOutput(String fileName, boolean expectedOutput) { 189 // Test for search related markup 190 checkOutput(fileName, expectedOutput, 191 "<link rel=\"stylesheet\" type=\"text/css\" href=\"jquery/jquery-ui.css\" title=\"Style\">\n", 192 "<script type=\"text/javascript\" src=\"jquery/jszip/dist/jszip.min.js\"></script>\n", 193 "<script type=\"text/javascript\" src=\"jquery/jszip-utils/dist/jszip-utils.min.js\"></script>\n", 194 "<!--[if IE]>\n", 195 "<script type=\"text/javascript\" src=\"jquery/jszip-utils/dist/jszip-utils-ie.min.js\"></script>\n", 196 "<![endif]-->\n", 197 "<script type=\"text/javascript\" src=\"jquery/jquery-1.10.2.js\"></script>\n", 198 "<script type=\"text/javascript\" src=\"jquery/jquery-ui.js\"></script>", 199 "var pathtoroot = \"./\";loadScripts(document, 'script');", 200 "<ul class=\"navListSearch\">\n", 201 "<li><span>SEARCH: </span>\n", 202 "<input type=\"text\" id=\"search\" value=\" \" disabled=\"disabled\">\n", 203 "<input type=\"reset\" id=\"reset\" value=\" \" disabled=\"disabled\">\n"); 204 checkOutput(fileName, true, 205 "<div class=\"fixedNav\">"); 206 } 207 208 void checkSingleIndex(boolean expectedOutput) { 209 // Test for search tags markup in index file. 210 checkOutput("index-all.html", expectedOutput, 211 "<dt><span class=\"searchTagLink\"><a href=\"pkg/package-summary.html#phrasewithspaces\">" 212 + "phrase with spaces</a></span> - Search tag in pkg</dt>", 213 "<dt><span class=\"searchTagLink\"><a href=\"pkg1/RegClass.html#searchphrase\">" 214 + "search phrase</a></span> - Search tag in pkg1.RegClass</dt>", 215 "<dt><span class=\"searchTagLink\"><a href=\"pkg1/RegClass.html#SearchWordWithDescription\">" 216 + "SearchWordWithDescription</a></span> - Search tag in pkg1.RegClass.CONSTANT_FIELD_1</dt>", 217 "<dt><span class=\"searchTagLink\"><a href=\"pkg2/TestAnnotationType.html#searchphrasewithdescdeprecated\">" 218 + "search phrase with desc deprecated</a></span> - Search tag in pkg2.TestAnnotationType</dt>", 219 "<dt><span class=\"searchTagLink\"><a href=\"pkg2/TestClass.html#SearchTagDeprecatedClass\">" 220 + "SearchTagDeprecatedClass</a></span> - Search tag in pkg2.TestClass</dt>", 221 "<dt><span class=\"searchTagLink\"><a href=\"pkg2/TestEnum.html#searchphrasedeprecated\">" 222 + "search phrase deprecated</a></span> - Search tag in pkg2.TestEnum.ONE</dt>", 223 "<dt><span class=\"searchTagLink\"><a href=\"pkg2/TestEnum.html#searchphrasedeprecated\">" 224 + "search phrase deprecated</a></span> - Search tag in pkg2.TestEnum.ONE</dt>", 225 "<dt><span class=\"searchTagLink\"><a href=\"pkg2/TestError.html#SearchTagDeprecatedMethod\">" 226 + "SearchTagDeprecatedMethod</a></span> - Search tag in pkg2.TestError</dt>", 227 "<dt><span class=\"searchTagLink\"><a href=\"pkg2/TestError.html#SearchTagDeprecatedMethod\">" 228 + "SearchTagDeprecatedMethod</a></span> - Search tag in pkg2.TestError</dt>", 229 "<dt><span class=\"searchTagLink\"><a href=\"pkg/package-summary.html#SingleWord\">" 230 + "SingleWord</a></span> - Search tag in pkg</dt>", 231 "<dt><span class=\"searchTagLink\"><a href=\"pkg/AnotherClass.ModalExclusionType.html" 232 + "#nested%7B@indexnested_tag_test%7D\">nested {@index nested_tag_test}</a></span> - " 233 + "Search tag in pkg.AnotherClass.ModalExclusionType.NO_EXCLUDE</dt>", 234 "<dt><span class=\"searchTagLink\"><a href=\"pkg/AnotherClass.ModalExclusionType.html" 235 + "#html-span-see-/span-\">html <span> see </span></a></span> - Search " 236 + "tag in pkg.AnotherClass.ModalExclusionType.APPLICATION_EXCLUDE</dt>", 237 "<dt><span class=\"searchTagLink\"><a href=\"pkg/AnotherClass.html#quoted\">quoted</a>" 238 + "</span> - Search tag in pkg.AnotherClass.CONSTANT1</dt>"); 239 checkOutput("index-all.html", true, 240 "<div class=\"block\"><span class=\"deprecationComment\">class_test1 passes. Search tag" 241 + " <a id=\"SearchTagDeprecatedClass\">SearchTagDeprecatedClass</a></span></div>", 242 "<div class=\"block\"><span class=\"deprecationComment\">error_test3 passes. Search tag for\n" 243 + " method <a id=\"SearchTagDeprecatedMethod\">SearchTagDeprecatedMethod</a></span></div>"); 244 } 245 246 void checkSplitIndex() { 247 // Test for search tags markup in split index file. 248 checkOutput("index-files/index-12.html", true, 249 "<dt><span class=\"searchTagLink\"><a href=\"../pkg1/RegClass.html#searchphrase\">" 250 + "search phrase</a></span> - Search tag in pkg1.RegClass</dt>", 251 "<dt><span class=\"searchTagLink\"><a href=\"../pkg1/RegClass.html#SearchWordWithDescription\">" 252 + "SearchWordWithDescription</a></span> - Search tag in pkg1.RegClass.CONSTANT_FIELD_1</dt>", 253 "<dt><span class=\"searchTagLink\"><a href=\"../pkg2/TestAnnotationType.html#searchphrasewithdescdeprecated\">" 254 + "search phrase with desc deprecated</a></span> - Search tag in pkg2.TestAnnotationType</dt>", 255 "<dt><span class=\"searchTagLink\"><a href=\"../pkg2/TestClass.html#SearchTagDeprecatedClass\">" 256 + "SearchTagDeprecatedClass</a></span> - Search tag in pkg2.TestClass</dt>", 257 "<dt><span class=\"searchTagLink\"><a href=\"../pkg2/TestEnum.html#searchphrasedeprecated\">" 258 + "search phrase deprecated</a></span> - Search tag in pkg2.TestEnum.ONE</dt>", 259 "<dt><span class=\"searchTagLink\"><a href=\"../pkg2/TestEnum.html#searchphrasedeprecated\">" 260 + "search phrase deprecated</a></span> - Search tag in pkg2.TestEnum.ONE</dt>", 261 "<dt><span class=\"searchTagLink\"><a href=\"../pkg2/TestError.html#SearchTagDeprecatedMethod\">" 262 + "SearchTagDeprecatedMethod</a></span> - Search tag in pkg2.TestError</dt>", 263 "<dt><span class=\"searchTagLink\"><a href=\"../pkg2/TestError.html#SearchTagDeprecatedMethod\">" 264 + "SearchTagDeprecatedMethod</a></span> - Search tag in pkg2.TestError</dt>", 265 "<dt><span class=\"searchTagLink\"><a href=\"../pkg/package-summary.html#SingleWord\">" 266 + "SingleWord</a></span> - Search tag in pkg</dt>"); 267 checkOutput("index-files/index-9.html", true, 268 "<dt><span class=\"searchTagLink\"><a href=\"../pkg/package-summary.html#phrasewithspaces\">" 269 + "phrase with spaces</a></span> - Search tag in pkg</dt>"); 270 checkOutput("index-files/index-8.html", true, 271 "<dt><span class=\"searchTagLink\"><a href=\"../pkg/AnotherClass.ModalExclusionType.html" 272 + "#nested%7B@indexnested_tag_test%7D\">nested {@index nested_tag_test}</a></span> - " 273 + "Search tag in pkg.AnotherClass.ModalExclusionType.NO_EXCLUDE</dt>"); 274 checkOutput("index-files/index-5.html", true, 275 "<dt><span class=\"searchTagLink\"><a href=\"../pkg/AnotherClass.ModalExclusionType.html" 276 + "#html-span-see-/span-\">html <span> see </span></a></span> - Search " 277 + "tag in pkg.AnotherClass.ModalExclusionType.APPLICATION_EXCLUDE</dt>"); 278 checkOutput("index-files/index-10.html", true, 279 "<dt><span class=\"searchTagLink\"><a href=\"../pkg/AnotherClass.html#quoted\">quoted</a>" 280 + "</span> - Search tag in pkg.AnotherClass.CONSTANT1</dt>"); 281 } 282 283 void checkIndexNoComment() { 284 // Test for search tags markup in index file when javadoc is executed with -nocomment. 285 checkOutput("index-all.html", false, 286 "<dt><span class=\"searchTagLink\"><a href=\"pkg/package-summary.html#phrasewithspaces\">" 287 + "phrase with spaces</a></span> - Search tag in pkg</dt>", 288 "<dt><span class=\"searchTagLink\"><a href=\"pkg1/RegClass.html#searchphrase\">" 289 + "search phrase</a></span> - Search tag in pkg1.RegClass</dt>", 290 "<dt><span class=\"searchTagLink\"><a href=\"pkg1/RegClass.html#SearchWordWithDescription\">" 291 + "SearchWordWithDescription</a></span> - Search tag in pkg1.RegClass.CONSTANT_FIELD_1</dt>", 292 "<dt><span class=\"searchTagLink\"><a href=\"pkg2/TestAnnotationType.html#searchphrasewithdescdeprecated\">" 293 + "search phrase with desc deprecated</a></span> - Search tag in pkg2.TestAnnotationType</dt>", 294 "<dt><span class=\"searchTagLink\"><a href=\"pkg2/TestClass.html#SearchTagDeprecatedClass\">" 295 + "SearchTagDeprecatedClass</a></span> - Search tag in pkg2.TestClass</dt>", 296 "<dt><span class=\"searchTagLink\"><a href=\"pkg/package-summary.html#SingleWord\">" 297 + "SingleWord</a></span> - Search tag in pkg</dt>", 298 "<div class=\"block\"><span class=\"deprecationComment\">class_test1 passes. Search tag" 299 + " <a id=\"SearchTagDeprecatedClass\">SearchTagDeprecatedClass</a></span></div>", 300 "<div class=\"block\"><span class=\"deprecationComment\">error_test3 passes. Search tag for\n" 301 + " method <a id=\"SearchTagDeprecatedMethod\">SearchTagDeprecatedMethod</a></span></div>"); 302 checkOutput("index-all.html", true, 303 "<dt><span class=\"searchTagLink\"><a href=\"pkg2/TestEnum.html#searchphrasedeprecated\">" 304 + "search phrase deprecated</a></span> - Search tag in pkg2.TestEnum.ONE</dt>", 305 "<dt><span class=\"searchTagLink\"><a href=\"pkg2/TestError.html#SearchTagDeprecatedMethod\">" 306 + "SearchTagDeprecatedMethod</a></span> - Search tag in pkg2.TestError</dt>"); 307 } 308 309 void checkIndexNoDeprecated() { 310 // Test for search tags markup in index file when javadoc is executed using -nodeprecated. 311 checkOutput("index-all.html", true, 312 "<dt><span class=\"searchTagLink\"><a href=\"pkg/package-summary.html#phrasewithspaces\">" 313 + "phrase with spaces</a></span> - Search tag in pkg</dt>", 314 "<dt><span class=\"searchTagLink\"><a href=\"pkg1/RegClass.html#searchphrase\">" 315 + "search phrase</a></span> - Search tag in pkg1.RegClass</dt>", 316 "<dt><span class=\"searchTagLink\"><a href=\"pkg1/RegClass.html#SearchWordWithDescription\">" 317 + "SearchWordWithDescription</a></span> - Search tag in pkg1.RegClass.CONSTANT_FIELD_1</dt>", 318 "<dt><span class=\"searchTagLink\"><a href=\"pkg/package-summary.html#SingleWord\">" 319 + "SingleWord</a></span> - Search tag in pkg</dt>"); 320 checkOutput("index-all.html", false, 321 "<dt><span class=\"searchTagLink\"><a href=\"pkg2/TestAnnotationType.html#searchphrasewithdescdeprecated\">" 322 + "search phrase with desc deprecated</a></span> - Search tag in pkg2.TestAnnotationType</dt>", 323 "<dt><span class=\"searchTagLink\"><a href=\"pkg2/TestClass.html#SearchTagDeprecatedClass\">" 324 + "SearchTagDeprecatedClass</a></span> - Search tag in pkg2.TestClass</dt>", 325 "<dt><span class=\"searchTagLink\"><a href=\"pkg2/TestEnum.html#searchphrasedeprecated\">" 326 + "search phrase deprecated</a></span> - Search tag in pkg2.TestEnum.ONE</dt>", 327 "<dt><span class=\"searchTagLink\"><a href=\"pkg2/TestError.html#SearchTagDeprecatedMethod\">" 328 + "SearchTagDeprecatedMethod</a></span> - Search tag in pkg2.TestError</dt>", 329 "<div class=\"block\"><span class=\"deprecationComment\">class_test1 passes. Search tag" 330 + " <a id=\"SearchTagDeprecatedClass\">SearchTagDeprecatedClass</a></span></div>", 331 "<div class=\"block\"><span class=\"deprecationComment\">error_test3 passes. Search tag for\n" 332 + " method <a id=\"SearchTagDeprecatedMethod\">SearchTagDeprecatedMethod</a></span></div>"); 333 } 334 335 void checkJavaFXOutput() { 336 checkOutput("index-all.html", false, "test treat as private"); 337 } 338 339 void checkInvalidUsageIndexTag() { 340 checkOutput(Output.WARNING, true, 341 "AnotherClass.java:33: warning - invalid usage of @index tag.", 342 "AnotherClass.java:38: warning - invalid usage of @index tag.", 343 "AnotherClass.java:43: warning - invalid usage of @index tag.", 344 "AnotherClass.java:75: warning - invalid usage of @index tag."); 345 } 346 347 void checkJqueryAndImageFiles(boolean expectedOutput) { 348 checkFiles(expectedOutput, 349 "search.js", 350 "jquery/jquery-1.10.2.js", 351 "jquery/jquery-ui.js", 352 "jquery/jquery-ui.css", 353 "jquery/jquery-ui.min.js", 354 "jquery/jquery-ui.min.css", 355 "jquery/jquery-ui.structure.min.css", 356 "jquery/jquery-ui.structure.css", 357 "jquery/external/jquery/jquery.js", 358 "jquery/jszip/dist/jszip.js", 359 "jquery/jszip/dist/jszip.min.js", 360 "jquery/jszip-utils/dist/jszip-utils.js", 361 "jquery/jszip-utils/dist/jszip-utils.min.js", 362 "jquery/jszip-utils/dist/jszip-utils-ie.js", 363 "jquery/jszip-utils/dist/jszip-utils-ie.min.js", 364 "jquery/images/ui-bg_flat_0_aaaaaa_40x100.png", 365 "jquery/images/ui-icons_454545_256x240.png", 366 "jquery/images/ui-bg_glass_95_fef1ec_1x400.png", 367 "jquery/images/ui-bg_glass_75_dadada_1x400.png", 368 "jquery/images/ui-bg_highlight-soft_75_cccccc_1x100.png", 369 "jquery/images/ui-icons_888888_256x240.png", 370 "jquery/images/ui-icons_2e83ff_256x240.png", 371 "jquery/images/ui-bg_glass_65_ffffff_1x400.png", 372 "jquery/images/ui-icons_cd0a0a_256x240.png", 373 "jquery/images/ui-bg_glass_55_fbf9ee_1x400.png", 374 "jquery/images/ui-icons_222222_256x240.png", 375 "jquery/images/ui-bg_glass_75_e6e6e6_1x400.png", 376 "jquery/images/ui-bg_flat_75_ffffff_40x100.png", 377 "resources/x.png", 378 "resources/glass.png"); 379 } 380} 381