1 /*
   2  * Copyright (c) 2009, 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      6786688 8008164 8162363 8169819 8183037 8182765 8184205
  27  * @summary  HTML tables should have table summary, caption and table headers.
  28  * @library  ../../lib
  29  * @modules jdk.javadoc/jdk.javadoc.internal.tool
  30  * @build    javadoc.tester.*
  31  * @run main TestHtmlTableTags
  32  */
  33 
  34 import javadoc.tester.JavadocTester;
  35 
  36 public class TestHtmlTableTags extends JavadocTester {
  37 
  38     //Javadoc arguments.
  39     private static final String[] ARGS = new String[] {
  40 
  41     };
  42 
  43 
  44     public static void main(String... args) throws Exception {
  45         TestHtmlTableTags tester = new TestHtmlTableTags();
  46         tester.runTests();
  47     }
  48 
  49     @Test
  50     public void test() {
  51         javadoc("-d", "out",
  52                 "-sourcepath", testSrc,
  53                 "-use",
  54                 "pkg1", "pkg2");
  55         checkExit(Exit.OK);
  56 
  57         checkHtmlTableTag();
  58         checkHtmlTableCaptions();
  59         checkHtmlTableHeaders();
  60     }
  61 
  62     /*
  63      * Tests for validating table tag for HTML tables
  64      */
  65     void checkHtmlTableTag() {
  66         //Package summary
  67         checkOutput("pkg1/package-summary.html", true,
  68                 "<div class=\"typeSummary\">\n<table>",
  69                 "<div class=\"typeSummary\">\n<table>");
  70 
  71         checkOutput("pkg2/package-summary.html", true,
  72                 "<div class=\"typeSummary\">\n<table>",
  73                 "<div class=\"typeSummary\">\n<table>");
  74 
  75         // Class documentation
  76         checkOutput("pkg1/C1.html", true,
  77                 "<div class=\"memberSummary\">\n<table>",
  78                 "<div class=\"memberSummary\">\n<table>");
  79 
  80         checkOutput("pkg2/C2.html", true,
  81                 "<div class=\"memberSummary\">\n<table>",
  82                 "<div class=\"memberSummary\">\n<table>");
  83 
  84         checkOutput("pkg2/C2.ModalExclusionType.html", true,
  85                 "<div class=\"memberSummary\">\n<table>");
  86 
  87         checkOutput("pkg2/C3.html", true,
  88                 "<div class=\"memberSummary\">\n<table>");
  89 
  90         checkOutput("pkg2/C4.html", true,
  91                 "<div class=\"memberSummary\">\n<table>");
  92 
  93         // Class use documentation
  94         checkOutput("pkg1/class-use/I1.html", true,
  95                 "<div class=\"useSummary\">\n<table>");
  96 
  97         checkOutput("pkg1/class-use/C1.html", true,
  98                 "<div class=\"useSummary\">\n<table>",
  99                 "<div class=\"useSummary\">\n<table>");
 100 
 101         checkOutput("pkg2/class-use/C2.html", true,
 102                 "<div class=\"useSummary\">\n<table>",
 103                 "<div class=\"useSummary\">\n<table>");
 104 
 105         checkOutput("pkg2/class-use/C2.ModalExclusionType.html", true,
 106                 "<div class=\"useSummary\">\n<table>");
 107 
 108         checkOutput("pkg2/class-use/C2.ModalExclusionType.html", true,
 109                 "<div class=\"useSummary\">\n<table>");
 110 
 111         // Package use documentation
 112         checkOutput("pkg1/package-use.html", true,
 113                 "<div class=\"useSummary\">\n<table>",
 114                 "<div class=\"useSummary\">\n<table>");
 115 
 116         checkOutput("pkg2/package-use.html", true,
 117                 "<div class=\"useSummary\">\n<table>",
 118                 "<div class=\"useSummary\">\n<table>");
 119 
 120         // Deprecated
 121         checkOutput("deprecated-list.html", true,
 122                 "<div class=\"deprecatedSummary\" id=\"field\">\n<table>",
 123                 "<div class=\"deprecatedSummary\" id=\"method\">\n<table>");
 124 
 125         // Constant values
 126         checkOutput("constant-values.html", true,
 127                 "<div class=\"constantsSummary\">\n<table>");
 128 
 129         // Overview Summary
 130         checkOutput("index.html", true,
 131                 "<div class=\"overviewSummary\">\n<table>");
 132     }
 133 
 134     /*
 135      * Tests for validating summary for HTML tables
 136      */
 137     void checkHtmlTableSummaries() {
 138         //Package summary
 139         checkOutput("pkg1/package-summary.html", true,
 140                 "<div class=\"typeSummary\">\n"
 141                 + "<table summary=\"Class Summary table, "
 142                 + "listing classes, and an explanation\">",
 143                 "<div class=\"typeSummary\">\n"
 144                 + "<table summary=\"Interface Summary table, "
 145                 + "listing interfaces, and an explanation\">");
 146 
 147         checkOutput("pkg2/package-summary.html", true,
 148                 "<div class=\"typeSummary\">\n"
 149                 + "<table summary=\"Enum Summary table, "
 150                 + "listing enums, and an explanation\">",
 151                 "<div class=\"typeSummary\">\n"
 152                 + "<table summary=\"Annotation Types Summary table, "
 153                 + "listing annotation types, and an explanation\">");
 154 
 155         // Class documentation
 156         checkOutput("pkg1/C1.html", true,
 157                 "<div class=\"memberSummary\">\n"
 158                 + "<table summary=\"Field Summary table, listing fields, "
 159                 + "and an explanation\">",
 160                 "<div class=\"memberSummary\">\n",
 161                 "<table summary=\"Method Summary table, listing methods, "
 162                 + "and an explanation\" aria-labelledby=\"t0\">");
 163 
 164         checkOutput("pkg2/C2.html", true,
 165                 "<div class=\"memberSummary\">\n"
 166                 + "<table summary=\"Nested Class Summary table, listing "
 167                 + "nested classes, and an explanation\">",
 168                 "<div class=\"memberSummary\">\n"
 169                 + "<table summary=\"Constructor Summary table, listing "
 170                 + "constructors, and an explanation\">");
 171 
 172         checkOutput("pkg2/C2.ModalExclusionType.html", true,
 173                 "<div class=\"memberSummary\">\n"
 174                 + "<table summary=\"Enum Constant Summary table, listing "
 175                 + "enum constants, and an explanation\">");
 176 
 177         checkOutput("pkg2/C3.html", true,
 178                 "<div class=\"memberSummary\">\n"
 179                 + "<table summary=\"Required Element Summary table, "
 180                 + "listing required elements, and an explanation\">");
 181 
 182         checkOutput("pkg2/C4.html", true,
 183                 "<div class=\"memberSummary\">\n"
 184                 + "<table summary=\"Optional Element Summary table, "
 185                 + "listing optional elements, and an explanation\">");
 186 
 187         // Class use documentation
 188         checkOutput("pkg1/class-use/I1.html", true,
 189                 "<div class=\"useSummary\">\n"
 190                 + "<table summary=\"Use table, listing packages, and an explanation\">");
 191 
 192         checkOutput("pkg1/class-use/C1.html", true,
 193                 "<div class=\"useSummary\">\n"
 194                 + "<table summary=\"Use table, listing fields, and an explanation\">",
 195                 "<div class=\"useSummary\">\n"
 196                 + "<table summary=\"Use table, listing methods, and an explanation\">");
 197 
 198         checkOutput("pkg2/class-use/C2.html", true,
 199                 "<div class=\"useSummary\">\n"
 200                 + "<table summary=\"Use table, listing fields, and an explanation\">",
 201                 "<div class=\"useSummary\">\n"
 202                 + "<table summary=\"Use table, listing methods, and an explanation\">");
 203 
 204         checkOutput("pkg2/class-use/C2.ModalExclusionType.html", true,
 205                 "<div class=\"useSummary\">\n"
 206                 + "<table summary=\"Use table, listing packages, and an explanation\">");
 207 
 208         checkOutput("pkg2/class-use/C2.ModalExclusionType.html", true,
 209                 "<div class=\"useSummary\">\n"
 210                 + "<table summary=\"Use table, listing methods, and an explanation\">");
 211 
 212         // Package use documentation
 213         checkOutput("pkg1/package-use.html", true,
 214                 "<div class=\"useSummary\">\n"
 215                 + "<table summary=\"Use table, listing packages, and an explanation\">",
 216                 "<div class=\"useSummary\">\n"
 217                 + "<table summary=\"Use table, listing classes, and an explanation\">");
 218 
 219         checkOutput("pkg2/package-use.html", true,
 220                 "<div class=\"useSummary\">\n"
 221                 + "<table summary=\"Use table, listing packages, and an explanation\">",
 222                 "<div class=\"useSummary\">\n"
 223                 + "<table summary=\"Use table, listing classes, and an explanation\">");
 224 
 225         // Deprecated
 226         checkOutput("deprecated-list.html", true,
 227                 "<div class=\"deprecatedSummary\" id=\"field\">\n"
 228                 + "<table summary=\"Fields table, listing fields, "
 229                 + "and an explanation\">",
 230                 "<div class=\"deprecatedSummary\" id=\"method\">\n"
 231                 + "<table summary=\"Methods table, listing methods, "
 232                 + "and an explanation\">");
 233 
 234         // Constant values
 235         checkOutput("constant-values.html", true,
 236                 "<div class=\"constantsSummary\">\n"
 237                 + "<table summary=\"Constant Field Values table, listing "
 238                 + "constant fields, and values\">");
 239 
 240         // Overview Summary
 241         checkOutput("index.html", true,
 242                 "<div class=\"overviewSummary\">\n"
 243                 + "<table summary=\"Package Summary table, listing packages, and an explanation\">");
 244     }
 245 
 246     /*
 247      * Tests for validating caption for HTML tables
 248      */
 249     void checkHtmlTableCaptions() {
 250         //Package summary
 251         checkOutput("pkg1/package-summary.html", true,
 252                 "<caption><span>Class Summary</span><span class=\"tabEnd\">"
 253                 + "&nbsp;</span></caption>",
 254                 "<caption><span>Interface Summary</span><span class=\"tabEnd\">"
 255                 + "&nbsp;</span></caption>");
 256 
 257         checkOutput("pkg2/package-summary.html", true,
 258                 "<caption><span>Enum Summary</span><span class=\"tabEnd\">"
 259                 + "&nbsp;</span></caption>",
 260                 "<caption><span>Annotation Types Summary</span><span class=\"tabEnd\">"
 261                 + "&nbsp;</span></caption>");
 262 
 263         // Class documentation
 264         checkOutput("pkg1/C1.html", true,
 265                 "<caption><span>Fields</span><span class=\"tabEnd\">&nbsp;</span></caption>",
 266                 "<div role=\"tablist\" aria-orientation=\"horizontal\"><button role=\"tab\""
 267                 + " aria-selected=\"true\" aria-controls=\"memberSummary_tabpanel\" tabindex=\"0\""
 268                 + " onkeydown=\"switchTab(event)\" id=\"t0\" class=\"activeTableTab\">All Methods"
 269                 + "</button><button role=\"tab\" aria-selected=\"false\""
 270                 + " aria-controls=\"memberSummary_tabpanel\" tabindex=\"-1\""
 271                 + " onkeydown=\"switchTab(event)\" id=\"t2\" class=\"tableTab\" onclick=\"show(2);\">"
 272                 + "Instance Methods</button><button role=\"tab\" aria-selected=\"false\""
 273                 + " aria-controls=\"memberSummary_tabpanel\" tabindex=\"-1\""
 274                 + " onkeydown=\"switchTab(event)\" id=\"t4\" class=\"tableTab\" onclick=\"show(8);\">"
 275                 + "Concrete Methods</button><button role=\"tab\" aria-selected=\"false\""
 276                 + " aria-controls=\"memberSummary_tabpanel\" tabindex=\"-1\" onkeydown=\"switchTab(event)\""
 277                 + " id=\"t6\" class=\"tableTab\" onclick=\"show(32);\">Deprecated Methods</button></div>\n");
 278 
 279         checkOutput("pkg2/C2.html", true,
 280                 "<caption><span>Nested Classes</span><span class=\"tabEnd\">&nbsp;</span></caption>",
 281                 "<caption><span>Constructors</span><span class=\"tabEnd\">&nbsp;</span></caption>");
 282 
 283         checkOutput("pkg2/C2.ModalExclusionType.html", true,
 284                 "<caption><span>Enum Constants</span><span class=\"tabEnd\">&nbsp;</span></caption>");
 285 
 286         checkOutput("pkg2/C3.html", true,
 287                 "<caption><span>Required Elements</span><span class=\"tabEnd\">&nbsp;"
 288                 + "</span></caption>");
 289 
 290         checkOutput("pkg2/C4.html", true,
 291                 "<caption><span>Optional Elements</span><span class=\"tabEnd\">&nbsp;"
 292                 + "</span></caption>");
 293 
 294         // Class use documentation
 295         checkOutput("pkg1/class-use/I1.html", true,
 296                 "<caption><span>Packages that use <a href=\"../I1.html\" "
 297                 + "title=\"interface in pkg1\">I1</a></span><span class=\"tabEnd\">"
 298                 + "&nbsp;</span></caption>");
 299 
 300         checkOutput("pkg1/class-use/C1.html", true,
 301                 "<caption><span>Fields in <a href=\"../../pkg2/package-summary.html\">"
 302                 + "pkg2</a> declared as <a href=\"../C1.html\" "
 303                 + "title=\"class in pkg1\">C1</a></span><span class=\"tabEnd\">&nbsp;"
 304                 + "</span></caption>",
 305                 "<caption><span>Methods in <a href=\"../../pkg2/package-summary.html\">"
 306                 + "pkg2</a> that return <a href=\"../C1.html\" "
 307                 + "title=\"class in pkg1\">C1</a></span><span class=\"tabEnd\">"
 308                 + "&nbsp;</span></caption>");
 309 
 310         checkOutput("pkg2/class-use/C2.html", true,
 311                 "<caption><span>Fields in <a href=\"../../pkg1/package-summary.html\">"
 312                 + "pkg1</a> declared as <a href=\"../C2.html\" "
 313                 + "title=\"class in pkg2\">C2</a></span><span class=\"tabEnd\">"
 314                 + "&nbsp;</span></caption>",
 315                 "<caption><span>Methods in <a href=\"../../pkg1/package-summary.html\">"
 316                 + "pkg1</a> that return <a href=\"../C2.html\" "
 317                 + "title=\"class in pkg2\">C2</a></span><span class=\"tabEnd\">"
 318                 + "&nbsp;</span></caption>");
 319 
 320         checkOutput("pkg2/class-use/C2.ModalExclusionType.html", true,
 321                 "<caption><span>Methods in <a href=\"../package-summary.html\">"
 322                 + "pkg2</a> that return <a href=\"../C2.ModalExclusionType.html\" "
 323                 + "title=\"enum in pkg2\">C2.ModalExclusionType</a></span>"
 324                 + "<span class=\"tabEnd\">&nbsp;</span></caption>");
 325 
 326         // Package use documentation
 327         checkOutput("pkg1/package-use.html", true,
 328                 "<caption><span>Packages that use <a href=\"package-summary.html\">"
 329                 + "pkg1</a></span><span class=\"tabEnd\">&nbsp;</span></caption>",
 330                 "<caption><span>Classes in <a href=\"package-summary.html\">"
 331                 + "pkg1</a> used by <a href=\"package-summary.html\">pkg1</a>"
 332                 + "</span><span class=\"tabEnd\">&nbsp;</span></caption>");
 333 
 334         checkOutput("pkg2/package-use.html", true,
 335                 "<caption><span>Packages that use <a href=\"package-summary.html\">"
 336                 + "pkg2</a></span><span class=\"tabEnd\">&nbsp;</span></caption>",
 337                 "<caption><span>Classes in <a href=\"package-summary.html\">"
 338                 + "pkg2</a> used by <a href=\"../pkg1/package-summary.html\">pkg1</a>"
 339                 + "</span><span class=\"tabEnd\">&nbsp;</span></caption>");
 340 
 341         // Deprecated
 342         checkOutput("deprecated-list.html", true,
 343                 "<caption><span>Fields</span><span class=\"tabEnd\">"
 344                 + "&nbsp;</span></caption>",
 345                 "<caption><span>Methods</span><span class=\"tabEnd\">"
 346                 + "&nbsp;</span></caption>");
 347 
 348         // Constant values
 349         checkOutput("constant-values.html", true,
 350                 "<caption><span>pkg1.<a href=\"pkg1/C1.html\" title=\"class in pkg1\">"
 351                 + "C1</a></span><span class=\"tabEnd\">&nbsp;</span></caption>");
 352 
 353         // Overview Summary
 354         checkOutput("index.html", true,
 355                 "<caption><span>Packages</span><span class=\"tabEnd\">&nbsp;</span></caption>");
 356     }
 357 
 358     /*
 359      * Test for validating headers for HTML tables
 360      */
 361     void checkHtmlTableHeaders() {
 362         //Package summary
 363         checkOutput("pkg1/package-summary.html", true,
 364                 "<th class=\"colFirst\" scope=\"col\">"
 365                 + "Class</th>\n"
 366                 + "<th class=\"colLast\" scope=\"col\""
 367                 + ">Description</th>",
 368                 "<th class=\"colFirst\" scope=\"col\">"
 369                 + "Interface</th>\n"
 370                 + "<th class=\"colLast\" scope=\"col\""
 371                 + ">Description</th>");
 372 
 373         checkOutput("pkg2/package-summary.html", true,
 374                 "<th class=\"colFirst\" scope=\"col\">"
 375                 + "Enum</th>\n"
 376                 + "<th class=\"colLast\" scope=\"col\""
 377                 + ">Description</th>",
 378                 "<th class=\"colFirst\" scope=\"col\">"
 379                 + "Annotation Type</th>\n"
 380                 + "<th class=\"colLast\""
 381                 + " scope=\"col\">Description</th>");
 382 
 383         // Class documentation
 384         checkOutput("pkg1/C1.html", true,
 385                 "<th class=\"colFirst\" scope=\"col\">Modifier and Type</th>\n"
 386                 + "<th class=\"colSecond\" scope=\"col\">Field</th>\n"
 387                 + "<th class=\"colLast\" scope=\"col\">Description</th>",
 388                 "<th class=\"colFirst\" scope=\"col\">Modifier and Type</th>\n"
 389                 + "<th class=\"colSecond\" scope=\"col\">Method</th>\n"
 390                 + "<th class=\"colLast\" scope=\"col\">Description</th>");
 391 
 392         checkOutput("pkg2/C2.html", true,
 393                 "<th class=\"colFirst\" scope=\"col\">Modifier and Type</th>\n"
 394                 + "<th class=\"colSecond\" scope=\"col\">Class</th>\n"
 395                 + "<th class=\"colLast\" scope=\"col\">Description</th>",
 396                 "<th class=\"colFirst\" scope=\"col\">Constructor</th>\n"
 397                 + "<th class=\"colLast\" scope=\"col\">Description</th>");
 398 
 399         checkOutput("pkg2/C2.ModalExclusionType.html", true,
 400                 "<th class=\"colFirst\" scope=\"col\">Enum Constant</th>\n"
 401                 + "<th class=\"colLast\" scope=\"col\">Description</th>");
 402 
 403         checkOutput("pkg2/C3.html", true,
 404                 "<th class=\"colFirst\" scope=\"col\">Modifier and Type</th>\n"
 405                 + "<th class=\"colSecond\" scope=\"col\">Required Element</th>\n"
 406                 + "<th class=\"colLast\" scope=\"col\">Description</th>");
 407 
 408         checkOutput("pkg2/C4.html", true,
 409                 "<th class=\"colFirst\" scope=\"col\">Modifier and Type</th>\n"
 410                 + "<th class=\"colSecond\" scope=\"col\">Optional Element</th>\n"
 411                 + "<th class=\"colLast\" scope=\"col\">Description</th>");
 412 
 413         // Class use documentation
 414         checkOutput("pkg1/class-use/I1.html", true,
 415                 "<th class=\"colFirst\" scope=\"col\">Package</th>\n"
 416                 + "<th class=\"colLast\" scope=\"col\">Description</th>");
 417 
 418         checkOutput("pkg1/class-use/C1.html", true,
 419                 "<th class=\"colFirst\" scope=\"col\">Modifier and Type</th>\n"
 420                 + "<th class=\"colSecond\" scope=\"col\">Field</th>\n"
 421                 + "<th class=\"colLast\" scope=\"col\">Description</th>",
 422                 "<th class=\"colFirst\" scope=\"col\">Modifier and Type</th>\n"
 423                 + "<th class=\"colSecond\" scope=\"col\">Method</th>\n"
 424                 + "<th class=\"colLast\" scope=\"col\">Description</th>");
 425 
 426         checkOutput("pkg2/class-use/C2.html", true,
 427                 "<th class=\"colFirst\" scope=\"col\">Modifier and Type</th>\n"
 428                 + "<th class=\"colSecond\" scope=\"col\">Field</th>\n"
 429                 + "<th class=\"colLast\" scope=\"col\">Description</th>",
 430                 "<th class=\"colFirst\" scope=\"col\">Modifier and Type</th>\n"
 431                 + "<th class=\"colSecond\" scope=\"col\">Method</th>\n"
 432                 + "<th class=\"colLast\" scope=\"col\">Description</th>");
 433 
 434         checkOutput("pkg2/class-use/C2.ModalExclusionType.html", true,
 435                 "<th class=\"colFirst\" scope=\"col\">Package</th>\n"
 436                 + "<th class=\"colLast\" scope=\"col\">Description</th>",
 437                 "<th class=\"colFirst\" scope=\"col\">Modifier and Type</th>\n"
 438                 + "<th class=\"colSecond\" scope=\"col\">Method</th>\n"
 439                 + "<th class=\"colLast\" scope=\"col\">Description</th>");
 440 
 441         // Package use documentation
 442         checkOutput("pkg1/package-use.html", true,
 443                 "<th class=\"colFirst\" scope=\"col\">Package</th>\n"
 444                 + "<th class=\"colLast\" scope=\"col\">Description</th>",
 445                 "<th class=\"colFirst\" scope=\"col\">Class</th>\n"
 446                 + "<th class=\"colLast\" scope=\"col\">Description</th>");
 447 
 448         checkOutput("pkg2/package-use.html", true,
 449                 "<th class=\"colFirst\" scope=\"col\">Package</th>\n"
 450                 + "<th class=\"colLast\" scope=\"col\">Description</th>",
 451                 "<th class=\"colFirst\" scope=\"col\">Class</th>\n"
 452                 + "<th class=\"colLast\" scope=\"col\">Description</th>");
 453 
 454         // Deprecated
 455         checkOutput("deprecated-list.html", true,
 456                 "<th class=\"colFirst\" scope=\"col\">Field</th>\n"
 457                 + "<th class=\"colLast\" scope=\"col\">Description</th>",
 458                 "<th class=\"colFirst\" scope=\"col\">Method</th>\n"
 459                 + "<th class=\"colLast\" scope=\"col\">Description</th>");
 460 
 461         // Constant values
 462         checkOutput("constant-values.html", true,
 463                 "<th class=\"colFirst\" scope=\"col\">"
 464                 + "Modifier and Type</th>\n"
 465                 + "<th class=\"colSecond\""
 466                 + " scope=\"col\">Constant Field</th>\n"
 467                 + "<th class=\"colLast\" scope=\"col\">Value</th>");
 468 
 469         // Overview Summary
 470         checkOutput("index.html", true,
 471                 "<th class=\"colFirst\" scope=\"col\">"
 472                 + "Package</th>\n"
 473                 + "<th class=\"colLast\" scope=\"col\""
 474                 + ">Description</th>");
 475     }
 476 }