1 /* 2 * Copyright (c) 2011, 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. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 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 test.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 javafx.scene.web.WebEngine; 39 import static org.junit.Assert.assertEquals; 40 import static org.junit.Assert.assertNotNull; 41 import static org.junit.Assert.fail; 42 import org.junit.Test; 43 import org.w3c.dom.Document; 44 45 public class MiscellaneousTest extends TestBase { 46 47 @Test public void testNoEffectOnFollowRedirects() { 48 assertEquals("Unexpected HttpURLConnection.getFollowRedirects() result", 49 true, HttpURLConnection.getFollowRedirects()); 50 load("test/html/ipsum.html"); 51 assertEquals("Unexpected HttpURLConnection.getFollowRedirects() result", 52 true, HttpURLConnection.getFollowRedirects()); 53 } 54 55 @Test public void testRT22458() throws Exception { 56 final WebEngine webEngine = createWebEngine(); 57 Platform.runLater(() -> { 58 webEngine.load(format("file://%d.ajax.googleapis.com/ajax", 59 new Random().nextInt())); 60 }); 61 Thread.sleep(200); 62 long startTime = System.currentTimeMillis(); 63 DummyClass.dummyField++; 64 long time = System.currentTimeMillis() - startTime; 65 if (time > 2000) { 66 fail(format("DummyClass took %f seconds to load", time / 1000.)); 67 } 68 } 69 70 private static final class DummyClass { 71 private static int dummyField; 72 } 73 74 @org.junit.Ignore 75 @Test public void testRT30835() throws Exception { 76 class Record { 77 private final Document document; 78 private final String location; 79 public Record(Document document, String location) { 80 this.document = document; 81 this.location = location; 82 } 83 } 84 final ArrayList<Record> records = new ArrayList<Record>(); 85 ChangeListener<State> listener = (ov, oldValue, newValue) -> { 86 if (newValue == State.SUCCEEDED) { 87 records.add(new Record( 88 getEngine().getDocument(), 89 getEngine().getLocation())); 90 } 91 }; 92 submit(() -> { 93 getEngine().getLoadWorker().stateProperty().addListener(listener); 94 }); 95 String location = new File("src/test/resources/test/html/RT30835.html") 96 .toURI().toASCIIString().replaceAll("^file:/", "file:///"); 97 load(location); 98 assertEquals(1, records.size()); 99 assertNotNull(records.get(0).document); 100 assertEquals(location, records.get(0).location); 101 } 102 103 @Test public void testRT26306() { 104 loadContent( 105 "<script language='javascript'>\n" + 106 "var s = '0123456789abcdef';\n" + 107 "while (true) {\n" + 108 " alert(s.length);\n" + 109 " s = s + s;\n" + 110 "}\n" + 111 "</script>"); 112 } 113 114 private WebEngine createWebEngine() { 115 return submit(() -> new WebEngine()); 116 } 117 }