|
16 | 16 |
|
17 | 17 | import static org.junit.Assert.fail;
|
18 | 18 |
|
| 19 | +import java.net.URL; |
| 20 | + |
19 | 21 | import org.junit.Test;
|
20 | 22 | import org.junit.runner.RunWith;
|
21 | 23 | import org.openqa.selenium.By;
|
@@ -891,4 +893,52 @@ public void ctorBooleanDocumentAll() throws Exception {
|
891 | 893 |
|
892 | 894 | loadPageWithAlerts2(html);
|
893 | 895 | }
|
| 896 | + |
| 897 | + /** |
| 898 | + * @throws Exception if the test fails |
| 899 | + */ |
| 900 | + @Test |
| 901 | + @Alerts("exception") |
| 902 | + public void javaNotAccessable() throws Exception { |
| 903 | + final String html = "<html><head>\n" |
| 904 | + + "<script>\n" |
| 905 | + + "function test() {\n" |
| 906 | + + " try {\n" |
| 907 | + + " alert(java.lang.Math.PI);\n" |
| 908 | + + " } catch (e) { alert('exception'); }\n" |
| 909 | + + "}\n" |
| 910 | + + "</script>\n" |
| 911 | + + "</head>\n" |
| 912 | + + "<body onload='test()'>\n" |
| 913 | + + "</body></html>"; |
| 914 | + |
| 915 | + loadPageWithAlerts2(html); |
| 916 | + } |
| 917 | + |
| 918 | + /** |
| 919 | + * @throws Exception if the test fails |
| 920 | + */ |
| 921 | + @Test |
| 922 | + @Alerts("Received: from worker - exception") |
| 923 | + public void javaNotAccessableFromWorker() throws Exception { |
| 924 | + final String html = "<html><body>\n" |
| 925 | + + "<script async>\n" |
| 926 | + + "try {\n" |
| 927 | + + " var myWorker = new Worker('worker.js');\n" |
| 928 | + + " myWorker.onmessage = function(e) {\n" |
| 929 | + + " alert('Received: ' + e.data);\n" |
| 930 | + + " };\n" |
| 931 | + + "} catch(e) { alert('exception' + e); }\n" |
| 932 | + + "</script></body></html>\n"; |
| 933 | + |
| 934 | + final String workerJs = "var pi = 'from worker';\n" |
| 935 | + + "try {\n" |
| 936 | + + " pi = pi + ' - ' + java.lang.Math.PI\n" |
| 937 | + + "} catch (e) { pi = pi + ' - ' + 'exception'; }\n" |
| 938 | + + "postMessage(pi);\n"; |
| 939 | + |
| 940 | + getMockWebConnection().setResponse(new URL(URL_FIRST, "worker.js"), workerJs); |
| 941 | + |
| 942 | + loadPageWithAlerts2(html, 2000); |
| 943 | + } |
894 | 944 | }
|
0 commit comments