Fix scripts in Firefox

This commit is contained in:
Alexey Andreev 2015-10-11 11:44:45 +03:00
parent bd61e4edec
commit 44173021f2
7 changed files with 148 additions and 98 deletions

View File

@ -76,6 +76,7 @@
<artifactId>teavm-maven-plugin</artifactId>
<version>${project.version}</version>
<executions>
<!--
<execution>
<id>generate-javascript-tests</id>
<goals>
@ -95,6 +96,7 @@
<incremental>${teavm.test.incremental}</incremental>
</configuration>
</execution>
-->
<execution>
<id>run-javascript-tests</id>
<goals>

View File

@ -209,6 +209,7 @@ public class TeaVMTestTool implements BaseTeaVMTool {
resourceToFile("org/teavm/javascript/runtime.js", "res/runtime.js");
String prefix = "org/teavm/tooling/test";
resourceToFile(prefix + "/res/junit-support.js", "res/junit-support.js");
resourceToFile(prefix + "/res/junit-client.js", "res/junit-client.js");
resourceToFile(prefix + "/res/junit.css", "res/junit.css");
resourceToFile(prefix + "/res/class_obj.png", "res/class_obj.png");
resourceToFile(prefix + "/res/control-000-small.png", "res/control-000-small.png");
@ -219,6 +220,7 @@ public class TeaVMTestTool implements BaseTeaVMTool {
resourceToFile(prefix + "/res/toggle-small-expand.png", "res/toggle-small-expand.png");
resourceToFile(prefix + "/res/toggle-small.png", "res/toggle-small.png");
resourceToFile(prefix + "/junit.html", "junit.html");
resourceToFile(prefix + "/junit-client.html", "junit-client.html");
ClassHolderSource classSource = new ClasspathClassHolderSource(classLoader);
if (incremental) {
classSource = new PreOptimizingClassHolderSource(classSource);

View File

@ -0,0 +1,25 @@
<!--
Copyright 2015 Alexey Andreev.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
</head>
<body>
<script type="text/javascript" src="res/junit-client.js"></script>
<script type="text/javascript" src="res/runtime.js"></script>
</body>
</html>

View File

@ -18,7 +18,6 @@
<head>
<title>TeaVM JUnit tests</title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
<title>TeaVM JUnit tests</title>
<link rel="stylesheet" href="res/junit.css" type="text/css"/>
<script type="text/javascript" src="res/junit-support.js"></script>
<script type="text/javascript" src="tests/all.js"></script>

View File

@ -0,0 +1,95 @@
"use strict";
var JUnitClient = {};
JUnitClient.run = function() {
var handler = function(event) {
switch (event.data.command) {
case "runTest":
window.removeEventListener("message", handler);
$rt_startThread(function() {
JUnitClient.runTest();
});
break;
}
}
window.addEventListener("message", handler);
window.parent.postMessage("ready", "*");
}
JUnitClient.runTest = function() {
var thread = $rt_nativeThread();
var instance;
var ptr = 0;
var message;
if (thread.isResuming()) {
ptr = thread.pop();
instance = thread.pop();
}
loop: while (true) { switch (ptr) {
case 0:
instance = new TestClass();
ptr = 1;
case 1:
try {
initInstance(instance);
} catch (e) {
message = {};
JUnitClient.makeErrorMessage(message, e);
break loop;
}
if (thread.isSuspending()) {
thread.push(instance);
thread.push(ptr);
return;
}
ptr = 2;
case 2:
try {
runTest(instance);
} catch (e) {
message = {};
JUnitClient.makeErrorMessage(message, e);
break loop;
}
if (thread.isSuspending()) {
thread.push(instance);
thread.push(ptr);
return;
}
message = {};
message.status = "ok";
break loop;
}}
window.parent.postMessage(message, "*");
}
JUnitClient.makeErrorMessage = function(message, e) {
message.status = "exception";
var stack = e.stack;
if (e.$javaException && e.$javaException.constructor.$meta) {
message.exception = e.$javaException.constructor.$meta.name;
message.stack = e.$javaException.constructor.$meta.name + ": ";
var exceptionMessage = extractException(e.$javaException);
message.stack += exceptionMessage ? $rt_ustr(exceptionMessage) : "";
}
message.stack += "\n" + stack;
}
JUnitClient.reportError = function(error) {
var handler = function() {
window.removeEventListener("message", handler);
var message = { status : "exception", stack : error };
window.parent.postMessage(message, "*");
};
window.addEventListener("message", handler);
}
JUnitClient.loadScript = function(scriptPath) {
var script = document.createElement("script");
script.src = scriptPath;
document.body.appendChild(script);
}
window.addEventListener("message", function(event) {
var data = event.data;
switch (data.command) {
case "loadScript":
JUnitClient.loadScript(data.script);
break;
}
});
window.parent.postMessage("loaded", "*");

View File

@ -77,34 +77,29 @@ JUnitServer.prototype.isExpectedException = function(ex) {
}
JUnitServer.prototype.loadCode = function(path, additionalScripts, callback) {
this.frame = document.createElement("iframe");
this.frame.src = "junit-client.html";
document.body.appendChild(this.frame);
var frameDoc = this.frame.contentWindow.document;
var self = this;
var sequence = ["res/junit-support.js", "res/runtime.js"];
if (additionalScripts) {
var sequence = [];
sequence.push(path);
for (var i = 0; i < additionalScripts.length; ++i) {
sequence.push(additionalScripts[i]);
}
}
sequence.push(path);
self.loadScripts(sequence, 0, callback);
}
JUnitServer.prototype.loadScripts = function(scripts, index, callback) {
var self = this;
if (index == scripts.length) {
callback();
} else {
this.loadScript(scripts[index], function() { self.loadScripts(scripts, index + 1, callback) });
var handler = function() {
window.removeEventListener("message", handler);
self.loadScripts(sequence, callback);
}
window.addEventListener("message", handler);
}
JUnitServer.prototype.loadScript = function(name, callback) {
var doc = this.frame.contentWindow.document;
var script = doc.createElement("script");
script.src = name;
doc.body.appendChild(script);
script.onload = function() {
JUnitServer.prototype.loadScripts = function(scripts, callback) {
for (var i = 0; i < scripts.length; ++i) {
this.frame.contentWindow.postMessage({ command : "loadScript", "script" : scripts[i] }, "*");
}
var handler = function() {
window.removeEventListener("message", handler);
callback();
}
window.addEventListener("message", handler);
}
JUnitServer.prototype.runTest = function(node, callback) {
node.indicator.className = "complete-indicator in-progress";
@ -118,10 +113,10 @@ JUnitServer.prototype.runTest = function(node, callback) {
window.removeEventListener("message", messageHandler);
var timeSpent = new Date().getTime() - startTime;
node.timeIndicator.appendChild(document.createTextNode("(" + (timeSpent / 1000).toFixed(3) + ")"));
self.handleEvent(JSON.parse(event.data), callback);
self.handleEvent(event.data, callback);
};
window.addEventListener("message", messageHandler);
self.frame.contentWindow.postMessage("runTest", "*");
self.frame.contentWindow.postMessage({ command : "runTest" }, "*");
});
} else {
var self = this;
@ -365,71 +360,3 @@ TreeNode.prototype.select = function() {
this.tree.selectionListeners[i](this);
}
}
var JUnitClient = {};
JUnitClient.run = function() {
var handler = window.addEventListener("message", $rt_threadStarter(function() {
var thread = $rt_nativeThread();
var instance;
var ptr = 0;
var message;
if (thread.isResuming()) {
ptr = thread.pop();
instance = thread.pop();
}
loop: while (true) { switch (ptr) {
case 0:
instance = new TestClass();
ptr = 1;
case 1:
try {
initInstance(instance);
} catch (e) {
message = {};
JUnitClient.makeErrorMessage(message, e);
break loop;
}
if (thread.isSuspending()) {
thread.push(instance);
thread.push(ptr);
return;
}
ptr = 2;
case 2:
try {
runTest(instance);
} catch (e) {
message = {};
JUnitClient.makeErrorMessage(message, e);
break loop;
}
if (thread.isSuspending()) {
thread.push(instance);
thread.push(ptr);
return;
}
message = {};
message.status = "ok";
break loop;
}}
window.parent.postMessage(JSON.stringify(message), "*");
}));
}
JUnitClient.makeErrorMessage = function(message, e) {
message.status = "exception";
var stack = e.stack;
if (e.$javaException && e.$javaException.constructor.$meta) {
message.exception = e.$javaException.constructor.$meta.name;
message.stack = e.$javaException.constructor.$meta.name + ": ";
var exceptionMessage = extractException(e.$javaException);
message.stack += exceptionMessage ? $rt_ustr(exceptionMessage) : "";
}
message.stack += "\n" + stack;
}
JUnitClient.reportError = function(error) {
var handler = window.addEventListener("message", function() {
window.removeEventListener("message", handler);
var message = { status : "exception", stack : error };
window.parent.postMessage(JSON.stringify(message), "*");
});
}

View File

@ -111,12 +111,6 @@ public class RunTestsMojo extends AbstractMojo {
}
}
if (failedTests > 0) {
throw new MojoExecutionException(failedTests + " of " + report.getResults().size() + " test(s) failed");
} else {
getLog().info("All of " + report.getResults().size() + " tests successfully passed");
}
ObjectMapper mapper = new ObjectMapper();
mapper.enable(SerializationFeature.INDENT_OUTPUT);
try (Writer writer = new OutputStreamWriter(new FileOutputStream(reportFile), "UTF-8")) {
@ -124,5 +118,11 @@ public class RunTestsMojo extends AbstractMojo {
} catch (IOException e) {
throw new MojoFailureException("Error writing test report", e);
}
if (failedTests > 0) {
throw new MojoExecutionException(failedTests + " of " + report.getResults().size() + " test(s) failed");
} else {
getLog().info("All of " + report.getResults().size() + " tests successfully passed");
}
}
}