14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package javafx.scene.web; 27 28 import java.io.File; 29 import static java.lang.String.format; 30 import java.net.HttpURLConnection; 31 import java.util.ArrayList; 32 import java.util.Random; 33 import java.util.concurrent.Callable; 34 import javafx.application.Platform; 35 import javafx.beans.value.ChangeListener; 36 import javafx.beans.value.ObservableValue; 37 import javafx.concurrent.Worker.State; 38 import static org.junit.Assert.assertEquals; 39 import static org.junit.Assert.assertNotNull; 40 import static org.junit.Assert.fail; 41 import org.junit.Test; 42 import org.w3c.dom.Document; 43 44 public class MiscellaneousTest extends TestBase { 45 46 @Test public void testNoEffectOnFollowRedirects() { 47 assertEquals("Unexpected HttpURLConnection.getFollowRedirects() result", 48 true, HttpURLConnection.getFollowRedirects()); 49 load("test/html/ipsum.html"); 50 assertEquals("Unexpected HttpURLConnection.getFollowRedirects() result", 51 true, HttpURLConnection.getFollowRedirects()); 52 } 53 54 @Test public void testRT22458() throws Exception { 55 final WebEngine webEngine = createWebEngine(); 56 Platform.runLater(() -> { 57 webEngine.load(format("file://%d.ajax.googleapis.com/ajax", 58 new Random().nextInt())); 59 }); 60 Thread.sleep(200); 61 long startTime = System.currentTimeMillis(); 62 DummyClass.dummyField++; 92 getEngine().getLoadWorker().stateProperty().addListener(listener); 93 }); 94 String location = new File("src/test/resources/html/RT30835.html") 95 .toURI().toASCIIString().replaceAll("^file:/", "file:///"); 96 load(location); 97 assertEquals(1, records.size()); 98 assertNotNull(records.get(0).document); 99 assertEquals(location, records.get(0).location); 100 } 101 102 @Test public void testRT26306() { 103 loadContent( 104 "<script language='javascript'>\n" + 105 "var s = '0123456789abcdef';\n" + 106 "while (true) {\n" + 107 " alert(s.length);\n" + 108 " s = s + s;\n" + 109 "}\n" + 110 "</script>"); 111 } 112 113 private WebEngine createWebEngine() { 114 return submit(() -> new WebEngine()); 115 } 116 } | 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package javafx.scene.web; 27 28 import java.io.File; 29 import static java.lang.String.format; 30 import java.net.HttpURLConnection; 31 import java.util.ArrayList; 32 import java.util.Random; 33 import java.util.concurrent.Callable; 34 import com.sun.javafx.PlatformUtil; 35 import javafx.application.Platform; 36 import javafx.beans.value.ChangeListener; 37 import javafx.beans.value.ObservableValue; 38 import javafx.concurrent.Worker.State; 39 import static org.junit.Assert.assertEquals; 40 import static org.junit.Assert.assertNotNull; 41 import static org.junit.Assert.assertTrue; 42 import static org.junit.Assert.fail; 43 import static javafx.concurrent.Worker.State.SUCCEEDED; 44 import javafx.event.Event; 45 import javafx.scene.input.Clipboard; 46 import javafx.scene.input.ClipboardContent; 47 import javafx.scene.input.KeyCode; 48 import org.junit.Test; 49 import org.w3c.dom.Document; 50 import org.w3c.dom.html.HTMLInputElement; 51 52 public class MiscellaneousTest extends TestBase { 53 54 @Test public void testNoEffectOnFollowRedirects() { 55 assertEquals("Unexpected HttpURLConnection.getFollowRedirects() result", 56 true, HttpURLConnection.getFollowRedirects()); 57 load("test/html/ipsum.html"); 58 assertEquals("Unexpected HttpURLConnection.getFollowRedirects() result", 59 true, HttpURLConnection.getFollowRedirects()); 60 } 61 62 @Test public void testRT22458() throws Exception { 63 final WebEngine webEngine = createWebEngine(); 64 Platform.runLater(() -> { 65 webEngine.load(format("file://%d.ajax.googleapis.com/ajax", 66 new Random().nextInt())); 67 }); 68 Thread.sleep(200); 69 long startTime = System.currentTimeMillis(); 70 DummyClass.dummyField++; 100 getEngine().getLoadWorker().stateProperty().addListener(listener); 101 }); 102 String location = new File("src/test/resources/html/RT30835.html") 103 .toURI().toASCIIString().replaceAll("^file:/", "file:///"); 104 load(location); 105 assertEquals(1, records.size()); 106 assertNotNull(records.get(0).document); 107 assertEquals(location, records.get(0).location); 108 } 109 110 @Test public void testRT26306() { 111 loadContent( 112 "<script language='javascript'>\n" + 113 "var s = '0123456789abcdef';\n" + 114 "while (true) {\n" + 115 " alert(s.length);\n" + 116 " s = s + s;\n" + 117 "}\n" + 118 "</script>"); 119 } 120 @Test public void testJDK8143894() { 121 loadContent("<!DOCTYPE html><html><body><input id=\"inputText\" value=\"Default text\" autofocus>" + 122 "<input id=\"pasteInputText\"></input><script>var pasteElement=document.getElementById('inputText');" + 123 "pasteElement.onpaste=function myFunction(e){document.getElementById(\"pasteInputText\").value=" + 124 "e.clipboardData.getData('text/plain');}</script></body></html>"); 125 126 assertTrue("Load task completed successfully", getLoadState() == SUCCEEDED); 127 128 submit(() -> { 129 String clipboardData = "Clipboard content"; 130 ClipboardContent content = new ClipboardContent(); 131 content.putString(clipboardData); 132 Clipboard.getSystemClipboard().setContent(content); 133 //paste the ClipboardConent to first inputText input element 134 //from javascript capture this paste and copy to pasteInputtext input element 135 javafx.scene.input.KeyEvent kv = new javafx.scene.input.KeyEvent(null, 136 getView(), // EventTarget 137 javafx.scene.input.KeyEvent.KEY_PRESSED, // eventType 138 "", // Character (unused unless evtType == KEY_TYPED) 139 "", // text 140 KeyCode.V, // KeyCode 141 false, // shiftDown 142 PlatformUtil.isMac() ? false : true, // ctrlDown 143 false, // altDown 144 PlatformUtil.isMac() ? true : false // metaDown 145 ); 146 Event.fireEvent(getView(), kv); 147 148 Document doc = getEngine().getDocument(); 149 HTMLInputElement el = (HTMLInputElement)doc.getElementById("inputText"); 150 assertNotNull("HTMLInputElement Not Null", el); 151 assertEquals("Default value", "Default text", el.getDefaultValue()); 152 assertEquals("Paste value", clipboardData, el.getValue()); 153 154 HTMLInputElement pl = (HTMLInputElement)doc.getElementById("pasteInputText"); 155 assertEquals("Paste value", clipboardData, pl.getValue()); 156 }); 157 } 158 159 private WebEngine createWebEngine() { 160 return submit(() -> new WebEngine()); 161 } 162 163 private State getLoadState() { 164 return submit(() -> getEngine().getLoadWorker().getState()); 165 } 166 } |