1# Copyright (c) 2015 The Chromium Authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4import json 5import os 6import unittest 7 8 9from catapult_build import dev_server 10from tracing_build import tracing_dev_server_config 11import webapp2 12 13class DevServerTests(unittest.TestCase): 14 15 def setUp(self): 16 self.pds = [ 17 tracing_dev_server_config.TracingDevServerConfig(), 18 ] 19 20 self.args = dev_server._AddCommandLineArguments(self.pds, []) 21 22 def testStaticDirectoryHandling(self): 23 app = dev_server.DevServerApp(self.pds, self.args) 24 request = webapp2.Request.blank('/tracing/tests.html') 25 response = request.get_response(app) 26 27 self.assertEqual(response.status_int, 200) 28 29 def testGetURLForAbsFilename(self): 30 app = dev_server.DevServerApp(self.pds, self.args) 31 class FakeServer(object): 32 pass 33 app.server = FakeServer() 34 35 cfg = tracing_dev_server_config.TracingDevServerConfig() 36 base_html_filename = os.path.join(cfg.project.tracing_src_path, 37 'base', 'base.html') 38 url = app.GetURLForAbsFilename(base_html_filename) 39 self.assertEqual(url, '/tracing/base/base.html') 40 41 url = app.GetURLForAbsFilename('/tmp/foo') 42 self.assertIsNone(url) 43 44 def testGetAbsFilenameForHref(self): 45 app = dev_server.DevServerApp(self.pds, self.args) 46 47 cfg = tracing_dev_server_config.TracingDevServerConfig() 48 base_html_filename = os.path.join(cfg.project.tracing_src_path, 49 'base', 'base.html') 50 51 filename = app.GetAbsFilenameForHref('/tracing/base/base.html') 52 self.assertEqual(base_html_filename, filename) 53 54 filename = app.GetAbsFilenameForHref('/etc/passwd') 55 self.assertIsNone(filename) 56 57 def testTestDataDirectory(self): 58 app = dev_server.DevServerApp(self.pds, self.args) 59 request = webapp2.Request.blank('/tracing/test_data/trivial_trace.json') 60 response = request.get_response(app) 61 62 self.assertEqual(response.status_int, 200) 63 64 def testTestDataDirectoryListing(self): 65 app = dev_server.DevServerApp(self.pds, self.args) 66 request = webapp2.Request.blank('/tracing/test_data/__file_list__') 67 response = request.get_response(app) 68 69 self.assertEqual(response.status_int, 200) 70 res = json.loads(response.body) 71 assert '/tracing/test_data/trivial_trace.json' in res 72 73 def testSkpDataDirectoryListing(self): 74 app = dev_server.DevServerApp(self.pds, self.args) 75 request = webapp2.Request.blank('/tracing/skp_data/__file_list__') 76 response = request.get_response(app) 77 78 self.assertEqual(response.status_int, 200) 79 res = json.loads(response.body) 80 assert '/tracing/skp_data/lthi_cats.skp' in res 81 82 def testTestListingHandler(self): 83 app = dev_server.DevServerApp(self.pds, self.args) 84 request = webapp2.Request.blank('/tracing/tests') 85 response = request.get_response(app) 86 87 self.assertEqual(response.status_int, 200) 88 res = json.loads(response.body) 89 self.assertTrue('test_relpaths' in res) 90 self.assertTrue(len(res['test_relpaths']) > 0) 91