X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fthird_party%2Flibaddressinput%2Fsrc%2Fjava%2Ftest%2Fcom%2Fandroid%2Fi18n%2Faddressinput%2FJsonpRequestBuilderTest.java;h=9a40d1a297a30c3627b4b984561331716d0f5522;hb=1afa4dd80ef85af7c90efaea6959db1d92330844;hp=392a68e9c2de740c1311db214da05ed59523e87d;hpb=90762837333c13ccf56f2ad88e4481fc71e8d281;p=platform%2Fframework%2Fweb%2Fcrosswalk.git diff --git a/src/third_party/libaddressinput/src/java/test/com/android/i18n/addressinput/JsonpRequestBuilderTest.java b/src/third_party/libaddressinput/src/java/test/com/android/i18n/addressinput/JsonpRequestBuilderTest.java index 392a68e..9a40d1a 100644 --- a/src/third_party/libaddressinput/src/java/test/com/android/i18n/addressinput/JsonpRequestBuilderTest.java +++ b/src/third_party/libaddressinput/src/java/test/com/android/i18n/addressinput/JsonpRequestBuilderTest.java @@ -27,131 +27,131 @@ import java.net.Socket; import java.net.SocketTimeoutException; public class JsonpRequestBuilderTest extends AsyncTestCase { - private JsonpRequestBuilder builder; - - @Override - public void setUp() { - builder = new JsonpRequestBuilder(); - } - - public void testRequestObject() throws Exception { - delayTestFinish(4000); - builder.setTimeout(2000); - - String url = HttpServer.execute(1000, "{\"id\": \"data\"}"); - - builder.requestObject(url, new AsyncCallback() { - @Override - public void onFailure(Throwable caught) { - fail(caught.toString()); - } - - @Override - public void onSuccess(JsoMap result) { - assertNotNull(result); - assertEquals("data", result.get("id")); - finishTest(); - } - }); - } - - public void testSetTimeout() throws Exception { - delayTestFinish(4000); - builder.setTimeout(1000); - - String url = HttpServer.execute(2000, "Fubar"); - - builder.requestObject(url, new AsyncCallback() { - @Override - public void onFailure(Throwable caught) { - assertNotNull(caught); - assertTrue(caught instanceof SocketTimeoutException); - finishTest(); - } - - @Override - public void onSuccess(JsoMap result) { - fail("The request should have timed out."); - } - }); - } - - public void testUrlEncoding() throws Exception { - delayTestFinish(4000); - builder.setTimeout(2000); - - String urlBase = HttpServer.execute(1000, "{\"id\": \"data\"}"); - String url = urlBase + "address/data/VN/B\u1EAFc K\u1EA1n"; - - builder.requestObject(url, new AsyncCallback() { - @Override - public void onFailure(Throwable caught) { - fail(caught.toString()); - } - - @Override - public void onSuccess(JsoMap result) { - assertNotNull(result); - assertEquals("data", result.get("id")); - finishTest(); - } - }); - } - + private JsonpRequestBuilder builder; + + @Override + public void setUp() { + builder = new JsonpRequestBuilder(); + } + + public void testRequestObject() throws Exception { + delayTestFinish(4000); + builder.setTimeout(2000); + + String url = HttpServer.execute(1000, "{\"id\": \"data\"}"); + + builder.requestObject(url, new AsyncCallback() { + @Override + public void onFailure(Throwable caught) { + fail(caught.toString()); + } + + @Override + public void onSuccess(JsoMap result) { + assertNotNull(result); + assertEquals("data", result.get("id")); + finishTest(); + } + }); + } + + public void testSetTimeout() throws Exception { + delayTestFinish(4000); + builder.setTimeout(1000); + + String url = HttpServer.execute(2000, "Fubar"); + + builder.requestObject(url, new AsyncCallback() { + @Override + public void onFailure(Throwable caught) { + assertNotNull(caught); + assertTrue(caught instanceof SocketTimeoutException); + finishTest(); + } + + @Override + public void onSuccess(JsoMap result) { + fail("The request should have timed out."); + } + }); + } + + public void testUrlEncoding() throws Exception { + delayTestFinish(4000); + builder.setTimeout(2000); + + String urlBase = HttpServer.execute(1000, "{\"id\": \"data\"}"); + String url = urlBase + "address/data/VN/B\u1EAFc K\u1EA1n"; + + builder.requestObject(url, new AsyncCallback() { + @Override + public void onFailure(Throwable caught) { + fail(caught.toString()); + } + + @Override + public void onSuccess(JsoMap result) { + assertNotNull(result); + assertEquals("data", result.get("id")); + finishTest(); + } + }); + } + + /** + * Simple implementation of an HTTP server. + */ + private static class HttpServer extends Thread { /** - * Simple implementation of an HTTP server. + * Start an HTTP server that will serve one request and then terminate. + * + * @param timeoutMillis + * Wait this long before answering a request. + * @param response + * Reply to any request with this response. + * @return The URL to the server. + * @throws IOException */ - private static class HttpServer extends Thread { - /** - * Start an HTTP server that will serve one request and then terminate. - * - * @param timeoutMillis - * Wait this long before answering a request. - * @param response - * Reply to any request with this response. - * @return The URL to the server. - * @throws IOException - */ - public static String execute(long timeoutMillis, String response) throws IOException { - HttpServer server = new HttpServer(timeoutMillis, response); - server.start(); - return "http://localhost:" + server.serverSocket.getLocalPort() + "/"; - } + public static String execute(long timeoutMillis, String response) throws IOException { + HttpServer server = new HttpServer(timeoutMillis, response); + server.start(); + return "http://localhost:" + server.serverSocket.getLocalPort() + "/"; + } - @Override - public void run() { - try { - Socket clientSocket = serverSocket.accept(); - try { - synchronized (this) { - wait(waitMillis); - } - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - InputStream inputStream = clientSocket.getInputStream(); - inputStream.read(new byte[1024]); // Discard input. - OutputStream outputStream = clientSocket.getOutputStream(); - outputStream.write(response); - outputStream.close(); - inputStream.close(); - clientSocket.close(); - serverSocket.close(); - } catch (IOException e) { - throw new RuntimeException(e); - } + @Override + public void run() { + try { + Socket clientSocket = serverSocket.accept(); + try { + synchronized (this) { + wait(waitMillis); + } + } catch (InterruptedException e) { + throw new RuntimeException(e); } + InputStream inputStream = clientSocket.getInputStream(); + inputStream.read(new byte[1024]); // Discard input. + OutputStream outputStream = clientSocket.getOutputStream(); + outputStream.write(response); + outputStream.close(); + inputStream.close(); + clientSocket.close(); + serverSocket.close(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } - private HttpServer(long waitMillis, String response) throws IOException { - this.waitMillis = waitMillis; - this.response = (header + response).getBytes(); - serverSocket = new ServerSocket(0); - } + private HttpServer(long waitMillis, String response) throws IOException { + this.waitMillis = waitMillis; + this.response = (header + response).getBytes(); + serverSocket = new ServerSocket(0); + } - private long waitMillis; - private byte[] response; - private ServerSocket serverSocket; + private long waitMillis; + private byte[] response; + private ServerSocket serverSocket; - private static final String header = "HTTP/1.0 200 OK\nContent-Type: text/plain\n\n"; - } + private static final String header = "HTTP/1.0 200 OK\nContent-Type: text/plain\n\n"; + } }