test/langtools/jdk/javadoc/doclet/testSearch/TestSearch.java
changeset 49427 d2fd2581325b
parent 49139 771616d26ca1
child 49879 601277b1d582
--- a/test/langtools/jdk/javadoc/doclet/testSearch/TestSearch.java	Mon Mar 26 17:30:14 2018 -0700
+++ b/test/langtools/jdk/javadoc/doclet/testSearch/TestSearch.java	Mon Mar 26 18:07:24 2018 -0700
@@ -24,7 +24,7 @@
 /*
  * @test
  * @bug 8141492 8071982 8141636 8147890 8166175 8168965 8176794 8175218 8147881
- *      8181622 8182263 8074407 8187521 8198522 8182765
+ *      8181622 8182263 8074407 8187521 8198522 8182765 8199278
  * @summary Test the search feature of javadoc.
  * @author bpatel
  * @library ../lib
@@ -307,14 +307,44 @@
 
     @Test
     void testNoModuleDirectories() {
-        javadoc("-d", "out-noMdlDir", "--no-module-directories", "-Xdoclint:none",
+        javadoc("-d", "out-noMdlDir",
+                "--no-module-directories",
+                "-Xdoclint:none",
                 "-sourcepath", testSrc,
-                "-use", "pkg", "pkg1", "pkg2", "pkg3");
+                "-use",
+                "pkg", "pkg1", "pkg2", "pkg3");
         checkExit(Exit.OK);
         checkSearchOutput(true, false);
         checkSearchJS();
     }
 
+    @Test
+    void testURLEncoding() {
+        javadoc("-d", "out-encode-html5",
+                "--no-module-directories",
+                "-Xdoclint:none",
+                "-sourcepath", testSrc,
+                "-use",
+                "pkg", "pkg1", "pkg2", "pkg3");
+        checkExit(Exit.OK);
+        checkSearchJS();
+        checkSearchIndex(true);
+    }
+
+    @Test
+    void testURLEncoding_html4() {
+        javadoc("-d", "out-encode-html4",
+                "-html4",
+                "--no-module-directories",
+                "-Xdoclint:none",
+                "-sourcepath", testSrc,
+                "-use",
+                "pkg", "pkg1", "pkg2", "pkg3");
+        checkExit(Exit.OK);
+        checkSearchJS();
+        checkSearchIndex(false);
+    }
+
     void checkDocLintErrors() {
         checkOutput(Output.OUT, true,
                 "A sample method. Testing search tag for {@index \"unclosed quote}.",
@@ -327,6 +357,19 @@
         checkSearchOutput("overview-summary.html", expectedOutput, true);
     }
 
+    void checkSearchIndex(boolean expectedOutput) {
+        checkOutput("member-search-index.js", expectedOutput,
+                "{\"p\":\"pkg\",\"c\":\"AnotherClass\",\"l\":\"AnotherClass()\",\"url\":\"%3Cinit%3E()\"}",
+                "{\"p\":\"pkg1\",\"c\":\"RegClass\",\"l\":\"RegClass()\",\"url\":\"%3Cinit%3E()\"}",
+                "{\"p\":\"pkg2\",\"c\":\"TestError\",\"l\":\"TestError()\",\"url\":\"%3Cinit%3E()\"}",
+                "{\"p\":\"pkg\",\"c\":\"AnotherClass\",\"l\":\"method(byte[], int, String)\",\"url\":\"method(byte[],int,java.lang.String)\"}");
+        checkOutput("member-search-index.js", !expectedOutput,
+                "{\"p\":\"pkg\",\"c\":\"AnotherClass\",\"l\":\"method(RegClass)\",\"url\":\"method-pkg1.RegClass-\"}",
+                "{\"p\":\"pkg2\",\"c\":\"TestClass\",\"l\":\"TestClass()\",\"url\":\"TestClass--\"}",
+                "{\"p\":\"pkg\",\"c\":\"TestError\",\"l\":\"TestError()\",\"url\":\"TestError--\"}",
+                "{\"p\":\"pkg\",\"c\":\"AnotherClass\",\"l\":\"method(byte[], int, String)\",\"url\":\"method-byte:A-int-java.lang.String-\"}");
+    }
+
     void checkSearchOutput(boolean expectedOutput, boolean moduleDirectoriesVar) {
         checkSearchOutput("overview-summary.html", expectedOutput, moduleDirectoriesVar);
     }
@@ -594,7 +637,8 @@
                 + "        }\n"
                 + "    }\n"
                 + "    return urlPrefix;\n"
-                + "}");
+                + "}",
+                "url += ui.item.l;");
     }
 
     void checkSingleIndexSearchTagDuplication() {