< prev index next >

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

Print this page


   1 /*
   2  * Copyright (c) 2012, 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 com.sun.javafx.scene.web.Debugger;
  29 import java.util.ArrayList;
  30 import java.util.Arrays;
  31 import java.util.List;

  32 import javafx.util.Callback;
  33 import static org.junit.Assert.assertEquals;
  34 import static org.junit.Assert.fail;
  35 import org.junit.Test;
  36 import org.junit.After;
  37 
  38 public class DebuggerTest extends TestBase {
  39 
  40     @Test
  41     public void testSimpleMessageExchange() {
  42         submit(() -> {
  43             Debugger debugger = getEngine().impl_getDebugger();
  44 
  45             final List<String> callbackMessages = new ArrayList<String>();
  46             debugger.setMessageCallback(message -> {
  47                 callbackMessages.add(message);
  48                 return null;
  49             });
  50             debugger.setEnabled(true);
  51             debugger.sendMessage(q(
  52                     "{'method':'Debugger.pause','id':16}"));
  53             assertEquals(
  54                     Arrays.asList(q("{'result':{},'id':16}")),
  55                     callbackMessages);
  56         });
  57     }
  58 
  59     @Test
  60     public void testEnabledProperty() {
  61         submit(() -> {
  62             Debugger debugger = getEngine().impl_getDebugger();
  63 
  64             assertEquals(false, debugger.isEnabled());
  65 
  66             debugger.setEnabled(true);
  67             assertEquals(true, debugger.isEnabled());
  68 
  69             debugger.setEnabled(false);
  70             assertEquals(false, debugger.isEnabled());
  71 
  72             debugger.setEnabled(true);
  73             debugger.setEnabled(true);
  74             assertEquals(true, debugger.isEnabled());
  75 
  76             debugger.setEnabled(false);
  77             debugger.setEnabled(false);
  78             assertEquals(false, debugger.isEnabled());
  79         });
  80     }
  81 
  82     @Test
  83     public void testMessageCallbackProperty() {
  84         submit(() -> {
  85             Debugger debugger = getEngine().impl_getDebugger();
  86             Callback<String,Void> callback = new Callback<String,Void>() {
  87                 public Void call(String message) {
  88                     return null;
  89                 }
  90             };
  91 
  92             assertEquals(null, debugger.getMessageCallback());
  93 
  94             debugger.setMessageCallback(callback);
  95             assertEquals(callback, debugger.getMessageCallback());
  96 
  97             debugger.setMessageCallback(null);
  98             assertEquals(null, debugger.getMessageCallback());
  99         });
 100     }
 101 
 102     @Test
 103     public void testSendMessageIllegalStateException() {
 104         submit(() -> {
 105             Debugger debugger = getEngine().impl_getDebugger();
 106             try {
 107                 debugger.sendMessage("foo");
 108                 fail("IllegalStateException expected but not thrown");
 109             } catch (IllegalStateException expected) {}
 110         });
 111     }
 112 
 113     @Test
 114     public void testSendMessageNullPointerException() {
 115         submit(() -> {
 116             Debugger debugger = getEngine().impl_getDebugger();
 117             debugger.setEnabled(true);
 118             try {
 119                 debugger.sendMessage(null);
 120                 fail("NullPointerException expected but not thrown");
 121             } catch (NullPointerException expected) {}
 122         });
 123     }
 124 
 125     @Test
 126     public void testThreadCheck() {
 127         Debugger debugger = getEngine().impl_getDebugger();
 128 
 129         try {
 130             debugger.isEnabled();
 131             fail("IllegalStateException expected but not thrown");
 132         } catch (IllegalStateException expected) {}
 133 
 134         try {
 135             debugger.setEnabled(true);
 136             fail("IllegalStateException expected but not thrown");
 137         } catch (IllegalStateException expected) {}
 138 
 139         try {
 140             debugger.sendMessage("foo");
 141             fail("IllegalStateException expected but not thrown");
 142         } catch (IllegalStateException expected) {}
 143 
 144         try {
 145             debugger.getMessageCallback();
 146             fail("IllegalStateException expected but not thrown");
 147         } catch (IllegalStateException expected) {}
 148 
 149         try {
 150             debugger.setMessageCallback(null);
 151             fail("IllegalStateException expected but not thrown");
 152         } catch (IllegalStateException expected) {}
 153     }
 154 
 155     private static String q(String s) {
 156         return s.replace('\'', '\"');
 157     }
 158 
 159     @After
 160     public void disableDebug() {
 161         submit(() -> {
 162             getEngine().impl_getDebugger().setEnabled(false);
 163         });
 164     }
 165 }
   1 /*
   2  * Copyright (c) 2012, 2016, 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 com.sun.javafx.scene.web.Debugger;
  29 import java.util.ArrayList;
  30 import java.util.Arrays;
  31 import java.util.List;
  32 import javafx.scene.web.WebEngineShim;
  33 import javafx.util.Callback;
  34 import static org.junit.Assert.assertEquals;
  35 import static org.junit.Assert.fail;
  36 import org.junit.Test;
  37 import org.junit.After;
  38 
  39 public class DebuggerTest extends TestBase {
  40 
  41     @Test
  42     public void testSimpleMessageExchange() {
  43         submit(() -> {
  44             Debugger debugger = WebEngineShim.getDebugger(getEngine());
  45 
  46             final List<String> callbackMessages = new ArrayList<String>();
  47             debugger.setMessageCallback(message -> {
  48                 callbackMessages.add(message);
  49                 return null;
  50             });
  51             debugger.setEnabled(true);
  52             debugger.sendMessage(q(
  53                     "{'method':'Debugger.pause','id':16}"));
  54             assertEquals(
  55                     Arrays.asList(q("{'result':{},'id':16}")),
  56                     callbackMessages);
  57         });
  58     }
  59 
  60     @Test
  61     public void testEnabledProperty() {
  62         submit(() -> {
  63             Debugger debugger = WebEngineShim.getDebugger(getEngine());
  64 
  65             assertEquals(false, debugger.isEnabled());
  66 
  67             debugger.setEnabled(true);
  68             assertEquals(true, debugger.isEnabled());
  69 
  70             debugger.setEnabled(false);
  71             assertEquals(false, debugger.isEnabled());
  72 
  73             debugger.setEnabled(true);
  74             debugger.setEnabled(true);
  75             assertEquals(true, debugger.isEnabled());
  76 
  77             debugger.setEnabled(false);
  78             debugger.setEnabled(false);
  79             assertEquals(false, debugger.isEnabled());
  80         });
  81     }
  82 
  83     @Test
  84     public void testMessageCallbackProperty() {
  85         submit(() -> {
  86             Debugger debugger = WebEngineShim.getDebugger(getEngine());
  87             Callback<String,Void> callback = new Callback<String,Void>() {
  88                 public Void call(String message) {
  89                     return null;
  90                 }
  91             };
  92 
  93             assertEquals(null, debugger.getMessageCallback());
  94 
  95             debugger.setMessageCallback(callback);
  96             assertEquals(callback, debugger.getMessageCallback());
  97 
  98             debugger.setMessageCallback(null);
  99             assertEquals(null, debugger.getMessageCallback());
 100         });
 101     }
 102 
 103     @Test
 104     public void testSendMessageIllegalStateException() {
 105         submit(() -> {
 106             Debugger debugger = WebEngineShim.getDebugger(getEngine());
 107             try {
 108                 debugger.sendMessage("foo");
 109                 fail("IllegalStateException expected but not thrown");
 110             } catch (IllegalStateException expected) {}
 111         });
 112     }
 113 
 114     @Test
 115     public void testSendMessageNullPointerException() {
 116         submit(() -> {
 117             Debugger debugger = WebEngineShim.getDebugger(getEngine());
 118             debugger.setEnabled(true);
 119             try {
 120                 debugger.sendMessage(null);
 121                 fail("NullPointerException expected but not thrown");
 122             } catch (NullPointerException expected) {}
 123         });
 124     }
 125 
 126     @Test
 127     public void testThreadCheck() {
 128         Debugger debugger = WebEngineShim.getDebugger(getEngine());
 129 
 130         try {
 131             debugger.isEnabled();
 132             fail("IllegalStateException expected but not thrown");
 133         } catch (IllegalStateException expected) {}
 134 
 135         try {
 136             debugger.setEnabled(true);
 137             fail("IllegalStateException expected but not thrown");
 138         } catch (IllegalStateException expected) {}
 139 
 140         try {
 141             debugger.sendMessage("foo");
 142             fail("IllegalStateException expected but not thrown");
 143         } catch (IllegalStateException expected) {}
 144 
 145         try {
 146             debugger.getMessageCallback();
 147             fail("IllegalStateException expected but not thrown");
 148         } catch (IllegalStateException expected) {}
 149 
 150         try {
 151             debugger.setMessageCallback(null);
 152             fail("IllegalStateException expected but not thrown");
 153         } catch (IllegalStateException expected) {}
 154     }
 155 
 156     private static String q(String s) {
 157         return s.replace('\'', '\"');
 158     }
 159 
 160     @After
 161     public void disableDebug() {
 162         submit(() -> {
 163             WebEngineShim.getDebugger(getEngine()).setEnabled(false);
 164         });
 165     }
 166 }
< prev index next >