< prev index next >

modules/web/src/test/java/test/javafx/scene/web/MiscellaneousTest.java

Print this page




  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 javafx.scene.web.WebView;
  40 import static org.junit.Assert.assertEquals;
  41 import static org.junit.Assert.assertNotNull;
  42 import static org.junit.Assert.fail;
  43 import org.junit.Test;
  44 import org.w3c.dom.Document;
  45 
  46 public class MiscellaneousTest extends TestBase {
  47 
  48     @Test public void testNoEffectOnFollowRedirects() {
  49         assertEquals("Unexpected HttpURLConnection.getFollowRedirects() result",
  50                 true, HttpURLConnection.getFollowRedirects());
  51         load("test/html/ipsum.html");
  52         assertEquals("Unexpected HttpURLConnection.getFollowRedirects() result",
  53                 true, HttpURLConnection.getFollowRedirects());
  54     }
  55 
  56     @Test public void testRT22458() throws Exception {
  57         final WebEngine webEngine = createWebEngine();


 126              engine.loadContent("<body> <a href=#>hello</a></body>");
 127         });
 128     }
 129 
 130     // JDK-8133775
 131     @Test(expected = IllegalStateException.class) public void testDOMObjectThreadOwnership() {
 132           class IllegalStateExceptionChecker {
 133               public Object resultObject;
 134               public void start() {
 135                  WebEngine engine = new WebEngine();
 136                  // Get DOM object from JavaFX Application Thread.
 137                  resultObject = engine.executeScript("document.createElement('span')");
 138               }
 139            }
 140            IllegalStateExceptionChecker obj = new IllegalStateExceptionChecker();
 141            submit(obj::start);
 142            // Try accessing the resultObject created in JavaFX Application Thread
 143            // from someother thread. It should throw an exception.
 144            obj.resultObject.toString();
 145      }
















 146 
 147     private WebEngine createWebEngine() {
 148         return submit(() -> new WebEngine());
 149     }
 150 }


  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.canvas.Canvas;
  39 import javafx.scene.canvas.GraphicsContext;
  40 import javafx.scene.paint.LinearGradient;
  41 import javafx.scene.web.WebEngine;
  42 import javafx.scene.web.WebView;
  43 import static org.junit.Assert.assertEquals;
  44 import static org.junit.Assert.assertNotNull;
  45 import static org.junit.Assert.fail;
  46 import org.junit.Test;
  47 import org.w3c.dom.Document;
  48 
  49 public class MiscellaneousTest extends TestBase {
  50 
  51     @Test public void testNoEffectOnFollowRedirects() {
  52         assertEquals("Unexpected HttpURLConnection.getFollowRedirects() result",
  53                 true, HttpURLConnection.getFollowRedirects());
  54         load("test/html/ipsum.html");
  55         assertEquals("Unexpected HttpURLConnection.getFollowRedirects() result",
  56                 true, HttpURLConnection.getFollowRedirects());
  57     }
  58 
  59     @Test public void testRT22458() throws Exception {
  60         final WebEngine webEngine = createWebEngine();


 129              engine.loadContent("<body> <a href=#>hello</a></body>");
 130         });
 131     }
 132 
 133     // JDK-8133775
 134     @Test(expected = IllegalStateException.class) public void testDOMObjectThreadOwnership() {
 135           class IllegalStateExceptionChecker {
 136               public Object resultObject;
 137               public void start() {
 138                  WebEngine engine = new WebEngine();
 139                  // Get DOM object from JavaFX Application Thread.
 140                  resultObject = engine.executeScript("document.createElement('span')");
 141               }
 142            }
 143            IllegalStateExceptionChecker obj = new IllegalStateExceptionChecker();
 144            submit(obj::start);
 145            // Try accessing the resultObject created in JavaFX Application Thread
 146            // from someother thread. It should throw an exception.
 147            obj.resultObject.toString();
 148      }
 149 
 150     // JDK-8155903
 151     @Test public void testGCfillWithLinearGradient() {
 152         submit(()->{
 153             Canvas canvas = new Canvas(100, 100);
 154             GraphicsContext gc = canvas.getGraphicsContext2D();
 155             LinearGradient lg = LinearGradient.valueOf(
 156                   "linear-gradient(white 0%, black 1%, red 1%, green 2%,"
 157                 + "yellow 3%, blue 4%, red 5%, red 6%, red 7%, red 8%, red 9%,"
 158                 + "red 10%, green 70%)");
 159             gc.setFill(lg);
 160             gc.fill();
 161             // Force paint
 162             assertNotNull(canvas.snapshot(null, null));
 163         });
 164     }
 165 
 166     private WebEngine createWebEngine() {
 167         return submit(() -> new WebEngine());
 168     }
 169 }
< prev index next >