jaroslav@623: /** jaroslav@623: * Back 2 Browser Bytecode Translator jaroslav@623: * Copyright (C) 2012 Jaroslav Tulach jaroslav@623: * jaroslav@623: * This program is free software: you can redistribute it and/or modify jaroslav@623: * it under the terms of the GNU General Public License as published by jaroslav@623: * the Free Software Foundation, version 2 of the License. jaroslav@623: * jaroslav@623: * This program is distributed in the hope that it will be useful, jaroslav@623: * but WITHOUT ANY WARRANTY; without even the implied warranty of jaroslav@623: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the jaroslav@623: * GNU General Public License for more details. jaroslav@623: * jaroslav@623: * You should have received a copy of the GNU General Public License jaroslav@623: * along with this program. Look for COPYING file in the top folder. jaroslav@623: * If not, see http://opensource.org/licenses/GPL-2.0. jaroslav@623: */ jaroslav@623: package org.apidesign.bck2brwsr.tck; jaroslav@623: jaroslav@623: import org.apidesign.bck2brwsr.core.JavaScriptBody; jaroslav@623: import org.apidesign.bck2brwsr.vmtest.BrwsrTest; jaroslav@623: import org.apidesign.bck2brwsr.vmtest.HttpResource; jaroslav@623: import org.apidesign.bck2brwsr.vmtest.VMTest; jaroslav@623: import org.testng.annotations.Factory; jaroslav@623: jaroslav@623: /** jaroslav@623: * jaroslav@623: * @author Jaroslav Tulach jaroslav@623: */ jaroslav@623: public class HttpResourceTest { jaroslav@623: jaroslav@623: @HttpResource(path = "/xhr", content = "Hello Brwsr!", mimeType = "text/plain") jaroslav@623: @BrwsrTest jaroslav@623: public String testReadContentViaXHR() throws Exception { jaroslav@623: String msg = read("/xhr"); jaroslav@623: assert "Hello Brwsr!".equals(msg) : "The message was " + msg; jaroslav@623: return msg; jaroslav@623: } jaroslav@623: jaroslav@623: @JavaScriptBody(args = { "url" }, body = jaroslav@623: "var req = new XMLHttpRequest();\n" jaroslav@623: + "req.open('GET', url, false);\n" jaroslav@623: + "req.send();\n" jaroslav@623: + "return req.responseText;" jaroslav@623: ) jaroslav@623: private static native String read(String url); jaroslav@623: jaroslav@623: jaroslav@623: @Factory jaroslav@623: public static Object[] create() { jaroslav@623: return VMTest.create(HttpResourceTest.class); jaroslav@623: } jaroslav@623: }