Skip to content

Commit

Permalink
Merge branch 'master' of https://code.google.com/p/js-test-driver
Browse files Browse the repository at this point in the history
Conflicts:
	JsTestDriver/src/com/google/jstestdriver/javascript/plugins/TestRunnerPlugin.js
  • Loading branch information
Cory Smith committed Jun 27, 2013
2 parents 0d1c066 + 2d61dbe commit f9e7fc2
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public void testBrowserPanic() throws Exception {
IMocksControl control = EasyMock.createControl();

HttpServletResponse response = control.createMock(HttpServletResponse.class);
response.setCharacterEncoding("UTF-8");
expect(response.getWriter()).andReturn(writer).anyTimes();
HttpServletRequest request = control.createMock(HttpServletRequest.class);
expect(request.getParameter("listBrowsers")).andReturn(null);
Expand Down
15 changes: 7 additions & 8 deletions JsTestDriver/src/com/google/jstestdriver/HttpServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
Expand All @@ -38,6 +35,7 @@
*/
public class HttpServer implements Server {
private static final Logger logger = LoggerFactory.getLogger(HttpServer.class);
private static final String UTF8_ENCODING = "UTF-8";
private final StopWatch stopWatch;

@Inject
Expand Down Expand Up @@ -94,12 +92,13 @@ public void ping(String url) {

private String toString(InputStream inputStream) throws IOException {
StringBuilder sb = new StringBuilder();
Reader reader = new InputStreamReader(inputStream, UTF8_ENCODING);
int ch;

while ((ch = inputStream.read()) != -1) {
while ((ch = reader.read()) != -1) {
sb.append((char) ch);
}
inputStream.close();
reader.close();
return sb.toString();
}

Expand All @@ -116,9 +115,9 @@ public String post(String url, Map<String, String> params) {
connection.setRequestMethod("POST");
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded; charset=" + UTF8_ENCODING);
connection.setRequestProperty("Content-Length", Integer
.toString(paramsString.getBytes().length));
.toString(paramsString.getBytes(UTF8_ENCODING).length));
OutputStreamWriter oWriter = new OutputStreamWriter(connection.getOutputStream());

oWriter.write(paramsString);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import java.io.ByteArrayInputStream;
import java.io.CharArrayWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.Writer;

/**
Expand All @@ -50,9 +52,32 @@ public FileInfo process(FileInfo file) {
Writer writer = new CharArrayWriter();
parser.parse(
lexer.createStream(
new ByteArrayInputStream(source.getBytes()))).write(writer);
new ByteArrayInputStream(source.getBytes("UTF-8")))).write(writer);
writer.flush();
return file.load(writer.toString(), file.getTimestamp());
return file.load(utf8ToUnicode(writer.toString()), file.getTimestamp());
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}

/**
* Convert a java string which contains UTF-8 characters into a java string
* which has unicode characters. For example, the input string might be
* "á" (0xc3 0xa1). But, this is just the utf-8 form of the unicode string "á".
* So return the latter string
*/
private String utf8ToUnicode(String source) {
try {
byte[] raw = source.getBytes("ISO-8859-1");
Reader hackReader = new InputStreamReader(new ByteArrayInputStream(raw), "UTF-8");
Writer hackWriter = new CharArrayWriter();
int nextChar = hackReader.read();
while (nextChar != -1) {
hackWriter.append((char) nextChar);
nextChar = hackReader.read();
}
return hackWriter.toString();
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException(e);
Expand Down
17 changes: 10 additions & 7 deletions JsTestDriver/src/com/google/jstestdriver/javascript/TestRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,22 @@ jstestdriver.TestRunner.prototype.runNextConfiguration_ = function() {
jstestdriver.TestRunner.prototype.runConfiguration = function(config,
onTestDone,
onComplete) {
if (this.captureConsole_) {
this.overrideConsole_();
var self = this;
if (self.captureConsole_) {
self.overrideConsole_();
}

jstestdriver.log("running configuration " + config);
this.pluginRegistrar_.runTestConfiguration(
config,
onTestDone,
onComplete);

if (this.captureConsole_) {
this.resetConsole_();
}
function() {
if (self.captureConsole_) {
self.resetConsole_();
}
onComplete.apply(this, arguments);
}
);
};


Expand Down
19 changes: 17 additions & 2 deletions JsTestDriver/src/com/google/jstestdriver/javascript/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,21 @@ jstestdriver.createSynchPost = function(jQuery) {
'async' : false,
'data' : data,
'type' : 'POST',
'url' : url
'url' : url,
'contentType': 'application/x-www-form-urlencoded; charset=UTF-8'
});
});
};

jstestdriver.createAsynchPost = function(jQuery) {
return jstestdriver.convertToJson(function(url, data, callback, type) {
return jQuery.ajax({
'data' : data,
'type' : 'POST',
'url' : url,
'success' : callback,
'dataType' : type,
'contentType': 'application/x-www-form-urlencoded; charset=UTF-8'
});
});
};
Expand Down Expand Up @@ -232,7 +246,7 @@ jstestdriver.utils.serializeObjectToArray =
var out = opt_out || out;
if (jstestdriver.utils.isNative(obj, 'Array')) {
out.push('[');
var arr = obj;
var arr = /** @type {Array.<Object>} */ (obj);
for ( var i = 0; i < arr.length; i++) {
jstestdriver.utils.serializeObjectToArray(arr[i], out);
if (i < arr.length - 1) {
Expand Down Expand Up @@ -382,6 +396,7 @@ jstestdriver.utils.toJsonArray = function (buf, obj, pretty, stack) {

// needed for compatibility with the Jasmine plugin.
// TODO(corysmith): Fix that.
jstestdriver.angular = {};
/**
* Serializes an object to Json while elegantly handling recursion.
* @param {Object} obj Object to serialize.
Expand Down
24 changes: 12 additions & 12 deletions JsTestDriver/src/com/google/jstestdriver/javascript/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,17 @@ jstestdriver.config = (function(module) {
stylesheetLoader,
jstestdriver.now);
var testRunnerPlugin =
new jstestdriver.plugins.TestRunnerPlugin(
Date,
function() {
jstestdriver.log(jstestdriver.jQuery('body')[0].innerHTML);
jstestdriver.jQuery('body').children().remove();
jstestdriver.jQuery(document).unbind();
jstestdriver.jQuery(document).die();
},
jstestdriver.pluginRegistrar,
jstestdriver.utils.serializeErrors,
runTestLoop);
new jstestdriver.plugins.TestRunnerPlugin(
Date,
function() {
jstestdriver.log(jstestdriver.jQuery('body')[0].innerHTML);
jstestdriver.jQuery('body').children().remove();
jstestdriver.jQuery(document).unbind();
jstestdriver.jQuery(document).die();
},
jstestdriver.pluginRegistrar,
jstestdriver.utils.serializeErrors,
runTestLoop);

jstestdriver.pluginRegistrar.register(
new jstestdriver.plugins.DefaultPlugin(
Expand Down Expand Up @@ -144,7 +144,7 @@ jstestdriver.config = (function(module) {
var streamingService = new jstestdriver.StreamingService(
url,
now,
jstestdriver.convertToJson(jstestdriver.jQuery.post),
jstestdriver.createAsynchPost(jstestdriver.jQuery),
jstestdriver.createSynchPost(jstestdriver.jQuery),
jstestdriver.setTimeout,
unloadSignal);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ goog.provide('jstestdriver.plugins.TestRunnerPlugin');
* @constructor
*/
jstestdriver.plugins.TestRunnerPlugin = function(dateObj,
clearBody,
pluginRegistrar,
serializeErrors,
opt_runTestLoop) {
clearBody,
pluginRegistrar,
serializeErrors,
opt_runTestLoop) {
this.dateObj_ = dateObj;
this.clearBody_ = clearBody;
this.boundRunTest_ = jstestdriver.bind(this, this.runTest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ jstestdriver.plugins.async.CallbackPoolDelegate.prototype.addErrback = function(
* @param {string=} opt_description The callback description.
* @return {Function} The wrapped callback.
* @export
* @deprecated Use addCallback().
*/
jstestdriver.plugins.async.CallbackPoolDelegate.prototype.add =
jstestdriver.plugins.async.CallbackPoolDelegate.prototype.addCallback;
Expand All @@ -101,6 +102,7 @@ jstestdriver.plugins.async.CallbackPoolDelegate.prototype.add =
* @param {string=} opt_description The description.
* @return {Function} A noop callback.
* @export
* @deprecated Use wait().
*/
jstestdriver.plugins.async.CallbackPoolDelegate.prototype.noop = function(
opt_n, opt_timeout, opt_description) {
Expand All @@ -113,3 +115,12 @@ jstestdriver.plugins.async.CallbackPoolDelegate.prototype.noop = function(
return this.pool_.addCallback(
jstestdriver.EMPTY_FUNC, opt_n, opt_timeout, opt_description);
};


/**
* Adds an empty callback to the queue.
* @return {Function} The callback.
* @export
*/
jstestdriver.plugins.async.CallbackPoolDelegate.prototype.wait =
jstestdriver.plugins.async.CallbackPoolDelegate.prototype.noop;
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public void handleIt() throws IOException {
} else if (request.getParameter("nextBrowserId") != null) {
response.getWriter().write(capturedBrowsers.getUniqueId());
} else {
response.setCharacterEncoding("UTF-8");
streamResponse(request.getParameter("id"), response.getWriter());
}
response.getWriter().flush();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,16 @@ public TestResourceHandler(
@Override
public void handleIt() throws IOException {
String fileName = request.getPathInfo().substring(1); /* remove the first / */
response.setCharacterEncoding("UTF-8");
service(fileName, response.getWriter());
}

public void service(String fileName, PrintWriter writer) throws IOException {
try {
String fileContent = store.getFileContent(fileName);
String mimeType = parseMimeType(fileName);
if (mimeType != null) {
response.setContentType(mimeType);
} else {
response.setHeader("Content-Type", "text/plain");
}
String parsedMimeType = parseMimeType(fileName);
String mimeType = parsedMimeType == null ? "text/plain" : parsedMimeType;
response.setContentType(mimeType);
writer.write(fileContent);
writer.flush();
} catch (FilesCache.MissingFileException e) {
Expand Down

0 comments on commit f9e7fc2

Please sign in to comment.