Index: chrome/test/remoting/http_server/http_server.py |
diff --git a/chrome/test/remoting/http_server/http_server.py b/chrome/test/remoting/http_server/http_server.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..0d4fb5774f902b81a27c836057d47345615810c5 |
--- /dev/null |
+++ b/chrome/test/remoting/http_server/http_server.py |
@@ -0,0 +1,77 @@ |
+import cherrypy |
anandc
2014/03/03 21:10:03
Would the BaseHttpServer module that comes with Py
anandc
2014/03/03 21:36:37
Just noticed that the link doesn't work. This does
chaitali
2014/03/04 19:33:45
Not for our purposes. Its pretty hard to code path
|
+import json |
+import os |
+ |
+ |
anandc
2014/03/03 21:10:03
Please run gpylint on this module. That should ide
chaitali
2014/03/04 19:33:45
Done on most things. It still complains about inva
|
+def http_methods_allowed(methods=['GET', 'HEAD']): |
+ method = cherrypy.request.method.upper() |
+ if method not in methods: |
+ cherrypy.response.headers['Allow'] = ", ".join(methods) |
+ raise cherrypy.HTTPError(405) |
+ |
+cherrypy.tools.allow = cherrypy.Tool('on_start_resource', http_methods_allowed) |
+ |
+class KeyTest(object): |
+ keytest_succeeded = False |
+ keytest_text = None |
+ |
+ @cherrypy.expose |
+ @cherrypy.tools.allow(methods=['POST']) |
+ def test(self, text): |
+ self.keytest_succeeded = True |
+ self.keytest_text = text |
+ |
+ def process(self): |
+ # Build the message that will be conveyed to client |
+ message = {} |
+ message['keypressSucceeded'] = self.keytest_succeeded |
+ message['keypressText'] = self.keytest_text |
+ |
+ # The message is now built so reset state on the server |
+ if self.keytest_succeeded: |
+ self.keytest_succeeded = False |
+ self.keytest_text = None |
+ |
+ return message |
+ |
+ |
+class Root(object): |
+ # Every test has its own class which should be instantiated here |
+ keytest = KeyTest() |
+ |
+ # Every test's class should have a process method that the client polling |
+ # will call when that test is running. |
+ # The method should be registered here with the test name. |
+ TEST_DICT = { |
+ 'keytest': keytest.process |
+ } |
+ |
+ @cherrypy.expose |
+ @cherrypy.tools.allow() |
+ def index(self): |
+ return "Simple HTTP Server for Chromoting Browser Tests!" |
+ |
+ @cherrypy.expose |
+ @cherrypy.tools.allow() |
+ def poll(self, test): |
+ print test |
+ if test not in self.TEST_DICT: |
+ cherrypy.response.status = 500 |
+ return |
+ |
+ cherrypy.response.headers['Content-Type'] = "application/json" |
+ return json.dumps(self.TEST_DICT[test]()) |
+ |
+ |
+app_config = { |
+ '/static':{ |
+ 'tools.staticdir.on': True, |
+ 'tools.staticdir.dir': |
+ os.path.abspath(os.path.dirname(__file__)) |
+ } |
+} |
+cherrypy.tree.mount(Root(), '/', config = app_config) |
+cherrypy.config.update({'server.socket_host': '0.0.0.0', |
+ }) |
+cherrypy.engine.start() |
+cherrypy.engine.block() |